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 com.google.common.base.Optional;
12 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation;
14 import java.util.ArrayList;
15 import java.util.Collections;
16 import java.util.List;
18 import static com.google.common.base.Preconditions.checkNotNull;
20 public class JavaFileInputBuilder {
22 private Optional<String> copyright = Optional.absent(), header = Optional.absent(), classJavaDoc = Optional.absent();
24 private TypeName typeName = TypeName.classType;
26 private FullyQualifiedName fqn;
28 private final List<String> classAnnotations = new ArrayList<>();
30 private final List<FullyQualifiedName> extendsFQNs = new ArrayList<>();
32 private final List<FullyQualifiedName> implementsFQNs = new ArrayList<>();
34 private final List<String> bodyElements = new ArrayList<>();
36 public void addToBody(String element) {
37 bodyElements.add(element + "\n");
40 public void addClassAnnotation(Annotation annotation) {
41 addClassAnnotation(annotation.toString());
44 public void addClassAnnotation(String annotation) {
45 classAnnotations.add(checkNotNull(annotation));
48 public void addExtendsFQN(FullyQualifiedName fqn) {
52 public void addImplementsFQN(FullyQualifiedName fqn) {
53 implementsFQNs.add(fqn);
56 public Optional<String> getCopyright() {
60 public void setCopyright(Optional<String> copyright) {
61 this.copyright = checkNotNull(copyright);
64 public Optional<String> getHeader() {
68 public void setHeader(Optional<String> header) {
69 this.header = checkNotNull(header);
73 public Optional<String> getClassJavaDoc() {
77 public void setClassJavaDoc(Optional<String> classJavaDoc) {
78 this.classJavaDoc = checkNotNull(classJavaDoc);
82 public FullyQualifiedName getFqn() {
86 public void setFqn(FullyQualifiedName fqn) {
90 public List<FullyQualifiedName> getExtendsFQNs() {
95 public List<FullyQualifiedName> getImplementsFQNs() {
96 return implementsFQNs;
100 public TypeName getTypeName() {
104 public void setTypeName(TypeName typeName) {
105 this.typeName = typeName;
109 public JavaFileInput build() {
110 checkNotNull(copyright);
111 checkNotNull(header);
112 checkNotNull(classJavaDoc);
113 checkNotNull(typeName);
116 return new JavaFileInput() {
119 public FullyQualifiedName getFQN() {
124 public Optional<String> getCopyright() {
129 public Optional<String> getHeader() {
134 public Optional<String> getClassJavaDoc() {
139 public TypeName getType() {
144 public List<FullyQualifiedName> getExtends() {
145 return Collections.unmodifiableList(extendsFQNs);
149 public List<FullyQualifiedName> getImplements() {
150 return Collections.unmodifiableList(implementsFQNs);
154 public List<String> getClassAnnotations() {
155 return Collections.unmodifiableList(classAnnotations);
159 public List<String> getBodyElements() {
160 return Collections.unmodifiableList(bodyElements);