- java.lang.Object
-
- com.aoapps.lang.attribute.Attribute<C,T>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAttribute.Name<T>A name without any specific scope or context.static classAttribute.OldValueA backup value from before attribute initialization, which must beclosedto restore the old value.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <T> Attribute.Name<T>attribute(String name)Attribute: Uses the given name, still needs scope or context.abstract <Ex extends Throwable>
Tcompute(BiFunctionE<? super String,? super T,? extends T,? extends Ex> remappingFunction)Much likeMap.compute(java.lang.Object, java.util.function.BiFunction), but for this attribute.abstract <Ex extends Throwable>
TcomputeIfAbsent(FunctionE<? super String,? extends T,? extends Ex> mappingFunction)Much likeMap.computeIfAbsent(java.lang.Object, java.util.function.Function), but for this attribute.abstract <Ex extends Throwable>
TcomputeIfPresent(BiFunctionE<? super String,? super T,? extends T,? extends Ex> remappingFunction)Much likeMap.computeIfPresent(java.lang.Object, java.util.function.BiFunction), but for this attribute.abstract Tget()Gets the value of this attribute.abstract Context<C>getContext()Gets the context for this attribute.StringgetName()Gets the attribute name.abstract TgetOrDefault(T defaultValue)Much likeMap.getOrDefault(java.lang.Object, java.lang.Object), but for this attribute.abstract Attribute.OldValueinit(T value)Initializes this attribute, returning a backup value, which must beclosedto restore the old value.abstract <Ex extends Throwable>
Tmerge(T value, BiFunctionE<? super T,? super T,? extends T,? extends Ex> remappingFunction)Much likeMap.merge(java.lang.Object, java.lang.Object, java.util.function.BiFunction), but for this attribute.abstract voidremove()Removes the value from this attribute.abstract booleanremove(T value)Much likeMap.remove(java.lang.Object, java.lang.Object), but for this attribute.abstract Treplace(T value)Much likeMap.replace(java.lang.Object, java.lang.Object), but for this attribute.abstract booleanreplace(T oldValue, T newValue)Much likeMap.replace(java.lang.Object, java.lang.Object, java.lang.Object), but for this attribute.abstract voidset(T value)Sets the value of this attribute.abstract TsetIfAbsent(T value)Much likeMap.putIfAbsent(java.lang.Object, java.lang.Object), but for this attribute.
-
-
-
Field Detail
-
name
protected final String name
-
-
Constructor Detail
-
Attribute
protected Attribute(String name)
-
-
Method Detail
-
getContext
public abstract Context<C> getContext()
Gets the context for this attribute.- Returns:
- the context or
nullwhen none
-
getName
public String getName()
Gets the attribute name.
-
init
public abstract Attribute.OldValue init(T value)
Initializes this attribute, returning a backup value, which must beclosedto restore the old value. This is best used in try-with-resources.
-
compute
public abstract <Ex extends Throwable> T compute(BiFunctionE<? super String,? super T,? extends T,? extends Ex> remappingFunction) throws Ex extends Throwable
Much likeMap.compute(java.lang.Object, java.util.function.BiFunction), but for this attribute. Synchronizes on context to ensure atomic operation.- Throws:
Ex extends Throwable- See Also:
Map.compute(java.lang.Object, java.util.function.BiFunction)
-
computeIfAbsent
public abstract <Ex extends Throwable> T computeIfAbsent(FunctionE<? super String,? extends T,? extends Ex> mappingFunction) throws Ex extends Throwable
Much likeMap.computeIfAbsent(java.lang.Object, java.util.function.Function), but for this attribute. Synchronizes on context to ensure atomic operation.- Throws:
Ex extends Throwable- See Also:
Map.computeIfAbsent(java.lang.Object, java.util.function.Function)
-
computeIfPresent
public abstract <Ex extends Throwable> T computeIfPresent(BiFunctionE<? super String,? super T,? extends T,? extends Ex> remappingFunction) throws Ex extends Throwable
Much likeMap.computeIfPresent(java.lang.Object, java.util.function.BiFunction), but for this attribute. Synchronizes on context to ensure atomic operation.- Throws:
Ex extends Throwable- See Also:
Map.computeIfPresent(java.lang.Object, java.util.function.BiFunction)
-
get
public abstract T get()
Gets the value of this attribute.- Returns:
getContext()may benull, which will returnnull
-
getOrDefault
public abstract T getOrDefault(T defaultValue)
Much likeMap.getOrDefault(java.lang.Object, java.lang.Object), but for this attribute.- Returns:
getContext()may benull, which will returndefaultValue- See Also:
Map.getOrDefault(java.lang.Object, java.lang.Object)
-
merge
public abstract <Ex extends Throwable> T merge(T value, BiFunctionE<? super T,? super T,? extends T,? extends Ex> remappingFunction) throws Ex extends Throwable
Much likeMap.merge(java.lang.Object, java.lang.Object, java.util.function.BiFunction), but for this attribute. Synchronizes on context to ensure atomic operation.- Throws:
Ex extends Throwable- See Also:
Map.merge(java.lang.Object, java.lang.Object, java.util.function.BiFunction)
-
remove
public abstract void remove()
Removes the value from this attribute.getContext()may benull, which will skip removal
-
remove
public abstract boolean remove(T value)
Much likeMap.remove(java.lang.Object, java.lang.Object), but for this attribute. Synchronizes on context to ensure atomic operation.
-
replace
public abstract T replace(T value)
Much likeMap.replace(java.lang.Object, java.lang.Object), but for this attribute. Synchronizes on context to ensure atomic operation.
-
replace
public abstract boolean replace(T oldValue, T newValue)
Much likeMap.replace(java.lang.Object, java.lang.Object, java.lang.Object), but for this attribute. Synchronizes on context to ensure atomic operation.
-
set
public abstract void set(T value)
Sets the value of this attribute.
-
setIfAbsent
public abstract T setIfAbsent(T value)
Much likeMap.putIfAbsent(java.lang.Object, java.lang.Object), but for this attribute. Synchronizes on context to ensure atomic operation.
-
attribute
public static <T> Attribute.Name<T> attribute(String name)
Attribute: Uses the given name, still needs scope or context.
-
-