import static org.opendaylight.yangtools.triemap.PresencePredicate.ABSENT;
import static org.opendaylight.yangtools.triemap.PresencePredicate.PRESENT;
+import com.google.common.base.VerifyException;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
final CNode<K, V> rn = (cn.gen == gen) ? cn : cn.renewed(gen, ct);
final MainNode<K, V> nn = rn.updatedAt(pos, inode(CNode.dual(sn, k, v, hc, lev + LEVEL_BITS, gen)), gen);
return GCAS (cn, nn, ct);
+ } else {
+ throw CNode.invalidElement(cnAtPos);
}
- } else {
- final CNode<K, V> rn = (cn.gen == gen) ? cn : cn.renewed(gen, ct);
- final MainNode<K, V> ncnode = rn.insertedAt(pos, flag, new SNode<>(k, v, hc), gen);
- return GCAS (cn, ncnode, ct);
}
+
+ final CNode<K, V> rn = (cn.gen == gen) ? cn : cn.renewed(gen, ct);
+ final MainNode<K, V> ncnode = rn.insertedAt(pos, flag, new SNode<>(k, v, hc), gen);
+ return GCAS (cn, ncnode, ct);
} else if (m instanceof TNode) {
clean(parent, ct, lev - LEVEL_BITS);
return false;
final LNodeEntry<K, V> entry = ln.get(ct.equiv(), k);
return entry != null ? replaceln(ln, entry, v, ct) : insertln(ln, k, v, ct);
} else {
- throw new IllegalStateException("Unhandled node " + m);
+ throw invalidElement(m);
}
-
- throw new RuntimeException ("Should not happen");
}
}
+ private static VerifyException invalidElement(final BasicNode elem) {
+ throw new VerifyException("An INode can host only a CNode, a TNode or an LNode, not " + elem);
+ }
+
/**
* Inserts a new key value pair, given that a specific condition is met.
*
return Optional.empty();
}
+ } else {
+ throw CNode.invalidElement(cnAtPos);
}
} else if (cond == null || cond == ABSENT) {
final CNode<K, V> rn = (cn.gen == gen) ? cn : cn.renewed(gen, ct);
return replaceln(ln, entry, v, ct) ? Optional.of(entry.getValue()) : null;
}
} else {
- throw new IllegalStateException("Unhandled node " + m);
+ throw invalidElement(m);
}
-
- throw new RuntimeException("Should never happen");
}
}
}
return null;
+ } else {
+ throw CNode.invalidElement(sub);
}
} else if (m instanceof TNode) {
// 3) non-live node
final LNodeEntry<K, V> entry = ((LNode<K, V>) m).get(ct.equiv(), k);
return entry != null ? entry.getValue() : null;
} else {
- throw new IllegalStateException("Unhandled node " + m);
+ throw invalidElement(m);
}
-
- throw new RuntimeException ("Should not happen");
}
}
final int pos = Integer.bitCount(bmp & (flag - 1));
final BasicNode sub = cn.array[pos];
- Optional<V> res = null;
+ final Optional<V> res;
if (sub instanceof INode) {
final INode<K, V> in = (INode<K, V>) sub;
if (startgen == in.gen) {
res = in.rec_remove(k, cond, hc, lev + LEVEL_BITS, this, startgen, ct);
} else {
- if (GCAS(cn, cn.renewed (startgen, ct), ct)) {
+ if (GCAS(cn, cn.renewed(startgen, ct), ct)) {
res = rec_remove(k, cond, hc, lev, parent, startgen, ct);
} else {
res = null;
}
}
-
} else if (sub instanceof SNode) {
final SNode<K, V> sn = (SNode<K, V>) sub;
if (sn.hc == hc && ct.equal(sn.k, k) && (cond == null || cond.equals(sn.v))) {
} else {
res = Optional.empty();
}
+ } else {
+ throw CNode.invalidElement(sub);
}
if (res == null || !res.isPresent()) {
return GCAS(ln, ln.removeChild(entry, hc), ct) ? Optional.of(value) : null;
} else {
- throw new IllegalStateException("Unhandled node " + m);
+ throw invalidElement(m);
}
}