// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KbaChangeSet.java
// enum Action {
//   ADD("add"),
//   REMOVE("remove"),
//   ;
// 
//   /**
//    * Label as it appears in the .kbd JSON file
//    */
//   private final String label;
// 
//   Action(String label) {
//     this.label = label;
//   }
// 
//   public static Action fromLabel(String someLabel) {
//     for (Action a : values()) {
//       if (a.label.equals(someLabel))
//         return a;
//     }
//     throw new IllegalArgumentException(String.format(
//         "'%s' is not a valid action",
//         someLabel));
//   }
// 
//   static Action forLabel(String label) {
//     for (Action action : values()) {
//       if (action.label.equals(label)) {
//         return action;
//       }
//     }
//     throw new IllegalArgumentException(label);
//   }
//     
//   @Override
//   public String toString() {
//     return label;
//   }
// }


import java.util.List;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.eclipse.mechanic.core.keybinding.KbaChangeSet.Action;
import com.google.gson.annotations.SerializedName;
/*******************************************************************************
 * Copyright (C) 2010, Google Inc.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

package com.google.eclipse.mechanic.core.keybinding;



/**
 * A java representation of a .kbd task, abbreviated as KBA.
 *
 * <p>This, in disk, is represented as a JSON string.
 * 
 * <p>This class operates with primitive types (Strings, ints, lists), not with
 * Eclipse constructs.
 *
 * @author zorzella@google.com
 */
class KeyBindingsModel {

  @SerializedName(KeyBindingsParser.METADATA_JSON_KEY)
  private final KbaMetaData kbaMetadata;
  @SerializedName(KeyBindingsParser.CHANGE_SETS_JSON_KEY)
  private final ImmutableList<KbaChangeSet> kbaChangeSetList;

  public KeyBindingsModel(List<KbaChangeSet> changeSetList, KbaMetaData metadata) {
    this.kbaChangeSetList = filteredChangeSetList(changeSetList);
    this.kbaMetadata = metadata;
  }

  private static ImmutableList<KbaChangeSet> filteredChangeSetList(
      List<KbaChangeSet> changeSetList) {
    Predicate<KbaChangeSet> filterOutRemoveActions = new Predicate<KbaChangeSet>() {
      public boolean apply(KbaChangeSet source) {
        // TODO: support remove
        if (KeyboardBindingsTask.ENABLE_EXP_REM()) {
          return true;
        }
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KbaChangeSet.java
// enum Action {
//   ADD("add"),
//   REMOVE("remove"),
//   ;
// 
//   /**
//    * Label as it appears in the .kbd JSON file
//    */
//   private final String label;
// 
//   Action(String label) {
//     this.label = label;
//   }
// 
//   public static Action fromLabel(String someLabel) {
//     for (Action a : values()) {
//       if (a.label.equals(someLabel))
//         return a;
//     }
//     throw new IllegalArgumentException(String.format(
//         "'%s' is not a valid action",
//         someLabel));
//   }
// 
//   static Action forLabel(String label) {
//     for (Action action : values()) {
//       if (action.label.equals(label)) {
//         return action;
//       }
//     }
//     throw new IllegalArgumentException(label);
//   }
//     
//   @Override
//   public String toString() {
//     return label;
//   }
// }


// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KeyBindingsModel.java
import java.util.List;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.eclipse.mechanic.core.keybinding.KbaChangeSet.Action;
import com.google.gson.annotations.SerializedName;

/*******************************************************************************
 * Copyright (C) 2010, Google Inc.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

package com.google.eclipse.mechanic.core.keybinding;



/**
 * A java representation of a .kbd task, abbreviated as KBA.
 *
 * <p>This, in disk, is represented as a JSON string.
 * 
 * <p>This class operates with primitive types (Strings, ints, lists), not with
 * Eclipse constructs.
 *
 * @author zorzella@google.com
 */
class KeyBindingsModel {

  @SerializedName(KeyBindingsParser.METADATA_JSON_KEY)
  private final KbaMetaData kbaMetadata;
  @SerializedName(KeyBindingsParser.CHANGE_SETS_JSON_KEY)
  private final ImmutableList<KbaChangeSet> kbaChangeSetList;

  public KeyBindingsModel(List<KbaChangeSet> changeSetList, KbaMetaData metadata) {
    this.kbaChangeSetList = filteredChangeSetList(changeSetList);
    this.kbaMetadata = metadata;
  }

  private static ImmutableList<KbaChangeSet> filteredChangeSetList(
      List<KbaChangeSet> changeSetList) {
    Predicate<KbaChangeSet> filterOutRemoveActions = new Predicate<KbaChangeSet>() {
      public boolean apply(KbaChangeSet source) {
        // TODO: support remove
        if (KeyboardBindingsTask.ENABLE_EXP_REM()) {
          return true;
        }
        return source.getAction() == Action.ADD;