2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.builder.util;
10 import com.google.common.collect.Iterables;
11 import java.util.Comparator;
12 import java.util.Iterator;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
15 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
16 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
18 public final class Comparators {
21 * Comparator based on alphabetical order of local name of SchemaNode's
24 public static final SchemaNodeComparator SCHEMA_NODE_COMP = new SchemaNodeComparator();
27 * Comparator based on augment target path.
29 public static final AugmentComparator AUGMENT_COMP = new AugmentComparator();
31 public static final AugmentBuilderComparator AUGMENT_BUILDER_COMP = new AugmentBuilderComparator();
33 private Comparators() {
36 private static final class SchemaNodeComparator implements Comparator<SchemaNode> {
38 public int compare(final SchemaNode o1, final SchemaNode o2) {
39 return o1.getQName().compareTo(o2.getQName());
43 private static final class AugmentBuilderComparator implements Comparator<AugmentationSchemaBuilder> {
45 public int compare(AugmentationSchemaBuilder o1, AugmentationSchemaBuilder o2) {
46 int length1 = Iterables.size(o1.getTargetPath().getPathFromRoot());
47 int length2 = Iterables.size(o2.getTargetPath().getPathFromRoot());
48 return length1 - length2;
52 private static final class AugmentComparator implements Comparator<AugmentationSchema> {
54 public int compare(AugmentationSchema augSchema1, AugmentationSchema augSchema2) {
55 final Iterator<QName> thisIt = augSchema1.getTargetPath().getPathFromRoot().iterator();
56 final Iterator<QName> otherIt = augSchema2.getTargetPath().getPathFromRoot().iterator();
58 while (thisIt.hasNext()) {
59 if (otherIt.hasNext()) {
60 final int comp = thisIt.next().compareTo(otherIt.next());
68 if (otherIt.hasNext()) {