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;
19 * @deprecated Pre-Beryllium implementation, scheduled for removal.
22 public final class Comparators {
25 * Comparator based on alphabetical order of local name of SchemaNode's
28 public static final SchemaNodeComparator SCHEMA_NODE_COMP = new SchemaNodeComparator();
31 * Comparator based on augment target path.
33 public static final AugmentComparator AUGMENT_COMP = new AugmentComparator();
35 public static final AugmentBuilderComparator AUGMENT_BUILDER_COMP = new AugmentBuilderComparator();
37 private Comparators() {
40 private static final class SchemaNodeComparator implements Comparator<SchemaNode> {
42 public int compare(final SchemaNode o1, final SchemaNode o2) {
43 return o1.getQName().compareTo(o2.getQName());
47 private static final class AugmentBuilderComparator implements Comparator<AugmentationSchemaBuilder> {
49 public int compare(final AugmentationSchemaBuilder o1, final AugmentationSchemaBuilder o2) {
50 int length1 = Iterables.size(o1.getTargetPath().getPathFromRoot());
51 int length2 = Iterables.size(o2.getTargetPath().getPathFromRoot());
52 return length1 - length2;
56 private static final class AugmentComparator implements Comparator<AugmentationSchema> {
58 public int compare(final AugmentationSchema augSchema1, final AugmentationSchema augSchema2) {
59 final Iterator<QName> thisIt = augSchema1.getTargetPath().getPathFromRoot().iterator();
60 final Iterator<QName> otherIt = augSchema2.getTargetPath().getPathFromRoot().iterator();
62 while (thisIt.hasNext()) {
63 if (otherIt.hasNext()) {
64 final int comp = thisIt.next().compareTo(otherIt.next());
72 if (otherIt.hasNext()) {