/*
 * Copyright 2000-2012 JetBrains s.r.o.
 *
 * 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.intellij.psi.codeStyle.arrangement.match;

import com.intellij.psi.codeStyle.arrangement.ArrangementUtil;
import com.intellij.psi.codeStyle.arrangement.std.ArrangementSettingsToken;
import org.jetbrains.annotations.NotNull;

import java.util.Set;

/**
 * Arrangement rule which uses {@link StdArrangementEntryMatcher standard settings-based matcher}.
 * <p/>
 * Not thread-safe.
 * 
 * @author Denis Zhdanov
 * @since 8/28/12 2:59 PM
 */
public class StdArrangementMatchRule extends ArrangementMatchRule implements Cloneable, Comparable<StdArrangementMatchRule> {

  public StdArrangementMatchRule(@NotNull StdArrangementEntryMatcher matcher) {
    super(matcher);
  }

  public StdArrangementMatchRule(@NotNull StdArrangementEntryMatcher matcher, @NotNull ArrangementSettingsToken orderType) {
    super(matcher, orderType);
  }

  @NotNull
  @Override
  public StdArrangementEntryMatcher getMatcher() {
    return (StdArrangementEntryMatcher)super.getMatcher();
  }

  @Override
  public StdArrangementMatchRule clone() {
    return new StdArrangementMatchRule(new StdArrangementEntryMatcher(getMatcher().getCondition().clone()), getOrderType());
  }

  @Override
  public int compareTo(@NotNull StdArrangementMatchRule o) {
    final Set<ArrangementSettingsToken> tokens = ArrangementUtil.extractTokens(getMatcher().getCondition()).keySet();
    final Set<ArrangementSettingsToken> tokens1 = ArrangementUtil.extractTokens(o.getMatcher().getCondition()).keySet();
    return tokens1.containsAll(tokens) ? 1 : tokens.containsAll(tokens1) ? -1 : 0;
  }
}

@@ -2068,24 +2068,65 @@
 ).keySet();%0A
+    if (tokens1.containsAll(tokens)) %7B%0A  
     return t
@@ -2126,25 +2126,24 @@
 eturn tokens
-1
 .containsAll
@@ -2153,15 +2153,49 @@
 kens
+1
 ) ? 
-1 :
+0 : 1;%0A    %7D%0A    else %7B%0A      return
  tok
@@ -2229,14 +2229,20 @@
 -1 : 0;%0A
+    %7D%0A
   %7D%0A%7D%0A

fix comparing of match rules [rev=denis.zhdanov]