Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/org/spongepowered/api/block/BlockSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.spongepowered.api.data.SerializableDataHolderBuilder;
import org.spongepowered.api.data.persistence.DataContainer;
import org.spongepowered.api.data.persistence.DataView;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.data.value.ValueLike;
import org.spongepowered.api.world.BlockChangeFlag;
import org.spongepowered.api.world.LocatableSnapshot;
import org.spongepowered.api.world.schematic.Schematic;
Expand Down Expand Up @@ -157,7 +157,7 @@ interface Builder extends SerializableDataHolderBuilder.Immutable<BlockSnapshot,
/**
* Sets the {@link BlockState} for this {@link BlockSnapshot}.
*
* <p>This method should be called before calling {@link #add(Value)} or
* <p>This method should be called before calling {@link #add(ValueLike)} or
* any variant thereof.</p>
*
* @param blockState The BlockState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.spongepowered.api.data.persistence.DataContainer;
import org.spongepowered.api.data.persistence.DataView;
import org.spongepowered.api.data.persistence.InvalidDataException;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.data.value.ValueLike;
import org.spongepowered.api.world.Archetype;
import org.spongepowered.api.world.server.ServerLocation;

Expand Down Expand Up @@ -149,7 +149,7 @@ default Builder blockEntity(Supplier<? extends BlockEntityType> type) {
* <li>{@link #state(BlockState)}</li>
* <li>{@link #blockEntity(BlockEntityType)}</li>
* <li>{@link #blockEntityData(DataView)}</li>
* <li>{@link #add(Value)}</li>
* <li>{@link #add(ValueLike)}</li>
* <li>{@link #add(Key, Object)}</li>
* <li>{@link #add(DataManipulator)}</li>
* </ul>
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/org/spongepowered/api/data/CompositeKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.api.data;

import org.spongepowered.api.data.value.CompositeValue;

public interface CompositeKey<K, V extends CompositeValue<K, ?>> extends Key<V> {

@Override
CompositeKey<K, ? extends CompositeValue<K, ?>> root();

Parent<K, ? extends CompositeValue.Parent<K, ?>> parent();

Child<K, ? extends CompositeValue.Child<K, ?>> child(K valueKey);

interface Parent<K, V extends CompositeValue.Parent<K, ?>> extends CompositeKey<K, V> {

}

interface Child<K, V extends CompositeValue.Child<K, ?>> extends CompositeKey<K, V> {

K valueKey();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
package org.spongepowered.api.data;

import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.data.value.ValueLike;

/**
* Represents a {@link DataHolder} that can be copied.
Expand All @@ -33,7 +33,7 @@ public interface CopyableDataHolder extends DataHolder {

/**
* Creates a clone copy of this {@link CopyableDataHolder} as a new
* {@link CopyableDataHolder} such that all the {@link Value}s are
* {@link CopyableDataHolder} such that all the {@link ValueLike}s are
* safely duplicated to the new instance. It is not guaranteed that
* the returning container is of the same type as this container.
*
Expand Down
60 changes: 41 additions & 19 deletions src/main/java/org/spongepowered/api/data/DataHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
package org.spongepowered.api.data;

import org.spongepowered.api.data.value.CollectionValue;
import org.spongepowered.api.data.value.CompositeValue;
import org.spongepowered.api.data.value.MapValue;
import org.spongepowered.api.data.value.MergeFunction;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.data.value.ValueContainer;
import org.spongepowered.api.data.value.ValueLike;
import org.spongepowered.api.util.annotation.DoNotStore;

import java.util.Collection;
Expand Down Expand Up @@ -102,7 +104,13 @@ default <E> DataTransactionResult transform(Supplier<? extends Key<? extends Val
* @param <E> The type of value
* @return The transaction result
*/
<E> DataTransactionResult offer(Key<? extends Value<E>> key, E value);
default <E> DataTransactionResult offer(Key<? extends Value<E>> key, E value) {
return this.offer(Value.immutableOf(key, value));
}

default <K, E> DataTransactionResult offer(CompositeKey<K, ? extends CompositeValue<K, E>> key, K valueKey, E value) {
return this.offer(CompositeValue.immutableChildOf(key, valueKey, value));
}

/**
* Offers the given {@code value} as defined by the provided {@link Key}
Expand Down Expand Up @@ -135,15 +143,15 @@ default <E> DataTransactionResult offer(Supplier<? extends Key<? extends Value<E
}

/**
* Offers the given {@link Value} as defined by the provided
* Offers the given {@link ValueLike} as defined by the provided
* {@link Key} such that a {@link DataTransactionResult} is returned for
* any successful, rejected, and replaced {@link Value}s from this
* any successful, rejected, and replaced {@link ValueLike}s from this
* {@link Mutable}.
*
* @param value The value to set
* @return The transaction result
*/
DataTransactionResult offer(Value<?> value);
DataTransactionResult offer(ValueLike<?> value);

<E> DataTransactionResult offerSingle(Key<? extends CollectionValue<E, ?>> key, E element);

Expand Down Expand Up @@ -238,7 +246,7 @@ default <E> DataTransactionResult tryOffer(Supplier<? extends Key<? extends Valu
/**
* Offers the given {@code value} as defined by the provided {@link Key}
* such that a {@link DataTransactionResult} is returned for any
* successful {@link Value}s from this {@link Mutable}.
* successful {@link ValueLike}s from this {@link Mutable}.
* Intentionally, however, this differs from {@link #offer(Key, Object)}
* as it will intentionally throw an exception if the result was a failure.
*
Expand All @@ -248,16 +256,16 @@ default <E> DataTransactionResult tryOffer(Supplier<? extends Key<? extends Valu
* @throws IllegalArgumentException If the result is a failure likely due to
* incompatibility
*/
default <E> DataTransactionResult tryOffer(Value<E> value) throws IllegalArgumentException {
final DataTransactionResult result = this.offer(value.key(), value.get());
default <E> DataTransactionResult tryOffer(ValueLike<E> value) throws IllegalArgumentException {
final DataTransactionResult result = this.offer(value);
if (!result.isSuccessful()) {
throw new IllegalArgumentException("Failed offer transaction!");
}
return result;
}

/**
* Attempts to remove the provided {@link Value}. All values that were
* Attempts to remove the provided {@link ValueLike}. All values that were
* successfully removed will be provided in
* {@link DataTransactionResult#replacedData()}. If the data can not be
* removed, the result will be an expected
Expand All @@ -266,7 +274,7 @@ default <E> DataTransactionResult tryOffer(Value<E> value) throws IllegalArgumen
* @param value The value to remove
* @return The transaction result
*/
default DataTransactionResult remove(Value<?> value) {
default DataTransactionResult remove(ValueLike<?> value) {
return this.remove(value.key());
}

Expand All @@ -282,6 +290,10 @@ default DataTransactionResult remove(Value<?> value) {
*/
DataTransactionResult remove(Key<?> key);

default <K> DataTransactionResult remove(CompositeKey<K, ? extends CompositeValue<K, ?>> key, K valueKey) {
return this.remove(key.child(valueKey));
}

/**
* Attempts to remove the data associated with the provided {@link Key}.
* All values that were successfully removed will be provided in
Expand Down Expand Up @@ -309,9 +321,9 @@ default DataTransactionResult remove(Supplier<? extends Key<?>> key) {
DataTransactionResult undo(DataTransactionResult result);

/**
* Performs an absolute copy of all {@link org.spongepowered.api.data.value.Value.Mutable}s and
* Performs an absolute copy of all {@link org.spongepowered.api.data.value.ValueLike.Mutable}s and
* {@link ValueContainer}s to this {@link Mutable} such that
* any overlapping {@link org.spongepowered.api.data.value.Value.Mutable}s are offered for replacement. The
* any overlapping {@link org.spongepowered.api.data.value.ValueLike.Mutable}s are offered for replacement. The
* result is provided as a {@link DataTransactionResult}.
*
* @param that The other {@link Mutable} to copy values from
Expand All @@ -322,9 +334,9 @@ default DataTransactionResult copyFrom(ValueContainer that) {
}

/**
* Performs an absolute copy of all {@link org.spongepowered.api.data.value.Value.Mutable}s and
* Performs an absolute copy of all {@link org.spongepowered.api.data.value.ValueLike.Mutable}s and
* {@link ValueContainer}s to this {@link Mutable} such that
* any overlapping {@link org.spongepowered.api.data.value.Value.Mutable}s are offered for replacement. The
* any overlapping {@link org.spongepowered.api.data.value.ValueLike.Mutable}s are offered for replacement. The
* result is provided as a {@link DataTransactionResult}.
*
* @param that The other {@link Mutable} to copy values from
Expand Down Expand Up @@ -376,7 +388,13 @@ default <E> Optional<I> transform(Supplier<? extends Key<? extends Value<E>>> ke
* @param <E> The type of value
* @return The new immutable value store
*/
<E> Optional<I> with(Key<? extends Value<E>> key, E value);
default <E> Optional<I> with(Key<? extends Value<E>> key, E value) {
return this.with(Value.immutableOf(key, value));
}

default <K, E> Optional<I> with(CompositeKey<K, ? extends CompositeValue<K, E>> key, K valueKey, E value) {
return this.with(CompositeValue.immutableChildOf(key, valueKey, value));
}

/**
* Creates a new {@link Immutable} with the provided
Expand All @@ -400,17 +418,17 @@ default <E> Optional<I> with(Supplier<? extends Key<? extends Value<E>>> key, E
* @param value The value to set
* @return The new immutable value store
*/
Optional<I> with(Value<?> value);
Optional<I> with(ValueLike<?> value);

/**
* Creates a new {@link Immutable} without the key of the provided
* {@link Value}. If the key is supported by this value store,
* {@link ValueLike}. If the key is supported by this value store,
* the returned value store will be present.
*
* @param value The value
* @return The new immutable value store
*/
default Optional<I> without(Value<?> value) {
default Optional<I> without(ValueLike<?> value) {
return this.without(value.key());
}

Expand All @@ -424,6 +442,10 @@ default Optional<I> without(Value<?> value) {
*/
Optional<I> without(Key<?> key);

default <K> Optional<I> without(CompositeKey<K, ? extends CompositeValue<K, ?>> key, K valueKey) {
return this.without(key.child(valueKey));
}

/**
* Creates a new {@link Immutable} without the provided {@link Key}. If the
* key is supported by this value store, the returned value store will
Expand All @@ -437,7 +459,7 @@ default Optional<I> without(Supplier<? extends Key<?>> key) {
}

/**
* Attempts to merge the {@link org.spongepowered.api.data.value.Value.Immutable}s from this
* Attempts to merge the {@link org.spongepowered.api.data.value.ValueLike.Immutable}s from this
* {@link Immutable} and the given {@link Immutable} to
* produce a new instance of the merged result.
*
Expand All @@ -449,7 +471,7 @@ default I mergeWith(I that) {
}

/**
* Attempts to merge the {@link org.spongepowered.api.data.value.Value.Immutable}s from this
* Attempts to merge the {@link org.spongepowered.api.data.value.ValueLike.Immutable}s from this
* {@link Immutable} and the given {@link Immutable} to
* produce a new instance of the merged result. Any overlapping
* {@link ValueContainer}s are merged through the {@link MergeFunction}.
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/org/spongepowered/api/data/DataHolderBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package org.spongepowered.api.data;

import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.data.value.ValueLike;
import org.spongepowered.api.util.Builder;
import org.spongepowered.api.util.CopyableBuilder;

Expand All @@ -33,35 +34,32 @@
public interface DataHolderBuilder<H extends DataHolder, B extends DataHolderBuilder<H, B>> extends Builder<H, B>, CopyableBuilder<H, B> {

/**
* Adds the given {@link Value} to the builder. The
* {@link Value} is copied when the {@link DataHolder}
* Adds the given {@link ValueLike} to the builder. The
* {@link ValueLike} is copied when the {@link DataHolder}
* is created.
*
* @param value The value to add
* @return This builder, for chaining
*/
@SuppressWarnings({"unchecked", "rawtypes"})
default B add(Value<?> value) {
return (B) this.add((Key) value.key(), value.get());
}
B add(ValueLike<?> value);

/**
* Adds all the {@link Value}s to the builder. The
* {@link Value}s are copied when the {@link DataHolder}
* Adds all the {@link ValueLike}s to the builder. The
* {@link ValueLike}s are copied when the {@link DataHolder}
* is created.
*
* @param values The values to add
* @return This builder, for chaining
*/
@SuppressWarnings("unchecked")
default B add(Iterable<? extends Value<?>> values) {
default B add(Iterable<? extends ValueLike<?>> values) {
values.forEach(this::add);
return (B) this;
}

/**
* Adds all the {@link Value}s from the {@link DataManipulator}
* to the builder. The {@link Value}s are copied when the
* Adds all the {@link ValueLike}s from the {@link DataManipulator}
* to the builder. The {@link ValueLike}s are copied when the
* {@link DataHolder} is created.
*
* @param manipulator The manipulator to add
Expand All @@ -72,8 +70,8 @@ default B add(DataManipulator manipulator) {
}

/**
* Adds all the {@link Value}s from the {@link DataHolder}
* to the builder. The {@link Value}s are copied when the
* Adds all the {@link ValueLike}s from the {@link DataHolder}
* to the builder. The {@link ValueLike}s are copied when the
* {@link DataHolder} is created.
*
* @param dataHolder The data holder to add data from
Expand All @@ -91,7 +89,9 @@ default B addFrom(DataHolder dataHolder) {
* @param <V> The type of the value
* @return This builder, for chaining
*/
<V> B add(Key<? extends Value<V>> key, V value);
default <V> B add(Key<? extends Value<V>> key, V value) {
return this.add(Value.immutableOf(key, value));
}

/**
* Adds the given {@link Key} with the given value.
Expand Down
Loading
Loading