diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TTreeSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/TTreeSet.java index de6f6cb68..30605ac50 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TTreeSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TTreeSet.java @@ -15,12 +15,17 @@ */ package org.teavm.classlib.java.util; +import org.teavm.classlib.java.lang.TCloneNotSupportedException; +import org.teavm.classlib.java.lang.TCloneable; +import org.teavm.classlib.java.lang.TObject; +import org.teavm.interop.Rename; + /** * * @author Alexey Andreev * @param */ -public class TTreeSet extends TAbstractSet implements TNavigableSet { +public class TTreeSet extends TAbstractSet implements TCloneable, TNavigableSet { private static final Object VALUE = new Object(); private TTreeMap map; @@ -66,6 +71,25 @@ public class TTreeSet extends TAbstractSet implements TNavigableSet { return map.keySet().iterator(); } + /** + * Returns a new {@code TreeSet} with the same elements and size as this + * {@code TreeSet}. + * + * @return a shallow copy of this {@code TreeSet}. + * @see java.lang.Cloneable + */ + @Rename("clone") + @SuppressWarnings("unchecked") + public TObject clone0() { + try { + TTreeSet clone = (TTreeSet) super.clone(); + clone.map = (TTreeMap) map.clone(); + return clone; + } catch (TCloneNotSupportedException e) { + return null; + } + } + @Override public void clear() { map.clear(); @@ -167,4 +191,9 @@ public class TTreeSet extends TAbstractSet implements TNavigableSet { public TNavigableSet tailSet(E fromElement, boolean inclusive) { return map.tailMap(fromElement, inclusive).navigableKeySet(); } + + @Override + public Object clone() { + return new TTreeSet<>(this); + } }