org.gephi.data.attributes.type
Class AbstractList<T>
java.lang.Object
org.gephi.data.attributes.type.AbstractList<T>
- Type Parameters:
T
- type parameter defining final List type
- Direct Known Subclasses:
- BooleanList, CharacterList, NumberList, StringList
public abstract class AbstractList<T>
- extends java.lang.Object
Complex type that defines list of any type of items. Can be created from an array or from single
string using either given or default separators. Internal representation of data is array of generic
type. This means that every primitive type must be first converted into wrapper type. The exact
conversion process from String value into given type is done by TypeConvertor
class.
Design guidelines
This is a basic abstract class that every other 'List' class should extend. In order to not misuse
the API, every extending type should be one of the following:
- helper type which restricts the type parameter and possibly brings some new functionality (e.g.
NumberList
). This is not final usable type so it should be declared as abstract.
- final type that extends any of defined helper types or basic class and sets the type parameter
(e.g. there are types for representing all primitive types, String, BigInteger & BigDecimal).
These are final usable types so they should be declared as final.
Flexibility
The flexibility of this API is done in 2 ways:
- We can add functionality by defining conversions from any other type in difference from general
supported types through defining new constructors (e.g.
StringList
class can
be created from array of characters). We can also restrict the functionality (e.g. BigInteger &
BigDecimal cannot be created from arrays of primitive types). The conversion process should be
done by TypeConvertor
type if the conversion can be used in more List
implementations or by 'private static T parseXXX()' method in appropriate List implementation if
only this type uses the conversion (e.g. StringList.parse(char[])
).
- Any other functionality required from 'List' implementations should be done by implementing
appropriate non-static methods in concrete 'List' implementations.
Extensibility
This API can be simply extended. New 'List' type should extend base or any helper 'List' type. We can
create final 'List' implementations as well as helper 'list' implementations with appropriate modifiers
(see Design Guidelines). We can define as many constructors responsible for conversions from other
types and as many additional methods as we want.
To fully integrate new 'List' type into the whole codebase we have to update following types:
AttributeType
:
- add appropriate enum constants
- update
parse(String)
method
DataIndex
:
- add appropriate type represented by Class object into
SUPPORTED_TYPES
array
This class defines method for recognizing size
of the list and
method for getting item by index
.
- Author:
- Martin Ć kurla
- See Also:
TypeConvertor
Constructor Summary |
AbstractList(java.lang.String input,
java.lang.Class<T> finalType)
|
AbstractList(java.lang.String input,
java.lang.String separator,
java.lang.Class<T> finalType)
|
AbstractList(T[] array)
|
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
DEFAULT_SEPARATOR
public static final java.lang.String DEFAULT_SEPARATOR
- See Also:
- Constant Field Values
list
protected final T[] list
AbstractList
public AbstractList(java.lang.String input,
java.lang.Class<T> finalType)
AbstractList
public AbstractList(java.lang.String input,
java.lang.String separator,
java.lang.Class<T> finalType)
AbstractList
public AbstractList(T[] array)
size
public int size()
getItem
public T getItem(int index)
contains
public boolean contains(T value)
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in class java.lang.Object
hashCode
public int hashCode()
- Overrides:
hashCode
in class java.lang.Object