combination) {
- return variants.contains(combination);
- }
-
- public String getInput() {
- return input;
- }
-
- @Override
- public String toString() {
- return input + " => " + variants;
- }
-
- @Override
- public boolean equals(Object arg0) {
- return arg0 == null ? false : variants.equals(((KeyboardModifierSet) arg0).variants);
- }
-
- @Override
- public int hashCode() {
- return variants.hashCode();
- }
-
- /**
- * Parse a set containing one or more modifier sets. Each modifier set is separated by a single
- * space and modifiers within a modifier set are separated by a '+'. For example {@code
- * "ctrl+opt?+caps?+shift? alt+caps+cmd?"} has two modifier sets, namely:
- *
- *
- * - {@code "ctrl+opt?+caps?+shift?"}
- *
- {@code "alt+caps+cmd?"}
- *
- *
- * The '?' symbol appended to some modifiers indicates that this modifier is optional (it can
- * be ON or OFF).
- *
- * @param input String representing the sets of modifier sets. This string must match the format
- * defined in the LDML Keyboard Standard.
- * @return A {@link KeyboardModifierSet} containing all possible variants of the specified
- * combinations.
- * @throws IllegalArgumentException if the input string is incorrectly formatted.
- */
- public static KeyboardModifierSet parseSet(String input) {
- if (input == null) {
- throw new IllegalArgumentException("Input string cannot be null");
- }
-
- String modifierSetInputs[] = input.trim().split(" ");
- Set> variants = new HashSet<>();
- for (String modifierSetInput : modifierSetInputs) {
- variants.addAll(parseSingleSet(modifierSetInput));
- }
- return new KeyboardModifierSet(input, variants);
- }
-
- /**
- * Parse a modifier set. The set typically looks something like {@code ctrl+opt?+caps?+shift?}
- * or {@code alt+caps+cmd?} and return a set containing all possible variants for that
- * particular modifier set.
- *
- * For example {@code alt+caps+cmd?} gets expanded into {@code alt+caps+cmd?, alt+caps} .
- *
- * @param input The input string representing the modifiers. This String must match the format
- * defined in the LDML Keyboard Standard.
- * @return {@link KeyboardModifierSet}.
- * @throws IllegalArgumentException if the input string is incorrectly formatted.
- */
- private static Set> parseSingleSet(String input) {
- if (input == null) {
- throw new IllegalArgumentException("Input string cannot be null");
- }
- if (input.contains(" ")) {
- throw new IllegalArgumentException("Input string contains more than one combination");
- }
-
- String modifiers[] = input.trim().split("\\+");
-
- List> variants = new ArrayList<>();
- variants.add(EnumSet.noneOf(Modifier.class)); // Add an initial set
- // which is empty
-
- // Trivial case
- if (input.isEmpty()) {
- return new HashSet<>(variants);
- }
-
- for (String modifier : modifiers) {
- String modifierElementString = modifier.replace("?", "");
-
- // Attempt to parse the modifier as a parent
- if (ModifierParent.isParentModifier(modifierElementString)) {
- ModifierParent parentModifier = ModifierParent.valueOf(modifierElementString);
-
- // Keep a collection of the new variants that need to be added
- // while iterating over the
- // existing ones
- Set> newVariants = new HashSet<>();
- for (EnumSet variant : variants) {
- // A parent key gets exploded into {Left, Right, Left+Right}
- // or {Left, Right, Left+Right,
- // (empty)} if it is a don't care
-
- // {Left}
- EnumSet leftVariant = EnumSet.copyOf(variant);
- leftVariant.add(parentModifier.leftChild);
- newVariants.add(leftVariant);
-
- // {Right}
- EnumSet rightVariant = EnumSet.copyOf(variant);
- rightVariant.add(parentModifier.rightChild);
- newVariants.add(rightVariant);
-
- // {Left+Right}
- // If it is a don't care, we need to leave the empty case
- // {(empty)}
- if (modifier.contains("?")) {
- EnumSet bothChildrenVariant = EnumSet.copyOf(variant);
- bothChildrenVariant.add(parentModifier.rightChild);
- bothChildrenVariant.add(parentModifier.leftChild);
- newVariants.add(bothChildrenVariant);
- }
- // No empty case, it is safe to add to the existing variants
- else {
- variant.add(parentModifier.rightChild);
- variant.add(parentModifier.leftChild);
- }
- }
- variants.addAll(newVariants);
- }
- // Otherwise, parse as a regular modifier
- else {
- Modifier modifierElement = Modifier.valueOf(modifierElementString);
- // On case, add the modifier to all existing variants
- if (!modifier.contains("?")) {
- for (EnumSet variant : variants) {
- variant.add(modifierElement);
- }
- }
- // Don't care case, make a copy of the existing variants and add
- // the new key to it.
- else {
- List> newVariants = new ArrayList<>();
- for (EnumSet variant : variants) {
- EnumSet newVariant = EnumSet.copyOf(variant);
- newVariant.add(modifierElement);
- newVariants.add(newVariant);
- }
- variants.addAll(newVariants);
- }
- }
- }
-
- return new HashSet<>(variants);
- }
-
- /** Enum of all parent modifier keys. Defines the relationships with their children. */
- private enum ModifierParent {
- ctrl(Modifier.ctrlL, Modifier.ctrlR),
- alt(Modifier.altL, Modifier.altR),
- opt(Modifier.optL, Modifier.optR),
- shift(Modifier.shiftL, Modifier.shiftR);
-
- private final Modifier leftChild;
- private final Modifier rightChild;
-
- private ModifierParent(Modifier leftChild, Modifier rightChild) {
- this.leftChild = leftChild;
- this.rightChild = rightChild;
- }
-
- /**
- * Determines if the String passed in is a valid parent key.
- *
- * @param modifier The modifier string to verify.
- * @return True if it is a parent key, false otherwise.
- */
- private static boolean isParentModifier(String modifier) {
- try {
- ModifierParent.valueOf(modifier);
- return true;
- } catch (IllegalArgumentException e) {
- return false;
- }
- }
- }
-
- public boolean containsSome(KeyboardModifierSet keyMapModifiers) {
- for (Set item : keyMapModifiers.variants) {
- if (variants.contains(item)) {
- return true;
- }
- }
- return false;
- }
-
- public String getShortInput() {
- int pos = input.indexOf(' ');
- if (pos < 0) return input;
- return input.substring(0, pos) + "…";
- }
-}
diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/CharacterMap.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/CharacterMap.java
deleted file mode 100644
index 44e36a55375..00000000000
--- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/CharacterMap.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.unicode.cldr.draft.keyboard;
-
-import com.google.common.base.Function;
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Objects;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-
-/**
- * Object representing a 1 to 1 mapping between an ISO Position ({@link IsoLayoutPosition}) and the
- * provided output that is received when pressing that particular key. This object also includes any
- * keys that are available by "long-pressing" on the key (prominent on mobile phones).
- */
-public final class CharacterMap implements Comparable {
- private final IsoLayoutPosition position;
- private final String output;
- private final ImmutableList longPressKeys;
- private final boolean transformNo;
-
- private CharacterMap(
- IsoLayoutPosition position,
- String output,
- ImmutableList longPressKeys,
- boolean transformNo) {
- this.position = Preconditions.checkNotNull(position);
- this.output = Preconditions.checkNotNull(output);
- this.longPressKeys = Preconditions.checkNotNull(longPressKeys);
- this.transformNo = transformNo;
- }
-
- /** Creates a new character map from the given position and output. */
- public static CharacterMap of(IsoLayoutPosition position, String output) {
- return new CharacterMap(position, output, ImmutableList.of(), false);
- }
-
- /** Creates a new character map from the given position, output and long press keys. */
- public static CharacterMap of(
- IsoLayoutPosition position, String output, ImmutableList longPressKeys) {
- return new CharacterMap(position, output, longPressKeys, false);
- }
-
- public IsoLayoutPosition position() {
- return position;
- }
-
- public String output() {
- return output;
- }
-
- public ImmutableList longPressKeys() {
- return longPressKeys;
- }
-
- public CharacterMap markAsTransformNo() {
- return new CharacterMap(position, output, longPressKeys, true);
- }
-
- public boolean isTransformNo() {
- return transformNo;
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("position", position)
- .add("output", output)
- .add("longPressKeys", longPressKeys)
- .toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o instanceof CharacterMap) {
- CharacterMap other = (CharacterMap) o;
- return position.equals(other.position)
- && output.equals(other.output)
- && longPressKeys.equals(other.longPressKeys);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(position, output, longPressKeys);
- }
-
- /** Sort character maps based on their ISO layout positions. */
- @Override
- public int compareTo(CharacterMap o) {
- return position.compareTo(o.position);
- }
-
- static Function isoLayoutPositionFunction() {
- return CharacterMapToIsoLayoutFunction.INSTANCE;
- }
-
- private enum CharacterMapToIsoLayoutFunction
- implements Function {
- INSTANCE;
-
- @Override
- public IsoLayoutPosition apply(CharacterMap character) {
- return character.position;
- }
- }
-}
diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/IsoLayoutPosition.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/IsoLayoutPosition.java
deleted file mode 100644
index 2bd467a5118..00000000000
--- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/IsoLayoutPosition.java
+++ /dev/null
@@ -1,140 +0,0 @@
-package org.unicode.cldr.draft.keyboard;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Enum which represents the corresponding position of a key using the ISO layout convention where
- * rows are identified by letters and columns are identified by numbers. For example, "D01"
- * corresponds to the “Q” key on a US keyboard. For the purposes of this enum, we depict an ISO
- * layout position by a one-letter row identifier followed by a two digit column number (like "B03",
- * "E12" or "C00").
- *
- * It is important to note that the physical placement of the keys is not encoded in this enum,
- * rather what is important is their logical placement using the ISO convention.
- *
- *
We can also extend the ISO Layout convention by adding rows as we please (such as adding an F
- * row) or adding columns (going beyond 13 or before 0, in which case we would introduce negative
- * column numbers). This extension can be used to map almost any key to the convention for our
- * purposes.
- *
- *
More information about the ISO layout positions can be found in the LDML
- * XML Keyboard Specification
- */
-public enum IsoLayoutPosition {
- /* Row 1 */
- E00('E', 0, "`"),
- E01('E', 1, "1"),
- E02('E', 2, "2"),
- E03('E', 3, "3"),
- E04('E', 4, "4"),
- E05('E', 5, "5"),
- E06('E', 6, "6"),
- E07('E', 7, "7"),
- E08('E', 8, "8"),
- E09('E', 9, "9"),
- E10('E', 10, "0"),
- E11('E', 11, "-"),
- E12('E', 12, "="),
- E13('E', 13, "(key to right of =)"), // Additional key in 106 keyboards (like Japanese
- // keyboards)
-
- /* Row 2 */
- D01('D', 1, "Q"),
- D02('D', 2, "W"),
- D03('D', 3, "E"),
- D04('D', 4, "R"),
- D05('D', 5, "T"),
- D06('D', 6, "Y"),
- D07('D', 7, "U"),
- D08('D', 8, "I"),
- D09('D', 9, "O"),
- D10('D', 10, "P"),
- D11('D', 11, "["),
- D12('D', 12, "]"),
- D13('D', 13, "\\"),
-
- /* Row 3 */
- C01('C', 1, "A"),
- C02('C', 2, "S"),
- C03('C', 3, "D"),
- C04('C', 4, "F"),
- C05('C', 5, "G"),
- C06('C', 6, "H"),
- C07('C', 7, "J"),
- C08('C', 8, "K"),
- C09('C', 9, "L"),
- C10('C', 10, ";"),
- C11('C', 11, "'"),
- C12('C', 12, "(key to right of ')"), // Additional key in 102+ layouts, typically is present
- // when D13 is not
-
- /* Row 4 */
- B00('B', 0, "(key to left of Z)"), // Additional key in 102 and 103 keyboards (like European
- // keyboards)
- B01('B', 1, "Z"),
- B02('B', 2, "X"),
- B03('B', 3, "C"),
- B04('B', 4, "V"),
- B05('B', 5, "B"),
- B06('B', 6, "N"),
- B07('B', 7, "M"),
- B08('B', 8, ","),
- B09('B', 9, "."),
- B10('B', 10, "/"),
- B11('B', 11, "(key to right of /)"),
- B12('B', 12, "(2 keys to right of /)"), // Additional key for Android
-
- /* Row 5 */
- A01('A', 1, "(2 keys to left of space)"), // Additional key for Android
- A02('A', 2, "(key to left of space)"), // Additional key for Android
- A03('A', 3, "space"),
- A04('A', 4, "(key to right of space)"), // Additional key for Android
- A05('A', 5, "(2 keys to right of space)"), // Additional key for Android
- A06('A', 6, "(3 keys to right of space)"), // Additional key for Android
- A07('A', 7, "(4 keys to right of space)"); // Additional key for Android
-
- private final char row;
- private final int column;
- private final String englishKeyName;
-
- private IsoLayoutPosition(char row, int column, String englishKeyName) {
- this.row = row;
- this.column = column;
- this.englishKeyName = checkNotNull(englishKeyName);
- }
-
- public char row() {
- return row;
- }
-
- public int column() {
- return column;
- }
-
- /**
- * Get the label that would be on the key on a US keyboard. This is for convenience and
- * readability purposes only. If the key does not appear on a US keyboard, it returns a
- * description of the position relative to the closest US keyboard key.
- */
- public String englishKeyName() {
- return englishKeyName;
- }
-
- /**
- * Returns the enum member for a given row and column. Throws an illegal argument exception if
- * the element does not exist.
- *
- * @param row the layout row, is an upper-case character between A and E (inclusive)
- * @param column the layout column, is an integer between 0 and 13 (inclusive), not all rows
- * contain elements for all 14 columns
- */
- public static IsoLayoutPosition forPosition(char row, int column) {
- for (IsoLayoutPosition position : values()) {
- if (position.row == row && position.column == column) {
- return position;
- }
- }
- throw new IllegalArgumentException("Missing ISO Position for " + row + ":" + column);
- }
-}
diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyMap.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyMap.java
deleted file mode 100644
index f3f2ac0eeba..00000000000
--- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyMap.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package org.unicode.cldr.draft.keyboard;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSortedMap;
-import com.google.common.collect.Maps;
-
-/**
- * Object that represents a full keyboard mapping for a given modifier key combination set.
- *
- *
For example, the English-US keyboard with the Shift modifier activated outputs:
- *
- *
- * - {@code ISO=E01 US-101 keyboard=[1] = '!'}
- *
- {@code E02 [2] = '@'}
- *
- {@code E03 [3] = '#'}
- *
- {@code E04 [4] = '$'}
- *
- {@code D01 [Q] = 'Q'}
- *
- And so on...
- *
- */
-public final class KeyMap implements Comparable {
- private final ModifierKeyCombinationSet modifierKeyCombinationSet;
- private final ImmutableSortedMap isoLayoutToCharacterMap;
-
- private KeyMap(
- ModifierKeyCombinationSet modifierKeyCombinationSet,
- ImmutableSortedMap isoLayoutToCharacterMap) {
- this.modifierKeyCombinationSet = checkNotNull(modifierKeyCombinationSet);
- this.isoLayoutToCharacterMap = checkNotNull(isoLayoutToCharacterMap);
- }
-
- /** Creates a key map from the given modifier key combination set and characer maps. */
- public static KeyMap of(
- ModifierKeyCombinationSet modifierKeyCombinationSet,
- ImmutableSet characterMaps) {
- return new KeyMap(
- modifierKeyCombinationSet,
- ImmutableSortedMap.copyOf(
- Maps.uniqueIndex(characterMaps, CharacterMap.isoLayoutPositionFunction())));
- }
-
- public ModifierKeyCombinationSet modifierKeyCombinationSet() {
- return modifierKeyCombinationSet;
- }
-
- public ImmutableSortedMap isoLayoutToCharacterMap() {
- return isoLayoutToCharacterMap;
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("modifierKeyCombinationSet", modifierKeyCombinationSet)
- .add("isoLayoutToCharacterMap", isoLayoutToCharacterMap)
- .toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o instanceof KeyMap) {
- KeyMap other = (KeyMap) o;
- return modifierKeyCombinationSet.equals(other.modifierKeyCombinationSet)
- && isoLayoutToCharacterMap.equals(other.isoLayoutToCharacterMap);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(modifierKeyCombinationSet, isoLayoutToCharacterMap);
- }
-
- @Override
- public int compareTo(KeyMap o) {
- // Order the key maps by their modifier sets.
- return modifierKeyCombinationSet.compareTo(o.modifierKeyCombinationSet);
- }
-}
diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/Keyboard.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/Keyboard.java
deleted file mode 100644
index 86d460cc08e..00000000000
--- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/Keyboard.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package org.unicode.cldr.draft.keyboard;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSortedSet;
-
-/**
- * Object representing a keyboard layout. Includes identifier information, platform given names,
- * platform specific names, all the key maps for all modifier set combinations and the possible
- * transforms.
- */
-public final class Keyboard {
- private final KeyboardId keyboardId;
- private final ImmutableList names;
- private final ImmutableSortedSet keyMaps;
- private final ImmutableSortedSet transforms;
- private volatile KeyMap baseMap;
-
- private Keyboard(
- KeyboardId keyboardId,
- ImmutableList names,
- ImmutableSortedSet keyMaps,
- ImmutableSortedSet transforms) {
- this.keyboardId = checkNotNull(keyboardId);
- this.names = checkNotNull(names);
- this.keyMaps = checkNotNull(keyMaps);
- this.transforms = checkNotNull(transforms);
- }
-
- /**
- * Creates a keyboard given an identifier, a list of platform given names, key maps and
- * transforms.
- */
- public static Keyboard of(
- KeyboardId keyboardId,
- ImmutableList names,
- ImmutableSortedSet keyMaps,
- ImmutableSortedSet transforms) {
- return new Keyboard(keyboardId, names, keyMaps, transforms);
- }
-
- public KeyboardId keyboardId() {
- return keyboardId;
- }
-
- public ImmutableList names() {
- return names;
- }
-
- public ImmutableSet keyMaps() {
- return keyMaps;
- }
-
- public KeyMap baseMap() {
- return baseMap == null ? baseMap = getBaseMap() : baseMap;
- }
-
- private KeyMap getBaseMap() {
- for (KeyMap keyMap : keyMaps) {
- if (keyMap.modifierKeyCombinationSet().isBase()) {
- return keyMap;
- }
- }
- throw new IllegalStateException("Missing base map for " + keyboardId);
- }
-
- public ImmutableSet transforms() {
- return transforms;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o instanceof Keyboard) {
- Keyboard other = (Keyboard) o;
- return keyboardId.equals(other.keyboardId)
- && names.equals(other.names)
- && keyMaps.equals(other.keyMaps)
- && transforms.equals(other.transforms);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(keyboardId, names, keyMaps, transforms);
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("keyboardIds", keyboardId)
- .add("names", names)
- .add("keyMaps", keyMaps)
- .add("transforms", transforms)
- .toString();
- }
-}
diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardBuilder.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardBuilder.java
deleted file mode 100644
index 4c2a2603c38..00000000000
--- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardBuilder.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package org.unicode.cldr.draft.keyboard;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.HashBasedTable;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSortedSet;
-import com.google.common.collect.ListMultimap;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Table;
-import com.ibm.icu.text.Collator;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/** Builder class to assist in constructing a keyboard object. */
-public final class KeyboardBuilder {
- private final ImmutableSet.Builder keyboardIds;
- private final ImmutableList.Builder names;
- private final Map transformSequenceToOutput;
- private final Table
- modifierAndPositionToCharacter;
-
- public KeyboardBuilder() {
- keyboardIds = ImmutableSet.builder();
- names = ImmutableList.builder();
- transformSequenceToOutput = Maps.newHashMap();
- modifierAndPositionToCharacter = HashBasedTable.create();
- }
-
- public KeyboardBuilder addKeyboardIds(Iterable keyboardIds) {
- this.keyboardIds.addAll(keyboardIds);
- return this;
- }
-
- public KeyboardBuilder addName(String name) {
- names.add(name);
- return this;
- }
-
- public KeyboardBuilder addTransform(String sequence, String output) {
- if (transformSequenceToOutput.containsKey(sequence)
- && !transformSequenceToOutput.get(sequence).equals(output)) {
- String errorMessage = String.format("Duplicate entry for [%s:%s]", sequence, output);
- throw new IllegalArgumentException(errorMessage);
- }
- transformSequenceToOutput.put(sequence, output);
- return this;
- }
-
- public KeyboardBuilder addCharacterMap(
- ModifierKeyCombination combination, CharacterMap characterMap) {
- checkNotNull(combination);
- if (modifierAndPositionToCharacter.contains(combination, characterMap.position())) {
- CharacterMap existing =
- modifierAndPositionToCharacter.get(combination, characterMap.position());
- checkArgument(
- existing.equals(characterMap),
- "Duplicate entry for [%s:%s:%s]",
- combination,
- characterMap,
- existing);
- }
- modifierAndPositionToCharacter.put(combination, characterMap.position(), characterMap);
- return this;
- }
-
- public KeyboardBuilder addCharacterMap(
- Collection combinations, CharacterMap characterMap) {
- for (ModifierKeyCombination combination : combinations) {
- addCharacterMap(combination, characterMap);
- }
- return this;
- }
-
- public ImmutableList build() {
- ImmutableSet keyboardIds = this.keyboardIds.build();
- checkArgument(keyboardIds.size() > 0, "KeyboardIds must contain at least one element");
- // See if key map consolidation is possible.
- ListMultimap, ModifierKeyCombination> charactersToCombinations =
- ArrayListMultimap.create();
- for (ModifierKeyCombination combination : modifierAndPositionToCharacter.rowKeySet()) {
- Collection characterMaps =
- modifierAndPositionToCharacter.row(combination).values();
- charactersToCombinations.put(ImmutableSet.copyOf(characterMaps), combination);
- }
- // Build the key maps.
- KeyboardId id = keyboardIds.iterator().next();
- ImmutableSortedSet.Builder keyMaps = ImmutableSortedSet.naturalOrder();
- for (ImmutableSet characterMaps : charactersToCombinations.keySet()) {
- List combinations = charactersToCombinations.get(characterMaps);
- ModifierKeyCombinationSet combinationSet =
- ModifierKeyCombinationSet.of(ImmutableSet.copyOf(combinations));
- keyMaps.add(KeyMap.of(combinationSet, characterMaps));
- }
- // Add the transforms.
- ImmutableSortedSet.Builder transforms =
- ImmutableSortedSet.orderedBy(collatorComparator(Collator.getInstance(id.locale())));
- for (Entry transformEntry : transformSequenceToOutput.entrySet()) {
- transforms.add(Transform.of(transformEntry.getKey(), transformEntry.getValue()));
- }
- ImmutableList.Builder keyboards = ImmutableList.builder();
- for (KeyboardId keyboardId : keyboardIds) {
- keyboards.add(
- Keyboard.of(keyboardId, names.build(), keyMaps.build(), transforms.build()));
- }
- return keyboards.build();
- }
-
- public Set transformSequences() {
- return transformSequenceToOutput.keySet();
- }
-
- private static Comparator collatorComparator(final Collator collator) {
- return new Comparator() {
- @Override
- public int compare(Transform o1, Transform o2) {
- return collator.compare(o1.sequence(), o2.sequence());
- }
- };
- }
-}
diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardId.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardId.java
deleted file mode 100644
index 08275ab69f8..00000000000
--- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardId.java
+++ /dev/null
@@ -1,174 +0,0 @@
-package org.unicode.cldr.draft.keyboard;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.Functions;
-import com.google.common.base.Joiner;
-import com.google.common.base.Objects;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import com.ibm.icu.util.ULocale;
-import org.unicode.cldr.draft.keyboard.KeyboardSettings.FallbackSetting;
-import org.unicode.cldr.draft.keyboard.KeyboardSettings.TransformFailureSetting;
-import org.unicode.cldr.draft.keyboard.KeyboardSettings.TransformPartialSetting;
-
-/**
- * An object that is used to uniquely identify a particular keyboard. This object can be serialized
- * as a string. The string has the following format: {@code
- * -t-k0----}
- *
- * The locale and platform tags are mandatory, the attributes are not.
- *
- *
The following are all valid keyboard locale strings:
- *
- *
- * - bn-t-k0-windows.xml
- *
- de-BE-t-k0-windows-var.xml
- *
- fi-t-k0-osx-extended-var.xml
- *
- es-US-t-k0-android-768dpi.xml
- *
- */
-public final class KeyboardId {
- private final ULocale locale;
- private final Platform platform;
- private final ImmutableList attributes;
-
- private KeyboardId(ULocale locale, Platform platform, ImmutableList attributes) {
- this.locale = checkNotNull(locale);
- this.platform = checkNotNull(platform);
- this.attributes = checkNotNull(attributes);
- }
-
- /** Creates a keyboard id from the given locale, platform and attributes. */
- public static KeyboardId of(
- ULocale locale, Platform platform, ImmutableList attributes) {
- return new KeyboardId(locale, platform, attributes);
- }
-
- /**
- * Creates a keyboard id from the given string. See class documentation for information on the
- * required format of the string.
- */
- public static KeyboardId fromString(String keyboardLocale) {
- int tExtensionLocation = keyboardLocale.indexOf("-t-k0-");
- checkArgument(tExtensionLocation != -1, keyboardLocale);
- String localeString = keyboardLocale.substring(0, tExtensionLocation);
- ULocale locale = ULocale.forLanguageTag(localeString);
- String[] attributeStrings = keyboardLocale.substring(tExtensionLocation + 6).split("-");
- checkArgument(attributeStrings.length > 0, keyboardLocale);
- Platform platform = Platform.fromString(attributeStrings[0]);
- ImmutableList attributes =
- attributeStrings.length > 1
- ? ImmutableList.copyOf(attributeStrings).subList(1, attributeStrings.length)
- : ImmutableList.of();
- return new KeyboardId(locale, platform, attributes);
- }
-
- /** Returns the keyboard's locale. */
- public ULocale locale() {
- return locale;
- }
-
- /** Returns the keyboard's platform. */
- public Platform platform() {
- return platform;
- }
-
- /** Returns the list of additional attributes associated with the keyboard (if any). */
- public ImmutableList attributes() {
- return attributes;
- }
-
- private static final Joiner DASH_JOINER = Joiner.on("-");
-
- @Override
- public String toString() {
- ImmutableList.Builder components = ImmutableList.builder();
- // We want to use dashes within the locale as opposed to underscores.
- components.add(locale.toString().replace("_", "-"));
- components.add("t-k0");
- components.add(platform.toString());
- components.addAll(FluentIterable.from(attributes).transform(Functions.toStringFunction()));
- return DASH_JOINER.join(components.build());
- }
-
- @Override
- public boolean equals(Object o) {
- if (o == this) {
- return true;
- }
- if (o instanceof KeyboardId) {
- KeyboardId other = (KeyboardId) o;
- return Objects.equal(locale, other.locale)
- && Objects.equal(platform, other.platform)
- && Objects.equal(attributes, other.attributes);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(locale, platform, attributes);
- }
-
- /** The current set of platforms supported. */
- public enum Platform {
- ANDROID(
- 4.4f,
- KeyboardSettings.of(
- FallbackSetting.NONE,
- TransformFailureSetting.NONE,
- TransformPartialSetting.NONE)),
- CHROMEOS(
- 33f,
- KeyboardSettings.of(
- FallbackSetting.BASE,
- TransformFailureSetting.OMIT,
- TransformPartialSetting.HIDE)),
- OSX(
- 10.9f,
- KeyboardSettings.of(
- FallbackSetting.BASE,
- TransformFailureSetting.EMIT,
- TransformPartialSetting.SHOW)),
- WINDOWS(
- 10f,
- KeyboardSettings.of(
- FallbackSetting.OMIT,
- TransformFailureSetting.EMIT,
- TransformPartialSetting.HIDE));
-
- private final float version;
- private final KeyboardSettings settings;
-
- private Platform(float version, KeyboardSettings settings) {
- this.version = version;
- this.settings = checkNotNull(settings);
- checkArgument(version >= 0);
- }
-
- public double version() {
- return version;
- }
-
- public KeyboardSettings settings() {
- return settings;
- }
-
- @Override
- public String toString() {
- return name().toLowerCase();
- }
-
- /**
- * Retrieves the enum value for the given string. Throws an illegal argument exception if
- * the given string does not correspond to an enum value.
- */
- private static Platform fromString(String platform) {
- Platform value = Platform.valueOf(platform.toUpperCase());
- checkArgument(platform != null, platform);
- return value;
- }
- }
-}
diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardIdMap.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardIdMap.java
deleted file mode 100644
index a2df18eb9af..00000000000
--- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardIdMap.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package org.unicode.cldr.draft.keyboard;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.Charsets;
-import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableCollection;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMultimap;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-import com.google.common.io.Resources;
-import com.ibm.icu.util.ULocale;
-import java.io.IOException;
-import java.util.List;
-import java.util.Set;
-import org.unicode.cldr.draft.keyboard.KeyboardId.Platform;
-
-public final class KeyboardIdMap {
- private final ImmutableMultimap nameToKeyboardId;
- // Internal only.
- private final Set coveredNames;
-
- private KeyboardIdMap(ImmutableMultimap nameToKeyboardId) {
- this.nameToKeyboardId = checkNotNull(nameToKeyboardId);
- coveredNames = Sets.newHashSet();
- }
-
- private static final Splitter LINE_SPLITTER = Splitter.on("\n").omitEmptyStrings();
- private static final Splitter COMMA_SPLITTER = Splitter.on(",");
- private static final Splitter DASH_SPLITTER = Splitter.on("-").omitEmptyStrings();
-
- /**
- * Creates the mapping from csv contents. The first line must contain the column headers
- * "name,locale,attributes".
- */
- public static KeyboardIdMap fromCsv(String csv, Platform platform) {
- checkArgument(!csv.isEmpty());
- List lines = LINE_SPLITTER.splitToList(csv);
- checkArgument(lines.get(0).equals("name,locale,attributes"), "Missing csv headers");
- ImmutableMultimap.Builder builder = ImmutableMultimap.builder();
- for (String line : Iterables.skip(lines, 1)) {
- // The first element may be between quotes (if it includes a comma), if so parse it
- // manually.
- String name;
- int closingQuote = line.startsWith("\"") ? line.indexOf("\"", 1) : 0;
- List components = COMMA_SPLITTER.splitToList(line.substring(closingQuote));
- if (closingQuote != 0) {
- name = line.substring(1, closingQuote);
- } else {
- name = components.get(0);
- }
- ULocale locale = ULocale.forLanguageTag(components.get(1));
- ImmutableList attributes =
- ImmutableList.copyOf(DASH_SPLITTER.splitToList(components.get(2)));
- builder.put(name, KeyboardId.of(locale, platform, attributes));
- }
- return new KeyboardIdMap(builder.build());
- }
-
- /** Retrieves the csv file relative to the class given. */
- public static KeyboardIdMap fromResource(Class> clazz, String fileName, Platform platform) {
- try {
- String csv = Resources.toString(Resources.getResource(clazz, fileName), Charsets.UTF_8);
- return fromCsv(csv, platform);
- } catch (IOException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- public ImmutableCollection getKeyboardId(String name) {
- coveredNames.add(name);
- ImmutableCollection ids = nameToKeyboardId.get(name);
- checkArgument(ids.size() > 0, "No keyboard id for %s [%s]", name, nameToKeyboardId);
- return ids;
- }
-
- public Set unmatchedIds() {
- return Sets.difference(nameToKeyboardId.keySet(), coveredNames);
- }
-}
diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardSettings.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardSettings.java
deleted file mode 100644
index 9cf57df6a77..00000000000
--- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardSettings.java
+++ /dev/null
@@ -1,119 +0,0 @@
-package org.unicode.cldr.draft.keyboard;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Objects;
-
-/** Describes various platform dependent settings that are pertinent to the keyboard use. */
-public final class KeyboardSettings {
- private final FallbackSetting fallbackSetting;
- private final TransformFailureSetting transformFailureSetting;
- private final TransformPartialSetting transformPartialSetting;
-
- private KeyboardSettings(
- FallbackSetting fallbackSetting,
- TransformFailureSetting transformFailureSetting,
- TransformPartialSetting transformPartialSetting) {
- this.fallbackSetting = checkNotNull(fallbackSetting);
- this.transformFailureSetting = checkNotNull(transformFailureSetting);
- this.transformPartialSetting = checkNotNull(transformPartialSetting);
- }
-
- /** Creates a keyboard settings object from the given options. */
- public static KeyboardSettings of(
- FallbackSetting fallbackSetting,
- TransformFailureSetting transformFailureSetting,
- TransformPartialSetting transformPartialSetting) {
- return new KeyboardSettings(
- fallbackSetting, transformFailureSetting, transformPartialSetting);
- }
-
- public FallbackSetting fallbackSetting() {
- return fallbackSetting;
- }
-
- public TransformFailureSetting transformFailureSetting() {
- return transformFailureSetting;
- }
-
- public TransformPartialSetting transformPartialSetting() {
- return transformPartialSetting;
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("fallbackSetting", fallbackSetting)
- .add("transformFailureSetting", transformFailureSetting)
- .add("transformPartialSetting", transformPartialSetting)
- .toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (o == this) {
- return true;
- }
- if (o instanceof KeyboardSettings) {
- KeyboardSettings other = (KeyboardSettings) o;
- return Objects.equal(fallbackSetting, other.fallbackSetting)
- && Objects.equal(transformFailureSetting, other.transformFailureSetting)
- && Objects.equal(transformPartialSetting, other.transformPartialSetting);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(fallbackSetting, transformFailureSetting, transformPartialSetting);
- }
-
- /**
- * Describes the behavior of the system when a key press fails. It specifies what happens if
- * there is no mapping for a particular key for the given set of modifier keys. This setting is
- * completely platform dependent. NONE indicates the setting does not apply to the platform.
- */
- public enum FallbackSetting {
- BASE,
- OMIT,
- NONE;
-
- @Override
- public String toString() {
- return name().toLowerCase();
- }
- }
-
- /**
- * Describes the behavior of the system when a transform fails. For example it specifies what
- * happens if a dead-key is pressed and the following key cannot be combined. This setting is
- * completely platform dependent. NONE indicates the setting does not apply to the platform.
- */
- public enum TransformFailureSetting {
- EMIT,
- OMIT,
- NONE;
-
- @Override
- public String toString() {
- return name().toLowerCase();
- }
- }
-
- /**
- * Describes the behavior of the system while a transform is in progress. It specifies whether
- * the pressed keys are displayed or not. This setting is completely platform dependent. NONE
- * indicates the setting does not apply to the platform.
- */
- public enum TransformPartialSetting {
- HIDE,
- SHOW,
- NONE;
-
- @Override
- public String toString() {
- return name().toLowerCase();
- }
- }
-}
diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardTool.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardTool.java
deleted file mode 100644
index 83974d8264d..00000000000
--- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardTool.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.unicode.cldr.draft.keyboard;
-
-import com.google.common.base.Charsets;
-import com.google.common.collect.ImmutableList;
-import com.google.common.io.Files;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.time.Instant;
-import java.util.Arrays;
-import org.unicode.cldr.draft.keyboard.KeyboardId.Platform;
-import org.unicode.cldr.draft.keyboard.out.KeyboardToXml;
-import org.unicode.cldr.draft.keyboard.out.KeycodeMapToXml;
-// import org.unicode.cldr.draft.keyboard.windows.KlcParser;
-import org.unicode.cldr.draft.keyboard.windows.KlcParser;
-
-public final class KeyboardTool {
-
- /**
- * First argument is output folder, second is the location of the windows keyboard source files.
- */
- public static void main(String[] args) throws IOException {
- System.out.println(Arrays.toString(args));
- long timestamp = Instant.now().getEpochSecond();
- String output = args[0] + "/" + timestamp;
- File outputFolder = new File(output);
- parseWindowsKeyboards(args[1], outputFolder);
- // parseOsxKeyboards("/Users/rwainman/Downloads/osx", outputFolder);
- }
-
- /*
- private static void parseOsxKeyboards(String inputFolder, File outputFolder) throws IOException {
- File macosKeyboardsDirectory = new File(inputFolder);
- File macosOutputFolder = new File(outputFolder + "/osx");
- macosOutputFolder.mkdirs();
- for (File keyboardLayout : macosKeyboardsDirectory.listFiles(KeylayoutFilenameFilter.INSTANCE)) {
- System.out.println("Parsing " + keyboardLayout);
- String contents = Files.toString(keyboardLayout, Charsets.UTF_8);
- KeylayoutParser.parseLayout(contents);
- for (Document document : KeyboardToXml.writeToXml(keyboard)) {
- Element keyboardElement = (Element) document.getFirstChild=();
- String locale = keyboardElement.getAttribute("locale");
- File outputFile = new File(macosOutputFolder + "/" + locale + ".xml");
- Files.write(documentToString(document), outputFile, Charsets.UTF_8);
- System.out.println(" Writing to " + outputFile);
- }
- return;
- }
- System.out.println(KeylayoutParser.KEYBOARD_ID_MAP.unmatchedIds());
- }
-
- private enum KeylayoutFilenameFilter implements FilenameFilter {
- INSTANCE;
- @Override public boolean accept(File dir, String name) {
- return name.endsWith(".keylayout");
- }
- }
- */
-
- private static void parseWindowsKeyboards(String inputFolder, File outputFolder)
- throws IOException {
- File windowsKeyboardsDirectory = new File(inputFolder);
- File windowsOutputFolder = new File(outputFolder + "/windows");
- windowsOutputFolder.mkdirs();
- for (File keyboardLayout :
- windowsKeyboardsDirectory.listFiles(KlcFilenameFilter.INSTANCE)) {
- System.out.println("Parsing " + keyboardLayout);
- String contents = Files.toString(keyboardLayout, Charsets.UTF_16);
- ImmutableList keyboards = KlcParser.parseLayout(contents);
- for (Keyboard keyboard : keyboards) {
- String id = keyboard.keyboardId().toString();
- File outputFile = new File(windowsOutputFolder + "/" + id + ".xml");
- StringWriter keyboardStringWriter = new StringWriter();
- KeyboardToXml.writeToXml(keyboard, keyboardStringWriter);
- FileWriter keyboardFileWriter = new FileWriter(outputFile);
- keyboardFileWriter.write(doLastMinuteFixesToXml(keyboardStringWriter.toString()));
- keyboardFileWriter.close();
- System.out.println(" Writing to " + outputFile);
- }
- }
- System.out.println("Writing _platform.xml");
- FileWriter platformFileWriter = new FileWriter(windowsOutputFolder + "/_platform.xml");
- KeycodeMapToXml.writeToXml(KlcParser.KEYCODE_MAP, Platform.WINDOWS, platformFileWriter);
- if (KlcParser.KEYBOARD_ID_MAP.unmatchedIds().size() != 0) {
- System.out.println(
- "Found the following keyboards with no id (add them to windows-locales.csv file):");
- System.out.println(KlcParser.KEYBOARD_ID_MAP.unmatchedIds());
- }
- }
-
- private enum KlcFilenameFilter implements FilenameFilter {
- INSTANCE;
-
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(".klc");
- }
- }
-
- private static String doLastMinuteFixesToXml(String ouputString) {
- String cleansedString =
- ouputString
- // The regular XML output does not escape the apostrophes.
- .replace("\"'\"", "\"'\"");
- return cleansedString;
- }
-}
diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeycodeMap.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeycodeMap.java
deleted file mode 100644
index 5ad85d9231c..00000000000
--- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeycodeMap.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package org.unicode.cldr.draft.keyboard;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.Charsets;
-import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableSortedMap;
-import com.google.common.collect.Iterables;
-import com.google.common.io.Resources;
-import java.io.IOException;
-import java.util.List;
-
-/**
- * An class which maps a hardware key code (the value that is sent from keyboard driver to the
- * application) to its actual iso layout position.
- */
-public final class KeycodeMap {
- private final ImmutableSortedMap keycodeToIsoLayout;
-
- private KeycodeMap(ImmutableSortedMap keycodeToIsoLayout) {
- this.keycodeToIsoLayout = checkNotNull(keycodeToIsoLayout);
- }
-
- private static final Splitter LINE_SPLITTER = Splitter.on("\n").omitEmptyStrings();
- private static final Splitter COMMA_SPLITTER = Splitter.on(",");
-
- /**
- * Creates the mapping from csv contents. The first line must contain the column headers
- * "keycode,iso".
- */
- public static KeycodeMap fromCsv(String csv) {
- checkArgument(!csv.isEmpty());
- List lines = LINE_SPLITTER.splitToList(csv);
- checkArgument(lines.get(0).equals("keycode,iso"), "Missing csv headers");
- ImmutableSortedMap.Builder builder =
- ImmutableSortedMap.naturalOrder();
- for (String line : Iterables.skip(lines, 1)) {
- // No fancy CSV parsing required since there are no strings.
- List components = COMMA_SPLITTER.splitToList(line);
- builder.put(
- Integer.valueOf(components.get(0)),
- IsoLayoutPosition.valueOf(components.get(1)));
- }
- return new KeycodeMap(builder.build());
- }
-
- /** Retrieves the csv file relative to the class given. */
- public static KeycodeMap fromResource(Class> clazz, String fileName) {
- try {
- String csv = Resources.toString(Resources.getResource(clazz, fileName), Charsets.UTF_8);
- return fromCsv(csv);
- } catch (IOException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- public boolean hasIsoLayoutPosition(Integer keycode) {
- return keycodeToIsoLayout.containsKey(keycode);
- }
-
- public IsoLayoutPosition getIsoLayoutPosition(Integer keycode) {
- return checkNotNull(
- keycodeToIsoLayout.get(keycode),
- "No keycode for %s [%s]",
- keycode,
- keycodeToIsoLayout);
- }
-
- public ImmutableSortedMap keycodeToIsoLayout() {
- return keycodeToIsoLayout;
- }
-}
diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKey.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKey.java
deleted file mode 100644
index c007a1e494a..00000000000
--- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKey.java
+++ /dev/null
@@ -1,136 +0,0 @@
-package org.unicode.cldr.draft.keyboard;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.Functions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-/**
- * Modifier keys used in the LDML Keyboard XML representation. A modifier key is pressed to change
- * the behavior of the keyboard. For example, pressing the Shift key on most Latin keyboards
- * produces upper-case variants of the characters.
- *
- * It is important NOT to change the ordering of the declared enum members because this
- * enumeration is used for sorting purposes.
- */
-public enum ModifierKey {
- COMMAND(Variant.NONE, "cmd"),
- CONTROL(Variant.PARENT, "ctrl"),
- CONTROL_LEFT(Variant.LEFT, "ctrl"),
- CONTROL_RIGHT(Variant.RIGHT, "ctrl"),
- ALT(Variant.PARENT, "alt"),
- ALT_LEFT(Variant.LEFT, "alt"),
- ALT_RIGHT(Variant.RIGHT, "alt"),
- OPTION(Variant.PARENT, "opt"),
- OPTION_LEFT(Variant.LEFT, "opt"),
- OPTION_RIGHT(Variant.RIGHT, "opt"),
- CAPSLOCK(Variant.NONE, "caps"),
- SHIFT(Variant.PARENT, "shift"),
- SHIFT_LEFT(Variant.LEFT, "shift"),
- SHIFT_RIGHT(Variant.RIGHT, "shift");
-
- // Map of modifier key identifiers (obtained by calling toString()) to the modifier key itself.
- private static final ImmutableMap STRING_TO_MODIFIER_KEY =
- Maps.uniqueIndex(
- Lists.newArrayList(ModifierKey.values()), Functions.toStringFunction());
- private static final ImmutableSet PARENTS =
- ImmutableSet.of(CONTROL, ALT, OPTION, SHIFT);
- private static final ImmutableSet SINGLES = ImmutableSet.of(COMMAND, CAPSLOCK);
-
- private final Variant variant;
- private final String keyType;
-
- private ModifierKey(Variant variant, String keyType) {
- this.variant = checkNotNull(variant);
- this.keyType = checkNotNull(keyType);
- }
-
- /** Retrieves a modifier key from its string identifier. */
- public static ModifierKey fromString(String string) {
- ModifierKey key = STRING_TO_MODIFIER_KEY.get(checkNotNull(string));
- checkArgument(key != null, string);
- return key;
- }
-
- /** Returns all keys that are parent keys. */
- public static ImmutableSet parents() {
- return PARENTS;
- }
-
- /** Returns all keys that are neither parent keys or children. */
- public static ImmutableSet singles() {
- return SINGLES;
- }
-
- /**
- * Returns the matching sibling of this key. For example, if this key is ctrlR return ctrlL. If
- * the key has no siblings this method simply returns itself.
- */
- public ModifierKey sibling() {
- if (variant == Variant.PARENT) {
- return this;
- }
- return fromString(keyType + variant.opposite());
- }
-
- /**
- * Returns the parent of this key. For example, if this key is ctrlR return ctrl. If the key is
- * already a parent key this method simply returns itself.
- */
- public ModifierKey parent() {
- if (variant == Variant.PARENT) {
- return this;
- }
- return fromString(keyType);
- }
-
- /**
- * Returns the children of this key. For example if this key is ctrl, return both ctrlL and
- * ctrlR. If this is not a parent key, returns an empty list. The left key is always returned
- * first.
- */
- public ImmutableList children() {
- if (variant != Variant.PARENT) {
- return ImmutableList.of();
- }
- return ImmutableList.of(
- fromString(keyType + Variant.LEFT), fromString(keyType + Variant.RIGHT));
- }
-
- @Override
- public String toString() {
- return keyType + variant.value;
- }
-
- /** The variant of the key. */
- private static enum Variant {
- PARENT(""),
- LEFT("L"),
- RIGHT("R"),
- NONE("");
-
- final String value;
-
- Variant(String value) {
- this.value = checkNotNull(value);
- }
-
- /**
- * Return the opposite variant. Only applicable to the left and right variants. Returns
- * itself otherwise.
- */
- Variant opposite() {
- return this == LEFT ? RIGHT : this == RIGHT ? LEFT : this;
- }
-
- @Override
- public String toString() {
- return value;
- }
- }
-}
diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeyCombination.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeyCombination.java
deleted file mode 100644
index be00e97578d..00000000000
--- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeyCombination.java
+++ /dev/null
@@ -1,200 +0,0 @@
-package org.unicode.cldr.draft.keyboard;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSortedSet;
-import com.google.common.collect.Sets;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * Object containing the combination of modifier keys that must be on and off for a particular
- * combination to be activated. All other keys are considered "don't care keys". This simulates
- * boolean logic for a 3 state system.
- *
- * For example, suppose we have three keys, "A", "B" and "C". Then the boolean expression: {@code
- * A AND !B} means that A must be on, B must be off and C is a don't care.
- *
- *
Some keys may have L and R variants (like Control which has a Left-Control and a
- * Right-Control). When the situation occurs that the parent key (the variant without a left or
- * right suffix) is included into the on keys or off keys sets, then the children are included into
- * the don't care pool and are omitted when the combination is printed out.
- *
- *
For example, suppose we have three keys "A", "B" and "C" and "A" has a left and right variant
- * which are "A-Right" and "A-Left" respectively. Continuing the example above, the keys fall into
- * the following categories:
- *
- *
- * - ON: { A }
- *
- OFF: { B }
- *
- DON'T CARE: { C, A-Left, A-Right }
- *
- *
- * However when printing out the combination, we would exclude the A-Left and A-Right keys
- * because their parent is already included in the ON set. Therefore the output result would be:
- * {@code A+C?}.
- *
- *
A slightly different behavior exists for parent modifier keys. When a parent modifier key is
- * given then its children are also added to the don't care keys pool. Once again, the
- * simplification is shown when printing out the combination.
- *
- *
For example, continuing the above example but this time assuming that C has a left and right
- * variant. Therefore the breakdown looks like:
- *
- *
- * - ON: { A }
- *
- OFF: { B }
- *
- DON'T CARE: { C, C-Left, C-Right, A-Left, A-Right }
- *
- */
-public final class ModifierKeyCombination implements Comparable {
- public static final ModifierKeyCombination BASE =
- ModifierKeyCombination.ofOnKeys(ImmutableSet.of());
-
- private final ImmutableSet onKeys;
- private final ImmutableSet offKeys;
-
- private ModifierKeyCombination(
- ImmutableSet onKeys, ImmutableSet offKeys) {
- this.onKeys = checkNotNull(onKeys);
- this.offKeys = checkNotNull(offKeys);
- }
-
- /**
- * Create a modifier key combination from a set of ON keys. This is the most common factory
- * method since most sources will provide the keys that MUST be on. Simplifies the set as
- * needed.
- */
- public static ModifierKeyCombination ofOnKeys(Set onKeys) {
- return ofOnAndDontCareKeys(ImmutableSet.copyOf(onKeys), ImmutableSet.of());
- }
-
- /**
- * Create a modifier key combination from a set of ON keys and a set of DON'T CARE keys. That is
- * a set of keys that MUST be ON and a set of keys that CAN be ON or OFF. Simplifies the sets as
- * needed.
- */
- public static ModifierKeyCombination ofOnAndDontCareKeys(
- Set onKeys, Set dontCareKeys) {
- checkArgument(
- Sets.intersection(onKeys, dontCareKeys).size() == 0,
- "On keys and don't care keys must be disjoint");
- return ModifierKeySimplifier.simplifyInput(
- ImmutableSet.copyOf(onKeys), ImmutableSet.copyOf(dontCareKeys));
- }
-
- /** Internal. */
- static ModifierKeyCombination of(
- ImmutableSet onKeys, ImmutableSet offKeys) {
- return new ModifierKeyCombination(onKeys, offKeys);
- }
-
- /** Returns the set of keys that have to be ON for this combination to be active. */
- public ImmutableSet onKeys() {
- return onKeys;
- }
-
- /** Returns the set of keys that have to be OFF for this combination to be active. */
- public ImmutableSet offKeys() {
- return offKeys;
- }
-
- /**
- * Determines if this combination is a base combination. That is, is this combination valid when
- * no modifier keys are pressed?
- */
- public boolean isBase() {
- return onKeys.isEmpty();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o instanceof ModifierKeyCombination) {
- ModifierKeyCombination other = (ModifierKeyCombination) o;
- return onKeys.equals(other.onKeys) && offKeys.equals(other.offKeys);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(onKeys, offKeys);
- }
-
- @Override
- public String toString() {
- // TODO: cache this result.
- return ModifierKeySimplifier.simplifyToString(this);
- }
-
- @Override
- public int compareTo(ModifierKeyCombination o) {
- // Compare on keys first.
- ImmutableSortedSet sortedOnKeys1 = ImmutableSortedSet.copyOf(onKeys);
- ImmutableSortedSet sortedOnKeys2 = ImmutableSortedSet.copyOf(o.onKeys);
- int result = compareSetsDescending(sortedOnKeys1, sortedOnKeys2);
- // If they are identical, compare off keys (this will be the opposite from the result from
- // the
- // on keys because what we really want is the order for the don't care keys which are simply
- // the
- // converse of the off keys)
- // Here is a simple illustrative example:
- // -Suppose Alphabetic order within a combination
- // -Suppose reverse Alphabetic order between combinations
- // -Suppose four keys {A, B, C, D}
- // -Suppose two combinations, A.B.~D (A+B+C?) and A.B.~C (A+B+D?).
- // We want them ordered: A+B+D? A+B+C?
- // Clearly, AB are identical in both so we move onto the off keys: ~D and ~C respectively.
- // According to our initial comparison, ~D comes before ~C, but this is incorrect when
- // looking
- // at the don't care keys which are C? and D? respectively. This is why we multiply the
- // result
- // received from the off keys comparison by -1.
- //
- // More on the reverse ordering scheme between combinations:
- // Within a combination: A+B+C (A comes before B and B comes before C)
- // Between combinations: Suppose two combinations, A+C and B+C. Then the order would be B+C
- // A+C.
- // (Reverse ordering so B comes before A).
- if (result == 0) {
- ImmutableSortedSet sortedOffKeys1 = ImmutableSortedSet.copyOf(offKeys);
- ImmutableSortedSet sortedOffKeys2 = ImmutableSortedSet.copyOf(o.offKeys);
- return -1 * compareSetsDescending(sortedOffKeys1, sortedOffKeys2);
- } else {
- return result;
- }
- }
-
- /**
- * Compare two sets of modifier key elements. Returns a negative integer if {@code set1} is less
- * than {@code set2}, a positive integer if {@code set1} is greater than {@code set2} and 0 if
- * both sets are equal.
- *
- * Compares the sets based on the reverse ordering of the natural order imposed by the
- * modifier key enum. This is the convention used in the LDML Keyboard Standard.
- */
- private static int compareSetsDescending(
- ImmutableSortedSet set1, ImmutableSortedSet set2) {
- Iterator iterator1 = set1.iterator();
- Iterator iterator2 = set2.iterator();
- // Compare on keys until a difference is found.
- while (iterator1.hasNext() && iterator2.hasNext()) {
- ModifierKey modifierKey1 = iterator1.next();
- ModifierKey modifierKey2 = iterator2.next();
- if (modifierKey1.compareTo(modifierKey2) < 0) {
- return 1;
- } else if (modifierKey1.compareTo(modifierKey2) > 0) {
- return -1;
- }
- }
- // If the first x elements are identical, then the set with more modifier keys should come
- // after the set with less.
- return set1.size() - set2.size();
- }
-}
diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeyCombinationSet.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeyCombinationSet.java
deleted file mode 100644
index 7e04fd0baed..00000000000
--- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeyCombinationSet.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package org.unicode.cldr.draft.keyboard;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.Joiner;
-import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSortedSet;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * This class wraps a set of modifier key combinations. This class also includes the necessary
- * functions to simplify and output these combinations according to the LDML Keyboard Standard.
- *
- * A modifier key combination set is active if any single contained modifier key combination is
- * active. That is, there is a disjunctive relationship between the combinations.
- *
- *
Combination1 OR Combination2 OR Combination3 ...
- */
-public final class ModifierKeyCombinationSet implements Comparable {
- private final ImmutableSortedSet combinations;
-
- private ModifierKeyCombinationSet(ImmutableSortedSet combinations) {
- this.combinations = checkNotNull(combinations);
- }
-
- /**
- * Creates a modifier key combination set from a set of combinations. Simplifies the set to its
- * simplest form.
- */
- public static ModifierKeyCombinationSet of(Set combinations) {
- ImmutableSet simplifiedSet =
- ModifierKeySimplifier.simplifySet(combinations);
- return new ModifierKeyCombinationSet(ImmutableSortedSet.copyOf(simplifiedSet));
- }
-
- /**
- * Merge multiple modifier key combinations into a single one. This method is useful when
- * consolidating identical key maps together.
- */
- public static ModifierKeyCombinationSet combine(Iterable sets) {
- ImmutableSet.Builder builder = ImmutableSet.builder();
- for (ModifierKeyCombinationSet combinationSet : sets) {
- builder.addAll(combinationSet.combinations);
- }
- return ModifierKeyCombinationSet.of(builder.build());
- }
-
- public ImmutableSortedSet combinations() {
- return combinations;
- }
-
- /**
- * Determines if this modifier key combination set is a base set. That is, is it active when no
- * modifiers are pressed?
- */
- public boolean isBase() {
- for (ModifierKeyCombination combination : combinations) {
- if (combination.isBase()) {
- return true;
- }
- }
- return false;
- }
-
- private static final Joiner SPACE_JOINER = Joiner.on(" ");
-
- @Override
- public String toString() {
- return SPACE_JOINER.join(combinations);
- }
-
- @Override
- public int compareTo(ModifierKeyCombinationSet o) {
- Iterator iterator1 = combinations.iterator();
- Iterator iterator2 = o.combinations.iterator();
- // Compare combinations until a difference is found.
- while (iterator1.hasNext() && iterator2.hasNext()) {
- ModifierKeyCombination combination1 = iterator1.next();
- ModifierKeyCombination combination2 = iterator2.next();
- if (combination1.compareTo(combination2) < 0) {
- return -1;
- } else if (combination1.compareTo(combination2) > 0) {
- return 1;
- }
- }
- // Otherwise compare them based on size.
- return combinations.size() - o.combinations.size();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o instanceof ModifierKeyCombinationSet) {
- ModifierKeyCombinationSet other = (ModifierKeyCombinationSet) o;
- return combinations.equals(other.combinations);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(combinations);
- }
-}
diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeySimplifier.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeySimplifier.java
deleted file mode 100644
index 73e15c8fc54..00000000000
--- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeySimplifier.java
+++ /dev/null
@@ -1,457 +0,0 @@
-package org.unicode.cldr.draft.keyboard;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableTable;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import com.google.common.collect.Sets.SetView;
-import java.util.EnumSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-
-/**
- * A helper class which helps simplify single key combinations. That is, keys which come in a parent
- * and child variants.
- *
- * The strategy used to build this simplification table was to minimize the number of terms in
- * the boolean algebra by simplifying most keys into a "don't care (?)" state as much as possible.
- * For example, to represent an empty combination of keys, we use "Parent = 0, Left Child = ?, Right
- * Child = ?" as opposed to "Parent = 0, Left Child = 0, Right Child = 0". (See the table above for
- * more details). Both forms are functionally equivalent but we feel that the first form is much
- * simpler to represent.
- */
-public final class ModifierKeySimplifier {
- /**
- * A mapping from input (given by a ON set and a DON'T CARE set) to the internal representation
- * of the combination. The order is always {@code }.
- *
- * Notation:
- *
- *
- * - "-" = Missing (not in any set)
- *
- "1" = In the ON set
- *
- "?" = In the DON'T CARE set
- *
- "0" = In the OFF set
- *
- */
- private static final ImmutableMap INPUT_COMBINATION_TO_INTERNAL =
- ImmutableMap.builder()
- .put("---", "0??")
- .put("--1", "?01")
- .put("--?", "?0?")
- .put("-1-", "?10")
- .put("-11", "?11")
- .put("-1?", "?1?")
- .put("-?-", "??0")
- .put("-?1", "??1")
- .put("-??", "???")
- .put("1--", "1??")
- .put("1-1", "??1")
- .put("1-?", "1??")
- .put("11-", "?1?")
- .put("111", "?11")
- .put("11?", "?1?")
- .put("1?-", "1??")
- .put("1?1", "??1")
- .put("1??", "1??")
- .put("?--", "???")
- .put("?-1", "??1")
- .put("?-?", "?0?")
- .put("?1-", "?1?")
- .put("?11", "?11")
- .put("?1?", "?1?")
- .put("??-", "??0")
- .put("??1", "??1")
- .put("???", "???")
- .build();
-
- /**
- * A mapping which maps the result of an OR between two combinations. Takes two combinations
- * (represented in the internal notation) and returns the simplified combination (also in the
- * internal notation).
- *
- * For example, "A? AL" simplifies to "A?", "AL AL+AR" simplifies to "AL+AR?" and so on. The
- * equivalence table is included in the document linked in the class header.
- *
- *
Notation:
- *
- *
- * - "%" = No simplification possible, both combinations must stay.
- *
- "1" = In the ON set
- *
- "?" = In the DON'T CARE set
- *
- "0" = In the OFF set
- *
- */
- private static final ImmutableTable COMBINATIONS_TO_SIMPLIFCATION =
- ImmutableTable.builder()
- .put("1??", "0??", "???")
- .put("?10", "0??", "??0")
- .put("?1?", "0??", "%")
- .put("??0", "0??", "??0")
- .put("?11", "0??", "%")
- .put("?01", "0??", "?0?")
- .put("??1", "0??", "%")
- .put("?0?", "0??", "?0?")
- .put("???", "0??", "???")
- .put("?10", "1??", "1??")
- .put("?1?", "1??", "1??")
- .put("??0", "1??", "???")
- .put("?11", "1??", "1??")
- .put("?01", "1??", "1??")
- .put("??1", "1??", "1??")
- .put("?0?", "1??", "???")
- .put("???", "1??", "???")
- .put("?1?", "?10", "?1?")
- .put("??0", "?10", "??0")
- .put("?11", "?10", "?1?")
- .put("?01", "?10", "%")
- .put("??1", "?10", "%")
- .put("?0?", "?10", "%")
- .put("???", "?10", "???")
- .put("??0", "?1?", "%")
- .put("?11", "?1?", "?1?")
- .put("?01", "?1?", "%")
- .put("??1", "?1?", "1??")
- .put("?0?", "?1?", "???")
- .put("???", "?1?", "???")
- .put("?11", "??0", "%")
- .put("?01", "??0", "%")
- .put("??1", "??0", "???")
- .put("?0?", "??0", "%")
- .put("???", "??0", "???")
- .put("?01", "?11", "??1")
- .put("??1", "?11", "??1")
- .put("?0?", "?11", "%")
- .put("???", "?11", "???")
- .put("??1", "?01", "??1")
- .put("?0?", "?01", "?0?")
- .put("???", "?01", "???")
- .put("?0?", "??1", "%")
- .put("???", "??1", "???")
- .put("???", "?0?", "???")
- .build();
-
- /**
- * Given a set of ON keys and DON'T CARE keys, simplify and determine the internal
- * representation of the combination.
- */
- public static ModifierKeyCombination simplifyInput(
- Set onKeys, Set dontCareKeys) {
- checkArgument(Sets.intersection(onKeys, dontCareKeys).size() == 0);
- ImmutableSet.Builder onKeysBuilder = ImmutableSet.builder();
- ImmutableSet.Builder offKeysBuilder = ImmutableSet.builder();
- // Add parent keys and their children.
- for (ModifierKey parentKey : ModifierKey.parents()) {
- StringBuilder inputRepresentation = new StringBuilder();
- // Parent key.
- inputRepresentation.append(getInputKeyState(parentKey, onKeys, dontCareKeys));
- // Children.
- for (ModifierKey child : parentKey.children()) {
- inputRepresentation.append(getInputKeyState(child, onKeys, dontCareKeys));
- }
- // Get the internal representation
- String result = INPUT_COMBINATION_TO_INTERNAL.get(inputRepresentation.toString());
- checkNotNull(result, "No internal mapping for %s", inputRepresentation);
- // Transform the String representation into the internal representation and add them to
- // the ON
- // and OFF sets.
- addInternalRepresentationFromString(parentKey, result, onKeysBuilder, offKeysBuilder);
- }
- // Add single keys.
- for (ModifierKey singleKey : ModifierKey.singles()) {
- if (onKeys.contains(singleKey)) {
- onKeysBuilder.add(singleKey);
- } else if (!dontCareKeys.contains(singleKey)) {
- offKeysBuilder.add(singleKey);
- }
- }
- return ModifierKeyCombination.of(onKeysBuilder.build(), offKeysBuilder.build());
- }
-
- /** Find the state of the given modifier key by evaluating the given sets. */
- private static char getInputKeyState(
- ModifierKey modifierKey, Set onKeys, Set dontCareKeys) {
- return onKeys.contains(modifierKey) ? '1' : dontCareKeys.contains(modifierKey) ? '?' : '-';
- }
-
- private static Joiner PLUS_JOINER = Joiner.on('+');
-
- /**
- * Given a set of ON keys and OFF keys in the internal representation, simplify the combination
- * and produce a string representing the combination in the format defined by the LDML Keyboard
- * Standard.
- *
- * Namely:
- *
- *
- * - All keys are separated by a '+'.
- *
- All don't care keys are suffixed by a '?'.
- *
- ON keys are grouped together and are displayed first, followed by the don't care keys.
- *
- The modifier keys should be in the order defined in the standard within a group.
- *
- The combination should be in its simplest form.
- *
- */
- public static String simplifyToString(ModifierKeyCombination combination) {
- ImmutableSet onKeys = combination.onKeys();
- ImmutableSet offKeys = combination.offKeys();
- TreeSet onKeysForOutput = Sets.newTreeSet();
- TreeSet dontCareKeysForOutput = Sets.newTreeSet();
- for (ModifierKey parentKey : ModifierKey.parents()) {
- String result = getStringFromInternalRepresentation(parentKey, onKeys, offKeys);
- char parentState = result.charAt(0);
- char leftChildState = result.charAt(1);
- char rightChildState = result.charAt(2);
- // If both children are don't cares, output the parent only in its state (don't output
- // the OFF
- // ones).
- if (leftChildState == '?' && rightChildState == '?') {
- if (parentState == '1') {
- onKeysForOutput.add(parentKey);
- } else if (parentState == '?') {
- dontCareKeysForOutput.add(parentKey);
- }
- }
- // Otherwise, add the child keys in their states (don't output the OFF ones).
- else {
- ImmutableList children = parentKey.children();
- if (leftChildState == '1') {
- onKeysForOutput.add(children.get(0));
- } else if (leftChildState == '?') {
- dontCareKeysForOutput.add(children.get(0));
- }
- if (rightChildState == '1') {
- onKeysForOutput.add(children.get(1));
- } else if (rightChildState == '?') {
- dontCareKeysForOutput.add(children.get(1));
- }
- }
- }
- // Add single keys
- for (ModifierKey singleKey : ModifierKey.singles()) {
- if (onKeys.contains(singleKey)) {
- onKeysForOutput.add(singleKey);
- } else if (!offKeys.contains(singleKey)) {
- dontCareKeysForOutput.add(singleKey);
- }
- }
- // Join on-keys.
- String onKeysString = PLUS_JOINER.join(onKeysForOutput);
- // Join don't care keys.
- List dontCareKeysList = Lists.newArrayList();
- for (ModifierKey dontCareKey : dontCareKeysForOutput) {
- dontCareKeysList.add(dontCareKey.toString() + "?");
- }
- String dontCareKeysString = PLUS_JOINER.join(dontCareKeysList);
- return dontCareKeysString.isEmpty()
- ? onKeysString
- : onKeysString.isEmpty()
- ? dontCareKeysString
- : PLUS_JOINER.join(onKeysString, dontCareKeysString);
- }
-
- /** Find the state of the given modifier key by evaluating the given sets. */
- private static char getInternalKeyState(
- ModifierKey modifierKey, Set onKeys, Set offKeys) {
- return onKeys.contains(modifierKey) ? '1' : offKeys.contains(modifierKey) ? '0' : '?';
- }
-
- /**
- * Simplifies the set of combinations into its most simple forms and returns a modifier key
- * combination set.
- */
- public static ImmutableSet simplifySet(
- Set