]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/util/Polarity.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / types / util / Polarity.java
1 package org.simantics.scl.compiler.types.util;
2
3
4 public enum Polarity {
5     NO_POLARITY("?"),
6     POSITIVE("+"),
7     NEGATIVE("-"),
8     BIPOLAR("=");
9     
10     private Polarity(String symbol) {
11         this.symbol = symbol;
12     }
13
14     private final String symbol;
15     private Polarity flipped;
16     private Polarity[] combi = new Polarity[4];
17     
18     static {
19         for(int ia=0;ia<4;++ia) {
20             Polarity a = values()[ia];
21             a.flipped = values()[ ((ia&1)<<1) | ((ia&2)>>1) ];
22             for(int ib=0;ib<4;++ib) {
23                 a.combi[ib] = values()[ia | ib];
24             }
25         }
26     }
27     
28     public Polarity flip() {
29         return flipped;
30     }
31     
32     public Polarity add(Polarity other) {
33         return combi[other.ordinal()];
34     }
35
36     public String getSymbol() {
37         return symbol;
38     }
39     
40     public boolean isPositive() {
41         return (ordinal()&1) != 0;                
42     }
43     
44     public boolean isNegative() {
45         return (ordinal()&2) != 0;
46     }
47 }