[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-patch-tracker] [patch #9067] java sources part 1
From: |
Ernst Reissner |
Subject: |
[Octave-patch-tracker] [patch #9067] java sources part 1 |
Date: |
Wed, 10 Aug 2016 12:21:14 +0000 (UTC) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:48.0) Gecko/20100101 Firefox/48.0 |
Follow-up Comment #2, patch #9067 (project octave):
Let me patch the patch:
We have to reinsert method
++
public static Object createArray (Object cls, int length)
--
and add some comments to method
++
public static Object createArray (Object cls, int[] length)
--
The following would do:
++
//! Return an array with entry type given by @c cls
//! with dimensions given by @c dims.
//! The class may be given directly as a @ref Class object
//! or as a string via its name.
//! Used by @file javaArray.m defining @c javaArray only.
//!
//! Note that if you invoke <code>javaArray('java.lang.Object', 1)</code>,
//! this is translated into invocation of
//! <code>ClassHelper.createArray("java.lang.Object", 1)</code>,
//! invoking ::createArray(Object, int),
//! whereas <code>javaArray('java.lang.Object', 1, 1)</code>
//! this is translated into invocation of
//! <code>ClassHelper.createArray("java.lang.Object", 1, 1)</code>,
//! invoking ::createArray(Object, int[]).
//!
//! @param cls
//! the atomic component class given as a class object or as a string.
//! If given as a string, the class is loaded via #loader.
//! @param dims
//! the dimensions which shall be non-negative but less than 256.
//! @return
//! an array with the given component type and dimensions.
//! If @c cls is a string, the class is loaded by #loader.
//! @throws ClassNotFoundException
//! if @c cls is a string representing a class name
//! and if #loader could not find the according class.
//! @see ::createArray(Object, int)
// based on loader but only partially.
// used by javaArray.m
public static Object createArray (Object cls, int[] dims)
throws ClassNotFoundException
{
// FIXME: seems as if used in javaArray.m only.
// Then more appropriate seems split into two methods:
// one with cls is a Class other one with cls is a String
// FIXME: if a class is given directly,
// it is not guaranteed, that this is loaded via #loader
// So this shall be fixed.
// Typically, different usages are treated in m file invoking error
// in the last else branch.
// This would be appropriate here also.
Class theClass;
if (cls instanceof Class)
{
theClass = (Class) cls;
}
else if (cls instanceof String)
{
// may throw ClassNotFoundException
theClass = Class.forName ((String) cls, true, loader);
}
else
{
throw new IllegalArgumentException ("invalid class specification " +
cls);
}
return Array.newInstance (theClass, dims);
}
//! Return a one-dimensional array with entry type given by @c cls
//! with length by @c length.
//! The class may be given directly as a @ref Class object
//! or as a string via its name.
//! Used by @file javaArray.m defining @c javaArray only.
//!
//! @param cls
//! the atomic component class given as a class object or as a string.
//! If given as a string, the class is loaded via #loader.
//! @param length
//! the length of the array to be created.
//! @return
//! an array with the given component type and length.
//! If @c cls is a string, the class is loaded by #loader.
//! @throws ClassNotFoundException
//! if @c cls is a string representing a class name
//! and if #loader could not find the according class.
//! @see ::createArray(Object, int)
// based on loader but only partially.
// used by javaArray.m
// would be superfluous with varargs introduced in java 1.5:
// the createArray (Object cls, int[] length)
// could be written createArray (Object cls, int... length)
public static Object createArray (Object cls, int length)
throws ClassNotFoundException
{
return createArray (cls, new int[] {length});
}
--
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/patch/?9067>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-patch-tracker] [patch #9067] java sources part 1, Ernst Reissner, 2016/08/03
- [Octave-patch-tracker] [patch #9067] java sources part 1, Ernst Reissner, 2016/08/09
- [Octave-patch-tracker] [patch #9067] java sources part 1,
Ernst Reissner <=
- [Octave-patch-tracker] [patch #9067] java sources part 1, Ernst Reissner, 2016/08/10
- [Octave-patch-tracker] [patch #9067] java sources part 1, Ernst Reissner, 2016/08/11
- [Octave-patch-tracker] [patch #9067] java sources part 1, Mike Miller, 2016/08/11
- [Octave-patch-tracker] [patch #9067] java sources part 1, Mike Miller, 2016/08/11
- [Octave-patch-tracker] [patch #9067] java sources part 1, Ernst Reissner, 2016/08/11
- [Octave-patch-tracker] [patch #9067] java sources part 1, Ernst Reissner, 2016/08/11
- [Octave-patch-tracker] [patch #9067] java sources part 1, Ernst Reissner, 2016/08/11
- [Octave-patch-tracker] [patch #9067] java sources part 1, Ernst Reissner, 2016/08/11
- [Octave-patch-tracker] [patch #9067] java sources part 1, John W. Eaton, 2016/08/12
- [Octave-patch-tracker] [patch #9067] java sources part 1, Mike Miller, 2016/08/12