diff --git a/com.ibm.wala.core/src/com/ibm/wala/classLoader/ClassLoaderImpl.java b/com.ibm.wala.core/src/com/ibm/wala/classLoader/ClassLoaderImpl.java index f177fba1f..639ea9f55 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/classLoader/ClassLoaderImpl.java +++ b/com.ibm.wala.core/src/com/ibm/wala/classLoader/ClassLoaderImpl.java @@ -25,7 +25,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.TreeSet; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; @@ -35,10 +34,8 @@ import com.ibm.wala.shrikeCT.InvalidClassFileException; import com.ibm.wala.ssa.SSAInstructionFactory; import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.types.TypeName; -import com.ibm.wala.util.collections.HashCodeComparator; import com.ibm.wala.util.collections.HashMapFactory; import com.ibm.wala.util.collections.HashSetFactory; -import com.ibm.wala.util.collections.Iterator2Collection; import com.ibm.wala.util.collections.Iterator2Iterable; import com.ibm.wala.util.config.SetOfClasses; import com.ibm.wala.util.io.FileProvider; @@ -125,11 +122,8 @@ public class ClassLoaderImpl implements IClassLoader { if (DEBUG_LEVEL > 0) { System.err.println("Get source files for " + M); } - TreeSet sortedEntries = new TreeSet(HashCodeComparator.instance()); - sortedEntries.addAll(Iterator2Collection.toSet(M.getEntries())); - HashSet result = HashSetFactory.make(); - for (Iterator it = sortedEntries.iterator(); it.hasNext();) { + for (Iterator it = M.getEntries(); it.hasNext();) { ModuleEntry entry = (ModuleEntry) it.next(); if (DEBUG_LEVEL > 0) { System.err.println("consider entry for source information: " + entry); @@ -157,10 +151,8 @@ public class ClassLoaderImpl implements IClassLoader { if (DEBUG_LEVEL > 0) { System.err.println("Get class files for " + M); } - TreeSet sortedEntries = new TreeSet(HashCodeComparator.instance()); - sortedEntries.addAll(Iterator2Collection.toSet(M.getEntries())); HashSet result = HashSetFactory.make(); - for (Iterator it = sortedEntries.iterator(); it.hasNext();) { + for (Iterator it = M.getEntries(); it.hasNext();) { ModuleEntry entry = (ModuleEntry) it.next(); if (DEBUG_LEVEL > 0) { System.err.println("ClassLoaderImpl.getClassFiles:Got entry: " + entry); diff --git a/com.ibm.wala.dalvik/src/com/ibm/wala/dalvik/classLoader/DexModuleEntry.java b/com.ibm.wala.dalvik/src/com/ibm/wala/dalvik/classLoader/DexModuleEntry.java index 5cebab8eb..9a9210f37 100644 --- a/com.ibm.wala.dalvik/src/com/ibm/wala/dalvik/classLoader/DexModuleEntry.java +++ b/com.ibm.wala.dalvik/src/com/ibm/wala/dalvik/classLoader/DexModuleEntry.java @@ -136,4 +136,34 @@ public class DexModuleEntry implements ModuleEntry { return asModule(); } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((className == null) ? 0 : className.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof DexModuleEntry)) { + return false; + } + DexModuleEntry other = (DexModuleEntry) obj; + if (className == null) { + if (other.className != null) { + return false; + } + } else if (!className.equals(other.className)) { + return false; + } + return true; + } + } diff --git a/com.ibm.wala.dalvik/src/com/ibm/wala/dalvik/classLoader/WDexClassLoaderImpl.java b/com.ibm.wala.dalvik/src/com/ibm/wala/dalvik/classLoader/WDexClassLoaderImpl.java index 3f143ecc3..270269d0d 100644 --- a/com.ibm.wala.dalvik/src/com/ibm/wala/dalvik/classLoader/WDexClassLoaderImpl.java +++ b/com.ibm.wala.dalvik/src/com/ibm/wala/dalvik/classLoader/WDexClassLoaderImpl.java @@ -53,7 +53,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; -import java.util.TreeSet; import com.ibm.wala.classLoader.ClassLoaderImpl; import com.ibm.wala.classLoader.IClass; @@ -63,9 +62,7 @@ import com.ibm.wala.classLoader.ModuleEntry; import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.types.TypeName; -import com.ibm.wala.util.collections.HashCodeComparator; import com.ibm.wala.util.collections.HashSetFactory; -import com.ibm.wala.util.collections.Iterator2Collection; import com.ibm.wala.util.config.SetOfClasses; import com.ibm.wala.util.warnings.Warning; import com.ibm.wala.util.warnings.Warnings; @@ -139,10 +136,8 @@ public class WDexClassLoaderImpl extends ClassLoaderImpl { } private Set getDexFiles(Module M) throws IOException { - TreeSet sortedEntries = new TreeSet(HashCodeComparator.instance()); - sortedEntries.addAll(Iterator2Collection.toSet(M.getEntries())); HashSet result = HashSetFactory.make(); - for (Iterator it = sortedEntries.iterator(); it.hasNext();) { + for (Iterator it = M.getEntries(); it.hasNext();) { ModuleEntry entry = (ModuleEntry) it.next(); if (entry instanceof DexModuleEntry) { result.add(entry); diff --git a/com.ibm.wala.util/src/com/ibm/wala/util/collections/HashCodeComparator.java b/com.ibm.wala.util/src/com/ibm/wala/util/collections/HashCodeComparator.java deleted file mode 100644 index ed310f08b..000000000 --- a/com.ibm.wala.util/src/com/ibm/wala/util/collections/HashCodeComparator.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 - 2006 IBM Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package com.ibm.wala.util.collections; - -import java.util.Comparator; - -/** - * A comparator based on hash codes - */ -public class HashCodeComparator implements Comparator { - - @SuppressWarnings("rawtypes") - private static final HashCodeComparator INSTANCE = new HashCodeComparator(); - - /* - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) - */ - @Override - public int compare(T o1, T o2) throws NullPointerException { - // by convention null is less than non-null - if (o1 == null) { - return o2 == null ? 0 : -1; - } else if (o2 == null) { - return 1; - } - return o1.hashCode() - o2.hashCode(); - } - - @SuppressWarnings("unchecked") - public static HashCodeComparator instance() { - return INSTANCE; - } - -}