plugins.adufour.vars.lang
Class VarGenericArray<A>

java.lang.Object
  extended by plugins.adufour.vars.lang.Var<A>
      extended by plugins.adufour.vars.lang.VarGenericArray<A>
Type Parameters:
A - the underlying array type (*not* the inner component type, e.g., int[] and not int)
All Implemented Interfaces:
icy.file.xml.XMLPersistent, ArrayType, VarListener<A>
Direct Known Subclasses:
VarArray, VarDoubleArrayNative, VarFileArray, VarFloatArrayNative, VarIntegerArrayNative, VarSequenceArray

public class VarGenericArray<A>
extends Var<A>
implements ArrayType

Class defining a variable holding an array of arbitrary type (including Java primitives). This class should be preferred to VarArray when dealing with large arrays of primitives in order to optimize performances.

Author:
Alexandre Dufour

Field Summary
 
Fields inherited from class plugins.adufour.vars.lang.Var
listeners, NO_VALUE, type, XML_KEY_ID
 
Constructor Summary
VarGenericArray(java.lang.String name, java.lang.Class<A> type, A defaultValue)
           
 
Method Summary
 int getDimensions()
           
 java.lang.Class<?> getInnerType()
           
 java.lang.String getSeparator(int dimension)
           
 A getValue()
           
 boolean isAssignableFrom(Var<?> source)
          Checks whether the type of the given variable is equal or extends this variable's type.
If the result is true, then the given variable can become a link source for this variable
 A parse(java.lang.String input)
          Parses the given String into the current type
 java.lang.Object parseComponent(java.lang.String s)
          Parse a string representing an element of the underlying array.
 int size()
           
 int size(int dimension)
           
 
Methods inherited from class plugins.adufour.vars.lang.Var
addListener, createVarEditor, createVarViewer, fireVariableChanged, fireVariableChanged, getDefaultEditorModel, getDefaultValue, getIterableReferrers, getName, getReference, getReferencingPolicy, getReferrers, getType, getTypeAsString, getValue, getValueAsString, getValueAsString, isEnabled, isOptional, isReferenced, loadFromXML, prettyPrint, referenceChanged, removeListener, removeListeners, saveToXML, setDefaultEditorModel, setEnabled, setOptional, setReference, setReferencingPolicy, setValue, toString, valueChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VarGenericArray

public VarGenericArray(java.lang.String name,
                       java.lang.Class<A> type,
                       A defaultValue)
Method Detail

getDimensions

public int getDimensions()
Specified by:
getDimensions in interface ArrayType
Returns:
the number of dimensions in this array

getInnerType

public java.lang.Class<?> getInnerType()
Specified by:
getInnerType in interface ArrayType
Returns:
the type of each element of this array

getSeparator

public java.lang.String getSeparator(int dimension)
Specified by:
getSeparator in interface ArrayType
Parameters:
dimension - the dimension for which the separator is wanted
Returns:
The character used to separate array values when displaying the value as a String

getValue

public A getValue()
Overrides:
getValue in class Var<A>
Returns:
the value stored in this variable, or the value in the referenced variable if the reference is not null. Note that this method may return null. To forbid null values, use the Var.getValue(boolean) method instead.
See Also:
Var.getReference()

isAssignableFrom

public boolean isAssignableFrom(Var<?> source)
Description copied from class: Var
Checks whether the type of the given variable is equal or extends this variable's type.
If the result is true, then the given variable can become a link source for this variable

Overrides:
isAssignableFrom in class Var<A>
Returns:
true if the source type is equal or wider than this variable's type, false otherwise (including if source has null type)

parse

public A parse(java.lang.String input)
Description copied from class: Var
Parses the given String into the current type

Overrides:
parse in class Var<A>
Returns:
The variable value corresponding to the given string

parseComponent

public java.lang.Object parseComponent(java.lang.String s)
                                throws java.lang.UnsupportedOperationException
Parse a string representing an element of the underlying array. Note that this method throws an UnsupportedOperationException by default, therefore the implementation must be provided by overriding classes

Specified by:
parseComponent in interface ArrayType
Parameters:
s - the string to parse
Returns:
a primitive type representing the given string
Throws:
java.lang.UnsupportedOperationException

size

public int size()
Returns:
the size of this array, or -1 if the array is null

size

public int size(int dimension)
         throws java.lang.ArrayIndexOutOfBoundsException
Specified by:
size in interface ArrayType
Parameters:
dimension - the dimension along which the size is wanted
Returns:
the size of the array in the specified dimension,or -1 if the array is null
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the dimension does not exist