org.bukkit.metadata
Class LazyMetadataValue

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

public class LazyMetadataValue
extends MetadataValueAdapter
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.
 
Field Summary
 
Fields inherited from class org.bukkit.metadata.MetadataValueAdapter
owningPlugin
 
Constructor Summary
protected LazyMetadataValue(Plugin owningPlugin)
          Protected special constructor used by FixedMetadataValue to bypass standard setup.
  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
 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 org.bukkit.metadata.MetadataValueAdapter
asBoolean, asByte, asDouble, asFloat, asInt, asLong, asShort, asString, getOwningPlugin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.bukkit.metadata.MetadataValue
asBoolean, asByte, asDouble, asFloat, asInt, asLong, asShort, asString, getOwningPlugin
 

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.

LazyMetadataValue

protected LazyMetadataValue(Plugin owningPlugin)
Protected special constructor used by FixedMetadataValue to bypass standard setup.

Method Detail

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.

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 © 2014. All rights reserved.