Class OperationList
Normalized list of image transform operations
associated with a source image that is identified by either a MetaIdentifier
or Identifier
.
This class has dual purposes:
- To describe a list of image transform operations;
- To uniquely identify a post-processed ("variant") image
created using the instance. For example, the return values of
toString()
ortoFilename()
may be used in cache keys.
Endpoints translate request arguments into instances of this class in
order to pass them off to processors
and caches
.
Processors should iterate the operations in the list and apply them
(generally in order) as best they can. They must take the scale constraint
into account when cropping and
scaling.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new empty instance.OperationList
(Identifier identifier) OperationList
(MetaIdentifier identifier) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Inserts an operation at the given index in the list.void
Adds an operation to the end of the list.void
Adds an operation immediately after the last instance of the given class in the list.void
Adds an operation immediately before the first instance of the given class in the list.void
applyNonEndpointMutations
(Info info, Delegate delegate) Most image processing operations (crop, scale, etc.) are supplied by a client in a request to an endpoint.static OperationList.Builder
builder()
void
clear()
boolean
void
freeze()
"Freezes" the instance and all of its operations so that they can no longer be mutated.Used for quickly checking theEncode
operation's format.int
Convenience method.getResultingSize
(Size fullSize) Convenience method that returns the instance ascribed to themeta-identifier
, if set, or a neutral instance otherwise.boolean
Determines whether the operations are effectively calling for the unmodified source image, based on the given source format.int
hashCode()
iterator()
void
void
void
setIdentifier
(Identifier identifier) void
setMetaIdentifier
(MetaIdentifier metaIdentifier) Sets the effective base scale of the source image upon which the instance is to be applied.stream()
Returns a filename-safe string guaranteed to uniquely represent the instance.toString()
void
Checks that anidentifier is set
Checks that anEncode
is present CallsOperation.validate(is.galia.image.Size, is.galia.image.ScaleConstraint)
on eachOperation
Checks that the resulting scale is not larger than allowed by thescale constraint
Checks that the resulting pixel area is greater than zero and less than or equal toKey.MAX_PIXELS
(if set) These are all general validations that are not endpoint-specific.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
OperationList
public OperationList()Creates a new empty instance. -
OperationList
-
OperationList
-
-
Method Details
-
builder
-
add
Adds an operation to the end of the list.- Parameters:
op
- Operation to add.null
values are silently discarded.- Throws:
IllegalStateException
- if the instance is frozen.
-
add
Inserts an operation at the given index in the list.- Parameters:
op
- Operation to add.null
values are silently discarded.- Throws:
IllegalStateException
- if the instance is frozen.
-
addAfter
Adds an operation immediately after the last instance of the given class in the list. If there are no such instances in the list, the operation will be added to the end of the list.- Parameters:
op
- Operation to add.null
values are silently discarded.afterClass
- The operation will be added after the last instance of this class in the list.- Throws:
IllegalStateException
- if the instance is frozen.
-
addBefore
Adds an operation immediately before the first instance of the given class in the list. If there are no such instances in the list, the operation will be added to the end of the list.- Parameters:
op
- Operation to add.beforeClass
- The operation will be added before the first instance of this class in the list.- Throws:
IllegalStateException
- if the instance is frozen.
-
applyNonEndpointMutations
Most image processing operations (crop, scale, etc.) are supplied by a client in a request to an endpoint. This method adds any other operations or options that endpoints have nothing to do with, and also adjusts existing operations according to either/both the application configuration and delegate method return values.
This method must be called after all endpoint operations have been added, as it may modify them. The instance's identifier must also be
set
.Subsequent invocations will have no effect.
- Parameters:
info
- Source image info.delegate
- Delegate for the current request.
-
clear
public void clear()- Throws:
IllegalStateException
- If the instance is frozen.
-
equals
-
freeze
public void freeze()"Freezes" the instance and all of its operations so that they can no longer be mutated. -
getFirst
-
getIdentifier
- Returns:
- The identifier ascribed to the instance, if set; otherwise the
meta-identifier
's identifier, if set; otherwisenull
.
-
getMetaIdentifier
-
getOperations
-
getOptions
-
getOutputFormat
Used for quickly checking the
Encode
operation's format.N.B.:
applyNonEndpointMutations(is.galia.image.Info, is.galia.delegate.Delegate)
may mutate theEncode
operation.- Returns:
- The output format.
-
getPageIndex
public int getPageIndex()Convenience method.- Returns:
- the effective page index of the
meta-identifier
, if set, or0
otherwise.
-
getResultingSize
-
getScaleConstraint
Convenience method that returns the instance ascribed to themeta-identifier
, if set, or a neutral instance otherwise. -
hasEffect
Determines whether the operations are effectively calling for the unmodified source image, based on the given source format.- Parameters:
fullSize
- Full size of the source image.format
- Source image format.- Returns:
- Whether the operations are effectively calling for the unmodified source image.
-
hashCode
-
iterator
- Specified by:
iterator
in interfaceIterable<Operation>
- Returns:
- Iterator over the instance's operations. If the instance is
frozen,
Iterator.remove()
will throw anUnsupportedOperationException
.
-
remove
-
replace
-
setIdentifier
- Parameters:
identifier
-- Throws:
IllegalStateException
- if the instance is frozen.- See Also:
-
setMetaIdentifier
Sets the effective base scale of the source image upon which the instance is to be applied.
- Parameters:
metaIdentifier
-- Throws:
IllegalStateException
- if the instance is frozen.- See Also:
-
stream
-
toFilename
Returns a filename-safe string guaranteed to uniquely represent the instance. The filename is in the format:
[hashed identifier]_[page number + hashed scale constraint + operation list + options list].[output format extension]
- Returns:
- Filename string.
-
toMap
Returns a map representing the instance with the following format (expressed in JSON, with
Map
s expressed as objects andList
s expressed as arrays):{ "identifier": "result of
Identifier.toString()
", "scale_constraint": result ofScaleConstraint.toMap()
"operations": [ result ofOperation.toMap(is.galia.image.Size, is.galia.image.ScaleConstraint)
], "options": { "key": value } }- Parameters:
fullSize
- Full size of the source image on which the instance is being applied.- Returns:
- Unmodifiable Map representation of the instance.
-
toString
-
validate
public void validate(Size fullSize, Format sourceFormat) throws VariantFormatException, OperationException - Checks that an
identifier is set
- Checks that an
Encode
is present - Calls
Operation.validate(is.galia.image.Size, is.galia.image.ScaleConstraint)
on eachOperation
- Checks that the resulting scale is not larger than allowed by
the
scale constraint
- Checks that the resulting pixel area is greater than zero and
less than or equal to
Key.MAX_PIXELS
(if set)
- Parameters:
fullSize
- Full size of the source image on which the instance is being applied.sourceFormat
- Source image format.- Throws:
IllegalSizeException
- if the resulting size exceedsKey.MAX_PIXELS
.IllegalScaleException
- if the resulting scale exceeds that allowed by thescale constraint
, if set.OperationException
- if the instance is invalid in some other way.VariantFormatException
- Checks that an
-