1 package net.sf.jpkgmk.pkgmap;
2
3 import net.sf.jpkgmk.AbstractLineProvider;
4 import net.sf.jpkgmk.pkgmap.PkgMapEntryHeader.PkgMapEntryHeaderParser;
5 import net.sf.jpkgmk.util.StringUtil;
6 import net.sf.jpkgmk.util.StringUtil.RemoveResult;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10
11
12
13
14
15
16
17
18 public class PkgMapEntryComment extends AbstractLineProvider implements PkgMapEntry
19 {
20
21 private PkgMapEntryType type = PkgMapEntryType.COMMENT;
22 private String text;
23
24
25
26
27
28 private boolean hasWhitespaceSeparator = true;
29
30 private Log log = LogFactory.getLog(PkgMapEntryComment.class);
31
32
33
34
35
36 public PkgMapEntryComment(String text)
37 {
38 this.text = text;
39 }
40
41
42
43
44 public boolean isHasWhitespaceSeparator() {
45 return hasWhitespaceSeparator;
46 }
47
48
49
50
51 public void setHasWhitespaceSeparator(boolean hasWhitespaceSeparator) {
52 this.hasWhitespaceSeparator = hasWhitespaceSeparator;
53 }
54
55
56
57
58
59 public String getLine()
60 {
61 log.debug("<getLine()>");
62
63 StringBuffer sb = new StringBuffer();
64 sb.append(this.type.getKey());
65 if(this.hasWhitespaceSeparator) {
66 sb.append(" ");
67 }
68 sb.append(this.text);
69 return sb.toString();
70
71 }
72
73
74
75
76 public PkgMapEntryType getType()
77 {
78 return this.type;
79 }
80
81
82 @Override
83 public int hashCode() {
84 final int prime = 31;
85 int result = 1;
86 result = prime * result + (hasWhitespaceSeparator ? 1231 : 1237);
87 result = prime * result + ((text == null) ? 0 : text.hashCode());
88 return result;
89 }
90
91 @Override
92 public boolean equals(Object obj) {
93 if (this == obj)
94 return true;
95 if (obj == null)
96 return false;
97 if (getClass() != obj.getClass())
98 return false;
99 final PkgMapEntryComment other = (PkgMapEntryComment) obj;
100 if (hasWhitespaceSeparator != other.hasWhitespaceSeparator)
101 return false;
102 if (text == null) {
103 if (other.text != null)
104 return false;
105 } else if (!text.equals(other.text))
106 return false;
107 return true;
108 }
109
110 public boolean equals(Object obj, boolean ignoreLastModified) {
111 return this.equals(obj);
112 }
113
114 @Override
115 public String toString()
116 {
117 StringBuffer sb = new StringBuffer();
118 sb.append("type=").append(type);
119 sb.append(",text=").append(text);
120 return sb.toString();
121 }
122
123
124 public static class PkgMapEntryCommentParser implements PkgMapEntryParser
125 {
126 private Log log = LogFactory.getLog(PkgMapEntryHeaderParser.class);
127
128 public PkgMapEntryCommentParser()
129 {
130
131 }
132
133 public PkgMapEntry parse(String line) {
134 log.debug("<entering> parse()");
135 RemoveResult removeResult = StringUtil.removePrefix(line, PkgMapEntryType.COMMENT.getKey());
136
137 PkgMapEntryComment result = new PkgMapEntryComment(removeResult.getCleanedString());
138 result.setHasWhitespaceSeparator(removeResult.isHasWhitespaceSeparator());
139 return result;
140 }
141 }
142
143 }