/** * Replaces given metadata with new {@code newVal} value only if its current value is equal to {@code curVal}. * Otherwise, it is no-op. * * @param key Key of the metadata. * @param curVal Current value to check. * @param newVal New value. * @return {@code true} if replacement occurred, {@code false} otherwise. */ @SuppressWarnings({"RedundantTypeArguments"}) public <V> boolean replaceMeta(int key, V curVal, V newVal) { assert newVal != null; assert curVal != null; synchronized (this) { if (hasMeta(key)) { V val = this.<V>meta(key); if (val != null && val.equals(curVal)) { addMeta(key, newVal); return true; } } return false; } }
/** * Replaces given metadata with new {@code newVal} value only if its current value is equal to {@code curVal}. * Otherwise, it is no-op. * * @param key Key of the metadata. * @param curVal Current value to check. * @param newVal New value. * @return {@code true} if replacement occurred, {@code false} otherwise. */ @SuppressWarnings({"RedundantTypeArguments"}) public <V> boolean replaceMeta(int key, V curVal, V newVal) { assert newVal != null; assert curVal != null; synchronized (this) { if (hasMeta(key)) { V val = this.<V>meta(key); if (val != null && val.equals(curVal)) { addMeta(key, newVal); return true; } } return false; } }