Class ParameterBlock
- All Implemented Interfaces:
-
Serializable
,Cloneable
public class ParameterBlock extends Object implements Cloneable, Serializable
ParameterBlock
encapsulates all the information about sources and parameters (Objects) required by a RenderableImageOp, or other classes that process images. Although it is possible to place arbitrary objects in the source Vector, users of this class may impose semantic constraints such as requiring all sources to be RenderedImages or RenderableImage. ParameterBlock
itself is merely a container and performs no checking on source or parameter types.
All parameters in a ParameterBlock
are objects; convenience add and set methods are available that take arguments of base type and construct the appropriate subclass of Number (such as Integer or Float). Corresponding get methods perform a downward cast and have return values of base type; an exception will be thrown if the stored values do not have the correct type. There is no way to distinguish between the results of "short s; add(s)" and "add(new Short(s))".
Note that the get and set methods operate on references. Therefore, one must be careful not to share references between ParameterBlock
s when this is inappropriate. For example, to create a new ParameterBlock
that is equal to an old one except for an added source, one might be tempted to write:
ParameterBlock addSource(ParameterBlock pb, RenderableImage im) { ParameterBlock pb1 = new ParameterBlock(pb.getSources()); pb1.addSource(im); return pb1; }
This code will have the side effect of altering the original ParameterBlock
, since the getSources operation returned a reference to its source Vector. Both pb and pb1 share their source Vector, and a change in either is visible to both.
A correct way to write the addSource function is to clone the source Vector:
ParameterBlock addSource (ParameterBlock pb, RenderableImage im) { ParameterBlock pb1 = new ParameterBlock(pb.getSources().clone()); pb1.addSource(im); return pb1; }
The clone method of ParameterBlock
has been defined to perform a clone of both the source and parameter Vectors for this reason. A standard, shallow clone is available as shallowClone.
The addSource, setSource, add, and set methods are defined to return 'this' after adding their argument. This allows use of syntax like:
ParameterBlock pb = new ParameterBlock(); op = new RenderableImageOp("operation", pb.add(arg1).add(arg2));
- See Also:
Field Summary
Modifier and Type | Field | Description |
---|---|---|
protected Vector<Object> |
parameters |
A Vector of non-source parameters, stored as arbitrary Objects. |
protected Vector<Object> |
sources |
A Vector of sources, stored as arbitrary Objects. |
Constructor Summary
Constructor | Description |
---|---|
ParameterBlock() |
A dummy constructor. |
ParameterBlock |
Constructs a ParameterBlock with a given Vector of sources. |
ParameterBlock |
Constructs a ParameterBlock with a given Vector of sources and Vector of parameters. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
ParameterBlock |
add |
Adds a Byte to the list of parameters. |
ParameterBlock |
add |
Adds a Character to the list of parameters. |
ParameterBlock |
add |
Adds a Double to the list of parameters. |
ParameterBlock |
add |
Adds a Float to the list of parameters. |
ParameterBlock |
add |
Adds a Integer to the list of parameters. |
ParameterBlock |
add |
Adds a Long to the list of parameters. |
ParameterBlock |
add |
Adds a Short to the list of parameters. |
ParameterBlock |
add |
Adds an object to the list of parameters. |
ParameterBlock |
addSource |
Adds an image to end of the list of sources. |
Object |
clone() |
Creates a copy of a ParameterBlock . |
byte |
getByteParameter |
A convenience method to return a parameter as a byte. |
char |
getCharParameter |
A convenience method to return a parameter as a char. |
double |
getDoubleParameter |
A convenience method to return a parameter as a double. |
float |
getFloatParameter |
A convenience method to return a parameter as a float. |
int |
getIntParameter |
A convenience method to return a parameter as an int. |
long |
getLongParameter |
A convenience method to return a parameter as a long. |
int |
getNumParameters() |
Returns the number of parameters (not including source images). |
int |
getNumSources() |
Returns the number of source images. |
Object |
getObjectParameter |
Gets a parameter as an object. |
Class<?>[] |
getParamClasses() |
Returns an array of Class objects describing the types of the parameters. |
Vector<Object> |
getParameters() |
Returns the entire Vector of parameters. |
RenderableImage |
getRenderableSource |
Returns a source as a RenderableImage. |
RenderedImage |
getRenderedSource |
Returns a source as a RenderedImage . |
short |
getShortParameter |
A convenience method to return a parameter as a short. |
Object |
getSource |
Returns a source as a general Object. |
Vector<Object> |
getSources() |
Returns the entire Vector of sources. |
void |
removeParameters() |
Clears the list of parameters. |
void |
removeSources() |
Clears the list of source images. |
ParameterBlock |
set |
Replaces an Object in the list of parameters with a Byte. |
ParameterBlock |
set |
Replaces an Object in the list of parameters with a Character. |
ParameterBlock |
set |
Replaces an Object in the list of parameters with a Double. |
ParameterBlock |
set |
Replaces an Object in the list of parameters with a Float. |
ParameterBlock |
set |
Replaces an Object in the list of parameters with an Integer. |
ParameterBlock |
set |
Replaces an Object in the list of parameters with a Long. |
ParameterBlock |
set |
Replaces an Object in the list of parameters with a Short. |
ParameterBlock |
set |
Replaces an Object in the list of parameters. |
void |
setParameters |
Sets the entire Vector of parameters to a given Vector. |
ParameterBlock |
setSource |
Replaces an entry in the list of source with a new source. |
void |
setSources |
Sets the entire Vector of sources to a given Vector. |
Object |
shallowClone() |
Creates a shallow copy of a ParameterBlock . |
Field Details
sources
protected Vector<Object> sources
parameters
protected Vector<Object> parameters
Constructor Details
ParameterBlock
public ParameterBlock()
ParameterBlock
public ParameterBlock(Vector<Object> sources)
ParameterBlock
with a given Vector of sources.- Parameters:
-
sources
- aVector
of source images
ParameterBlock
public ParameterBlock(Vector<Object> sources, Vector<Object> parameters)
ParameterBlock
with a given Vector of sources and Vector of parameters.- Parameters:
-
sources
- aVector
of source images -
parameters
- aVector
of parameters to be used in the rendering operation
Method Details
shallowClone
public Object shallowClone()
ParameterBlock
. The source and parameter Vectors are copied by reference -- additions or changes will be visible to both versions.- Returns:
- an Object clone of the
ParameterBlock
.
clone
public Object clone()
ParameterBlock
. The source and parameter Vectors are cloned, but the actual sources and parameters are copied by reference. This allows modifications to the order and number of sources and parameters in the clone to be invisible to the original ParameterBlock
. Changes to the shared sources or parameters themselves will still be visible.addSource
public ParameterBlock addSource(Object source)
- Parameters:
-
source
- an image object to be stored in the source list. - Returns:
- a new
ParameterBlock
containing the specifiedsource
.
getSource
public Object getSource(int index)
- Parameters:
-
index
- the index of the source to be returned. - Returns:
- an
Object
that represents the source located at the specified index in thesources
Vector
. - See Also:
setSource
public ParameterBlock setSource(Object source, int index)
- Parameters:
-
source
- the specified source image -
index
- the index into thesources
Vector
at which to insert the specifiedsource
- Returns:
- a new
ParameterBlock
that contains the specifiedsource
at the specifiedindex
. - See Also:
getRenderedSource
public RenderedImage getRenderedSource(int index)
RenderedImage
. This method is a convenience method. An exception will be thrown if the source is not a RenderedImage.- Parameters:
-
index
- the index of the source to be returned - Returns:
- a
RenderedImage
that represents the source image that is at the specified index in thesources Vector
.
getRenderableSource
public RenderableImage getRenderableSource(int index)
- Parameters:
-
index
- the index of the source to be returned - Returns:
- a
RenderableImage
that represents the source image that is at the specified index in thesources Vector
.
getNumSources
public int getNumSources()
- Returns:
- the number of source images in the
sources
Vector
.
getSources
public Vector<Object> getSources()
- Returns:
- the
sources Vector
. - See Also:
setSources
public void setSources(Vector<Object> sources)
- Parameters:
-
sources
- theVector
of source images - See Also:
removeSources
public void removeSources()
getNumParameters
public int getNumParameters()
- Returns:
- the number of parameters in the
parameters
Vector
.
getParameters
public Vector<Object> getParameters()
- Returns:
- the
parameters Vector
. - See Also:
setParameters
public void setParameters(Vector<Object> parameters)
- Parameters:
-
parameters
- the specifiedVector
of parameters - See Also:
removeParameters
public void removeParameters()
add
public ParameterBlock add(Object obj)
- Parameters:
-
obj
- theObject
to add to theparameters Vector
- Returns:
- a new
ParameterBlock
containing the specified parameter.
add
public ParameterBlock add(byte b)
- Parameters:
-
b
- the byte to add to theparameters Vector
- Returns:
- a new
ParameterBlock
containing the specified parameter.
add
public ParameterBlock add(char c)
- Parameters:
-
c
- the char to add to theparameters Vector
- Returns:
- a new
ParameterBlock
containing the specified parameter.
add
public ParameterBlock add(short s)
- Parameters:
-
s
- the short to add to theparameters Vector
- Returns:
- a new
ParameterBlock
containing the specified parameter.
add
public ParameterBlock add(int i)
- Parameters:
-
i
- the int to add to theparameters Vector
- Returns:
- a new
ParameterBlock
containing the specified parameter.
add
public ParameterBlock add(long l)
- Parameters:
-
l
- the long to add to theparameters Vector
- Returns:
- a new
ParameterBlock
containing the specified parameter.
add
public ParameterBlock add(float f)
- Parameters:
-
f
- the float to add to theparameters Vector
- Returns:
- a new
ParameterBlock
containing the specified parameter.
add
public ParameterBlock add(double d)
- Parameters:
-
d
- the double to add to theparameters Vector
- Returns:
- a new
ParameterBlock
containing the specified parameter.
set
public ParameterBlock set(Object obj, int index)
- Parameters:
-
obj
- the parameter that replaces the parameter at the specified index in theparameters Vector
-
index
- the index of the parameter to be replaced with the specified parameter - Returns:
- a new
ParameterBlock
containing the specified parameter.
set
public ParameterBlock set(byte b, int index)
- Parameters:
-
b
- the parameter that replaces the parameter at the specified index in theparameters Vector
-
index
- the index of the parameter to be replaced with the specified parameter - Returns:
- a new
ParameterBlock
containing the specified parameter.
set
public ParameterBlock set(char c, int index)
- Parameters:
-
c
- the parameter that replaces the parameter at the specified index in theparameters Vector
-
index
- the index of the parameter to be replaced with the specified parameter - Returns:
- a new
ParameterBlock
containing the specified parameter.
set
public ParameterBlock set(short s, int index)
- Parameters:
-
s
- the parameter that replaces the parameter at the specified index in theparameters Vector
-
index
- the index of the parameter to be replaced with the specified parameter - Returns:
- a new
ParameterBlock
containing the specified parameter.
set
public ParameterBlock set(int i, int index)
- Parameters:
-
i
- the parameter that replaces the parameter at the specified index in theparameters Vector
-
index
- the index of the parameter to be replaced with the specified parameter - Returns:
- a new
ParameterBlock
containing the specified parameter.
set
public ParameterBlock set(long l, int index)
- Parameters:
-
l
- the parameter that replaces the parameter at the specified index in theparameters Vector
-
index
- the index of the parameter to be replaced with the specified parameter - Returns:
- a new
ParameterBlock
containing the specified parameter.
set
public ParameterBlock set(float f, int index)
- Parameters:
-
f
- the parameter that replaces the parameter at the specified index in theparameters Vector
-
index
- the index of the parameter to be replaced with the specified parameter - Returns:
- a new
ParameterBlock
containing the specified parameter.
set
public ParameterBlock set(double d, int index)
- Parameters:
-
d
- the parameter that replaces the parameter at the specified index in theparameters Vector
-
index
- the index of the parameter to be replaced with the specified parameter - Returns:
- a new
ParameterBlock
containing the specified parameter.
getObjectParameter
public Object getObjectParameter(int index)
- Parameters:
-
index
- the index of the parameter to get - Returns:
- an
Object
representing the the parameter at the specified index into theparameters
Vector
.
getByteParameter
public byte getByteParameter(int index)
null
or not a Byte
.- Parameters:
-
index
- the index of the parameter to be returned. - Returns:
- the parameter at the specified index as a
byte
value. - Throws:
-
ClassCastException
- if the parameter at the specified index is not aByte
-
NullPointerException
- if the parameter at the specified index isnull
-
ArrayIndexOutOfBoundsException
- ifindex
is negative or not less than the current size of thisParameterBlock
object
getCharParameter
public char getCharParameter(int index)
null
or not a Character
.- Parameters:
-
index
- the index of the parameter to be returned. - Returns:
- the parameter at the specified index as a
char
value. - Throws:
-
ClassCastException
- if the parameter at the specified index is not aCharacter
-
NullPointerException
- if the parameter at the specified index isnull
-
ArrayIndexOutOfBoundsException
- ifindex
is negative or not less than the current size of thisParameterBlock
object
getShortParameter
public short getShortParameter(int index)
null
or not a Short
.- Parameters:
-
index
- the index of the parameter to be returned. - Returns:
- the parameter at the specified index as a
short
value. - Throws:
-
ClassCastException
- if the parameter at the specified index is not aShort
-
NullPointerException
- if the parameter at the specified index isnull
-
ArrayIndexOutOfBoundsException
- ifindex
is negative or not less than the current size of thisParameterBlock
object
getIntParameter
public int getIntParameter(int index)
null
or not an Integer
.- Parameters:
-
index
- the index of the parameter to be returned. - Returns:
- the parameter at the specified index as an
int
value. - Throws:
-
ClassCastException
- if the parameter at the specified index is not anInteger
-
NullPointerException
- if the parameter at the specified index isnull
-
ArrayIndexOutOfBoundsException
- ifindex
is negative or not less than the current size of thisParameterBlock
object
getLongParameter
public long getLongParameter(int index)
null
or not a Long
.- Parameters:
-
index
- the index of the parameter to be returned. - Returns:
- the parameter at the specified index as a
long
value. - Throws:
-
ClassCastException
- if the parameter at the specified index is not aLong
-
NullPointerException
- if the parameter at the specified index isnull
-
ArrayIndexOutOfBoundsException
- ifindex
is negative or not less than the current size of thisParameterBlock
object
getFloatParameter
public float getFloatParameter(int index)
null
or not a Float
.- Parameters:
-
index
- the index of the parameter to be returned. - Returns:
- the parameter at the specified index as a
float
value. - Throws:
-
ClassCastException
- if the parameter at the specified index is not aFloat
-
NullPointerException
- if the parameter at the specified index isnull
-
ArrayIndexOutOfBoundsException
- ifindex
is negative or not less than the current size of thisParameterBlock
object
getDoubleParameter
public double getDoubleParameter(int index)
null
or not a Double
.- Parameters:
-
index
- the index of the parameter to be returned. - Returns:
- the parameter at the specified index as a
double
value. - Throws:
-
ClassCastException
- if the parameter at the specified index is not aDouble
-
NullPointerException
- if the parameter at the specified index isnull
-
ArrayIndexOutOfBoundsException
- ifindex
is negative or not less than the current size of thisParameterBlock
object
getParamClasses
public Class<?>[] getParamClasses()
- Returns:
- an array of
Class
objects.
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/image/renderable/ParameterBlock.html