1 package net.mograsim.logic.core.types;
3 import net.mograsim.logic.core.types.ColorDefinition.BuiltInColor;
4 import net.mograsim.logic.core.wires.Wire.ReadEnd;
6 public class BitVectorFormatter
8 public static String formatValueAsString(ReadEnd end)
10 return formatAsString(end == null ? null : end.getValues());
13 public static String formatAsString(BitVector bitVector)
15 if (bitVector == null)
17 return bitVector.toString();
20 public static ColorDefinition formatAsColor(ReadEnd end)
22 return formatAsColor(end == null ? null : end.getValues());
25 public static ColorDefinition formatAsColor(BitVector bitVector)
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))
33 return new ColorDefinition(BuiltInColor.COLOR_GREEN);
35 return new ColorDefinition(BuiltInColor.COLOR_CYAN);
37 return new ColorDefinition(BuiltInColor.COLOR_RED);
39 return new ColorDefinition(BuiltInColor.COLOR_YELLOW);
41 return new ColorDefinition(BuiltInColor.COLOR_GRAY);
43 throw new IllegalArgumentException("Unknown enum constant: " + bitVector.getBit(0));
47 private BitVectorFormatter()
49 throw new UnsupportedOperationException("No BitVectorFormatter instances");