2 * Copyright (c) 2013 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
9 package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
11 import static com.google.common.base.Preconditions.checkNotNull;
13 import com.google.common.base.Optional;
14 import java.util.ArrayList;
15 import java.util.Collections;
16 import java.util.List;
17 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation;
19 public class JavaFileInputBuilder {
21 private Optional<String> copyright = Optional.absent(), header = Optional.absent(), classJavaDoc = Optional.absent();
23 private TypeName typeName = TypeName.classType;
25 private FullyQualifiedName fqn;
27 private final List<String> classAnnotations = new ArrayList<>();
29 private final List<FullyQualifiedName> importFQNs = new ArrayList<>();
31 private final List<FullyQualifiedName> extendsFQNs = new ArrayList<>();
33 private final List<FullyQualifiedName> implementsFQNs = new ArrayList<>();
35 private final List<String> bodyElements = new ArrayList<>();
37 public void addToBody(String element) {
38 bodyElements.add(element + "\n");
41 public void addClassAnnotation(Annotation annotation) {
42 addClassAnnotation(annotation.toString());
45 public void addClassAnnotation(String annotation) {
46 classAnnotations.add(checkNotNull(annotation));
49 public void addImportFQN(FullyQualifiedName fqn) {
53 public void addExtendsFQN(FullyQualifiedName fqn) {
57 public void addImplementsFQN(FullyQualifiedName fqn) {
58 implementsFQNs.add(fqn);
61 public Optional<String> getCopyright() {
65 public void setCopyright(Optional<String> copyright) {
66 this.copyright = checkNotNull(copyright);
69 public Optional<String> getHeader() {
73 public void setHeader(Optional<String> header) {
74 this.header = checkNotNull(header);
78 public Optional<String> getClassJavaDoc() {
82 public void setClassJavaDoc(Optional<String> classJavaDoc) {
83 this.classJavaDoc = checkNotNull(classJavaDoc);
87 public FullyQualifiedName getFqn() {
91 public void setFqn(FullyQualifiedName fqn) {
95 public List<FullyQualifiedName> getExtendsFQNs() {
100 public List<FullyQualifiedName> getImplementsFQNs() {
101 return implementsFQNs;
105 public TypeName getTypeName() {
109 public void setTypeName(TypeName typeName) {
110 this.typeName = typeName;
114 public JavaFileInput build() {
115 checkNotNull(copyright);
116 checkNotNull(header);
117 checkNotNull(classJavaDoc);
118 checkNotNull(typeName);
121 return new JavaFileInput() {
124 public FullyQualifiedName getFQN() {
129 public Optional<String> getCopyright() {
134 public Optional<String> getHeader() {
139 public List<FullyQualifiedName> getImports() {
140 return Collections.unmodifiableList(importFQNs);
144 public Optional<String> getClassJavaDoc() {
149 public TypeName getType() {
154 public List<FullyQualifiedName> getExtends() {
155 return Collections.unmodifiableList(extendsFQNs);
159 public List<FullyQualifiedName> getImplements() {
160 return Collections.unmodifiableList(implementsFQNs);
164 public List<String> getClassAnnotations() {
165 return Collections.unmodifiableList(classAnnotations);
169 public List<String> getBodyElements() {
170 return Collections.unmodifiableList(bodyElements);