View Javadoc
1   /*-
2    * #%L
3    * io.earcam.instrumental.module.manifest
4    * %%
5    * Copyright (C) 2018 earcam
6    * %%
7    * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT)
8    * 
9    * You <b>must</b> choose to accept, in full - any individual or combination of 
10   * the following licenses:
11   * <ul>
12   * 	<li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li>
13   * 	<li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li>
14   * 	<li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li>
15   * 	<li><a href="https://opensource.org/licenses/MIT">MIT</a></li>
16   * </ul>
17   * #L%
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   * <p>
35   * ManifestInfoBuilder interface.
36   * </p>
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  	 * <p>
87  	 * attribute.
88  	 * </p>
89  	 *
90  	 * @param key a {@link java.lang.CharSequence} object.
91  	 * @param value a {@link java.lang.CharSequence} object.
92  	 * @return a {@link java.util.Map.Entry} object.
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 	 * <p>
103 	 * attribute.
104 	 * </p>
105 	 *
106 	 * @param key a {@link java.util.jar.Attributes.Name} object.
107 	 * @param value a {@link java.lang.CharSequence} object.
108 	 * @return a {@link java.util.Map.Entry} object.
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 	 * <p>
119 	 * manifestMain.
120 	 * </p>
121 	 *
122 	 * @param attribute a {@link java.util.Map.Entry} object.
123 	 * @return a T object.
124 	 */
125 	public abstract T manifestMain(Map.Entry<Name, ? extends CharSequence> attribute);
126 
127 
128 	/**
129 	 * <p>
130 	 * manifestNamed.
131 	 * </p>
132 	 *
133 	 * @param entry a {@link io.earcam.instrumental.module.manifest.ManifestInfoBuilder.ManifestNamedEntry} object.
134 	 * @return a T object.
135 	 */
136 	public abstract T manifestNamed(ManifestNamedEntry entry);
137 
138 
139 	/**
140 	 * <p>
141 	 * mergeFrom.
142 	 * </p>
143 	 *
144 	 * @param manifest a {@link java.util.jar.Manifest} object.
145 	 * @return a T object.
146 	 */
147 	public abstract T mergeFrom(Manifest manifest);
148 
149 
150 	/**
151 	 * <p>
152 	 * toManifest.
153 	 * </p>
154 	 *
155 	 * @return a {@link java.util.jar.Manifest} object.
156 	 */
157 	public default Manifest toManifest()
158 	{
159 		Manifest manifest = new Manifest();
160 		return to(manifest);
161 	}
162 
163 
164 	/**
165 	 * <p>
166 	 * to.
167 	 * </p>
168 	 *
169 	 * @param manifest a {@link java.util.jar.Manifest} object.
170 	 * @return a {@link java.util.jar.Manifest} object.
171 	 */
172 	public abstract Manifest to(Manifest manifest);
173 
174 
175 	/**
176 	 * <p>
177 	 * to.
178 	 * </p>
179 	 *
180 	 * @param out a {@link java.io.OutputStream} object.
181 	 */
182 	public abstract void to(@WillNotClose OutputStream out);
183 }