Merge pull request #134 from joana-team/pull-request__getridofhashcodecomparator
get rid of HashCodeComparator and all its usages
This commit is contained in:
commit
71b505cfc8
|
@ -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<ModuleEntry> sortedEntries = new TreeSet<ModuleEntry>(HashCodeComparator.instance());
|
||||
sortedEntries.addAll(Iterator2Collection.toSet(M.getEntries()));
|
||||
|
||||
HashSet<ModuleEntry> 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<ModuleEntry> sortedEntries = new TreeSet<ModuleEntry>(HashCodeComparator.instance());
|
||||
sortedEntries.addAll(Iterator2Collection.toSet(M.getEntries()));
|
||||
HashSet<ModuleEntry> 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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<ModuleEntry> getDexFiles(Module M) throws IOException {
|
||||
TreeSet<ModuleEntry> sortedEntries = new TreeSet<ModuleEntry>(HashCodeComparator.instance());
|
||||
sortedEntries.addAll(Iterator2Collection.toSet(M.getEntries()));
|
||||
HashSet<ModuleEntry> result = HashSetFactory.make();
|
||||
for (Iterator<ModuleEntry> it = sortedEntries.iterator(); it.hasNext();) {
|
||||
for (Iterator<? extends ModuleEntry> it = M.getEntries(); it.hasNext();) {
|
||||
ModuleEntry entry = (ModuleEntry) it.next();
|
||||
if (entry instanceof DexModuleEntry) {
|
||||
result.add(entry);
|
||||
|
|
|
@ -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<T> implements Comparator<T> {
|
||||
|
||||
@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 <T> HashCodeComparator<T> instance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue