From: <pj...@us...> - 2009-05-03 07:37:22
|
Revision: 6288 http://jython.svn.sourceforge.net/jython/?rev=6288&view=rev Author: pjenvey Date: 2009-05-03 07:37:09 +0000 (Sun, 03 May 2009) Log Message: ----------- cleanup/coding standards Modified Paths: -------------- trunk/jython/src/org/python/core/PyBaseString.java trunk/jython/src/org/python/core/PySequence.java trunk/jython/src/org/python/core/PySequenceList.java trunk/jython/src/org/python/core/PyXRange.java trunk/jython/src/org/python/core/io/FileIO.java trunk/jython/src/org/python/core/io/StreamIO.java Modified: trunk/jython/src/org/python/core/PyBaseString.java =================================================================== --- trunk/jython/src/org/python/core/PyBaseString.java 2009-05-03 06:09:20 UTC (rev 6287) +++ trunk/jython/src/org/python/core/PyBaseString.java 2009-05-03 07:37:09 UTC (rev 6288) @@ -10,10 +10,6 @@ public static final PyType TYPE = PyType.fromClass(PyBaseString.class); - public PyBaseString() { - super(); - } - protected PyBaseString(PyType type) { super(type); } Modified: trunk/jython/src/org/python/core/PySequence.java =================================================================== --- trunk/jython/src/org/python/core/PySequence.java 2009-05-03 06:09:20 UTC (rev 6287) +++ trunk/jython/src/org/python/core/PySequence.java 2009-05-03 07:37:09 UTC (rev 6288) @@ -2,8 +2,8 @@ package org.python.core; /** - * The abstract superclass of PyObjects that implements a Sequence. Minimize the work in creating - * such objects. + * The abstract superclass of PyObjects that implements a Sequence. Minimize the work in + * creating such objects. * * Method names are designed to make it possible for subclasses of PySequence to implement * java.util.List. @@ -14,50 +14,41 @@ */ public abstract class PySequence extends PyObject { - public PySequence() {} - protected PySequence(PyType type) { super(type); } // These methods must be defined for any sequence /** - * @param index - * index of element to return. + * @param index index of element to return. * @return the element at the given position in the list. */ - abstract protected PyObject pyget(int index); + protected abstract PyObject pyget(int index); /** * Returns a range of elements from the sequence. * - * @param start - * the position of the first element. - * @param stop - * one more than the position of the last element. - * @param step - * the step size. + * @param start the position of the first element. + * @param stop one more than the position of the last element. + * @param step the step size. * @return a sequence corresponding the the given range of elements. */ - abstract protected PyObject getslice(int start, int stop, int step); + protected abstract PyObject getslice(int start, int stop, int step); /** * Repeats the given sequence. * - * @param count - * the number of times to repeat the sequence. + * @param count the number of times to repeat the sequence. * @return this sequence repeated count times. */ - abstract protected PyObject repeat(int count); + protected abstract PyObject repeat(int count); // These methods only apply to mutable sequences /** * Sets the given element of the sequence. * - * @param index - * index of the element to set. - * @param value - * the value to set this element to. + * @param index index of the element to set. + * @param value the value to set this element to. */ protected void pyset(int index, PyObject value) { throw Py.TypeError("can't assign to immutable object"); @@ -71,7 +62,7 @@ getType().fastGetName())); } - protected void del(int i) throws PyException { + protected void del(int i) { throw Py.TypeError(String.format("'%s' object does not support item deletion", getType().fastGetName())); } @@ -82,6 +73,7 @@ } + @Override public boolean __nonzero__() { return seq___nonzero__(); } @@ -90,6 +82,7 @@ return __len__() != 0; } + @Override public PyObject __iter__() { return seq___iter__(); } @@ -98,166 +91,182 @@ return new PySequenceIter(this); } + @Override public PyObject __eq__(PyObject o) { return seq___eq__(o); } final PyObject seq___eq__(PyObject o) { - if(!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { + if (getType() != o.getType() && !getType().isSubType(o.getType())) { return null; } int tl = __len__(); int ol = o.__len__(); - if(tl != ol) { + if (tl != ol) { return Py.False; } int i = cmp(this, tl, o, ol); - return (i < 0) ? Py.True : Py.False; + return i < 0 ? Py.True : Py.False; } + @Override public PyObject __ne__(PyObject o) { return seq___ne__(o); } final PyObject seq___ne__(PyObject o) { - if(!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { + if (getType() != o.getType() && !getType().isSubType(o.getType())) { return null; } int tl = __len__(); int ol = o.__len__(); - if(tl != ol) { + if (tl != ol) { return Py.True; } int i = cmp(this, tl, o, ol); - return (i < 0) ? Py.False : Py.True; + return i < 0 ? Py.False : Py.True; } + @Override public PyObject __lt__(PyObject o) { return seq___lt__(o); } final PyObject seq___lt__(PyObject o) { - if(!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { + if (getType() != o.getType() && !getType().isSubType(o.getType())) { return null; } int i = cmp(this, -1, o, -1); - if(i < 0) { - return (i == -1) ? Py.True : Py.False; + if (i < 0) { + return i == -1 ? Py.True : Py.False; } return __finditem__(i)._lt(o.__finditem__(i)); } + @Override public PyObject __le__(PyObject o) { return seq___le__(o); } final PyObject seq___le__(PyObject o) { - if(!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { + if (getType() != o.getType() && !getType().isSubType(o.getType())) { return null; } int i = cmp(this, -1, o, -1); - if(i < 0) { - return (i == -1 || i == -2) ? Py.True : Py.False; + if (i < 0) { + return i == -1 || i == -2 ? Py.True : Py.False; } return __finditem__(i)._le(o.__finditem__(i)); } + @Override public PyObject __gt__(PyObject o) { return seq___gt__(o); } final PyObject seq___gt__(PyObject o) { - if(!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { + if (getType() != o.getType() && !getType().isSubType(o.getType())) { return null; } int i = cmp(this, -1, o, -1); - if(i < 0) - return (i == -3) ? Py.True : Py.False; + if (i < 0) { + return i == -3 ? Py.True : Py.False; + } return __finditem__(i)._gt(o.__finditem__(i)); } + @Override public PyObject __ge__(PyObject o) { return seq___ge__(o); } final PyObject seq___ge__(PyObject o) { - if(!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { + if (getType() != o.getType() && !getType().isSubType(o.getType())) { return null; } int i = cmp(this, -1, o, -1); - if(i < 0) { - return (i == -3 || i == -2) ? Py.True : Py.False; + if (i < 0) { + return i == -3 || i == -2 ? Py.True : Py.False; } return __finditem__(i)._ge(o.__finditem__(i)); } - // Return value >= 0 is the index where the sequences differs. - // -1: reached the end of o1 without a difference - // -2: reached the end of both seqeunces without a difference - // -3: reached the end of o2 without a difference + /** + * Compare the specified object/length pairs. + * + * @return value >= 0 is the index where the sequences differs. + * -1: reached the end of o1 without a difference + * -2: reached the end of both seqeunces without a difference + * -3: reached the end of o2 without a difference + */ protected static int cmp(PyObject o1, int ol1, PyObject o2, int ol2) { - if(ol1 < 0) { + if (ol1 < 0) { ol1 = o1.__len__(); } - if(ol2 < 0) { + if (ol2 < 0) { ol2 = o2.__len__(); } - for(int i = 0; i < ol1 && i < ol2; i++) { - if(!o1.__getitem__(i)._eq(o2.__getitem__(i)).__nonzero__()) { + for (int i = 0; i < ol1 && i < ol2; i++) { + if (!o1.__getitem__(i)._eq(o2.__getitem__(i)).__nonzero__()) { return i; } } - if(ol1 == ol2) { + if (ol1 == ol2) { return -2; } - return (ol1 < ol2) ? -1 : -3; + return ol1 < ol2 ? -1 : -3; } - // Return a copy of a sequence where the __len__() method is - // telling the truth. + /** + * Return a copy of a sequence where the __len__() method is telling the truth. + */ protected static PySequence fastSequence(PyObject seq, String msg) { if (seq instanceof PySequence) { return (PySequence)seq; } PyList list = new PyList(); PyObject iter = Py.iter(seq, msg); - for(PyObject item = null; (item = iter.__iternext__()) != null;) { + for (PyObject item = null; (item = iter.__iternext__()) != null;) { list.append(item); } return list; } - // make step a long in case adding the start, stop and step together overflows an int + /** + * Make step a long in case adding the start, stop and step together overflows an int. + */ protected static final int sliceLength(int start, int stop, long step) { int ret; - if(step > 0) { + if (step > 0) { ret = (int)((stop - start + step - 1) / step); } else { ret = (int)((stop - start + step + 1) / step); } - if(ret < 0) { + if (ret < 0) { return 0; } return ret; } /** - * Adjusts <code>index</code> such that it's >= 0 and <= __len__. If <code>index</code> starts - * off negative, it's treated as an index from the end of the sequence going back to the start. + * Adjusts <code>index</code> such that it's >= 0 and <= __len__. If + * <code>index</code> starts off negative, it's treated as an index from the end of + * the sequence going back to the start. */ protected int boundToSequence(int index) { int length = __len__(); - if(index < 0) { + if (index < 0) { index += length; - if(index < 0) { + if (index < 0) { index = 0; } - } else if(index > length) { + } else if (index > length) { index = length; } return index; } + @Override public PyObject __finditem__(int index) { return seq___finditem__(index); } @@ -266,6 +275,7 @@ return delegator.checkIdxAndFindItem(index); } + @Override public PyObject __finditem__(PyObject index) { return seq___finditem__(index); } @@ -274,6 +284,7 @@ return delegator.checkIdxAndFindItem(index); } + @Override public PyObject __getitem__(PyObject index) { return seq___getitem__(index); } @@ -282,14 +293,17 @@ return delegator.checkIdxAndGetItem(index); } + @Override public boolean isMappingType() throws PyIgnoreMethodTag { return false; } + @Override public boolean isNumberType() throws PyIgnoreMethodTag { return false; } + @Override public PyObject __getslice__(PyObject start, PyObject stop, PyObject step) { return seq___getslice__(start, stop, step); } @@ -298,17 +312,12 @@ return delegator.getSlice(new PySlice(start, stop, step)); } - public void __setslice__(PyObject start, - PyObject stop, - PyObject step, - PyObject value) { + @Override + public void __setslice__(PyObject start, PyObject stop, PyObject step, PyObject value) { seq___setslice__(start, stop, step, value); } - final void seq___setslice__(PyObject start, - PyObject stop, - PyObject step, - PyObject value) { + final void seq___setslice__(PyObject start, PyObject stop, PyObject step, PyObject value) { if (value == null) { value = step; step = null; @@ -316,6 +325,7 @@ delegator.checkIdxAndSetSlice(new PySlice(start, stop, step), value); } + @Override public void __delslice__(PyObject start, PyObject stop, PyObject step) { seq___delslice__(start, stop, step); } @@ -324,10 +334,12 @@ delegator.checkIdxAndDelItem(new PySlice(start, stop, step)); } + @Override public void __setitem__(int index, PyObject value) { delegator.checkIdxAndSetItem(index, value); } + @Override public void __setitem__(PyObject index, PyObject value) { seq___setitem__(index, value); } @@ -336,6 +348,7 @@ delegator.checkIdxAndSetItem(index, value); } + @Override public void __delitem__(PyObject index) { seq___delitem__(index); } @@ -344,18 +357,19 @@ delegator.checkIdxAndDelItem(index); } - public synchronized Object __tojava__(Class c) throws PyIgnoreMethodTag { - if(c.isArray()) { - Class component = c.getComponentType(); + @Override + public synchronized Object __tojava__(Class<?> c) throws PyIgnoreMethodTag { + if (c.isArray()) { + Class<?> component = c.getComponentType(); try { int n = __len__(); PyArray array = new PyArray(component, n); - for(int i = 0; i < n; i++) { + for (int i = 0; i < n; i++) { PyObject o = pyget(i); array.set(i, o); } return array.getArray(); - } catch(Throwable t) { + } catch (Throwable t) { // ok } } @@ -367,8 +381,9 @@ * * {0} is the op name. {1} is the left operand type. {2} is the right operand type. */ + @Override protected String unsupportedopMessage(String op, PyObject o2) { - if(op.equals("*")) { + if (op.equals("*")) { return "can''t multiply sequence by non-int of type ''{2}''"; } return null; @@ -379,8 +394,9 @@ * * {0} is the op name. {1} is the left operand type. {2} is the right operand type. */ + @Override protected String runsupportedopMessage(String op, PyObject o2) { - if(op.equals("*")) { + if (op.equals("*")) { return "can''t multiply sequence by non-int of type ''{1}''"; } return null; Modified: trunk/jython/src/org/python/core/PySequenceList.java =================================================================== --- trunk/jython/src/org/python/core/PySequenceList.java 2009-05-03 06:09:20 UTC (rev 6287) +++ trunk/jython/src/org/python/core/PySequenceList.java 2009-05-03 07:37:09 UTC (rev 6288) @@ -7,9 +7,6 @@ public abstract class PySequenceList extends PySequence { - public PySequenceList() { - } - protected PySequenceList(PyType type) { super(type); } Modified: trunk/jython/src/org/python/core/PyXRange.java =================================================================== --- trunk/jython/src/org/python/core/PyXRange.java 2009-05-03 06:09:20 UTC (rev 6287) +++ trunk/jython/src/org/python/core/PyXRange.java 2009-05-03 07:37:09 UTC (rev 6288) @@ -28,6 +28,8 @@ } public PyXRange(int ilow, int ihigh, int istep) { + super(TYPE); + if (istep == 0) { throw Py.ValueError("xrange() arg 3 must not be zero"); } Modified: trunk/jython/src/org/python/core/io/FileIO.java =================================================================== --- trunk/jython/src/org/python/core/io/FileIO.java 2009-05-03 06:09:20 UTC (rev 6287) +++ trunk/jython/src/org/python/core/io/FileIO.java 2009-05-03 07:37:09 UTC (rev 6288) @@ -13,7 +13,6 @@ import java.nio.channels.FileChannel; import com.kenai.constantine.platform.Errno; -import org.python.core.imp; import org.python.core.Py; import org.python.core.util.FileUtil; import org.python.core.util.RelativeFile; @@ -168,8 +167,9 @@ // open("/dev/null", "w") works fine. Because we have // to simulate the "w" mode in Java, we suppress the // exception. - if (ioe.getMessage().equals("Invalid argument")) + if (ioe.getMessage().equals("Invalid argument")) { return; + } throw Py.IOError(ioe); } } Modified: trunk/jython/src/org/python/core/io/StreamIO.java =================================================================== --- trunk/jython/src/org/python/core/io/StreamIO.java 2009-05-03 06:09:20 UTC (rev 6287) +++ trunk/jython/src/org/python/core/io/StreamIO.java 2009-05-03 07:37:09 UTC (rev 6288) @@ -173,8 +173,9 @@ } catch (Exception e) { // XXX: masking other exceptions } finally { - if (inField != null && inField.isAccessible()) + if (inField != null && inField.isAccessible()) { inField.setAccessible(false); + } } } return null; @@ -197,8 +198,9 @@ } catch (Exception e) { // XXX: masking other exceptions } finally { - if (outField != null && outField.isAccessible()) + if (outField != null && outField.isAccessible()) { outField.setAccessible(false); + } } } return null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |