BUG 1131: untangling package cyclic dependencies in yang-parser-impl
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / util / Comparators.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.parser.builder.util;
9
10 import java.util.Comparator;
11
12 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
13 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
14
15 public final class Comparators {
16
17     /**
18      * Comparator based on alphabetical order of local name of SchemaNode's qname.
19      */
20     public static final SchemaNodeComparator SCHEMA_NODE_COMP = new SchemaNodeComparator();
21
22     /**
23      * Comparator based on augment target path length.
24      */
25     @Deprecated
26     public static final AugmentComparator AUGMENT_COMP = new AugmentComparator();
27
28     private Comparators() {
29     }
30
31     private static final class SchemaNodeComparator implements Comparator<SchemaNode> {
32         @Override
33         public int compare(final SchemaNode o1, final SchemaNode o2) {
34             return o1.getQName().compareTo(o2.getQName());
35         }
36     }
37
38     private static final class AugmentComparator implements Comparator<AugmentationSchemaBuilder> {
39         @Override
40         public int compare(final AugmentationSchemaBuilder o1, final AugmentationSchemaBuilder o2) {
41             return o1.getTargetPath().getPath().size() - o2.getTargetPath().getPath().size();
42         }
43
44     }
45
46 }