Fix CanonicalValueViolation.getMessage()
[yangtools.git] / yang / yang-common / src / main / java / org / opendaylight / yangtools / yang / common / YangNames.java
1 /*
2  * Copyright (c) 2016 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.common;
9
10 import com.google.common.annotations.Beta;
11 import java.util.AbstractMap.SimpleEntry;
12 import java.util.Map.Entry;
13 import org.eclipse.jdt.annotation.NonNullByDefault;
14 import org.eclipse.jdt.annotation.Nullable;
15
16 /**
17  * Utility class for handling various naming conventions mentioned in YANG and related specifications.
18  *
19  * @author Robert Varga
20  */
21 @Beta
22 @NonNullByDefault
23 public final class YangNames {
24     private YangNames() {
25         // Hidden on purpose
26     }
27
28     /**
29      * Parse a file name according to rules outlined in https://tools.ietf.org/html/rfc6020#section-5.2. Input string
30      * should be the base path with file extension stripped.
31      *
32      * @param baseName file base name
33      * @return A tuple containing the module name and parsed revision, if present.
34      * @throws NullPointerException if {@code baseName} is null
35      */
36     public static Entry<String, @Nullable String> parseFilename(final String baseName) {
37         final int zavinac = baseName.lastIndexOf('@');
38         if (zavinac < 0) {
39             return new SimpleEntry<>(baseName, null);
40         }
41
42         return new SimpleEntry<>(baseName.substring(0, zavinac), baseName.substring(zavinac + 1));
43     }
44 }