2 * Copyright (c) 2014 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.model.util;
10 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
11 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
13 import com.google.common.base.Optional;
15 public class SchemaNodeUtils {
17 private SchemaNodeUtils() {
18 throw new UnsupportedOperationException("Utility class");
21 public static final Optional<SchemaNode> getOriginalIfPossible(final SchemaNode node) {
22 if(node instanceof DerivableSchemaNode) {
23 @SuppressWarnings("unchecked")
24 final Optional<SchemaNode> ret = (Optional<SchemaNode>) (((DerivableSchemaNode) node).getOriginal());
27 return Optional.absent();
30 public static final SchemaNode getRootOriginalIfPossible(final SchemaNode data) {
31 Optional<SchemaNode> previous = Optional.absent();
32 Optional<SchemaNode> next = getOriginalIfPossible(data);
33 while(next.isPresent()) {
35 next = getOriginalIfPossible(next.get());
37 return previous.orNull();