public boolean add(E e)
{
IdentityWrapper el = (new IdentityWrapper(e, set.size()));
- return set.putIfAbsent(el, el) == null;
+ // Map.putIfAbsent() from Java 8
+ // return set.putIfAbsent(el, el) == null;
+ return putIfAbsent(el, el) == null;
+ }
+
+ /**
+ * If the specified key is not already associated with a value (or is mapped
+ * to null) associates it with the given value and returns null, else returns
+ * the current value.
+ *
+ * Method added for Java 7 (can remove for Java 8)
+ *
+ * @param key
+ * @param value
+ * @return
+ * @see https
+ * ://docs.oracle.com/javase/8/docs/api/java/util/Map.html#putIfAbsent
+ * -K-V-
+ */
+ private IdentityWrapper putIfAbsent(IdentityWrapper key,
+ IdentityWrapper value)
+ {
+ IdentityWrapper v = set.get(key);
+ if (v == null)
+ {
+ v = set.put(key, value);
+ }
+ return v;
}
@Override
{
return (E) se.next().obj;
}
+
+ @Override
+ public void remove()
+ {
+ // Java 8 default behaviour
+ throw new UnsupportedOperationException();
+ }
};
}