Merge "BUG-582: pre-cache Pattern instances"
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / 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.util;
9
10 import java.util.Comparator;
11 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
12 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
13
14 public final class Comparators {
15
16     /**
17      * Comparator based on alphabetical order of local name of SchemaNode's qname.
18      */
19     public static final SchemaNodeComparator SCHEMA_NODE_COMP = new SchemaNodeComparator();
20
21     /**
22      * Comparator based on augment target path length.
23      */
24     public static final AugmentComparator AUGMENT_COMP = new AugmentComparator();
25
26     private Comparators() {
27     }
28
29     private static final class SchemaNodeComparator implements Comparator<SchemaNode> {
30         @Override
31         public int compare(SchemaNode o1, SchemaNode o2) {
32             return o1.getQName().compareTo(o2.getQName());
33         }
34     }
35
36     private static final class AugmentComparator implements Comparator<AugmentationSchemaBuilder> {
37         @Override
38         public int compare(AugmentationSchemaBuilder o1, AugmentationSchemaBuilder o2) {
39             return o1.getTargetPath().getPath().size() - o2.getTargetPath().getPath().size();
40         }
41
42     }
43
44 }