Renamed project folders to match the respective project name
[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                 else
18                         return bitVector.toString();
19         }
20
21         public static ColorDefinition formatAsColor(ReadEnd end)
22         {
23                 return formatAsColor(end == null ? null : end.getValues());
24         }
25
26         public static ColorDefinition formatAsColor(BitVector bitVector)
27         {
28                 // TODO maybe find a color assignment for multiple-bit bit vectors?
29                 if (bitVector == null || bitVector.length() != 1)
30                         return new ColorDefinition(BuiltInColor.COLOR_BLACK);
31                 else
32                         switch (bitVector.getBit(0))
33                         {
34                         case ONE:
35                                 return new ColorDefinition(BuiltInColor.COLOR_GREEN);
36                         case U:
37                                 return new ColorDefinition(BuiltInColor.COLOR_CYAN);
38                         case X:
39                                 return new ColorDefinition(BuiltInColor.COLOR_RED);
40                         case Z:
41                                 return new ColorDefinition(BuiltInColor.COLOR_YELLOW);
42                         case ZERO:
43                                 return new ColorDefinition(BuiltInColor.COLOR_GRAY);
44                         default:
45                                 throw new IllegalArgumentException("Unknown enum constant: " + bitVector.getBit(0));
46                         }
47         }
48
49         private BitVectorFormatter()
50         {
51                 throw new UnsupportedOperationException("No BitVectorFormatter instances");
52         }
53 }