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