it.cnr.istc.pst.cognition.koala.lang.dictionary.KoalaPropertyDictionary.getPropertyByURI(String)   F
last analyzed

Complexity

Conditions 14

Size

Total Lines 44
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 44
c 0
b 0
f 0
cc 14
rs 3.6

How to fix   Complexity   

Complexity

Complex classes like it.cnr.istc.pst.cognition.koala.lang.dictionary.KoalaPropertyDictionary.getPropertyByURI(String) often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
package it.cnr.istc.pst.cognition.koala.lang.dictionary;
2
3
/**
4
 * 
5
 * @author alessandroumbrico
6
 *
7
 */
8
public enum KoalaPropertyDictionary 
9
{
10
	KOALA_TEMPERATURE("http://pst.istc.cnr.it/ontologies/2017/1/koala#Temperature"),
11
	
12
	KOALA_PRESENCE("http://pst.istc.cnr.it/ontologies/2017/1/koala#Presence"),
13
	
14
	KOALA_LUMINOSITY("http://pst.istc.cnr.it/ontologies/2017/1/koala#Luminosity"),
15
	
16
	KOALA_CONTACT("http://pst.istc.cnr.it/ontologies/2017/1/koala#Contact"),
17
	
18
	KOALA_ENERGY("http://pst.istc.cnr.it/ontologies/2017/1/koala#Energy"),
19
	
20
	KOALA_BODY_TEMPERATURE("http://pst.istc.cnr.it/ontologies/2017/1/koala#BodyTemperature"),
21
	
22
	KOALA_BODY_WEIGHT("http://pst.istc.cnr.it/ontologies/2017/1/koala#BodyWeight"),
23
	
24
	KOALA_BLOOD_SUGAR("http://pst.istc.cnr.it/ontologies/2017/1/koala#BloodSugar"),
25
	
26
	KOALA_BLOOD_PRESSURE("http://pst.istc.cnr.it/ontologies/2017/1/koala#BloodPressure"),
27
	
28
	KOALA_HEART_RATE("http://pst.istc.cnr.it/ontologies/2017/1/koala#HeartRate"),
29
	
30
	KOALA_OXIMETRY("http://pst.istc.cnr.it/ontologies/2017/1/koala#Oximetry"),
31
	
32
	KOALA_VOICE_COMMAND("http://pst.istc.cnr.it/ontologies/2017/1/koala#VoiceCommand"),
33
	
34
	KOALA_BATTERY_LEVEL("http://pst.istc.cnr.it/ontologies/2017/1/koala#BatteryLevel");
35
	
36
	private String uri;
37
	
38
	/**
39
	 * 
40
	 * @param uri
41
	 */
42
	private KoalaPropertyDictionary(String uri) {
43
		this.uri = uri;
44
	}
45
	
46
	/**
47
	 * 
48
	 * @return
49
	 */
50
	public String getUri() {
51
		return uri;
52
	}
53
	
54
	/**
55
	 * 
56
	 * @param propertyUri
57
	 * @return
58
	 */
59
	public static KoalaPropertyDictionary getPropertyByURI(String propertyUri)
60
	{
61
		if (propertyUri.equals(KOALA_TEMPERATURE.uri)) {
62
			return KOALA_TEMPERATURE;
63
		}
64
		else if (propertyUri.equals(KOALA_PRESENCE.uri)) {
65
			return KOALA_PRESENCE;
66
		}
67
		else if (propertyUri.equals(KOALA_LUMINOSITY.uri)) {
68
			return KOALA_LUMINOSITY;
69
		}
70
		else if (propertyUri.equals(KOALA_CONTACT.uri)) {
71
			return KOALA_CONTACT;
72
		}
73
		else if (propertyUri.equals(KOALA_ENERGY.uri)) {
74
			return KOALA_ENERGY;
75
		}
76
		else if (propertyUri.equals(KOALA_BODY_TEMPERATURE.uri)) {
77
			return KOALA_BODY_TEMPERATURE;
78
		}
79
		else if (propertyUri.equals(KOALA_BODY_WEIGHT.uri)) {
80
			return KOALA_BODY_WEIGHT;
81
		}
82
		else if (propertyUri.equals(KOALA_BLOOD_SUGAR.uri)) {
83
			return KOALA_BLOOD_SUGAR;
84
		}
85
		else if (propertyUri.equals(KOALA_BLOOD_PRESSURE.uri)) {
86
			return KOALA_BLOOD_PRESSURE;
87
		}
88
		else if (propertyUri.equals(KOALA_HEART_RATE.uri)) {
89
			return KOALA_HEART_RATE;
90
		}
91
		else if (propertyUri.equals(KOALA_OXIMETRY.uri)) {
92
			return KOALA_OXIMETRY;
93
		}
94
		else if (propertyUri.equals(KOALA_VOICE_COMMAND.uri)) {
95
			return KOALA_VOICE_COMMAND;
96
		}
97
		else if (propertyUri.equals(KOALA_BATTERY_LEVEL.uri)) {
98
			return KOALA_BATTERY_LEVEL;
99
		}
100
		else {
101
			// unknown 
102
			throw new RuntimeException("Unknown property URI " + propertyUri + "\n");
0 ignored issues
show
Best Practice introduced by
Dedicated exceptions should be preferred over throwing the generic Exception.
Loading history...
103
		}
104
	}
105
}
106