-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClConstraint.java
88 lines (63 loc) · 2.03 KB
/
ClConstraint.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// $Id$
//
// Cassowary Incremental Constraint Solver
// Original Smalltalk Implementation by Alan Borning
// This Java Implementation by Greg J. Badros, <[email protected]>
// http://www.cs.washington.edu/homes/gjb
// (C) 1998, 1999 Greg J. Badros and Alan Borning
// See ../LICENSE for legal details regarding this software
//
// ClConstraint
//
package EDU.Washington.grad.gjb.cassowary;
import java.lang.*;
public abstract class ClConstraint
{
public ClConstraint(ClStrength strength, double weight)
{ _strength = strength; _weight = weight; _times_added = 0; }
public ClConstraint(ClStrength strength)
{ _strength = strength; _weight = 1.0; _times_added = 0; }
public ClConstraint()
{ _strength = ClStrength.required; _weight = 1.0; _times_added = 0; }
public abstract ClLinearExpression expression();
public boolean isEditConstraint()
{ return false; }
public boolean isInequality()
{ return false; }
public boolean isRequired()
{ return _strength.isRequired(); }
public boolean isStayConstraint()
{ return false; }
public ClStrength strength()
{ return _strength; }
public double weight()
{ return _weight; }
public String toString()
{ return _strength.toString() +
" {" + weight() + "} (" + expression(); }
public void setAttachedObject(Object o)
{ _attachedObject = o; }
public Object getAttachedObject()
{ return _attachedObject; }
public void changeStrength(ClStrength strength)
throws ExCLTooDifficult
{
if (_times_added == 0) {
setStrength(strength);
} else {
throw new ExCLTooDifficult();
}
}
public void addedTo(ClSimplexSolver solver)
{ ++_times_added; }
public void removedFrom(ClSimplexSolver solver)
{ --_times_added; }
private void setStrength(ClStrength strength)
{ _strength = strength; }
private void setWeight(double weight)
{ _weight = weight; }
private ClStrength _strength;
private double _weight;
private Object _attachedObject;
private int _times_added;
}