content: /*
   * Copyright (C) 2010-2101 Alibaba Group Holding Limited.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package com.alibaba.otter.shared.arbitrate.impl.setl.helper;
  
  import java.util.Comparator;
  import java.util.Map;
  
  import com.alibaba.otter.shared.arbitrate.impl.ArbitrateConstants;
  import com.google.common.collect.Maps;
  
  /**
   * stage阶段的排序因子
   * 
   * @author jianghang 2011-9-22 上午09:57:17
   * @version 4.0.0
   */
  public class StageComparator implements Comparator<String> {
  
      private static final Map<String, Integer> stageIndex = Maps.newHashMap();
      static {
          stageIndex.put(ArbitrateConstants.NODE_SELECTED, 1);
          stageIndex.put(ArbitrateConstants.NODE_EXTRACTED, 2);
          stageIndex.put(ArbitrateConstants.NODE_TRANSFORMED, 3);
          // stageIndex.put(ArbitrateConstants.NODE_LOADED, 4);
      }
  
      @Override
      public int compare(String o1, String o2) {
          int i1 = (stageIndex.get(o1) == null ? 0 : stageIndex.get(o1));
          int i2 = (stageIndex.get(o2) == null ? 0 : stageIndex.get(o2));
  
          if (i1 > i2) {
              return 1;
          } else if (i1 == i2) {
              return 0;
          } else {
              return -1;
          }
      }
  
  }
  