1 package org
.argeo
.suite
;
6 * Key used to classify and filter available components (typically provided by
10 public class RankingKey
implements Comparable
<RankingKey
> {
11 public final static String SERVICE_PID
= "service.pid";
12 public final static String SERVICE_ID
= "service.id";
13 public final static String SERVICE_RANKING
= "service.ranking";
14 public final static String DATA_TYPE
= "data.type";
17 private Integer ranking
= 0;
19 private String dataType
;
20 private String dataPath
;
22 public RankingKey(String pid
, Integer ranking
, Long id
, String dataType
, String dataPath
) {
25 this.ranking
= ranking
;
27 this.dataType
= dataType
;
28 this.dataPath
= dataPath
;
31 public RankingKey(Map
<String
, Object
> properties
) {
32 this.pid
= properties
.containsKey(SERVICE_PID
) ? properties
.get(SERVICE_PID
).toString() : null;
33 this.ranking
= properties
.containsKey(SERVICE_RANKING
)
34 ? Integer
.parseInt(properties
.get(SERVICE_RANKING
).toString())
36 this.id
= properties
.containsKey(SERVICE_ID
) ?
(Long
) properties
.get(SERVICE_ID
) : null;
39 this.dataType
= properties
.containsKey(DATA_TYPE
) ? properties
.get(DATA_TYPE
).toString() : null;
43 public int hashCode() {
46 result
= +pid
.hashCode();
50 result
= +dataType
.hashCode();
55 protected Object
clone() throws CloneNotSupportedException
{
56 return new RankingKey(pid
, ranking
, id
, dataType
, dataPath
);
60 public String
toString() {
61 StringBuilder sb
= new StringBuilder("");
64 if (ranking
!= null && ranking
!= 0)
65 sb
.append(' ').append(ranking
);
67 sb
.append(' ').append(dataType
);
72 public boolean equals(Object obj
) {
73 if (!(obj
instanceof RankingKey
))
75 RankingKey other
= (RankingKey
) obj
;
76 return equalsOrBothNull(pid
, other
.pid
) && equalsOrBothNull(ranking
, other
.ranking
)
77 && equalsOrBothNull(id
, other
.id
) && equalsOrBothNull(dataType
, other
.dataType
)
78 && equalsOrBothNull(dataPath
, other
.dataPath
);
82 public int compareTo(RankingKey o
) {
83 if (pid
!= null && o
.pid
!= null) {
84 if (pid
.equals(o
.pid
)) {
85 if (ranking
.equals(o
.ranking
))
86 if (id
!= null && o
.id
!= null)
87 return id
.compareTo(o
.id
);
91 return ranking
.compareTo(o
.ranking
);
93 return pid
.compareTo(o
.pid
);
97 if (dataType
!= null && o
.dataType
!= null) {
98 if (dataType
.equals(o
.dataType
)) {
100 if (ranking
.equals(o
.ranking
))
101 if (id
!= null && o
.id
!= null)
102 return id
.compareTo(o
.id
);
106 return ranking
.compareTo(o
.ranking
);
108 return dataPath
.compareTo(o
.dataType
);
115 public String
getPid() {
119 public Integer
getRanking() {
123 public Long
getId() {
127 public String
getDataType() {
131 public String
getDataPath() {
135 public static RankingKey
minPid(String pid
) {
136 return new RankingKey(pid
, Integer
.MIN_VALUE
, null, null, null);
139 public static RankingKey
maxPid(String pid
) {
140 return new RankingKey(pid
, Integer
.MAX_VALUE
, null, null, null);
143 public static RankingKey
minDataType(String dataType
) {
144 return new RankingKey(null, Integer
.MIN_VALUE
, null, dataType
, null);
147 public static RankingKey
maxDataType(String dataType
) {
148 return new RankingKey(null, Integer
.MAX_VALUE
, null, dataType
, null);
151 private static boolean equalsOrBothNull(Object o1
, Object o2
) {
152 if (o1
== null && o2
== null)
154 if (o1
== null && o2
!= null)
156 if (o1
!= null && o2
== null)
158 return o2
.equals(o1
);