View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //  Generated by Modello Velocity from model.vm
3   //  template, any modifications will be overwritten.
4   // ==============================================================
5   package org.apache.maven.api.model;
6   
7   import java.io.Serializable;
8   import java.util.Collections;
9   import java.util.HashMap;
10  import java.util.Map;
11  import java.util.Objects;
12  import java.util.Optional;
13  import java.util.Set;
14  import java.util.stream.Collectors;
15  import java.util.stream.Stream;
16  import org.apache.maven.api.annotations.Experimental;
17  import org.apache.maven.api.annotations.Generated;
18  import org.apache.maven.api.annotations.Immutable;
19  import org.apache.maven.api.annotations.Nonnull;
20  import org.apache.maven.api.annotations.NotThreadSafe;
21  import org.apache.maven.api.annotations.ThreadSafe;
22  
23  /**
24   * Information about the issue tracking (or bug tracking) system used to manage this
25   * project.
26   */
27  @Experimental
28  @Generated @ThreadSafe @Immutable
29  public class IssueManagement
30      implements Serializable, InputLocationTracker
31  {
32      /**
33       * The name of the issue management system, e.g. Bugzilla
34       */
35      final String system;
36      /**
37       * URL for the issue management system used by the project.
38       */
39      final String url;
40      /** Locations */
41      final Map<Object, InputLocation> locations;
42      /** Location tracking */
43      final InputLocation importedFrom;
44  
45      /**
46        * Constructor for this class, to be called from its subclasses and {@link Builder}.
47        * @see Builder#build()
48        */
49      protected IssueManagement(Builder builder) {
50          this.system = builder.system != null ? builder.system : (builder.base != null ? builder.base.system : null);
51          this.url = builder.url != null ? builder.url : (builder.base != null ? builder.base.url : null);
52          this.locations = builder.computeLocations();
53          this.importedFrom = builder.importedFrom;
54      }
55  
56      /**
57       * The name of the issue management system, e.g. Bugzilla
58       *
59       * @return a {@code String}
60       */
61      public String getSystem() {
62          return this.system;
63      }
64  
65      /**
66       * URL for the issue management system used by the project.
67       *
68       * @return a {@code String}
69       */
70      public String getUrl() {
71          return this.url;
72      }
73  
74      /**
75       * Gets the location of the specified field in the input source.
76       */
77      public InputLocation getLocation(Object key) {
78          return locations.get(key);
79      }
80  
81      /**
82       * Gets the keys of the locations of the input source.
83       */
84      public Set<Object> getLocationKeys() {
85          return locations.keySet();
86      }
87  
88      protected Stream<Object> getLocationKeyStream() {
89          return locations.keySet().stream();
90      }
91  
92      /**
93       * Gets the input location that caused this model to be read.
94       */
95      public InputLocation getImportedFrom() {
96          return importedFrom;
97      }
98  
99      /**
100      * Creates a new builder with this object as the basis.
101      *
102      * @return a {@code Builder}
103      */
104     @Nonnull
105     public Builder with() {
106         return newBuilder(this);
107     }
108     /**
109      * Creates a new {@code IssueManagement} instance using the specified system.
110      *
111      * @param system the new {@code String} to use
112      * @return a {@code IssueManagement} with the specified system
113      */
114     @Nonnull
115     public IssueManagement withSystem(String system) {
116         return newBuilder(this, true).system(system).build();
117     }
118     /**
119      * Creates a new {@code IssueManagement} instance using the specified url.
120      *
121      * @param url the new {@code String} to use
122      * @return a {@code IssueManagement} with the specified url
123      */
124     @Nonnull
125     public IssueManagement withUrl(String url) {
126         return newBuilder(this, true).url(url).build();
127     }
128 
129     /**
130      * Creates a new {@code IssueManagement} instance.
131      * Equivalent to {@code newInstance(true)}.
132      * @see #newInstance(boolean)
133      *
134      * @return a new {@code IssueManagement}
135      */
136     @Nonnull
137     public static IssueManagement newInstance() {
138         return newInstance(true);
139     }
140 
141     /**
142      * Creates a new {@code IssueManagement} instance using default values or not.
143      * Equivalent to {@code newBuilder(withDefaults).build()}.
144      *
145      * @param withDefaults the boolean indicating whether default values should be used
146      * @return a new {@code IssueManagement}
147      */
148     @Nonnull
149     public static IssueManagement newInstance(boolean withDefaults) {
150         return newBuilder(withDefaults).build();
151     }
152 
153     /**
154      * Creates a new {@code IssueManagement} builder instance.
155      * Equivalent to {@code newBuilder(true)}.
156      * @see #newBuilder(boolean)
157      *
158      * @return a new {@code Builder}
159      */
160     @Nonnull
161     public static Builder newBuilder() {
162         return newBuilder(true);
163     }
164 
165     /**
166      * Creates a new {@code IssueManagement} builder instance using default values or not.
167      *
168      * @param withDefaults the boolean indicating whether default values should be used
169      * @return a new {@code Builder}
170      */
171     @Nonnull
172     public static Builder newBuilder(boolean withDefaults) {
173         return new Builder(withDefaults);
174     }
175 
176     /**
177      * Creates a new {@code IssueManagement} builder instance using the specified object as a basis.
178      * Equivalent to {@code newBuilder(from, false)}.
179      *
180      * @param from the {@code IssueManagement} instance to use as a basis
181      * @return a new {@code Builder}
182      */
183     @Nonnull
184     public static Builder newBuilder(IssueManagement from) {
185         return newBuilder(from, false);
186     }
187 
188     /**
189      * Creates a new {@code IssueManagement} builder instance using the specified object as a basis.
190      *
191      * @param from the {@code IssueManagement} instance to use as a basis
192      * @param forceCopy the boolean indicating if a copy should be forced
193      * @return a new {@code Builder}
194      */
195     @Nonnull
196     public static Builder newBuilder(IssueManagement from, boolean forceCopy) {
197         return new Builder(from, forceCopy);
198     }
199 
200     /**
201      * Builder class used to create IssueManagement instances.
202      * @see #with()
203      * @see #newBuilder()
204      */
205     @NotThreadSafe
206     public static class Builder
207     {
208         IssueManagement base;
209         String system;
210         String url;
211         Map<Object, InputLocation> locations;
212         InputLocation importedFrom;
213 
214         protected Builder(boolean withDefaults) {
215             if (withDefaults) {
216             }
217         }
218 
219         protected Builder(IssueManagement base, boolean forceCopy) {
220             if (forceCopy) {
221                 this.system = base.system;
222                 this.url = base.url;
223                 this.locations = base.locations;
224                 this.importedFrom = base.importedFrom;
225             } else {
226                 this.base = base;
227             }
228         }
229 
230         @Nonnull
231         public Builder system(String system) {
232             this.system = system;
233             return this;
234         }
235 
236         @Nonnull
237         public Builder url(String url) {
238             this.url = url;
239             return this;
240         }
241 
242 
243         @Nonnull
244         public Builder location(Object key, InputLocation location) {
245             if (location != null) {
246                 if (!(this.locations instanceof HashMap)) {
247                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
248                 }
249                 this.locations.put(key, location);
250             }
251             return this;
252         }
253 
254         @Nonnull
255         public Builder importedFrom(InputLocation importedFrom) {
256             this.importedFrom = importedFrom;
257             return this;
258         }
259 
260         @Nonnull
261         public IssueManagement build() {
262             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
263             if (base != null
264                     && (system == null || system == base.system)
265                     && (url == null || url == base.url)
266             ) {
267                 return base;
268             }
269             return new IssueManagement(this);
270         }
271 
272         Map<Object, InputLocation> computeLocations() {
273             Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
274             Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
275             if (newlocs.isEmpty()) {
276                 return Map.copyOf(oldlocs);
277             }
278             if (oldlocs.isEmpty()) {
279                 return Map.copyOf(newlocs);
280             }
281             return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
282                     // Keep value from newlocs in case of duplicates
283                     .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
284         }
285     }
286 
287 
288             
289     /**
290      * @see java.lang.Object#toString()
291      */
292     public String toString()
293     {
294         return "IssueManagement {system=" + getSystem() + ", url=" + getUrl() + "}";
295     }
296             
297           
298 }