1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package io.earcam.instrumental.module.manifest;
20
21 import java.util.jar.Attributes.Name;
22
23 import javax.annotation.WillNotClose;
24
25 import io.earcam.instrumental.fluent.Fluent;
26
27 import java.util.jar.Manifest;
28 import java.io.OutputStream;
29 import java.util.AbstractMap;
30 import java.util.HashMap;
31 import java.util.Map;
32
33
34
35
36
37
38
39 public interface ManifestInfoBuilder<T extends ManifestInfoBuilder<T>> {
40
41 public static class ManifestNamedEntry {
42 private final String name;
43 private final Map<Name, CharSequence> attributes = new HashMap<>();
44
45
46 private ManifestNamedEntry(String name)
47 {
48 this.name = name;
49 }
50
51
52 @Fluent
53 public static ManifestNamedEntry entry(CharSequence name)
54 {
55 return new ManifestNamedEntry(name.toString());
56 }
57
58
59 public ManifestNamedEntry attribute(CharSequence key, CharSequence value)
60 {
61 return attribute(new Name(key.toString()), value);
62 }
63
64
65 public ManifestNamedEntry attribute(Name key, CharSequence value)
66 {
67 attributes.put(key, value);
68 return this;
69 }
70
71
72 public String name()
73 {
74 return name;
75 }
76
77
78 public Map<Name, CharSequence> attributes()
79 {
80 return attributes;
81 }
82 }
83
84
85
86
87
88
89
90
91
92
93
94 @Fluent
95 public static Map.Entry<Name, CharSequence> attribute(CharSequence key, CharSequence value)
96 {
97 return attribute(new Name(key.toString()), value);
98 }
99
100
101
102
103
104
105
106
107
108
109
110 @Fluent
111 public static Map.Entry<Name, CharSequence> attribute(Name key, CharSequence value)
112 {
113 return new AbstractMap.SimpleEntry<>(key, value);
114 }
115
116
117
118
119
120
121
122
123
124
125 public abstract T manifestMain(Map.Entry<Name, ? extends CharSequence> attribute);
126
127
128
129
130
131
132
133
134
135
136 public abstract T manifestNamed(ManifestNamedEntry entry);
137
138
139
140
141
142
143
144
145
146
147 public abstract T mergeFrom(Manifest manifest);
148
149
150
151
152
153
154
155
156
157 public default Manifest toManifest()
158 {
159 Manifest manifest = new Manifest();
160 return to(manifest);
161 }
162
163
164
165
166
167
168
169
170
171
172 public abstract Manifest to(Manifest manifest);
173
174
175
176
177
178
179
180
181
182 public abstract void to(@WillNotClose OutputStream out);
183 }