mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-14 07:43:40 +01:00
Implemented the Comparable interface
Former-commit-id: 306cee400d6cc08ff2a61cd45019c3df8f223a29
This commit is contained in:
@@ -23,7 +23,7 @@ package org.owasp.dependencycheck.dependency;
|
||||
*
|
||||
* @author Jeremy Long (jeremy.long@gmail.com)
|
||||
*/
|
||||
public class Evidence {
|
||||
public class Evidence implements Comparable<Evidence> {
|
||||
|
||||
/**
|
||||
* The confidence that the evidence is "high" quality.
|
||||
@@ -222,4 +222,29 @@ public class Evidence {
|
||||
private boolean testEquality(String l, String r) {
|
||||
return l == null ? r == null : l.equalsIgnoreCase(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of the comparable interface.
|
||||
* @param o the evidence being compared
|
||||
* @return an integer indicating the ordering of the two objects
|
||||
*/
|
||||
public int compareTo(Evidence o) {
|
||||
if (source.equals(o.source)) {
|
||||
if (name.equals(o.name)) {
|
||||
if (value.equals(o.value)) {
|
||||
if (confidence.equals(o.confidence)) {
|
||||
return 0; //they are equal
|
||||
} else {
|
||||
return confidence.compareTo(o.confidence);
|
||||
}
|
||||
} else {
|
||||
return value.compareToIgnoreCase(o.value);
|
||||
}
|
||||
} else {
|
||||
return name.compareToIgnoreCase(o.name);
|
||||
}
|
||||
} else {
|
||||
return source.compareToIgnoreCase(o.source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.owasp.dependencycheck.dependency;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import org.owasp.dependencycheck.utils.Filter;
|
||||
|
||||
/**
|
||||
@@ -103,7 +104,7 @@ public class EvidenceCollection implements Iterable<Evidence> {
|
||||
* Creates a new EvidenceCollection.
|
||||
*/
|
||||
public EvidenceCollection() {
|
||||
list = new HashSet<Evidence>();
|
||||
list = new TreeSet<Evidence>();
|
||||
weightedStrings = new HashSet<String>();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ package org.owasp.dependencycheck.dependency;
|
||||
*
|
||||
* @author Jeremy Long (jeremy.long@gmail.com)
|
||||
*/
|
||||
public class Identifier {
|
||||
public class Identifier implements Comparable<Identifier> {
|
||||
|
||||
/**
|
||||
* Constructs a new Identifier with the specified data.
|
||||
@@ -165,4 +165,14 @@ public class Identifier {
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of the comparator interface. This compares the
|
||||
* value of the identifier only.
|
||||
*
|
||||
* @param o the object being compared
|
||||
* @return an integer indicating the ordering
|
||||
*/
|
||||
public int compareTo(Identifier o) {
|
||||
return this.value.compareTo(o.value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user