protected void clear() { synchronized (this) { ConfigValue oldValue = this.value; value = new NullConfigValue(this); oldValue.clear(); } } // }}}
@Override public <T> List<T> getList(Function<Object, T> transformer) { final ImmutableList.Builder<T> build = ImmutableList.builder(); ConfigValue value = this.value; if (value instanceof ListConfigValue) { for (SimpleConfigurationNode o : value.iterateChildren()) { T transformed = transformer.apply(o.getValue()); if (transformed != null) { build.add(transformed); } } } else { T transformed = transformer.apply(value.getValue()); if (transformed != null) { build.add(transformed); } } return build.build(); }
@Override public boolean removeChild(Object key) { return possiblyDetach(value.putChild(key, null)) != null; }
newValue = new ListConfigValue(this, oldValue.getValue()); SimpleConfigurationNode oldChild = newValue.putChildIfAbsent(child.key, child); if (oldChild != null) { return oldChild; detachIfNonNull(newValue.putChild(child.key, child)); value = newValue; oldValue.clear();
protected SimpleConfigurationNode getChild(Object key, boolean attach) { SimpleConfigurationNode child = value.getChild(key); if (child == null) { // Does not currently exist! if (attach) { attachIfNecessary(); SimpleConfigurationNode existingChild = value.putChildIfAbsent(key, (child = createNode(key))); if (existingChild != null) { child = existingChild; } else { attachChild(child); } } else { child = createNode(key); } } return child; }
newValue = new ListConfigValue(this, oldValue.getValue()); SimpleConfigurationNode oldChild = newValue.putChildIfAbsent(child.key, child); if (oldChild != null) { return oldChild; oldValue.clear();
protected void attachChild(SimpleConfigurationNode child) { if (isVirtual()) { throw new IllegalStateException("This parent is not currently attached. This is an internal state violation."); } if (!child.getParentAttached().equals(this)) { throw new IllegalStateException("Child " + child + " path is not a direct parent of me (" + this + "), cannot attach"); } ConfigValue oldValue, newValue; synchronized (this) { newValue = oldValue = this.value; if (!(oldValue instanceof MapConfigValue)) { if (child.key instanceof Integer) { if (oldValue instanceof NullConfigValue) { newValue = new ListConfigValue(this); } else if (!(oldValue instanceof ListConfigValue)) { newValue = new ListConfigValue(this, oldValue.getValue()); } } else { newValue = new MapConfigValue(this); } } possiblyDetach(newValue.putChild(child.key, child)); value = newValue; } if (newValue != oldValue) { oldValue.clear(); } child.attached = true; }
@Override public Object getValue(Object def) { Object ret = value.getValue(); return ret == null ? storeDefault(def) : ret; }
void clear() { for (Iterator<SimpleConfigurationNode> it = iterateChildren().iterator(); it.hasNext();) { SimpleConfigurationNode node = it.next(); node.attached = false; it.remove(); if (node.getParentAttached().equals(holder)) { node.clear(); } } }
private void insertNewValue(Object newValue, boolean onlyIfNull) { attachIfNecessary(); synchronized (this) { ConfigValue oldValue, value; oldValue = value = this.value; if (onlyIfNull && !(oldValue instanceof NullConfigValue)){ return; } if (newValue instanceof Collection) { if (!(value instanceof ListConfigValue)) { value = new ListConfigValue(this); } } else if (newValue instanceof Map) { if (!(value instanceof MapConfigValue)) { value = new MapConfigValue(this); } } else if (!(value instanceof ScalarConfigValue)) { value = new ScalarConfigValue(this); } value.setValue(newValue); /*if (oldValue != null && oldValue != value) { oldValue.clear(); }*/ this.value = value; } }
newChild.attached = true; newChild.setValue(ent.getValue()); SimpleConfigurationNode existing = newValue.putChildIfAbsent(ent.getKey(), newChild); if (existing != null) { existing.mergeValuesFrom(newChild);
protected SimpleConfigurationNode(SimpleConfigurationNode parent, SimpleConfigurationNode copyOf) { this.options = copyOf.options; this.attached = true; // copies are always attached this.key = copyOf.key; this.parent = parent; this.value = copyOf.value.copy(this); }
@NonNull @Override public ValueType getValueType() { return this.value.getType(); }
newValue = new ListConfigValue(this, oldValue.getValue()); SimpleConfigurationNode oldChild = newValue.putChildIfAbsent(child.key, child); if (oldChild != null) { return oldChild; detachIfNonNull(newValue.putChild(child.key, child)); value = newValue; oldValue.clear();
/** * Gets a child node, relative to this. * * @param key The key * @param attach If the resultant node should be automatically attached * @return The child node */ protected SimpleConfigurationNode getChild(Object key, boolean attach) { SimpleConfigurationNode child = value.getChild(key); // child doesn't currently exist if (child == null) { if (attach) { // attach ourselves first attachIfNecessary(); // insert the child node into the value SimpleConfigurationNode existingChild = value.putChildIfAbsent(key, (child = createNode(key))); if (existingChild != null) { child = existingChild; } else { attachChild(child); } } else { // just create a new virtual (detached) node child = createNode(key); } } return child; }
@Override public Object getValue(Object def) { Object ret = value.getValue(); return ret == null ? calculateDef(def) : ret; }
/** * Clears the set value (or any attached child values) from this value */ void clear() { for (Iterator<SimpleConfigurationNode> it = iterateChildren().iterator(); it.hasNext();) { SimpleConfigurationNode node = it.next(); node.attached = false; it.remove(); if (node.getParentEnsureAttached().equals(holder)) { node.clear(); } } }
value.setValue(newValue);
newChild.setValue(ent.getValue()); SimpleConfigurationNode existing = newValue.putChildIfAbsent(ent.getKey(), newChild);
/** * Gets a child node, relative to this. * * @param key The key * @param attach If the resultant node should be automatically attached * @return The child node */ protected SimpleConfigurationNode getChild(Object key, boolean attach) { SimpleConfigurationNode child = value.getChild(key); // child doesn't currently exist if (child == null) { if (attach) { // attach ourselves first attachIfNecessary(); // insert the child node into the value SimpleConfigurationNode existingChild = value.putChildIfAbsent(key, (child = createNode(key))); if (existingChild != null) { child = existingChild; } else { attachChild(child); } } else { // just create a new virtual (detached) node child = createNode(key); } } return child; }