source: josm/trunk/src/org/openstreetmap/josm/actions/mapmode/ModifiersSpec.java@ 6889

Last change on this file since 6889 was 6889, checked in by Don-vip, 10 years ago

fix some Sonar issues (JLS order)

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1// License: GPL. See LICENSE file for details.
2package org.openstreetmap.josm.actions.mapmode;
3
4/**
5 * TODO: rewrite to use awt modifers flag instead.
6 *
7 * @author Ole Jørgen Brønner (olejorgenb)
8 */
9public class ModifiersSpec {
10 public static final int ON = 1, OFF = 0, UNKNOWN = 2;
11 public int alt = UNKNOWN;
12 public int shift = UNKNOWN;
13 public int ctrl = UNKNOWN;
14
15 /**
16 * 'A' = Alt, 'S' = Shift, 'C' = Ctrl
17 * Lowercase signifies off and '?' means unknown/optional.
18 * Order is Alt, Shift, Ctrl
19 * @param str
20 */
21 public ModifiersSpec(String str) {
22 assert (str.length() == 3);
23 char a = str.charAt(0);
24 char s = str.charAt(1);
25 char c = str.charAt(2);
26 // @formatter:off
27 alt = (a == '?' ? UNKNOWN : (a == 'A' ? ON : OFF));
28 shift = (s == '?' ? UNKNOWN : (s == 'S' ? ON : OFF));
29 ctrl = (c == '?' ? UNKNOWN : (c == 'C' ? ON : OFF));
30 // @formatter:on
31 }
32
33 public ModifiersSpec(final int alt, final int shift, final int ctrl) {
34 this.alt = alt;
35 this.shift = shift;
36 this.ctrl = ctrl;
37 }
38
39 public boolean matchWithKnown(final int knownAlt, final int knownShift, final int knownCtrl) {
40 return match(alt, knownAlt) && match(shift, knownShift) && match(ctrl, knownCtrl);
41 }
42
43 public boolean matchWithKnown(final boolean knownAlt, final boolean knownShift, final boolean knownCtrl) {
44 return match(alt, knownAlt) && match(shift, knownShift) && match(ctrl, knownCtrl);
45 }
46
47 private boolean match(final int a, final int knownValue) {
48 assert (knownValue == ON | knownValue == OFF);
49 return a == knownValue || a == UNKNOWN;
50 }
51
52 private boolean match(final int a, final boolean knownValue) {
53 return a == (knownValue ? ON : OFF) || a == UNKNOWN;
54 }
55 // does java have built in 3-state support?
56}
Note: See TracBrowser for help on using the repository browser.