Merge "Bug 509: Improve logging in InMemoryDataStore."
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / ftl / model / Field.java
1 /*
2  * Copyright (c) 2013 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.controller.config.yangjmxgenerator.plugin.ftl.model;
9
10 import com.google.common.collect.Lists;
11
12 import java.util.List;
13
14 import static com.google.common.base.Preconditions.checkNotNull;
15
16 public class Field {
17     private final String type;
18     private final String name;
19     private final String definition;
20     private final List<String> modifiers;
21     private final boolean needsDepResolver;
22
23     public Field(String type, String name) {
24         this(Lists.<String> newArrayList(), type, name, null, false);
25     }
26
27     public Field(String type, String name, String definition) {
28         this(Lists.<String> newArrayList(), type, name, definition, false);
29     }
30
31     public Field(List<String> modifiers, String type, String name) {
32         this(modifiers, type, name, null, false);
33     }
34
35     public Field(List<String> modifiers, String type, String name,
36             String definition) {
37         this(modifiers, type, name, definition, false);
38     }
39
40     public Field(List<String> modifiers, String type, String name,
41             String nullableDefinition, boolean needsDepResolver) {
42         this.modifiers = checkNotNull(modifiers);
43         this.type = checkNotNull(type);
44         this.name = checkNotNull(name);
45         this.definition = nullableDefinition;
46         this.needsDepResolver = needsDepResolver;
47     }
48
49     public Field(String type, String name, String definition, boolean needsDepResolver) {
50         this(Lists.<String> newArrayList(), type, name, definition, needsDepResolver);
51     }
52
53     public boolean isNeedsDepResolver() {
54         return needsDepResolver;
55     }
56
57     public String getType() {
58         return type;
59     }
60
61     public String getGenericInnerType() {
62         return type.substring(type.indexOf("<") + 1, type.indexOf(">"));
63     }
64
65     public List<String> getModifiers() {
66         return modifiers;
67     }
68
69     public String getName() {
70         return name;
71     }
72
73     public String getDefinition() {
74         return definition;
75     }
76
77     public boolean isArray() {
78         return type.endsWith("[]");
79     }
80
81     @Override
82     public String toString() {
83         return FieldSerializer.toString(this);
84     }
85 }