E
- The type of extent containing this locationpublic final class Location<E extends Extent> extends Object implements DataHolder
Extent
.
This class is primarily a helper class to represent a location in a
particular Extent
. The methods provided are proxy methods to ones on
Extent
.
Each instance can be used to either represent a block or a location on a continuous coordinate system. Internally, positions are stored using doubles. When a block-related method is used, the components of the position are each rounded to an integer.
Locations are immutable. Methods that change the properties of the location create a new instance.
Constructor and Description |
---|
Location(E extent,
double x,
double y,
double z)
Create a new instance.
|
Location(E extent,
int x,
int y,
int z)
Create a new instance.
|
Location(E extent,
com.flowpowered.math.vector.Vector3d position)
Create a new instance.
|
Location(E extent,
com.flowpowered.math.vector.Vector3i blockPosition)
Create a new instance.
|
Modifier and Type | Method and Description |
---|---|
Location<E> |
add(double x,
double y,
double z)
Add vector components to the position on this instance, returning a new
Location instance.
|
Location<E> |
add(com.flowpowered.math.vector.Vector3d v)
Add another Vector3d to the position on this instance, returning a new
Location instance.
|
Location<E> |
add(com.flowpowered.math.vector.Vector3i v)
Add another Vector3i to the position on this instance, returning a new
Location instance.
|
ScheduledBlockUpdate |
addScheduledUpdate(int priority,
int ticks)
Adds a new
ScheduledBlockUpdate to this block. |
Location<E> |
asHighestLocation()
Gets the highest
Location at this location. |
Location<E> |
copy()
Creates a clone copy of this
ValueContainer as a new
ValueContainer such that all the BaseValue s are
safely duplicated to the new instance. |
DataTransactionResult |
copyFrom(DataHolder that)
Performs an absolute copy of all
Value s and
ValueContainer s to this CompositeValueStore such that
any overlapping Value s are offered for replacement. |
DataTransactionResult |
copyFrom(DataHolder that,
MergeFunction strategy)
Performs an absolute copy of all
Value s and
ValueContainer s to this CompositeValueStore such that
any overlapping Value s are offered for replacement. |
Entity |
createEntity(EntityType type)
Create an entity instance at the given position.
|
BlockSnapshot |
createSnapshot()
Gets a snapshot of this block at the current point in time.
|
boolean |
equals(Object other) |
<T extends DataManipulator<?,?>> |
get(Class<T> containerClass)
|
<T> Optional<T> |
get(Key<? extends BaseValue<T>> key)
|
Collection<Property<?,?>> |
getApplicableProperties()
Gets an immutable collection of all known
Property s pertaining
to this PropertyHolder . |
BiomeType |
getBiome()
Gets the block at this location.
|
com.flowpowered.math.vector.Vector3i |
getBiomePosition()
Gets the underlying biome position.
|
BlockState |
getBlock()
Gets the
BlockState for this position. |
com.flowpowered.math.vector.Vector3i |
getBlockPosition()
Gets the underlying block position.
|
Location<E> |
getBlockRelative(Direction direction)
Gets the location next to this one in the given direction.
|
BlockType |
getBlockType()
Gets the base type of block.
|
int |
getBlockX()
Gets the floored X component of this instance's position.
|
int |
getBlockY()
Gets the floored Y component of this instance's position.
|
int |
getBlockZ()
Gets the floored Z component of this instance's position.
|
com.flowpowered.math.vector.Vector3i |
getChunkPosition()
Gets the underlying chunk position.
|
Collection<DataManipulator<?,?>> |
getContainers()
Gets an copied collection of all known
ValueContainer s
belonging to this CompositeValueStore . |
int |
getContentVersion()
Gets the content version of this
DataSerializable . |
E |
getExtent()
Gets the underlying extent.
|
Set<Key<?>> |
getKeys()
Gets all applicable
Key s for this ValueContainer . |
Optional<LocatableBlock> |
getLocatableBlock()
|
<T extends DataManipulator<?,?>> |
getOrCreate(Class<T> containerClass)
|
com.flowpowered.math.vector.Vector3d |
getPosition()
Gets the underlying position.
|
<T extends Property<?,?>> |
getProperty(Class<T> propertyClass)
Attempts to retrieve a specific
Property type of this
PropertyHolder . |
Location<E> |
getRelative(Direction direction)
Gets the location next to this one in the given direction.
|
Collection<ScheduledBlockUpdate> |
getScheduledUpdates()
Gets a list of
ScheduledBlockUpdate s on this block. |
Optional<TileEntity> |
getTileEntity()
Gets the associated
TileEntity on this block. |
<T,V extends BaseValue<T>> |
getValue(Key<V> key)
|
Set<ImmutableValue<?>> |
getValues()
Gets all applicable
BaseValue s associated with this
ValueContainer . |
double |
getX()
Gets the X component of this instance's position.
|
double |
getY()
Gets the Y component of this instance's position.
|
double |
getZ()
Gets the Z component of this instance's position.
|
boolean |
hasBiome()
Returns true if this location has a biome at its
getBiomePosition() . |
boolean |
hasBlock()
Returns true if this location has a block at its
getBlockPosition() ()}. |
int |
hashCode() |
boolean |
hasTileEntity()
Checks for whether the block at this position contains tile entity data.
|
boolean |
inExtent(Extent extent)
Returns true if this location is in the given extent.
|
boolean |
isAvailable()
Gets if the
Extent this location refers to is still loaded and
available. |
<T> T |
map(BiFunction<E,com.flowpowered.math.vector.Vector3d,T> mapper)
Calls the mapper function on the extent and position.
|
<T> T |
mapBiome(BiFunction<E,com.flowpowered.math.vector.Vector3i,T> mapper)
Calls the mapper function on the extent and biome position.
|
<T> T |
mapBlock(BiFunction<E,com.flowpowered.math.vector.Vector3i,T> mapper)
Calls the mapper function on the extent and block position.
|
<T> T |
mapChunk(BiFunction<E,com.flowpowered.math.vector.Vector3i,T> mapper)
Calls the mapper function on the extent and chunk position.
|
<T> DataTransactionResult |
offer(BaseValue<T> value)
Offers the given
BaseValue as defined by the provided
Key such that a DataTransactionResult is returned for
any successful, rejected, and replaced BaseValue s from this
CompositeValueStore . |
DataTransactionResult |
offer(DataManipulator<?,?> valueContainer)
Offers the given
ValueContainer such that all of the available
BaseValue s from the given ValueContainer are offered
to this CompositeValueStore . |
DataTransactionResult |
offer(DataManipulator<?,?> valueContainer,
MergeFunction function)
Offers the given
ValueContainer such that all of the available
BaseValue s from the given ValueContainer are offered
to this CompositeValueStore . |
DataTransactionResult |
offer(Iterable<DataManipulator<?,?>> valueHolders)
Offers all provided
ValueContainer s to this
CompositeValueStore much like CompositeValueStore.offer(ValueContainer)
except all in a single batch. |
DataTransactionResult |
offer(Iterable<DataManipulator<?,?>> values,
MergeFunction function)
Offers all provided
ValueContainer s to this
CompositeValueStore much like CompositeValueStore.offer(ValueContainer)
except all in a single batch. |
<T> DataTransactionResult |
offer(Key<? extends BaseValue<T>> key,
T value)
Offers the given
value as defined by the provided Key
such that a DataTransactionResult is returned for any
successful, rejected, and replaced BaseValue s from this
CompositeValueStore . |
DataTransactionResult |
remove(BaseValue<?> value)
Attempts to remove the provided
BaseValue . |
DataTransactionResult |
remove(Class<? extends DataManipulator<?,?>> containerClass)
Attempts to remove all
Value s associated with the class of the
provided ValueContainer class. |
DataTransactionResult |
remove(Key<?> key)
Attempts to remove the data associated with the provided
Key . |
boolean |
removeBlock()
Remove the block at this position by replacing it with
BlockTypes.AIR . |
void |
removeScheduledUpdate(ScheduledBlockUpdate update)
Removes a
ScheduledBlockUpdate from this block. |
boolean |
restoreSnapshot(BlockSnapshot snapshot,
boolean force,
BlockChangeFlag flag)
Replace the block at this position with a copy of the given snapshot.
|
boolean |
setBlock(BlockState state)
Replace the block at this position with a new state.
|
boolean |
setBlock(BlockState state,
BlockChangeFlag flag)
Replace the block at this position with a new state.
|
Location<E> |
setBlockPosition(com.flowpowered.math.vector.Vector3i position)
Create a new instance with a new block position.
|
boolean |
setBlockType(BlockType type)
Replace the block type at this position by a new type.
|
boolean |
setBlockType(BlockType type,
BlockChangeFlag flag)
Replace the block type at this position by a new type.
|
Location<E> |
setExtent(E extent)
Create a new instance with a new extent.
|
Location<E> |
setPosition(com.flowpowered.math.vector.Vector3d position)
Create a new instance with a new position.
|
void |
setRawData(DataView container)
Attempts to set all data of this
DataHolder according to the
DataContainer 's held information. |
Collection<Entity> |
spawnEntities(Iterable<? extends Entity> entities)
Similar to
spawnEntity(Entity) except where multiple
entities can be attempted to be spawned with a customary Cause . |
boolean |
spawnEntity(Entity entity)
Spawns an
Entity using the already set properties (extent,
position, rotation) and applicable DataManipulator s with the
specified Cause for spawning the entity. |
Location<E> |
sub(double x,
double y,
double z)
Subtract vector components to the position on this instance, returning a
new Location instance.
|
Location<E> |
sub(com.flowpowered.math.vector.Vector3d v)
Subtract another Vector3d to the position on this instance, returning
a new Location instance.
|
Location<E> |
sub(com.flowpowered.math.vector.Vector3i v)
Subtract another Vector3i to the position on this instance, returning
a new Location instance.
|
boolean |
supports(Class<? extends DataManipulator<?,?>> holderClass)
|
boolean |
supports(Key<?> key)
Checks if the given
Key is supported by this
ValueContainer . |
DataContainer |
toContainer()
Serializes this object into a comprehensible
DataContainer . |
String |
toString() |
<T> DataTransactionResult |
transform(Key<? extends BaseValue<T>> key,
Function<T,T> function)
Applies a transformation on the provided
BaseValue such that
the return value of Function.apply(Object) will become the end
resulting value set into this CompositeValueStore . |
DataTransactionResult |
undo(DataTransactionResult result)
Attempts to "revert" a
DataTransactionResult such that any
of the DataTransactionResult.getReplacedData() are offered
back, and any DataTransactionResult.getSuccessfulData() are
removed if they were not the same types as any exising in the
replaced values. |
boolean |
validateRawData(DataView container)
Validates the container with known data required to set the raw data to
this
DataHolder . |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
require, tryOffer, tryOffer, tryOffer, tryOffer
getOrElse, getOrNull, require, supports
public Location(E extent, com.flowpowered.math.vector.Vector3d position)
extent
- The extentposition
- The positionpublic Location(E extent, double x, double y, double z)
extent
- The extentx
- The X-axis positiony
- The Y-axis positionz
- The Z-axis positionpublic Location(E extent, com.flowpowered.math.vector.Vector3i blockPosition)
extent
- The extentblockPosition
- The positionpublic Location(E extent, int x, int y, int z)
extent
- The extentx
- The X-axis positiony
- The Y-axis positionz
- The Z-axis positionpublic boolean isAvailable()
Extent
this location refers to is still loaded and
available.true
if this extent is available.public E getExtent()
If the referenced Extent
has been unloaded, this will throw
an exception.
IllegalStateException
- If the Extent
has been unloaded and
is no longer available.public com.flowpowered.math.vector.Vector3d getPosition()
public com.flowpowered.math.vector.Vector3i getBlockPosition()
public com.flowpowered.math.vector.Vector3i getChunkPosition()
public com.flowpowered.math.vector.Vector3i getBiomePosition()
public double getX()
public double getY()
public double getZ()
public int getBlockX()
public int getBlockY()
public int getBlockZ()
public boolean inExtent(Extent extent)
Object.equals(Object)
check.extent
- The extent to checkpublic boolean hasBiome()
getBiomePosition()
.public boolean hasBlock()
getBlockPosition()
()}.public Optional<LocatableBlock> getLocatableBlock()
public Location<E> setExtent(E extent)
extent
- The new extentpublic Location<E> setPosition(com.flowpowered.math.vector.Vector3d position)
position
- The new positionpublic Location<E> setBlockPosition(com.flowpowered.math.vector.Vector3i position)
position
- The new positionpublic Location<E> sub(com.flowpowered.math.vector.Vector3d v)
v
- The vector to subtractpublic Location<E> sub(com.flowpowered.math.vector.Vector3i v)
v
- The vector to subtractpublic Location<E> sub(double x, double y, double z)
x
- The x componenty
- The y componentz
- The z componentpublic Location<E> add(com.flowpowered.math.vector.Vector3d v)
v
- The vector to addpublic Location<E> add(com.flowpowered.math.vector.Vector3i v)
v
- The vector to addpublic Location<E> add(double x, double y, double z)
x
- The x componenty
- The y componentz
- The z componentpublic <T> T map(BiFunction<E,com.flowpowered.math.vector.Vector3d,T> mapper)
T
- The return type of the mappermapper
- The mapperpublic <T> T mapBlock(BiFunction<E,com.flowpowered.math.vector.Vector3i,T> mapper)
T
- The return type of the mappermapper
- The mapperpublic <T> T mapChunk(BiFunction<E,com.flowpowered.math.vector.Vector3i,T> mapper)
T
- The return type of the mappermapper
- The mapperpublic <T> T mapBiome(BiFunction<E,com.flowpowered.math.vector.Vector3i,T> mapper)
T
- The return type of the mappermapper
- The mapperpublic Location<E> getRelative(Direction direction)
direction
- The direction to move inpublic Location<E> getBlockRelative(Direction direction)
Direction.Division.SECONDARY_ORDINAL
directions are not a valid argument. These will throw an exception.
direction
- The direction to move inIllegalArgumentException
- If the direction is a
Direction.Division.SECONDARY_ORDINAL
public BiomeType getBiome()
public BlockType getBlockType()
The type does not include block data such as the contents of inventories.
public BlockState getBlock()
BlockState
for this position.public boolean hasTileEntity()
public Optional<TileEntity> getTileEntity()
TileEntity
on this block.public boolean setBlock(BlockState state)
This will remove any extended block data at the given position.
state
- The new block statepublic boolean setBlock(BlockState state, BlockChangeFlag flag)
This will remove any extended block data at the given position.
state
- The new block stateflag
- The various change flags controlling some interactionspublic boolean setBlockType(BlockType type)
This will remove any extended block data at the given position.
type
- The new typepublic boolean setBlockType(BlockType type, BlockChangeFlag flag)
This will remove any extended block data at the given position.
type
- The new typeflag
- The various change flags controlling some interactionspublic boolean restoreSnapshot(BlockSnapshot snapshot, boolean force, BlockChangeFlag flag)
Changing the snapshot afterwards will not affect the block that has been placed at this location.
snapshot
- The snapshotforce
- If true, forces block state to be set even if the
BlockType
does not match the snapshot one.flag
- The various change flags controlling some interactionspublic boolean removeBlock()
BlockTypes.AIR
.
This will remove any extended block data at the given position.
public Entity createEntity(EntityType type)
Creating an entity does not spawn the entity into the world. An entity
created means the entity can be spawned at the given location. If
Optional.empty()
was returned, the entity is not able to spawn at
the given location. Furthermore, this allows for the Entity
to be
customized further prior to traditional "ticking" and processing by core
systems.
type
- The typeIllegalArgumentException
- If the position or entity type is not
valid to createIllegalStateException
- If a constructor cannot be foundEntityUniverse.createEntity(EntityType, Vector3d)
public boolean spawnEntity(Entity entity)
Entity
using the already set properties (extent,
position, rotation) and applicable DataManipulator
s with the
specified Cause
for spawning the entity.
Note that for the Cause
to be useful in the expected
SpawnEntityEvent
, a SpawnType
should be provided in the
EventContext
for other plugins to understand and have finer
control over the event.
The requirements involve that all necessary setup of states and data
is already preformed on the entity retrieved from the various
EntityUniverse.createEntity(EntityType,Vector3d)
methods. Calling
this will make the now-spawned entity able to be processed by various
systems.
If the entity was unable to spawn, the entity is not removed, but it should be taken note that there can be many reasons for a failure.
entity
- The entity to spawnEntityUniverse.spawnEntity(Entity)
public Collection<Entity> spawnEntities(Iterable<? extends Entity> entities)
spawnEntity(Entity)
except where multiple
entities can be attempted to be spawned with a customary Cause
.
The recommended use is to easily process the entity spawns without
interference with the cause tracking system.entities
- The entities which spawned correctly, or empty if noneEntityUniverse.spawnEntities(Iterable)
public Location<E> asHighestLocation()
Location
at this location.Extent.getHighestPositionAt(Vector3i)
public DataTransactionResult remove(Class<? extends DataManipulator<?,?>> containerClass)
CompositeValueStore
Value
s associated with the class of the
provided ValueContainer
class. All values that were successfully
removed will be provided in
DataTransactionResult.getReplacedData()
. If the data can not be
removed, the result will be an expected
DataTransactionResult.Type.FAILURE
.remove
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
containerClass
- The container classpublic DataTransactionResult remove(BaseValue<?> value)
CompositeValueStore
BaseValue
. All values that were
successfully removed will be provided in
DataTransactionResult.getReplacedData()
. If the data can not be
removed, the result will be an expected
DataTransactionResult.Type.FAILURE
.remove
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
value
- The value to removepublic DataTransactionResult remove(Key<?> key)
CompositeValueStore
Key
.
All values that were successfully removed will be provided in
DataTransactionResult.getReplacedData()
. If the data can not be
removed, the result will be an expected
DataTransactionResult.Type.FAILURE
.remove
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
key
- The key of the datapublic BlockSnapshot createSnapshot()
A snapshot is disconnected from the Extent
that it was taken
from so changes to the original block do not affect the snapshot.
public Collection<ScheduledBlockUpdate> getScheduledUpdates()
ScheduledBlockUpdate
s on this block.public ScheduledBlockUpdate addScheduledUpdate(int priority, int ticks)
ScheduledBlockUpdate
to this block.priority
- The priority of the scheduled updateticks
- The ticks until the scheduled update should be processedpublic void removeScheduledUpdate(ScheduledBlockUpdate update)
ScheduledBlockUpdate
from this block.update
- The ScheduledBlockUpdate to removepublic <T extends Property<?,?>> Optional<T> getProperty(Class<T> propertyClass)
PropertyHolder
Property
type of this
PropertyHolder
. If the property is not applicable,
Optional.empty()
is returned.
properties
can define various immutable information
about a PropertyHolder
that is dependent on the instance of the
holder. As properties
cannot be changed, the
PropertyHolder
can not change the information about its own
properties either.
getProperty
in interface PropertyHolder
T
- The type of propertypropertyClass
- The property classpublic Collection<Property<?,?>> getApplicableProperties()
PropertyHolder
Property
s pertaining
to this PropertyHolder
.
properties
can not be changed such that the property
is attached to the instance of the residing PropertyHolder
.
getApplicableProperties
in interface PropertyHolder
properties
public boolean validateRawData(DataView container)
DataHolder
DataHolder
. If the container is incomplete or contains
invalid data, false
is returned.
This validation should be checked prior to calling
DataHolder.setRawData(DataView)
to avoid exceptions.
validateRawData
in interface DataHolder
container
- The raw data to validatepublic void setRawData(DataView container) throws InvalidDataException
DataHolder
DataHolder
according to the
DataContainer
's held information. Using this to modify known
DataManipulator
is unsupported and if the data is invalid, an
InvalidDataException
is thrown.
This setter is used to provide setting custom data that is not
represented by the Data API, including forge mods and other
unknown data. Attempts at validating known DataManipulator
s
contained in the data container are made with the assumption that all
necessary data exists.
setRawData
in interface DataHolder
container
- A container containing all raw data to set on this
data holderInvalidDataException
- If the container is missing or has invalid
data that this holder will refusepublic int getContentVersion()
DataSerializable
DataSerializable
. The version
may differ between instances of plugins and implementations such that
the DataView
from DataSerializable.toContainer()
may include different
information, or remove other information as they are no longer deemed
necessary. The version goes hand in hand with DataContentUpdater
as it is required when there exists any DataView
of this
DataSerializable
with an "older" version.getContentVersion
in interface DataSerializable
public DataContainer toContainer()
DataSerializable
DataContainer
.toContainer
in interface DataSerializable
public <T extends DataManipulator<?,?>> Optional<T> get(Class<T> containerClass)
CompositeValueStore
Gets the desired ValueContainer
of type H
if the
ValueContainer
is compatible. Since the return type is an
Optional
, a short way of checking compatibility and presence
of the requested data is to mimic the following:
// MyCompositeValueStore extends
CompositeValueStore<MyCompositeValueStore,
DataManipulator<?>>
MyCompositeValueStore valueStore;
final Optional<DisplayNameData> displayOptional =
valueStore.get(DisplayNameData.class);
if (displayOptional.isPresent()) {
// We know that we have a present DataManipulator and it's
supported
System.out.println(displayOptional.get().displayName().get().toString());
}
This is the equivalent to performing the following:
MyCompositeValueStore valueStore;
if (valueStore.supports(DisplayNameData.class)) {
System.out.println(valueStore.getOrNull(DisplayNameData.class
).displayName().get().toString());
}
The advantage of this returning an Optional
is that the
ValueContainer
may be unsupported, the required data missing
and ignoring the possibility of null
s, it is a guarantee that if
the Optional.isPresent()
is true
, the
ValueContainer
not only is supported, but there is already pre-
existing data for the ValueContainer
.
If it is necessary to ignore the Optional
,
Optional.orElse(Object)
can be used to return a potentially
null
ValueContainer
.
get
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
T
- The type of ValueContainer
containerClass
- The container classpublic <T> Optional<T> get(Key<? extends BaseValue<T>> key)
ValueContainer
BaseValue
linked to the provided Key
. If the Key
is not
supported, Optional.empty()
is returned. It is important
to check for support of a Key
by either calling
ValueContainer.supports(BaseValue)
or ValueContainer.supports(Key)
.get
in interface ValueContainer<DataHolder>
T
- The type of valuekey
- The key linking thepublic <T extends DataManipulator<?,?>> Optional<T> getOrCreate(Class<T> containerClass)
CompositeValueStore
Gets the desired ValueContainer
of type H
if the
ValueContainer
is compatible. If insufficient data is available
to provide a ValueContainer
with all Value
s preset, a
new instance of the ValueContainer
is returned with "default"
values. Since the return type is an Optional
, a short way of
checking compatibility and presence of the requested data is to mimic
the following:
// MyCompositeValueStore extends
CompositeValueStore<MyCompositeValueStore,
DataManipulator<?>>
MyCompositeValueStore valueStore;
final Optional<DisplayNameData> displayOptional =
valueStore.getOrCreate(DisplayNameData.class);
if (displayOptional.isPresent()) {
// We know that we have a present DataManipulator and it's
supported
System.out.println(displayOptional.get().displayName().get().toString()
);
}
This is the equivalent to performing the following:
MyCompositeValueStore valueStore;
if (valueStore.supports(DisplayNameData.class)) {
System.out.println(valueStore.get(DisplayNameData.class
).get().displayName().get().toString());
}
The advantage of this returning an Optional
is that the
ValueContainer
may be unsupported, the required data missing
and ignoring the possibility of null
s, it is a guarantee that if
the Optional.isPresent()
is true
, the
ValueContainer
not only is supported, but some default values
can be generated to create the desired ValueContainer
.
If it is necessary to ignore the Optional
,
Optional.orElse(Object)
can be used to return a potentially
null
ValueContainer
.
getOrCreate
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
T
- The type of ValueContainer
containerClass
- The container classpublic <T> DataTransactionResult offer(Key<? extends BaseValue<T>> key, T value)
CompositeValueStore
value
as defined by the provided Key
such that a DataTransactionResult
is returned for any
successful, rejected, and replaced BaseValue
s from this
CompositeValueStore
.offer
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
T
- The type of valuekey
- The key to the value to setvalue
- The value to setpublic DataTransactionResult offer(Iterable<DataManipulator<?,?>> valueHolders)
CompositeValueStore
ValueContainer
s to this
CompositeValueStore
much like CompositeValueStore.offer(ValueContainer)
except all in a single batch. The end result of the values successfully
offered, rejected, and replaced are stored in the returned
DataTransactionResult
.offer
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
valueHolders
- The values to setpublic DataTransactionResult offer(Iterable<DataManipulator<?,?>> values, MergeFunction function)
CompositeValueStore
ValueContainer
s to this
CompositeValueStore
much like CompositeValueStore.offer(ValueContainer)
except all in a single batch. The end result of the values successfully
offered, rejected, and replaced are stored in the returned
DataTransactionResult
. Any merge conflicts are resolved through
the MergeFunction
.offer
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
values
- The values to setfunction
- The function to resolve the valuespublic <T> DataTransactionResult offer(BaseValue<T> value)
CompositeValueStore
BaseValue
as defined by the provided
Key
such that a DataTransactionResult
is returned for
any successful, rejected, and replaced BaseValue
s from this
CompositeValueStore
.offer
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
T
- The type of the element wrapped by the valuevalue
- The value to setpublic DataTransactionResult offer(DataManipulator<?,?> valueContainer)
CompositeValueStore
ValueContainer
such that all of the available
BaseValue
s from the given ValueContainer
are offered
to this CompositeValueStore
. The end result of the values
successfully offered, rejected, and replaced are stored in the returned
DataTransactionResult
.offer
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
valueContainer
- The value to setpublic DataTransactionResult offer(DataManipulator<?,?> valueContainer, MergeFunction function)
CompositeValueStore
ValueContainer
such that all of the available
BaseValue
s from the given ValueContainer
are offered
to this CompositeValueStore
. The end result of the values
successfully offered, rejected, and replaced are stored in the returned
DataTransactionResult
. Any overlaps of data are merged via
the MergeFunction
.offer
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
valueContainer
- The value to setfunction
- The merge functionpublic DataTransactionResult undo(DataTransactionResult result)
CompositeValueStore
DataTransactionResult
such that any
of the DataTransactionResult.getReplacedData()
are offered
back, and any DataTransactionResult.getSuccessfulData()
are
removed if they were not the same types as any exising in the
replaced values.undo
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
result
- The result to undopublic boolean supports(Class<? extends DataManipulator<?,?>> holderClass)
CompositeValueStore
supports
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
holderClass
- The container classpublic boolean supports(Key<?> key)
ValueContainer
Key
is supported by this
ValueContainer
.supports
in interface ValueContainer<DataHolder>
key
- The key to checkpublic <T> DataTransactionResult transform(Key<? extends BaseValue<T>> key, Function<T,T> function)
CompositeValueStore
BaseValue
such that
the return value of Function.apply(Object)
will become the end
resulting value set into this CompositeValueStore
. It is not
necessary that the input is actually present, in which case the
Key
ed data is compatible, but not necessarily present. Writing
a Function
to properly handle the potential for a null input
is required for this method to execute without exception.transform
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
T
- The type of valuekey
- The key linked tofunction
- The function to manipulate the valuepublic DataTransactionResult copyFrom(DataHolder that)
CompositeValueStore
Value
s and
ValueContainer
s to this CompositeValueStore
such that
any overlapping Value
s are offered for replacement. The
result is provided as a DataTransactionResult
.copyFrom
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
that
- The other CompositeValueStore
to copy values frompublic DataTransactionResult copyFrom(DataHolder that, MergeFunction strategy)
CompositeValueStore
Value
s and
ValueContainer
s to this CompositeValueStore
such that
any overlapping Value
s are offered for replacement. The
result is provided as a DataTransactionResult
.copyFrom
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
that
- The other CompositeValueStore
to copy values fromstrategy
- The function to resolve merge conflictspublic Collection<DataManipulator<?,?>> getContainers()
CompositeValueStore
ValueContainer
s
belonging to this CompositeValueStore
. An individual
ValueContainer
can be used for data processing for various
purposes.getContainers
in interface CompositeValueStore<DataHolder,DataManipulator<?,?>>
ValueContainer
s originating
from this value storepublic <T,V extends BaseValue<T>> Optional<V> getValue(Key<V> key)
ValueContainer
getValue
in interface ValueContainer<DataHolder>
T
- The type of the return typeV
- The type of valuekey
- The key linked to the BaseValue
public Location<E> copy()
ValueContainer
ValueContainer
as a new
ValueContainer
such that all the BaseValue
s are
safely duplicated to the new instance.copy
in interface ValueContainer<DataHolder>
public Set<Key<?>> getKeys()
ValueContainer
Key
s for this ValueContainer
.
Changes can not be made to the set to alter the ValueContainer
,
nor can the BaseValue
s be changed with the provided
ImmutableSet
.getKeys
in interface ValueContainer<DataHolder>
Key
spublic Set<ImmutableValue<?>> getValues()
ValueContainer
BaseValue
s associated with this
ValueContainer
. As the data backed by the values are copied,
any modifications to the BaseValue
s will not be reflected onto
this ValueContainer
.getValues
in interface ValueContainer<DataHolder>