Package org.spongepowered.api.data.value
Interface ValueContainer
-
- All Known Subinterfaces:
Aerial
,Ageable
,Agent
,Ambient
,Animal
,Aquatic
,Archetype<S,E>
,AreaEffectCloud
,ArmorStand
,Arrow
,ArrowEntity
,Banner
,Barrel
,Bat
,Beacon
,Bed
,Bee
,Beehive
,Bell
,BlastFurnace
,Blaze
,BlockEntity
,BlockEntityArchetype
,BlockEntityInventory<T>
,BlockOccupiedMinecart
,BlockSnapshot
,BlockState
,BlockType
,Boat
,Boss
,BrewingStand
,Campfire
,CarriedInventory<C>
,CarrierBlockEntity
,CarrierMinecart<M>
,Cat
,CaveSpider
,Chest
,ChestMinecart
,Chicken
,ClientPlayer
,Cod
,CommandBlock
,CommandBlockMinecart
,Comparator
,ComplexLiving<T>
,ComplexLivingPart<P>
,Conduit
,Container
,CopyableDataHolder
,CopyableValueContainer
,Cow
,CraftingGridInventory
,CraftingInventory
,CraftingOutput
,Creature
,Creeper
,DamagingProjectile
,DataHolder
,DataHolder.Immutable<I>
,DataHolder.Mutable
,DataManipulator
,DataManipulator.Immutable
,DataManipulator.Mutable
,DaylightDetector
,DirectionRelativeDataHolder
,DirectionRelativeDataHolder.Immutable<I>
,DirectionRelativeDataHolder.Mutable
,Dispenser
,Dolphin
,Donkey
,DragonFireball
,Dropper
,Drowned
,Egg
,ElderGuardian
,EmptyInventory
,EnchantmentTable
,EndCrystal
,EnderChest
,EnderDragon
,EnderDragonPart
,Enderman
,Endermite
,EnderPearl
,EndGateway
,EndPortal
,Entity
,EntityArchetype
,EntitySnapshot
,EntityTargetingProjectile
,EquipmentInventory
,EquipmentSlot
,Evoker
,EvokerFangs
,ExperienceBottle
,ExperienceOrb
,Explosive
,ExplosiveFireball
,EyeOfEnder
,FallingBlock
,FilteringSlot
,FireballEntity
,FireworkRocket
,Fish
,FishingBobber
,FluidStack
,FluidStackSnapshot
,FluidState
,FluidType
,Fox
,FuelSlot
,Furnace
,FurnaceBlockEntity
,FurnaceMinecart
,FusedExplosive
,Ghast
,Giant
,Golem
,GridInventory
,Guardian
,Hanging
,Hoglin
,Hopper
,HopperMinecart
,Horse
,HorseLike
,Hostile
,Hotbar
,Human
,Humanoid
,Husk
,Illager
,Illusioner
,InputSlot
,Inventory
,Inventory2D
,InventoryColumn
,InventoryRow
,IronGolem
,Item
,ItemFrame
,ItemStack
,ItemStackSnapshot
,ItemType
,Jigsaw
,Jukebox
,LeashKnot
,Lectern
,LightningBolt
,Living
,Llama
,LlamaLike
,LlamaSpit
,LocalPlayer
,LocatableBlock
,LocatableSnapshot<T>
,MagmaCube
,MapInfo
,Merchant
,Minecart
,MinecartLike
,MobSpawner
,Monster
,Mooshroom
,Mule
,NameableBlockEntity
,NameableCarrierBlockEntity
,Ocelot
,OutputSlot
,PackHorse
,Painting
,Panda
,Parrot
,Patroller
,PersistentInventory
,Phantom
,Pig
,Piglin
,PiglinBrute
,PiglinLike
,Pillager
,Piston
,Player
,PlayerInventory
,PolarBear
,Potion
,PrimaryPlayerInventory
,PrimedTNT
,Projectile
,Pufferfish
,Rabbit
,Raider
,Ranger
,Ravager
,RemotePlayer
,Salmon
,SchoolingFish
,SerializableDataHolder
,SerializableDataHolder.Immutable<I>
,SerializableDataHolder.Mutable
,ServerLocation
,ServerPlayer
,Sheep
,Shulker
,ShulkerBox
,ShulkerBullet
,SidedSlot
,Sign
,Silverfish
,Sittable
,Skeleton
,SkeletonHorse
,SkeletonLike
,Skull
,Slime
,Slot
,SmallFireball
,Smoker
,Snowball
,SnowGolem
,Spawner
,SpawnerMinecart
,SpectralArrow
,Spellcaster
,Spider
,Squid
,State<S>
,Stray
,Strider
,StructureBlock
,TameableAnimal
,TameableHorse
,TNTMinecart
,Trader
,TraderLlama
,TrappedChest
,Trident
,TropicalFish
,Turtle
,User
,UserInventory
,Vehicle
,Vex
,ViewableInventory
,Villager
,Vindicator
,WanderingTrader
,WeatherEffect
,Witch
,Wither
,WitherSkeleton
,WitherSkull
,Wolf
,Zoglin
,Zombie
,ZombieHorse
,ZombieLike
,ZombieVillager
,ZombifiedPiglin
public interface ValueContainer
A value holder is a holder of a particular set ofValue
s. While there exists aDataHolder
andDataManipulator
, the emphasis ofValueContainer
is that it only contains "data". It is not known whether aValueHolder
is mutable or immutable.Being that a
ValueHolder
is literally a container ofValue
s, it itself does not contain the underlying values of data. AValueContainer
may not always be parented by anotherValueContainer
, such as the case forDataManipulator
s andDataHolder.Mutable
s, it is recommended to knowingly understand the fundamental differences between them.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description <E> java.util.Optional<E>
get(Key<? extends Value<E>> key)
default java.util.OptionalDouble
getDouble(Key<? extends Value<java.lang.Double>> key)
default java.util.OptionalInt
getInt(Key<? extends Value<java.lang.Integer>> key)
java.util.Set<Key<?>>
getKeys()
Gets all applicableKey
s for thisValueContainer
.default java.util.OptionalLong
getLong(Key<? extends Value<java.lang.Long>> key)
default <E> E
getOrElse(Key<? extends Value<E>> key, E defaultValue)
Attempts to get the underlying value if available.default <E> @Nullable E
getOrNull(Key<? extends Value<E>> key)
Attempts to get the underlying value if available and supported.<E,V extends Value<E>>
java.util.Optional<V>getValue(Key<V> key)
java.util.Set<Value.Immutable<?>>
getValues()
Gets all applicableValue
s associated with thisValueContainer
.default <E> E
require(Key<? extends Value<E>> key)
default <E,V extends Value<E>>
VrequireValue(Key<V> key)
boolean
supports(Key<?> key)
Checks if the givenKey
is supported by thisValueContainer
.default boolean
supports(Value<?> value)
Checks if the providedValue
is supported.
-
-
-
Method Detail
-
get
<E> java.util.Optional<E> get(Key<? extends Value<E>> key)
Attempts to get the underlying value backed by aValue
linked to the providedKey
. If theKey
is not supported,Optional.empty()
is returned. It is important to check for support of aKey
by either callingsupports(Value)
orsupports(Key)
.- Type Parameters:
E
- The type of value- Parameters:
key
- The key to retrieve the value for- Returns:
- The value, if available
-
getInt
default java.util.OptionalInt getInt(Key<? extends Value<java.lang.Integer>> key)
Attempts to get the underlying int value backed by aValue
linked to the providedKey
. If theKey
is not supported,Optional.empty()
is returned. It is important to check for support of aKey
by either callingsupports(Value)
orsupports(Key)
.- Parameters:
key
- The key to retrieve the value for- Returns:
- The value, if available
-
getDouble
default java.util.OptionalDouble getDouble(Key<? extends Value<java.lang.Double>> key)
Attempts to get the underlying double value backed by aValue
linked to the providedKey
. If theKey
is not supported,Optional.empty()
is returned. It is important to check for support of aKey
by either callingsupports(Value)
orsupports(Key)
.- Parameters:
key
- The key to retrieve the value for- Returns:
- The value, if available
-
getLong
default java.util.OptionalLong getLong(Key<? extends Value<java.lang.Long>> key)
Attempts to get the underlying long value backed by aValue
linked to the providedKey
. If theKey
is not supported,Optional.empty()
is returned. It is important to check for support of aKey
by either callingsupports(Value)
orsupports(Key)
.- Parameters:
key
- The key to retrieve the value for- Returns:
- The value, if available
-
require
default <E> E require(Key<? extends Value<E>> key)
Attempts to get the underlying value backed by aValue
linked to the providedKey
.If the
Key
is not supported or available,NoSuchElementException
will be thrown.- Type Parameters:
E
- The type of value- Parameters:
key
- The key- Returns:
- The value
- Throws:
java.util.NoSuchElementException
- If the value is not supported or present
-
getOrNull
default <E> @Nullable E getOrNull(Key<? extends Value<E>> key)
Attempts to get the underlying value if available and supported. If theValue
is not supported whatsoever by thisValueContainer
, an exception is thrown.
-
getOrElse
default <E> E getOrElse(Key<? extends Value<E>> key, E defaultValue)
Attempts to get the underlying value if available. If the value is not set, the givendefaultValue
is returned, if theValue
is even supported.- Type Parameters:
E
- The type of value- Parameters:
key
- The key backing theValue
defaultValue
- The value to default to if not set- Returns:
- The value, or default if not set
-
getValue
<E,V extends Value<E>> java.util.Optional<V> getValue(Key<V> key)
- Type Parameters:
E
- The type of the return typeV
- The type of value- Parameters:
key
- The key linked to theValue
- Returns:
- The value, if available
-
requireValue
default <E,V extends Value<E>> V requireValue(Key<V> key)
Attempts to get the underlying value backed by aValue
linked to the providedKey
.If the
Key
is not supported or available,NoSuchElementException
will be thrown.- Type Parameters:
E
- The type of element wrapped by the valueV
- The type of value- Parameters:
key
- The key- Returns:
- The value
- Throws:
java.util.NoSuchElementException
- If the value is not supported or present
-
supports
boolean supports(Key<?> key)
Checks if the givenKey
is supported by thisValueContainer
.- Parameters:
key
- The key to check- Returns:
- True if the key and value backed by the key is supported
-
supports
default boolean supports(Value<?> value)
Checks if the providedValue
is supported.- Parameters:
value
- The base value to check- Returns:
- True if the base value is supported
-
getKeys
java.util.Set<Key<?>> getKeys()
Gets all applicableKey
s for thisValueContainer
. Changes can not be made to the set to alter theValueContainer
, nor can theValue
s be changed with the providedImmutableSet
.- Returns:
- An immutable set of known
Key
s
-
getValues
java.util.Set<Value.Immutable<?>> getValues()
Gets all applicableValue
s associated with thisValueContainer
. As the data backed by the values are copied, any modifications to theValue
s will not be reflected onto thisValueContainer
.- Returns:
- An immutable set of copied values
-
-