All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.grignaak.collections.Change Maven / Gradle / Ivy

The newest version!
package com.github.grignaak.collections;

/**
 * This gets passed to nodes during an update so the inner leaves can return modification
 * state. It is common for builders to keep one of these and use it on every mutate.
 *
 * 

Invariants

*
    *
  • isReplaced implies isModified
  • *
  • replacedValue != null implies isReplaced
  • *
*/ class Change { private V replacedValue; private boolean isModified; private boolean isReplaced; public boolean isModified() { return isModified; } public boolean isReplaced() { return isReplaced; } public void modified() { this.isModified = true; } public void updated(V replacement) { this.replacedValue = replacement; this.isReplaced = true; this.isModified = true; } public V getAndClear() { V ret = replacedValue; replacedValue = null; isModified = false; isReplaced = false; return ret; } public boolean isModifiedAndClear() { boolean wasModified = isModified; replacedValue = null; isModified = false; isReplaced = false; return wasModified; } @Override public String toString() { if (isReplaced) return String.format("Replaced{%s}", replacedValue); else if (isModified) return "Modified"; else return "Unchanged"; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy