Split Restconf implementations (draft02 and RFC) - move
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / utils / parser / builder / ParserBuilderConstants.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.restconf.nb.rfc8040.utils.parser.builder;
9
10 import com.google.common.base.CharMatcher;
11 import java.util.Arrays;
12 import org.opendaylight.restconf.nb.rfc8040.utils.parser.YangInstanceIdentifierDeserializer;
13 import org.opendaylight.restconf.nb.rfc8040.utils.parser.YangInstanceIdentifierSerializer;
14
15 /**
16  * Util class of constants of {@link YangInstanceIdentifierSerializer} and
17  * {@link YangInstanceIdentifierDeserializer}.
18  *
19  */
20 public final class ParserBuilderConstants {
21
22     private ParserBuilderConstants() {
23         throw new UnsupportedOperationException("Util class");
24     }
25
26     /**
27      * Constants for {@link YangInstanceIdentifierSerializer}.
28      *
29      */
30     public static final class Serializer {
31
32         private Serializer() {
33             throw new UnsupportedOperationException("Util class");
34         }
35
36         public static final String DISABLED_CHARS = Arrays.toString(new char[] { ':', '/', '?', '#', '[', ']', '@' })
37                 .concat(Arrays.toString(new char[] { '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=' }));
38
39         public static final CharMatcher PERCENT_ENCODE_CHARS = CharMatcher.anyOf(DISABLED_CHARS).precomputed();
40     }
41
42     /**
43      * Constants for {@link YangInstanceIdentifierSerializer}.
44      *
45      */
46     public static final class Deserializer {
47
48         private Deserializer() {
49             throw new UnsupportedOperationException("Util class");
50         }
51
52         public static final CharMatcher BASE = CharMatcher.inRange('a', 'z').or(CharMatcher.inRange('A', 'Z'))
53                 .precomputed();
54
55         public static final CharMatcher IDENTIFIER_FIRST_CHAR = BASE.or(CharMatcher.is('_')).precomputed();
56
57         public static final CharMatcher IDENTIFIER = IDENTIFIER_FIRST_CHAR.or(CharMatcher.inRange('0', '9'))
58                 .or(CharMatcher.anyOf(".-")).precomputed();
59
60         public static final CharMatcher IDENTIFIER_HEXA = CharMatcher.inRange('a', 'f')
61                 .or(CharMatcher.inRange('A', 'F')).or(CharMatcher.inRange('0', '9')).precomputed();
62
63         public static final char COLON = ':';
64         public static final char EQUAL = '=';
65         public static final char COMMA = ',';
66         public static final char HYPHEN = '-';
67         public static final char PERCENT_ENCODING = '%';
68
69         public static final CharMatcher IDENTIFIER_PREDICATE = CharMatcher.noneOf(
70                 Serializer.DISABLED_CHARS).precomputed();
71
72         public static final String EMPTY_STRING = "";
73
74         // position of the first encoded char after percent sign in percent encoded string
75         public static final int FIRST_ENCODED_CHAR = 1;
76         // position of the last encoded char after percent sign in percent encoded string
77         public static final int LAST_ENCODED_CHAR = 3;
78         // percent encoded radix for parsing integers
79         public static final int PERCENT_ENCODED_RADIX = 16;
80     }
81 }