1 package org
.argeo
.suite
;
5 import org
.argeo
.api
.NodeConstants
;
8 * Key used to classify and filter available components (typically provided by
11 public class RankingKey
implements Comparable
<RankingKey
> {
12 public final static String SERVICE_PID
= "service.pid";
13 public final static String SERVICE_ID
= "service.id";
14 public final static String SERVICE_RANKING
= "service.ranking";
15 public final static String DATA_TYPE
= "data.type";
18 private Integer ranking
= 0;
20 private String dataType
;
21 private String dataPath
;
23 public RankingKey(String pid
, Integer ranking
, Long id
, String dataType
, String dataPath
) {
26 this.ranking
= ranking
;
28 this.dataType
= dataType
;
29 this.dataPath
= dataPath
;
32 public RankingKey(Map
<String
, Object
> properties
) {
33 this.pid
= properties
.containsKey(SERVICE_PID
) ? properties
.get(SERVICE_PID
).toString() : null;
34 this.ranking
= properties
.containsKey(SERVICE_RANKING
)
35 ? Integer
.parseInt(properties
.get(SERVICE_RANKING
).toString())
37 this.id
= properties
.containsKey(SERVICE_ID
) ?
(Long
) properties
.get(SERVICE_ID
) : null;
40 this.dataType
= properties
.containsKey(DATA_TYPE
) ? properties
.get(DATA_TYPE
).toString() : null;
44 public int hashCode() {
47 result
= +pid
.hashCode();
51 result
= +dataType
.hashCode();
56 protected Object
clone() throws CloneNotSupportedException
{
57 return new RankingKey(pid
, ranking
, id
, dataType
, dataPath
);
61 public String
toString() {
62 StringBuilder sb
= new StringBuilder("");
65 if (ranking
!= null && ranking
!= 0)
66 sb
.append(' ').append(ranking
);
68 sb
.append(' ').append(dataType
);
73 public boolean equals(Object obj
) {
74 if (!(obj
instanceof RankingKey
))
76 RankingKey other
= (RankingKey
) obj
;
77 return equalsOrBothNull(pid
, other
.pid
) && equalsOrBothNull(ranking
, other
.ranking
)
78 && equalsOrBothNull(id
, other
.id
) && equalsOrBothNull(dataType
, other
.dataType
)
79 && equalsOrBothNull(dataPath
, other
.dataPath
);
83 public int compareTo(RankingKey o
) {
84 if (pid
!= null && o
.pid
!= null) {
85 if (pid
.equals(o
.pid
)) {
86 if (ranking
.equals(o
.ranking
))
87 if (id
!= null && o
.id
!= null)
88 return id
.compareTo(o
.id
);
92 return ranking
.compareTo(o
.ranking
);
94 return pid
.compareTo(o
.pid
);
98 if (dataType
!= null && o
.dataType
!= null) {
99 if (dataType
.equals(o
.dataType
)) {
101 if (ranking
.equals(o
.ranking
))
102 if (id
!= null && o
.id
!= null)
103 return id
.compareTo(o
.id
);
107 return ranking
.compareTo(o
.ranking
);
109 return dataPath
.compareTo(o
.dataType
);
116 public String
getPid() {
120 public Integer
getRanking() {
124 public Long
getId() {
128 public String
getDataType() {
132 public String
getDataPath() {
136 public static RankingKey
minPid(String pid
) {
137 return new RankingKey(pid
, Integer
.MIN_VALUE
, null, null, null);
140 public static RankingKey
maxPid(String pid
) {
141 return new RankingKey(pid
, Integer
.MAX_VALUE
, null, null, null);
144 public static RankingKey
minDataType(String dataType
) {
145 return new RankingKey(null, Integer
.MIN_VALUE
, null, dataType
, null);
148 public static RankingKey
maxDataType(String dataType
) {
149 return new RankingKey(null, Integer
.MAX_VALUE
, null, dataType
, null);
152 private static boolean equalsOrBothNull(Object o1
, Object o2
) {
153 if (o1
== null && o2
== null)
155 if (o1
== null && o2
!= null)
157 if (o1
!= null && o2
== null)
159 return o2
.equals(o1
);