View Javadoc

1   /*	
2   	Copyright 2007-2014 Fraunhofer IGD, http://www.igd.fraunhofer.de
3   	Fraunhofer-Gesellschaft - Institute for Computer Graphics Research
4   	
5   	See the NOTICE file distributed with this work for additional 
6   	information regarding copyright ownership
7   	
8   	Licensed under the Apache License, Version 2.0 (the "License");
9   	you may not use this file except in compliance with the License.
10  	You may obtain a copy of the License at
11  	
12  	  http://www.apache.org/licenses/LICENSE-2.0
13  	
14  	Unless required by applicable law or agreed to in writing, software
15  	distributed under the License is distributed on an "AS IS" BASIS,
16  	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  	See the License for the specific language governing permissions and
18  	limitations under the License.
19   */
20  package org.universAAL.middleware.owl.supply;
21  
22  import org.universAAL.middleware.owl.ComparableIndividual;
23  
24  /**
25   * An enumeration originally designed for rating the perceived quality of a
26   * service but kept at a more generally shared level, because it can be used not
27   * only for rating services but generally as a rating system. It is based on the
28   * German marks system for students' work, which has the following scale:
29   * <ul>
30   * <li>"very good" = {1, 1.3 | 1-}
31   * <li>"good" = {1.7 | 2+, 2, 2.3 | 2-}
32   * <li>"satisfying" = {2.7 | 3+, 3, 3.3 | 3-}
33   * <li>"sufficient" = {3.7 | 4+, 4, 4.3 | 4-}
34   * <li>"poor" = {4.7 | 5+, 5}
35   * </ul>
36   * 
37   * @author mtazari - <a href="mailto:Saied.Tazari@igd.fraunhofer.de">Saied
38   *         Tazari</a>
39   * @author Carsten Stockloew
40   */
41  public final class Rating extends ComparableIndividual {
42  
43      public static final String MY_URI = uAAL_VOCABULARY_NAMESPACE + "Rating";
44  
45      public static final int POOR = 0;
46      public static final int ALMOST_POOR = 1;
47      public static final int ALMOST_SUFFICIENT = 2;
48      public static final int SUFFICIENT = 3;
49      public static final int RICH_SUFFICIENT = 4;
50      public static final int ALMOST_SATISFYING = 5;
51      public static final int SATISFYING = 6;
52      public static final int RICH_SATISFYING = 7;
53      public static final int ALMOST_GOOD = 8;
54      public static final int GOOD = 9;
55      public static final int RICH_GOOD = 10;
56      public static final int ALMOST_EXCELLENT = 11;
57      public static final int EXCELLENT = 12;
58  
59      private static final String[] names = { "poor", "almost_poor",
60  	    "almost_sufficient", "sufficient", "rich_sufficient",
61  	    "almost_satisfying", "satisfying", "rich_satisfying",
62  	    "almost_good", "good", "rich_good", "almost_excellent", "excellent" };
63  
64      public static final Rating poor = new Rating(POOR);
65      public static final Rating almostPoor = new Rating(ALMOST_POOR);
66      public static final Rating almostSufficient = new Rating(ALMOST_SUFFICIENT);
67      public static final Rating sufficient = new Rating(SUFFICIENT);
68      public static final Rating richSufficient = new Rating(RICH_SUFFICIENT);
69      public static final Rating almostSatisfying = new Rating(ALMOST_SATISFYING);
70      public static final Rating satisfying = new Rating(SATISFYING);
71      public static final Rating richSatisfying = new Rating(RICH_SATISFYING);
72      public static final Rating almostGood = new Rating(ALMOST_GOOD);
73      public static final Rating good = new Rating(GOOD);
74      public static final Rating richGood = new Rating(RICH_GOOD);
75      public static final Rating almostExcellent = new Rating(ALMOST_EXCELLENT);
76      public static final Rating excellent = new Rating(EXCELLENT);
77  
78      /** The current value of this object. */
79      private int order;
80  
81      // prevent the usage of the default constructor
82      private Rating() {
83      }
84  
85      private Rating(int order) {
86  	super(uAAL_VOCABULARY_NAMESPACE + names[order]);
87  	this.order = order;
88      }
89  
90      /** @see org.universAAL.middleware.owl.ManagedIndividual#getClassURI() */
91      public String getClassURI() {
92  	return MY_URI;
93      }
94  
95      public static Rating getMaxValue() {
96  	return excellent;
97      }
98  
99      public static Rating getMinValue() {
100 	return poor;
101     }
102 
103     public static Rating getRatingByOrder(int order) {
104 	switch (order) {
105 	case POOR:
106 	    return poor;
107 	case ALMOST_POOR:
108 	    return almostPoor;
109 	case ALMOST_SUFFICIENT:
110 	    return almostSufficient;
111 	case SUFFICIENT:
112 	    return sufficient;
113 	case RICH_SUFFICIENT:
114 	    return richSufficient;
115 	case ALMOST_SATISFYING:
116 	    return almostSatisfying;
117 	case SATISFYING:
118 	    return satisfying;
119 	case RICH_SATISFYING:
120 	    return richSatisfying;
121 	case ALMOST_GOOD:
122 	    return almostGood;
123 	case GOOD:
124 	    return good;
125 	case RICH_GOOD:
126 	    return richGood;
127 	case ALMOST_EXCELLENT:
128 	    return almostExcellent;
129 	case EXCELLENT:
130 	    return excellent;
131 	default:
132 	    return null;
133 	}
134     }
135 
136     public static final Rating valueOf(String name) {
137 	for (int i = POOR; i <= EXCELLENT; i++)
138 	    if (names[i].equals(name))
139 		return getRatingByOrder(i);
140 	return null;
141     }
142 
143     public int compareTo(Object other) {
144 	return (this == other) ? 0 : (order < ((Rating) other).order) ? -1 : 1;
145     }
146 
147     public ComparableIndividual getNext() {
148 	return getRatingByOrder(order + 1);
149     }
150 
151     public ComparableIndividual getPrevious() {
152 	return getRatingByOrder(order - 1);
153     }
154 
155     public int getPropSerializationType(String propURI) {
156 	return PROP_SERIALIZATION_OPTIONAL;
157     }
158 
159     /** @see org.universAAL.middleware.rdf.Resource#isWellFormed() */
160     public boolean isWellFormed() {
161 	return true;
162     }
163 
164     /** Get a human-readable description for this Rating value. */
165     public String name() {
166 	return names[order];
167     }
168 
169     public int ord() {
170 	return order;
171     }
172 
173     /**
174      * Overrides the default method to prevent properties from being added.
175      * 
176      * @see org.universAAL.middleware.rdf.Resource#setProperty(String, Object)
177      */
178     public boolean setProperty(String propURI, Object o) {
179 	// do nothing
180 	return false;
181     }
182 }