1 package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
3 import static com.google.common.base.Preconditions.checkNotNull;
5 import com.google.common.base.Optional;
6 import com.google.common.collect.Maps;
7 import com.google.common.io.Files;
9 import java.io.IOException;
10 import java.nio.charset.StandardCharsets;
11 import java.util.Map.Entry;
12 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil;
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 || !dstFile.exists()) {
35 Files.createParentDirs(dstFile);
37 Files.write(content, dstFile, StandardCharsets.UTF_8);
38 return Optional.of(Maps.immutableEntry(fqn, dstFile));
40 return Optional.absent();
44 public Optional<Entry<FullyQualifiedName,File>> persist(File srcDirectory) throws IOException {
45 return persist(srcDirectory, true);
49 public String toString() {
50 return getClass().getSimpleName() + "{" +
56 public boolean equals(Object o) {
60 if (o == null || getClass() != o.getClass()) {
64 GeneratedObject that = (GeneratedObject) o;
66 return fqn.equals(that.fqn);
71 public int hashCode() {
72 return fqn.hashCode();