Cleanup; Cleared warnings in the logic core
[Mograsim.git] / net.mograsim.logic.core / src / net / mograsim / logic / core / types / BitVectorFormatter.java
1 package net.mograsim.logic.core.types;
2
3 import net.mograsim.logic.core.types.ColorDefinition.BuiltInColor;
4 import net.mograsim.logic.core.wires.Wire.ReadEnd;
5
6 public class BitVectorFormatter
7 {
8         public static String formatValueAsString(ReadEnd end)
9         {
10                 return formatAsString(end == null ? null : end.getValues());
11         }
12
13         public static String formatAsString(BitVector bitVector)
14         {
15                 if (bitVector == null)
16                         return "null";
17                 return bitVector.toString();
18         }
19
20         public static ColorDefinition formatAsColor(ReadEnd end)
21         {
22                 return formatAsColor(end == null ? null : end.getValues());
23         }
24
25         public static ColorDefinition formatAsColor(BitVector bitVector)
26         {
27                 // TODO maybe find a color assignment for multiple-bit bit vectors?
28                 if (bitVector == null || bitVector.length() != 1)
29                         return new ColorDefinition(BuiltInColor.COLOR_BLACK);
30                 switch (bitVector.getBit(0))
31                 {
32                 case ONE:
33                         return new ColorDefinition(BuiltInColor.COLOR_GREEN);
34                 case U:
35                         return new ColorDefinition(BuiltInColor.COLOR_CYAN);
36                 case X:
37                         return new ColorDefinition(BuiltInColor.COLOR_RED);
38                 case Z:
39                         return new ColorDefinition(BuiltInColor.COLOR_YELLOW);
40                 case ZERO:
41                         return new ColorDefinition(BuiltInColor.COLOR_GRAY);
42                 default:
43                         throw new IllegalArgumentException("Unknown enum constant: " + bitVector.getBit(0));
44                 }
45         }
46
47         private BitVectorFormatter()
48         {
49                 throw new UnsupportedOperationException("No BitVectorFormatter instances");
50         }
51 }