If these are musical notes with a fixed set of key-value pairs, then you can use enuma reverse lookup card. You will still get two HashMaps, but at least they are combined into an enumeration.
enum Note {
C("C",60), CSHARP("C#",61), D("D",62), DSHARP("D#",63);
final int value;
final String symbol;
static final Map<Integer, Note> lookup = new HashMap<Integer, Note>();
static {
for(Note n : Note.values()) {
lookup.put(n.value, n);
}
}
Note(String symbol, int value) {
this.symbol = symbol;
this.value = value;
}
static Note get(int i) {
return lookup.get(i);
}
}
Then, to get the values ββand characters, use this
System.out.println(Note.get(61));
System.out.println(Note.get(61).symbol);
System.out.println(Note.CSHARP.value);
System.out.println(Note.CSHARP.symbol);
leading to
CSHARP
C
61
C
PS. Modifiers are removed for brevity. Pss. Add another search map for the symbol.
source
share