/** * Exists. * * @param state * the {@link State} to search for this {@link StateEntry} * @return {@code true} is specified {@code state} contains this * {@link StateEntry}'s key, {@code false} otherwise * @see java.util.Map#containsKey(Object) */ public boolean exists(final State state) { return state.containsKey(getKey()); }
/** * Put value if unchanged. * * @param state * the {@link State} to update with specified {@code value} * @param newValue * the new value for this {@link StateEntry} in specified * @param currentValue * the current/precondition value for this {@link StateEntry} in * specified {@code state} * @return the previous value or {@code null} if none existed {@code state} */ public boolean putValueIfUnchanged(final State state, final T newValue, final T currentValue) { return state.putIfUnchanged(getKey(), newValue, currentValue); }
/** * Gets the value. * * @param state * the {@link State} from which to retrieve this * @return the value retrieved from specified {@code state} or {@code null} * if none exists {@code StateEntry}'s value * @see java.util.Map#get(Object) */ public T getValue(final State state) { try { return state.get(getKey(), valueType); } catch (final ClassCastException e) { LOG.log(Level.WARNING, "Problem casting agent's state value, key: " + key, e); return null; } }
/** * Put value. * * @param state * the {@link State} to update with specified {@code value} * @param value * the new value for this {@link StateEntry} in specified * @return the previous value or {@code null} if none existed {@code state} * @see java.util.Map#put(Object, Object) */ public T putValue(final State state, final T value) { try { return TypeUtil.inject(state.put(getKey(), value), valueType); } catch (final ClassCastException e) { LOG.log(Level.WARNING, "Problem casting agent's previous state value, key: " + key, e); return null; } }