1 22 23 24 package com.mchange.v1.util; 25 26 import java.util.Iterator ; 27 import java.util.Set ; 28 import java.util.AbstractSet ; 29 import java.util.HashSet ; 30 31 public final class SetUtils 32 { 33 public static Set oneElementUnmodifiableSet(final Object elem) 34 { 35 return new AbstractSet () 36 { 37 public Iterator iterator() 38 { return IteratorUtils.oneElementUnmodifiableIterator( elem ); } 39 40 public int size() { return 1; } 41 42 public boolean isEmpty() 43 { return false; } 44 45 public boolean contains(Object o) 46 { return o == elem; } 47 48 }; 49 } 50 51 public static Set setFromArray(Object [] array) 52 { 53 HashSet out = new HashSet (); 54 for (int i = 0, len = array.length; i < len; ++i) 55 out.add( array[i] ); 56 return out; 57 } 58 59 public static boolean equivalentDisregardingSort(Set a, Set b) 60 { 61 return 62 a.containsAll( b ) && 63 b.containsAll( a ); 64 } 65 66 72 public static int hashContentsDisregardingSort(Set s) 73 { 74 int out = 0; 75 for (Iterator ii = s.iterator(); ii.hasNext(); ) 76 { 77 Object o = ii.next(); 78 if (o != null) out ^= o.hashCode(); 79 } 80 return out; 81 } 82 } 83 84 | Popular Tags |