public abstract class TypedAttribute<T> extends Object implements Attribute
T
.Attribute.AttributeCreator, Attribute.AttributeCreatorProvider
Modifier and Type | Field and Description |
---|---|
protected T |
value
Reference to the value of this attribute.
|
Modifier | Constructor and Description |
---|---|
protected |
TypedAttribute()
Default constructor which initializes
value to null . |
protected |
TypedAttribute(T value)
Initializes
this.value by copying a reference to the parameter
value . |
Modifier and Type | Method and Description |
---|---|
protected static <E extends Enum<E>> |
checkedValueOf(int ordinal,
Class<E> cls)
Returns the enumeration constant
e such that
(e.ordinal() == ordinal) or throws EXRIOException
if a match is not found. |
protected static void |
checkSize(int expected,
int actual)
Helper method that throws an
EXRIOException if
(expected != actual) . |
TypedAttribute |
clone()
Creates a deep-copy of this attribute.
|
protected abstract T |
cloneValue()
Clones the value, required by
clone() . |
boolean |
equals(Object obj)
Compares this typed attribute to the specified object.
|
T |
getValue()
Returns a reference to the current value of this attribute instance.
|
int |
hashCode()
Returns a hash code for this typed attribute.
|
protected void |
readValueFrom(XdrInput input,
int version)
Set the value of this attribute by reading from the given input buffer.
|
void |
readValueFrom(XdrInput input,
int size,
int version)
Set the value of this attribute by reading from the given input buffer.
|
void |
setValue(T value)
Replaces the value of an attribute instance by copying a reference to
the parameter
value . |
String |
toString()
Returns a string representation of the typed attribute.
|
protected static <E extends Enum<E>> |
valueOf(int ordinal,
Class<E> cls)
Returns the enumeration constant
e such that
(e.ordinal() == ordinal) or null if a match is not found. |
protected void |
writeValueTo(XdrOutput output)
Writes the value of this attribute into the given output buffer.
|
void |
writeValueTo(XdrOutput output,
int version)
Writes the value of this attribute into the given output buffer.
|
protected T value
protected TypedAttribute()
value
to null
.protected TypedAttribute(T value)
this.value
by copying a reference to the parameter
value
.value
- reference to the initial value of this attributeNullPointerException
- if value
is null
.protected static <E extends Enum<E>> E valueOf(int ordinal, Class<E> cls)
e
such that
(e.ordinal() == ordinal)
or null
if a match is not found.
For simplicity this implementation does a linear search in the values
returned by cls.getEnumConstants()
.
E
- an enumeration classordinal
- desired ordinal to matchcls
- class of the desired enumeratione
such that
(e.ordinal() == ordinal)
or null
Class.getEnumConstants()
protected static <E extends Enum<E>> E checkedValueOf(int ordinal, Class<E> cls) throws EXRIOException
e
such that
(e.ordinal() == ordinal)
or throws EXRIOException
if a match is not found.
For simplicity this implementation does a linear search in the values
returned by cls.getEnumConstants()
.
E
- an enumeration classordinal
- desired ordinal to matchcls
- class of the desired enumeratione
such that
(e.ordinal() == ordinal)
EXRIOException
- if a matching enumeration constant is not foundClass.getEnumConstants()
protected static void checkSize(int expected, int actual) throws EXRIOException
EXRIOException
if
(expected != actual)
.expected
- number of bytes expectedactual
- number of bytes of the actual I/O operationEXRIOException
- if (expected != actual)
protected void readValueFrom(XdrInput input, int version) throws EXRIOException
version
parameters is the 4-byte integer
following the magic number at the beginning of an OpenEXR file with the
file version and feature flags.
The default implementation throws an
UnsupportedOperationException
.
input
- data input from which the value will be read.version
- file version and flags as provided in the OpenEXR file.EXRIOException
- if there is an error in the file format
or if there is an I/O errorpublic void readValueFrom(XdrInput input, int size, int version) throws EXRIOException
size
parameter contains the size in bytes specified in the
header for the attribute's value; version
is the 4-byte integer
following the magic number at the beginning of an OpenEXR file with the
file version and feature flags.
The default implementation calls readValueFrom(XdrInput, int)
and checks that the actual bytes consumed from input
match those
specified by size
, throwing an EXRIOException
if that
is not the case.
readValueFrom
in interface Attribute
input
- data input from which the value will be read.size
- amount of bytes to be read according to the header.version
- file version and flags as provided in the OpenEXR file.EXRIOException
- if there is an error in the file format or
an I/O error.protected void writeValueTo(XdrOutput output) throws EXRIOException
writeValueTo(XdrOutput, int)
.
The default implementation throws an
UnsupportedOperationException
.
output
- data output into which the value will be written.EXRIOException
- if there is an I/O error.public void writeValueTo(XdrOutput output, int version) throws EXRIOException
version
parameter is the 4-byte integer following the
magic number at the beginning of an OpenEXR file with the
file version and feature flags.
The default implementation simply calls
writeValueTo(XdrOutput)
.
writeValueTo
in interface Attribute
output
- data output into which the value will be written.version
- file version and flags as provided in the OpenEXR file.EXRIOException
- if there is an I/O error.public T getValue()
public void setValue(T value)
value
.value
- reference to the new value of this attributeNullPointerException
- if value
is null
.public String toString()
toString
method for class TypedAttribute
returns a string consisting of the attribute's type name, the opening
brace character `{', the string representation of the current
attribute's value, and the closing brace character `}'.
In other words, this method returns a string equal to the value of:
typeName() + '{' + value + '}'
public int hashCode()
TypedAttribute<T>
object is computed as the aggregate of the
hash values of Attribute.typeName()
and value
.public boolean equals(Object obj)
true
if and only if the argument is not null
, is a
TypedAttribute
of the same class as this object, their
Attribute.typeName()
method returns the same string and their values
are equal.protected abstract T cloneValue()
clone()
. Most of the times
instances should create a deep copy of their value.