Wolfizen

"Enhanced" ImmutableDataManipulator code

Apr 22nd, 2016
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. public class ImmutableData<M extends DataManipulator<M, ImmutableData<M>>> implements ImmutableDataManipulator<ImmutableData<M>, M> {
  2.  
  3.     private final M mutable;
  4.  
  5.     /**
  6.      * Constructors a wrapper ImmutableData around the specified mutable copy.
  7.      * <p>
  8.      *     All calls to this ImmutableData will be relayed directly to an inner copy of {@link M}.
  9.      *     If a certain mutable manipulator is not side-effect free, they are required to extend this class and override the offending operations.
  10.      * </p>
  11.      *
  12.      * @param mutable The mutable version to represent
  13.      */
  14.     public ImmutableData(M mutable) {
  15.         this.mutable = mutable.copy();
  16.     }
  17.  
  18.     @Override
  19.     public M asMutable() {
  20.         return mutable.copy();
  21.     }
  22.  
  23.     @Override
  24.     public int compareTo(ImmutableData<M> o) {
  25.         return mutable.compareTo(o.mutable);
  26.     }
  27.  
  28.     @Override
  29.     public <E> Optional<E> get(Key<? extends BaseValue<E>> key) {
  30.         return mutable.get(key);
  31.     }
  32.  
  33.     @Override
  34.     public int getContentVersion() {
  35.         return mutable.getContentVersion();
  36.     }
  37.  
  38.     @Override
  39.     public Set<Key<?>> getKeys() {
  40.         return mutable.getKeys();
  41.     }
  42.  
  43.     @Override
  44.     public <E, V extends BaseValue<E>> Optional<V> getValue(Key<V> key) {
  45.         return mutable.getValue(key);
  46.     }
  47.  
  48.     @Override
  49.     public Set<ImmutableValue<?>> getValues() {
  50.         return mutable.getValues();
  51.     }
  52.  
  53.     @Override
  54.     public DataContainer toContainer() {
  55.         return mutable.toContainer();
  56.     }
  57.  
  58.     @Override
  59.     public boolean supports(BaseValue<?> baseValue) {
  60.         return mutable.supports(baseValue);
  61.     }
  62.  
  63.     @Override
  64.     public boolean supports(Key<?> key) {
  65.         return mutable.supports(key);
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment