Personal tools
You are here: Home Developers Corner Java API documentation Comparison between Java and Python API
Document Actions

Comparison between Java and Python API

by Wayne Boucher last modified 2007-12-21 00:07

A (no doubt incomplete) discussion about some of the differences between the Java and Python APIs.

Typing issues

Java is of course typed, so the main difference is that you need to type everything.  In most cases this behaves as you would expect.


There is an issue if we have a function A.getB() and a superclass equivalent superA.getSuperB(), where the corresponding data model link has hicard != 1.  In this case the return type of both functions is Collection<SuperB>.  It is not Collection<B> for A.getB().  This is because Collection<B> is not a subclass of Collection<SuperB>.  (Here Collection is either Set or List, depending on whether the link is unique or not.)


Extra functions

Java has quite a few extra functions in comparison with Python.

(1) toString(), compareTo(), equals() and hashCode()

    See the discussion here.

(2) Extra constructors and "factory" (i.e. the "new") functions, with "required" arguments only.  The default constructor has a dictionary giving a mapping between arbitrary attributes/roles and values.  In Python you can either pass in a dictionary (using the ** syntax) or pass in key/value pairs, and in almost all cases people would do the latter.  In Java you can only do the former, so we have tried to add a pale imitation of the latter.  In Java you can overload functions, fortunately.  Given the generic nature of the problem, we decided to provide one specific extra form, with arguments for each "required" attribute/role that does not have a default value.  This turns out to be a fairly common type of constructor to use.  The arguments are listed in alphabetic order.

[ Technical aside.  The specific arguments are determined by the function requiredInputElements() in scripts_v2/core/ModelPortal.py.  The attribute/role must have locard > 0 (i.e. mandatory) and not be derived or implementation or automatic, and without a default value.  The roles must be crosslinks (i.e. not child or parent). ]

(3) Extra findFirst and findAll functions, which appear for the same reason as given above.  Here the default version has a dictionary passed in, with each key restricting the corresponding attribute to have the corresponding value.  The extra versions allow the key/value pairs to be listed explicitly as arguments, anywhere from 0 to 4 pairs.  So, for example, findFirstXyz(key1, value1, key2, value2, key3, value3).



Powered by Plone, the Open Source Content Management System

This site conforms to the following standards: