From 7fc7484218653f84479934b65ec646d9a329b73f Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 5 Sep 2016 16:30:03 +0100 Subject: [PATCH] JAL-2154 made Java 7 compatible --- src/jalview/util/LinkedIdentityHashSet.java | 36 ++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/jalview/util/LinkedIdentityHashSet.java b/src/jalview/util/LinkedIdentityHashSet.java index 5cdbeb1..bce540f 100644 --- a/src/jalview/util/LinkedIdentityHashSet.java +++ b/src/jalview/util/LinkedIdentityHashSet.java @@ -65,7 +65,34 @@ public class LinkedIdentityHashSet extends AbstractSet 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 @@ -87,6 +114,13 @@ public class LinkedIdentityHashSet extends AbstractSet { return (E) se.next().obj; } + + @Override + public void remove() + { + // Java 8 default behaviour + throw new UnsupportedOperationException(); + } }; } -- 1.7.10.2