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 / java / GeneratedObject.java
1 package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
2
3 import static com.google.common.base.Preconditions.checkNotNull;
4
5 import com.google.common.base.Optional;
6 import com.google.common.collect.Maps;
7 import java.io.File;
8 import java.io.IOException;
9 import java.util.Map.Entry;
10 import org.apache.commons.io.FileUtils;
11 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil;
12
13 public class GeneratedObject {
14
15     private final FullyQualifiedName fqn;
16     private final String content;
17
18     public GeneratedObject(FullyQualifiedName fqn, String content) {
19         this.fqn = checkNotNull(fqn);
20         this.content = StringUtil.formatJavaSource(checkNotNull(content));
21     }
22
23     public FullyQualifiedName getFQN(){
24         return fqn;
25     }
26
27     public String getContent() {
28         return content;
29     }
30
31     public Optional<Entry<FullyQualifiedName,File>> persist(File srcDirectory, boolean overwrite) throws IOException {
32         File dstFile = fqn.toFile(srcDirectory);
33         if (overwrite == true || dstFile.exists() == false) {
34             FileUtils.write(dstFile, content);
35             return Optional.of(Maps.immutableEntry(fqn, dstFile));
36         } else {
37             return Optional.absent();
38         }
39     }
40
41     public Optional<Entry<FullyQualifiedName,File>> persist(File srcDirectory) throws IOException {
42         return persist(srcDirectory, true);
43     }
44
45     @Override
46     public String toString() {
47         return getClass().getSimpleName() + "{" +
48                 "fqn=" + fqn +
49                 '}';
50     }
51
52     @Override
53     public boolean equals(Object o) {
54         if (this == o) {
55             return true;
56         }
57         if (o == null || getClass() != o.getClass()) {
58             return false;
59         }
60
61         GeneratedObject that = (GeneratedObject) o;
62
63         if (!fqn.equals(that.fqn)) {
64             return false;
65         }
66
67         return true;
68     }
69
70     @Override
71     public int hashCode() {
72         return fqn.hashCode();
73     }
74 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.