1 package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
3 import com.google.common.base.Optional;
4 import com.google.common.collect.Maps;
5 import org.apache.commons.io.FileUtils;
6 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil;
9 import java.io.IOException;
10 import java.util.Map.Entry;
12 import static com.google.common.base.Preconditions.checkNotNull;
14 public class GeneratedObject {
16 private final FullyQualifiedName fqn;
17 private final String content;
19 public GeneratedObject(FullyQualifiedName fqn, String content) {
20 this.fqn = checkNotNull(fqn);
21 this.content = StringUtil.formatJavaSource(checkNotNull(content));
24 public FullyQualifiedName getFQN(){
28 public String getContent() {
32 public Optional<Entry<FullyQualifiedName,File>> persist(File srcDirectory, boolean overwrite) throws IOException {
33 File dstFile = fqn.toFile(srcDirectory);
34 if (overwrite == true || dstFile.exists() == false) {
35 FileUtils.write(dstFile, content);
36 return Optional.of(Maps.immutableEntry(fqn, dstFile));
38 return Optional.absent();
42 public Optional<Entry<FullyQualifiedName,File>> persist(File srcDirectory) throws IOException {
43 return persist(srcDirectory, true);
47 public String toString() {
48 return getClass().getSimpleName() + "{" +
54 public boolean equals(Object o) {
58 if (o == null || getClass() != o.getClass()) {
62 GeneratedObject that = (GeneratedObject) o;
64 if (!fqn.equals(that.fqn)) {
72 public int hashCode() {
73 return fqn.hashCode();