|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.cohort.array.Attributes
public class Attributes
This class holds a list of attributes (name=value, where name is a String and value is a PrimitiveArray). The backing datastructure (ConcurrentHashMap) is thread-safe.
| Field Summary | |
|---|---|
static java.lang.String |
ERROR
"ERROR" is defined here (from String2.ERROR) so that it is consistent in log files. |
static boolean |
verbose
Set this to true (by calling verbose=true in your program, not but changing the code here) if you want lots of diagnostic messages sent to String2.log. |
| Constructor Summary | |
|---|---|
Attributes()
This constructs a new, empty Attributes object. |
|
Attributes(Attributes attributes)
This constructs a new Attributes object which is a clone of 'attributes'. |
|
Attributes(Attributes moreImportant,
Attributes lessImportant)
This constructs a new Attributes object which has the contents of moreImportant and lessImportant. |
|
| Method Summary | |
|---|---|
Attributes |
add(Attributes moreImportant)
This is like the similar set() method, but returns 'this'. |
Attributes |
add(java.lang.String name,
byte value)
This is like the similar set() method, but returns 'this'. |
Attributes |
add(java.lang.String name,
char value)
This is like the similar set() method, but returns 'this'. |
Attributes |
add(java.lang.String name,
double value)
This is like the similar set() method, but returns 'this'. |
Attributes |
add(java.lang.String name,
float value)
This is like the similar set() method, but returns 'this'. |
Attributes |
add(java.lang.String name,
int value)
This is like the similar set() method, but returns 'this'. |
Attributes |
add(java.lang.String name,
long value)
This is like the similar set() method, but returns 'this'. |
Attributes |
add(java.lang.String name,
PrimitiveArray value)
This is like the similar set() method, but returns 'this'. |
Attributes |
add(java.lang.String name,
short value)
This is like the similar set() method, but returns 'this'. |
Attributes |
add(java.lang.String name,
java.lang.String value)
This is like the similar set() method, but returns 'this'. |
void |
clear()
This clears all the attributes being held. |
java.lang.Object |
clone()
This makes a deep clone of the current table (data and attributes). |
void |
copyTo(Attributes destination)
This makes destination's contents equal this Attribute's contents. |
boolean |
equals(java.lang.Object o)
This tests if o is an Attributes and has the same data. |
PrimitiveArray |
get(java.lang.String name)
This returns the value of a specific attribute (or null if the name isn't defined). |
double |
getDouble(java.lang.String name)
A convenience method which returns the first element of the attribute's value PrimitiveArray as a double, regardless of the type used to store it. |
float |
getFloat(java.lang.String name)
A convenience method which returns the first element of the attribute's value PrimitiveArray as a float, regardless of the type used to store it. |
int |
getInt(java.lang.String name)
A convenience method which returns the first element of the attribute's value PrimitiveArray as an int, regardless of the type used to store it. |
long |
getLong(java.lang.String name)
A convenience method which returns the first element of the attribute's value PrimitiveArray as a long, regardless of the type used to store it. |
java.lang.String[] |
getNames()
This returns an array with the names of all of the attributes. |
double |
getNiceDouble(java.lang.String name)
A convenience method which returns the first element of the attribute's value PrimitiveArray as a double, regardless of the type used to store it. |
java.lang.String |
getString(java.lang.String name)
A convenience method which returns the first element of the attribute's value PrimitiveArray as a String, regardless of the type used to store it. |
java.lang.String[] |
getStringsFromCSV(java.lang.String name)
A convenience method which assumes the first element of the attribute's value PrimitiveArray is a CSV String and which splits the string into parts. |
PrimitiveArray |
remove(java.lang.String name)
This removes a specific attribute. |
void |
removeIfSame(Attributes otherAtts)
This removes keys and values from this Attributes which are the same in otherAtts. |
void |
removeValue(java.lang.String value)
This removes any entry which has a String value of 'value'. |
void |
set(Attributes moreImportant)
This calls set() for all the attributes in 'additional'. |
PrimitiveArray |
set(java.lang.String name,
byte value)
A convenience method which stores the byte in an ByteArray then stores the attribute. |
PrimitiveArray |
set(java.lang.String name,
char value)
A convenience method which stores the char in an CharArray then stores the attribute. |
PrimitiveArray |
set(java.lang.String name,
double value)
A convenience method which stores the double in a DoubleArray then stores the attribute. |
PrimitiveArray |
set(java.lang.String name,
float value)
A convenience method which stores the float in a FloatArray then stores the attribute. |
PrimitiveArray |
set(java.lang.String name,
int value)
A convenience method which stores the int in an IntArray then stores the attribute. |
PrimitiveArray |
set(java.lang.String name,
long value)
A convenience method which stores the long in an LongArray then stores the attribute. |
PrimitiveArray |
set(java.lang.String name,
PrimitiveArray value)
This is the main method to set the value of a specific attribute (adding it if it doesn't exist, revising it if it does, or removing it if value is (PrimitiveArray)null). |
PrimitiveArray |
set(java.lang.String name,
short value)
A convenience method which stores the short in an ShortArray then stores the attribute. |
PrimitiveArray |
set(java.lang.String name,
java.lang.String value)
A convenience method which stores the String in a StringArray then stores the attribute. |
PrimitiveArray |
setIfNotAlreadySet(java.lang.String name,
java.lang.String value)
Like set, but only sets the value if there is no current value. |
int |
size()
This returns the number of nameValue pairs in the data structure. |
static void |
test()
This tests the methods in this class. |
java.lang.String |
toNcString(java.lang.String prefix,
java.lang.String suffix)
This generates a String with "[prefix][name]=[value][suffix]" on each line. |
java.lang.String |
toString()
This prints the attributes to a newline separated String, one per line: " [name]=[value]". |
static java.lang.String |
valueToNcString(PrimitiveArray pa)
This returns a netcdf-style String representation of a PrimitiveArray: StringArray is newline separated, others are comma separated. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static boolean verbose
public static final java.lang.String ERROR
| Constructor Detail |
|---|
public Attributes()
public Attributes(Attributes attributes)
attributes -
public Attributes(Attributes moreImportant,
Attributes lessImportant)
moreImportant - lessImportant - | Method Detail |
|---|
public void clear()
public int size()
public java.lang.Object clone()
clone in class java.lang.Objectpublic PrimitiveArray get(java.lang.String name)
name -
public java.lang.String[] getNames()
public java.lang.String getString(java.lang.String name)
name -
public java.lang.String[] getStringsFromCSV(java.lang.String name)
name -
public double getDouble(java.lang.String name)
name -
public double getNiceDouble(java.lang.String name)
name -
public float getFloat(java.lang.String name)
name -
public long getLong(java.lang.String name)
name -
public int getInt(java.lang.String name)
name -
public PrimitiveArray remove(java.lang.String name)
name - the name of the attribute
public PrimitiveArray set(java.lang.String name,
PrimitiveArray value)
name - the name of the attributevalue - a PrimitiveArray which is the value associate with the 'name'.
If value is null or size==0 or it is one String="", name is removed from attributes.
public Attributes add(java.lang.String name,
PrimitiveArray value)
name - the name of the attributevalue - a PrimitiveArray which is the value associate with the 'name'
public void set(Attributes moreImportant)
moreImportant - the Attributes to be added.public Attributes add(Attributes moreImportant)
moreImportant - the Attributes to be added
public PrimitiveArray set(java.lang.String name,
java.lang.String value)
name - the name of the attributevalue - a PrimitiveArray which is the value associate with the 'name'.
If value is null or "", name is removed from attributes.
public PrimitiveArray setIfNotAlreadySet(java.lang.String name,
java.lang.String value)
name - the name of the attributevalue - a PrimitiveArray which is the value associate with the 'name'.
If value is null or "", name is removed from attributes.
public Attributes add(java.lang.String name,
java.lang.String value)
name - the name of the attributevalue - a String which is the value associate with the 'name'
public PrimitiveArray set(java.lang.String name,
double value)
name - the name of the attributevalue - a PrimitiveArray which is the value associate with the 'name'
public Attributes add(java.lang.String name,
double value)
name - the name of the attributevalue - a double which is the value associate with the 'name'
public PrimitiveArray set(java.lang.String name,
float value)
name - the name of the attributevalue - a PrimitiveArray which is the value associate with the 'name'
public Attributes add(java.lang.String name,
float value)
name - the name of the attributevalue - a float which is the value associate with the 'name'
public PrimitiveArray set(java.lang.String name,
long value)
name - the name of the attributevalue - a PrimitiveArray which is the value associate with the 'name'
public Attributes add(java.lang.String name,
long value)
name - the name of the attributevalue - a long which is the value associate with the 'name'
public PrimitiveArray set(java.lang.String name,
int value)
name - the name of the attributevalue - a PrimitiveArray which is the value associate with the 'name'
public Attributes add(java.lang.String name,
int value)
name - the name of the attributevalue - an int which is the value associate with the 'name'
public PrimitiveArray set(java.lang.String name,
short value)
name - the name of the attributevalue - a PrimitiveArray which is the value associate with the 'name'
public Attributes add(java.lang.String name,
short value)
name - the name of the attributevalue - a short which is the value associate with the 'name'
public PrimitiveArray set(java.lang.String name,
char value)
name - the name of the attributevalue - a PrimitiveArray which is the value associate with the 'name'
public Attributes add(java.lang.String name,
char value)
name - the name of the attributevalue - a char which is the value associate with the 'name'
public PrimitiveArray set(java.lang.String name,
byte value)
name - the name of the attributevalue - a PrimitiveArray which is the value associate with the 'name'
public Attributes add(java.lang.String name,
byte value)
name - the name of the attributevalue - a byte which is the value associate with the 'name'
public java.lang.String toString()
toString in class java.lang.Objectpublic void removeValue(java.lang.String value)
public java.lang.String toNcString(java.lang.String prefix,
java.lang.String suffix)
This nc-style version is used to print netcdf header attributes. It uses String2.toJson for String attributes.
prefix - suffix -
public void copyTo(Attributes destination)
destination - the Attributes which will be made equal to 'source'.public boolean equals(java.lang.Object o)
equals in class java.lang.Objecto - an object, presumably an Attributes
java.lang.Exception - if a difference is found.public static java.lang.String valueToNcString(PrimitiveArray pa)
pa -
public void removeIfSame(Attributes otherAtts)
otherAtts -
public static void test()
throws java.lang.Exception
java.lang.Exception
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||