@@ -291,7 +291,43 @@ public final List<A> toList() {
291291 return foldMap (List .cons (List .<A >nil ()), Monoid .<A >listMonoid ());
292292 }
293293
294- /**
294+ /**
295+ * Returns a java.util.Set representation of this set.
296+ *
297+ * @return a java.util.Set representation of this set.
298+ */
299+ public final java .util .Set <A > toJavaSet () {
300+ return toJavaHashSet ();
301+ }
302+
303+ /**
304+ * Returns a java.util.HashSet representation of this set.
305+ *
306+ * @return a java.util.HashSet representation of this set.
307+ */
308+ public final java .util .HashSet <A > toJavaHashSet () {
309+ return new java .util .HashSet <A >(toStream ().toCollection ());
310+ }
311+
312+ /**
313+ * Returns a java.util.TreeSet representation of this set.
314+ *
315+ * @return a java.util.TreeSet representation of this set.
316+ */
317+ public final java .util .TreeSet <A > toJavaTreeSet () {
318+ return new java .util .TreeSet <A >(toStream ().toCollection ());
319+ }
320+
321+ /**
322+ * Returns a java.util.List representation of this set.
323+ *
324+ * @return a java.util.List representation of this set.
325+ */
326+ public final java .util .List toJavaList () {
327+ return new java .util .ArrayList <A >(toStream ().toCollection ());
328+ }
329+
330+ /**
295331 * Returns a list representation of this set in reverse order.
296332 *
297333 * @return a list representation of this set in reverse order.
@@ -509,17 +545,53 @@ public static <A> Set<A> join(final Ord<A> o, final Set<Set<A>> s) {
509545 /**
510546 * Return the elements of the given iterable as a set.
511547 *
548+ * @deprecated As of release 4.5, use {@link #fromIterable}
549+ *
512550 * @param o An order for the elements of the new set.
513551 * @param as An iterable of elements to add to a set.
514552 * @return A new set containing the elements of the given iterable.
515553 */
554+ @ Deprecated
516555 public static <A > Set <A > iterableSet (final Ord <A > o , final Iterable <A > as ) {
556+ return fromIterable (o , as );
557+ }
558+
559+ /**
560+ * Return the elements of the given iterable as a set.
561+ *
562+ * @param o An order for the elements of the new set.
563+ * @param as An iterable of elements to add to a set.
564+ * @return A new set containing the elements of the given iterable.
565+ */
566+ public static <A > Set <A > fromIterable (final Ord <A > o , final Iterable <A > as ) {
517567 Set <A > s = empty (o );
518568 for (final A a : as )
519569 s = s .insert (a );
520570 return s ;
521571 }
522572
573+ /**
574+ * Return the elements of the given java.util.Set as a set.
575+ *
576+ * @param o An order for the elements of the new set.
577+ * @param as A set of elements to create the set.
578+ * @return A new set containing the elements of the given set.
579+ */
580+ public static <A > Set <A > fromJavaSet (final Ord <A > o , final java .util .Set <A > as ) {
581+ return fromIterable (o , as );
582+ }
583+
584+ /**
585+ * Return the elements of the given iterator as a set.
586+ *
587+ * @param o An order for the elements of the new set.
588+ * @param as An iterator of elements to add to a set.
589+ * @return A new set containing the elements of the given iterator.
590+ */
591+ public static <A > Set <A > fromIterator (final Ord <A > o , final Iterator <A > as ) {
592+ return fromIterable (o , () -> as );
593+ }
594+
523595 /**
524596 * Constructs a set from the given elements.
525597 *
@@ -535,17 +607,24 @@ public static <A> Set<A> iterableSet(final Ord<A> o, final Iterable<A> as) {
535607 }
536608
537609 /**
538- * Constructs a set from the given elements.
610+ * Constructs a set from the list.
611+ *
612+ * @deprecated As of release 4.5, use {@link #fromList}
539613 *
540614 * @param o An order for the elements of the new set.
541615 * @param list The elements to add to a set.
542616 * @return A new set containing the elements of the given list.
543617 */
618+ @ Deprecated
544619 public static <A > Set <A > set (final Ord <A > o , List <A > list ) {
545- Set <A > s = empty (o );
546- for (final A a : list )
547- s = s .insert (a );
548- return s ;
620+ return fromList (o , list );
621+ }
622+
623+ /**
624+ * Constructs a set from the list.
625+ */
626+ public static <A > Set <A > fromList (final Ord <A > o , List <A > list ) {
627+ return fromIterable (o , list );
549628 }
550629
551630}
0 commit comments