org.bukkit.metadata
Class LazyMetadataValue

java.lang.Object
  extended by org.bukkit.metadata.LazyMetadataValue
All Implemented Interfaces:
MetadataValue
Direct Known Subclasses:
FixedMetadataValue

public class LazyMetadataValue
extends Object
implements MetadataValue

The LazyMetadataValue class implements a type of metadata that is not computed until another plugin asks for it. By making metadata values lazy, no computation is done by the providing plugin until absolutely necessary (if ever). Additionally, LazyMetadataValue objects cache their values internally unless overridden by a LazyMetadataValue.CacheStrategy or invalidated at the individual or plugin level. Once invalidated, the LazyMetadataValue will recompute its value when asked.


Nested Class Summary
static class LazyMetadataValue.CacheStrategy
          Describes possible caching strategies for metadata.
 
Constructor Summary
LazyMetadataValue(Plugin owningPlugin, Callable<Object> lazyValue)
          Initialized a LazyMetadataValue object with the default CACHE_AFTER_FIRST_EVAL cache strategy.
LazyMetadataValue(Plugin owningPlugin, LazyMetadataValue.CacheStrategy cacheStrategy, Callable<Object> lazyValue)
          Initializes a LazyMetadataValue object with a specific cache strategy.
 
Method Summary
 boolean asBoolean()
          Attempts to convert the value of this metadata item into a boolean.
 byte asByte()
          Attempts to convert the value of this metadata item into a byte.
 double asDouble()
          Attempts to convert the value of this metadata item into a double.
 float asFloat()
          Attempts to convert the value of this metadata item into a float.
 int asInt()
          Attempts to convert the value of this metadata item into an int.
 long asLong()
          Attempts to convert the value of this metadata item into a long.
 short asShort()
          Attempts to convert the value of this metadata item into a short.
 String asString()
          Attempts to convert the value of this metadata item into a string.
 Plugin getOwningPlugin()
          Returns the Plugin that created this metadata item.
 void invalidate()
          Invalidates this metadata item, forcing it to recompute when next accessed.
 Object value()
          Fetches the value of this metadata item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LazyMetadataValue

public LazyMetadataValue(Plugin owningPlugin,
                         Callable<Object> lazyValue)
Initialized a LazyMetadataValue object with the default CACHE_AFTER_FIRST_EVAL cache strategy.

Parameters:
owningPlugin - the Plugin that created this metadata value.
lazyValue - the lazy value assigned to this metadata value.

LazyMetadataValue

public LazyMetadataValue(Plugin owningPlugin,
                         LazyMetadataValue.CacheStrategy cacheStrategy,
                         Callable<Object> lazyValue)
Initializes a LazyMetadataValue object with a specific cache strategy.

Parameters:
owningPlugin - the Plugin that created this metadata value.
cacheStrategy - determines the rules for caching this metadata value.
lazyValue - the lazy value assigned to this metadata value.
Method Detail

getOwningPlugin

public Plugin getOwningPlugin()
Description copied from interface: MetadataValue
Returns the Plugin that created this metadata item.

Specified by:
getOwningPlugin in interface MetadataValue
Returns:
the plugin that owns this metadata value. This should never be null.

value

public Object value()
Description copied from interface: MetadataValue
Fetches the value of this metadata item.

Specified by:
value in interface MetadataValue
Returns:
the metadata value.

asInt

public int asInt()
Description copied from interface: MetadataValue
Attempts to convert the value of this metadata item into an int.

Specified by:
asInt in interface MetadataValue
Returns:
the value as an int.

asFloat

public float asFloat()
Description copied from interface: MetadataValue
Attempts to convert the value of this metadata item into a float.

Specified by:
asFloat in interface MetadataValue
Returns:
the value as a float.

asDouble

public double asDouble()
Description copied from interface: MetadataValue
Attempts to convert the value of this metadata item into a double.

Specified by:
asDouble in interface MetadataValue
Returns:
the value as a double.

asLong

public long asLong()
Description copied from interface: MetadataValue
Attempts to convert the value of this metadata item into a long.

Specified by:
asLong in interface MetadataValue
Returns:
the value as a long.

asShort

public short asShort()
Description copied from interface: MetadataValue
Attempts to convert the value of this metadata item into a short.

Specified by:
asShort in interface MetadataValue
Returns:
the value as a short.

asByte

public byte asByte()
Description copied from interface: MetadataValue
Attempts to convert the value of this metadata item into a byte.

Specified by:
asByte in interface MetadataValue
Returns:
the value as a byte.

asBoolean

public boolean asBoolean()
Description copied from interface: MetadataValue
Attempts to convert the value of this metadata item into a boolean.

Specified by:
asBoolean in interface MetadataValue
Returns:
the value as a boolean.

asString

public String asString()
Description copied from interface: MetadataValue
Attempts to convert the value of this metadata item into a string.

Specified by:
asString in interface MetadataValue
Returns:
the value as a string.

invalidate

public void invalidate()
Description copied from interface: MetadataValue
Invalidates this metadata item, forcing it to recompute when next accessed.

Specified by:
invalidate in interface MetadataValue


Copyright © 2013. All Rights Reserved.