Wolfizen icon

"Enhanced" ImmutableDataManipulator code

Wolfizen | PRO | 04/22/16 06:18:01 AM UTC | 0 ⭐ | 226 👁️ | Never ⏰ | []
Java |

1.76 KB

|

None

|

0 👍

/

0 👎

public class ImmutableData<M extends DataManipulator<M, ImmutableData<M>>> implements ImmutableDataManipulator<ImmutableData<M>, M> {
 
    private final M mutable;
 
    /**
     * Constructors a wrapper ImmutableData around the specified mutable copy.
     * <p>
     *     All calls to this ImmutableData will be relayed directly to an inner copy of {@link M}.
     *     If a certain mutable manipulator is not side-effect free, they are required to extend this class and override the offending operations.
     * </p>
     *
     * @param mutable The mutable version to represent
     */
    public ImmutableData(M mutable) {
        this.mutable = mutable.copy();
    }
 
    @Override
    public M asMutable() {
        return mutable.copy();
    }
 
    @Override
    public int compareTo(ImmutableData<M> o) {
        return mutable.compareTo(o.mutable);
    }
 
    @Override
    public <E> Optional<E> get(Key<? extends BaseValue<E>> key) {
        return mutable.get(key);
    }
 
    @Override
    public int getContentVersion() {
        return mutable.getContentVersion();
    }
 
    @Override
    public Set<Key<?>> getKeys() {
        return mutable.getKeys();
    }
 
    @Override
    public <E, V extends BaseValue<E>> Optional<V> getValue(Key<V> key) {
        return mutable.getValue(key);
    }
 
    @Override
    public Set<ImmutableValue<?>> getValues() {
        return mutable.getValues();
    }
 
    @Override
    public DataContainer toContainer() {
        return mutable.toContainer();
    }
 
    @Override
    public boolean supports(BaseValue<?> baseValue) {
        return mutable.supports(baseValue);
    }
 
    @Override
    public boolean supports(Key<?> key) {
        return mutable.supports(key);
    }
}

Comments