Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.metadata.LazyMetadataValue Class Reference
Inheritance diagram for org.bukkit.metadata.LazyMetadataValue:
org.bukkit.metadata.MetadataValueAdapter org.bukkit.metadata.MetadataValue org.bukkit.metadata.MetadataValue org.bukkit.metadata.FixedMetadataValue


enum  CacheStrategy

Public Member Functions

 LazyMetadataValue (Plugin owningPlugin, Callable< Object > lazyValue)
 LazyMetadataValue (Plugin owningPlugin, CacheStrategy cacheStrategy, Callable< Object > lazyValue)
Object value ()
synchronized void invalidate ()

Protected Member Functions

 LazyMetadataValue (Plugin owningPlugin)

Additional Inherited Members

Detailed Description

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 CacheStrategy or invalidated at the individual or plugin level. Once invalidated, the LazyMetadataValue will recompute its value when asked.

Definition at line 20 of file LazyMetadataValue.java.

Constructor & Destructor Documentation

org.bukkit.metadata.LazyMetadataValue.LazyMetadataValue ( Plugin  owningPlugin,
Callable< Object >  lazyValue 

Initialized a LazyMetadataValue object with the default CACHE_AFTER_FIRST_EVAL cache strategy.

owningPluginthe Plugin that created this metadata value.
lazyValuethe lazy value assigned to this metadata value.

Definition at line 34 of file LazyMetadataValue.java.

References org.bukkit.metadata.LazyMetadataValue.CacheStrategy.CACHE_AFTER_FIRST_EVAL.

34  {
35  this(owningPlugin, CacheStrategy.CACHE_AFTER_FIRST_EVAL, lazyValue);
36  }
org.bukkit.metadata.LazyMetadataValue.LazyMetadataValue ( Plugin  owningPlugin,
CacheStrategy  cacheStrategy,
Callable< Object >  lazyValue 

Initializes a LazyMetadataValue object with a specific cache strategy.

owningPluginthe Plugin that created this metadata value.
cacheStrategydetermines the rules for caching this metadata value.
lazyValuethe lazy value assigned to this metadata value.

Definition at line 47 of file LazyMetadataValue.java.

47  {
48  super(owningPlugin);
49  Validate.notNull(cacheStrategy, "cacheStrategy cannot be null");
50  Validate.notNull(lazyValue, "lazyValue cannot be null");
51  this.internalValue = new SoftReference<Object>(null);
52  this.lazyValue = lazyValue;
53  this.cacheStrategy = cacheStrategy;
54  }
org.bukkit.metadata.LazyMetadataValue.LazyMetadataValue ( Plugin  owningPlugin)

Protected special constructor used by FixedMetadataValue to bypass standard setup.

Definition at line 60 of file LazyMetadataValue.java.

60  {
61  super(owningPlugin);
62  }

Member Function Documentation

synchronized void org.bukkit.metadata.LazyMetadataValue.invalidate ( )

Invalidates this metadata item, forcing it to recompute when next accessed.

Implements org.bukkit.metadata.MetadataValue.

Definition at line 93 of file LazyMetadataValue.java.

References org.bukkit.metadata.LazyMetadataValue.CacheStrategy.CACHE_ETERNALLY.

93  {
94  if (cacheStrategy != CacheStrategy.CACHE_ETERNALLY) {
95  internalValue.clear();
96  }
97  }
Object org.bukkit.metadata.LazyMetadataValue.value ( )

Fetches the value of this metadata item.

the metadata value.

Implements org.bukkit.metadata.MetadataValue.

Definition at line 64 of file LazyMetadataValue.java.

64  {
65  eval();
66  Object value = internalValue.get();
67  if (value == ACTUALLY_NULL) {
68  return null;
69  }
70  return value;
71  }

The documentation for this class was generated from the following file: