X-Git-Url: http://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=blobdiff_plain;f=org.argeo.suite.core%2Fsrc%2Forg%2Fargeo%2Fsuite%2FRankingKey.java;fp=org.argeo.suite.core%2Fsrc%2Forg%2Fargeo%2Fsuite%2FRankingKey.java;h=0000000000000000000000000000000000000000;hp=e0991953e2d326682c2a78328e46f5e187c3237e;hb=418ea1efbf3f0d6b706603c6ff1c0fdd17314773;hpb=70010c4afc5799622fcad5b075740d94da074798 diff --git a/org.argeo.suite.core/src/org/argeo/suite/RankingKey.java b/org.argeo.suite.core/src/org/argeo/suite/RankingKey.java deleted file mode 100644 index e099195..0000000 --- a/org.argeo.suite.core/src/org/argeo/suite/RankingKey.java +++ /dev/null @@ -1,160 +0,0 @@ -package org.argeo.suite; - -import java.util.Map; - -/** - * Key used to classify and filter available components (typically provided by - * OSGi services). - */ -@Deprecated -public class RankingKey implements Comparable { - public final static String SERVICE_PID = "service.pid"; - public final static String SERVICE_ID = "service.id"; - public final static String SERVICE_RANKING = "service.ranking"; - public final static String DATA_TYPE = "data.type"; - - private String pid; - private Integer ranking = 0; - private Long id = 0l; - private String dataType; - private String dataPath; - - public RankingKey(String pid, Integer ranking, Long id, String dataType, String dataPath) { - super(); - this.pid = pid; - this.ranking = ranking; - this.id = id; - this.dataType = dataType; - this.dataPath = dataPath; - } - - public RankingKey(Map properties) { - this.pid = properties.containsKey(SERVICE_PID) ? properties.get(SERVICE_PID).toString() : null; - this.ranking = properties.containsKey(SERVICE_RANKING) - ? Integer.parseInt(properties.get(SERVICE_RANKING).toString()) - : 0; - this.id = properties.containsKey(SERVICE_ID) ? (Long) properties.get(SERVICE_ID) : null; - - // Argeo specific - this.dataType = properties.containsKey(DATA_TYPE) ? properties.get(DATA_TYPE).toString() : null; - } - - @Override - public int hashCode() { - Integer result = 0; - if (pid != null) - result = +pid.hashCode(); - if (ranking != null) - result = +ranking; - if (dataType != null) - result = +dataType.hashCode(); - return result; - } - - @Override - protected Object clone() throws CloneNotSupportedException { - return new RankingKey(pid, ranking, id, dataType, dataPath); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(""); - if (pid != null) - sb.append(pid); - if (ranking != null && ranking != 0) - sb.append(' ').append(ranking); - if (dataType != null) - sb.append(' ').append(dataType); - return sb.toString(); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof RankingKey)) - return false; - RankingKey other = (RankingKey) obj; - return equalsOrBothNull(pid, other.pid) && equalsOrBothNull(ranking, other.ranking) - && equalsOrBothNull(id, other.id) && equalsOrBothNull(dataType, other.dataType) - && equalsOrBothNull(dataPath, other.dataPath); - } - - @Override - public int compareTo(RankingKey o) { - if (pid != null && o.pid != null) { - if (pid.equals(o.pid)) { - if (ranking.equals(o.ranking)) - if (id != null && o.id != null) - return id.compareTo(o.id); - else - return 0; - else - return ranking.compareTo(o.ranking); - } else { - return pid.compareTo(o.pid); - } - - } else { - if (dataType != null && o.dataType != null) { - if (dataType.equals(o.dataType)) { - // TODO factorise - if (ranking.equals(o.ranking)) - if (id != null && o.id != null) - return id.compareTo(o.id); - else - return 0; - else - return ranking.compareTo(o.ranking); - } else { - return dataPath.compareTo(o.dataType); - } - } - } - return -1; - } - - public String getPid() { - return pid; - } - - public Integer getRanking() { - return ranking; - } - - public Long getId() { - return id; - } - - public String getDataType() { - return dataType; - } - - public String getDataPath() { - return dataPath; - } - - public static RankingKey minPid(String pid) { - return new RankingKey(pid, Integer.MIN_VALUE, null, null, null); - } - - public static RankingKey maxPid(String pid) { - return new RankingKey(pid, Integer.MAX_VALUE, null, null, null); - } - - public static RankingKey minDataType(String dataType) { - return new RankingKey(null, Integer.MIN_VALUE, null, dataType, null); - } - - public static RankingKey maxDataType(String dataType) { - return new RankingKey(null, Integer.MAX_VALUE, null, dataType, null); - } - - private static boolean equalsOrBothNull(Object o1, Object o2) { - if (o1 == null && o2 == null) - return true; - if (o1 == null && o2 != null) - return false; - if (o1 != null && o2 == null) - return false; - return o2.equals(o1); - } -}