Passed
Push — master ( ba4614...ebb470 )
by Alessandro
05:51
created

compareTo(PrecedenceConstraint)   A

Complexity

Conditions 3

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
eloc 3
1
package it.cnr.istc.pst.platinum.ai.framework.microkernel.resolver.timeline.scheduling;
2
3
import it.cnr.istc.pst.platinum.ai.framework.domain.component.Decision;
4
5
/**
6
 * 
7
 * @author alessandro
8
 *
9
 */
10
public class PrecedenceConstraint implements Comparable<PrecedenceConstraint>
11
{
12
	private Decision reference;				// reference decision of the precedence constraint
13
	private Decision target;				// target decision of the precedence constraint
14
	private double preserved;				// value computed by means of heuristics introduced in [Laborie 2005]
15
	
16
	/**
17
	 * 
18
	 * @param reference
19
	 * @param target
20
	 */
21
	protected PrecedenceConstraint(Decision reference, Decision target) {
22
		this.reference = reference;
23
		this.target = target;
24
	}
25
	
26
	/**
27
	 * 
28
	 * @param preserved
29
	 */
30
	public void setPreservedSpace(double preserved) {
31
		this.preserved = preserved;
32
	}
33
	
34
	/**
35
	 * 
36
	 * @return
37
	 */
38
	public double getPreservedValue() {
39
		return this.preserved;
40
	}
41
	
42
	/**
43
	 * 
44
	 * @return
45
	 */
46
	public Decision getReference() {
47
		return reference;
48
	}
49
50
	/**
51
	 * 
52
	 * @return
53
	 */
54
	public Decision getTarget() {
55
		return target;
56
	}
57
	
58
	/**
59
	 * 
60
	 */
61
	@Override
62
	public String toString() {
63
		// JSON style object description
64
		return "{ \"type\": \"PRECEDENCE_CONSTRAINT\", "
65
				+ "\"reference\": " + this.reference + ", "
66
				+ "\"target\": " + this.target + ", "
67
				+ "\"preserved-space-heuristic\": " + this.preserved + " }";
68
	}
69
70
	/**
71
	 * 
72
	 */
73
	@Override
74
	public int compareTo(PrecedenceConstraint pc) {
0 ignored issues
show
Bug introduced by
When overriding compareTo(), you should always override equals() to provide the same behaviour.

compareTo() and equals() must provide the same behaviour so that if, and only if, compareTo() returns 0, equals() returns true.

Loading history...
75
		// compare preserved space heuristic
76
		return this.preserved < pc.preserved ? -1 : this.preserved > pc.preserved ? 1 : 0;
77
	}
78
}
79