EOS 2  1.1.0
Einfache Objektbasierte Sprache
ShapeOrder.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.game.geom;
2 
12 class ShapeOrder implements Comparable<ShapeOrder> {
13 
17  public static enum OrderType {
18 
20 
21  X0,
23  X1,
25  Y0,
27  Y1
28  };
29 
33  public static enum Bracket {
34 
35  OPEN(1), CLOSE(2);
36  public final int order;
37 
38  private Bracket(int order) {
39  this.order = order;
40  }
41  };
42 
46  public final double value;
50  public final Bracket bracket;
54  public final Shape shape;
55 
62  public ShapeOrder(OrderType type, Shape shape) {
63  this.shape = shape;
64  switch (type) {
65  case X0:
66  value = shape.getLeft();
67  bracket = Bracket.OPEN;
68  break;
69  case X1:
70  value = shape.getRight();
71  bracket = Bracket.CLOSE;
72  break;
73  case Y0:
74  value = shape.getBottom();
75  bracket = Bracket.OPEN;
76  break;
77  case Y1:
78  value = shape.getTop();
79  bracket = Bracket.CLOSE;
80  break;
81  // BEGIN DELETE ME
82  default:
83  // We need the default case as the java compiler is unable to
84  // process enumerations correctly
85  // This is really dangerous and bad code, as it will prevent this
86  // code from throwing a
87  // compile time error if someone extends the enumeration
88  // sometimes Java just sucks (20080830)
89  bracket = Bracket.OPEN;
90  value = 0;
91  System.err.println("unknown order type occured, incomplete code change");
92  System.exit(-1);
93  // END DELETE ME
94  }
95  }
96 
100  @Override
101  public int compareTo(ShapeOrder o) {
102  double diff = value - o.value;
103  if (diff < 0) {
104  return -1;
105  } else if (diff > 0) {
106  return +1;
107  } else {
108  /*
109  * Remark: we may only return 0 if the two objects are really
110  * identical, identical in our case means same type AND same id
111  */
112  int result = shape.id - o.shape.id;
113  if (result != 0) {
114  return result;
115  } else {
116  return bracket.order - o.bracket.order;
117  }
118  }
119  }
120 
126  @Override
127  public String toString() {
128  StringBuilder result = new StringBuilder();
129  switch (bracket) {
130  case OPEN:
131  result.append("open");
132  break;
133  case CLOSE:
134  result.append("close");
135  }
136  result.append(value);
137  return result.toString();
138  }
139 }
Integer id
ID des zugehörigen Weltobjekts.
Definition: Shape.java:67
Impressum