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.settings;
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 org.apache.maven.api.annotations.Experimental;
13  import org.apache.maven.api.annotations.Generated;
14  import org.apache.maven.api.annotations.Immutable;
15  import org.apache.maven.api.annotations.Nonnull;
16  import org.apache.maven.api.annotations.NotThreadSafe;
17  import org.apache.maven.api.annotations.ThreadSafe;
18  
19  /**
20   * Repository contains the information needed for establishing
21   * connections with remote repository
22   */
23  @Experimental
24  @Generated @ThreadSafe @Immutable
25  public class Repository
26      extends RepositoryBase
27      implements Serializable
28  {
29      /**
30       * How to handle downloading of releases from this repository
31       */
32      final RepositoryPolicy releases;
33      /**
34       * How to handle downloading of snapshots from this repository
35       */
36      final RepositoryPolicy snapshots;
37  
38      /**
39        * Constructor for this class, package protected.
40        * @see Builder#build()
41        */
42      Repository(
43          String id,
44          String name,
45          String url,
46          String layout,
47          RepositoryPolicy releases,
48          RepositoryPolicy snapshots
49      )
50      {
51          super(
52              id,
53              name,
54              url,
55              layout
56          );
57          this.releases = releases;
58          this.snapshots = snapshots;
59      }
60  
61      @Override
62      public boolean equals( Object o )
63      {
64          if ( this == o )
65          {
66              return true;
67          }
68          if ( o == null || !( o instanceof Repository ) )
69          {
70              return false;
71          }
72          Repository that = ( Repository ) o;
73          return Objects.equals( this.id, that.id );
74      }
75  
76      @Override
77      public int hashCode()
78      {
79          return Objects.hash( id );
80      }
81  
82      /**
83       * How to handle downloading of releases from this repository
84       *
85       * @return a {@code RepositoryPolicy}
86       */
87      public RepositoryPolicy getReleases()
88      {
89          return this.releases;
90      }
91  
92      /**
93       * How to handle downloading of snapshots from this repository
94       *
95       * @return a {@code RepositoryPolicy}
96       */
97      public RepositoryPolicy getSnapshots()
98      {
99          return this.snapshots;
100     }
101 
102     /**
103      * Creates a new builder with this object as the basis.
104      *
105      * @return a {@code Builder}
106      */
107     @Nonnull
108     public Builder with()
109     {
110         return newBuilder( this );
111     }
112     /**
113      * Creates a new {@code Repository} instance using the specified id.
114      *
115      * @param id the new {@code String} to use
116      * @return a {@code Repository} with the specified id
117      */
118     @Nonnull
119     public Repository withId( String id )
120     {
121         return with().id( id ).build();
122     }
123     /**
124      * Creates a new {@code Repository} instance using the specified name.
125      *
126      * @param name the new {@code String} to use
127      * @return a {@code Repository} with the specified name
128      */
129     @Nonnull
130     public Repository withName( String name )
131     {
132         return with().name( name ).build();
133     }
134     /**
135      * Creates a new {@code Repository} instance using the specified url.
136      *
137      * @param url the new {@code String} to use
138      * @return a {@code Repository} with the specified url
139      */
140     @Nonnull
141     public Repository withUrl( String url )
142     {
143         return with().url( url ).build();
144     }
145     /**
146      * Creates a new {@code Repository} instance using the specified layout.
147      *
148      * @param layout the new {@code String} to use
149      * @return a {@code Repository} with the specified layout
150      */
151     @Nonnull
152     public Repository withLayout( String layout )
153     {
154         return with().layout( layout ).build();
155     }
156     /**
157      * Creates a new {@code Repository} instance using the specified releases.
158      *
159      * @param releases the new {@code RepositoryPolicy} to use
160      * @return a {@code Repository} with the specified releases
161      */
162     @Nonnull
163     public Repository withReleases( RepositoryPolicy releases )
164     {
165         return with().releases( releases ).build();
166     }
167     /**
168      * Creates a new {@code Repository} instance using the specified snapshots.
169      *
170      * @param snapshots the new {@code RepositoryPolicy} to use
171      * @return a {@code Repository} with the specified snapshots
172      */
173     @Nonnull
174     public Repository withSnapshots( RepositoryPolicy snapshots )
175     {
176         return with().snapshots( snapshots ).build();
177     }
178 
179     /**
180      * Creates a new {@code Repository} instance.
181      * Equivalent to {@code newInstance( true )}.
182      * @see #newInstance(boolean)
183      *
184      * @return a new {@code Repository}
185      */
186     @Nonnull
187     public static Repository newInstance()
188     {
189         return newInstance( true );
190     }
191 
192     /**
193      * Creates a new {@code Repository} instance using default values or not.
194      * Equivalent to {@code newBuilder( withDefaults ).build()}.
195      *
196      * @param withDefaults the boolean indicating whether default values should be used
197      * @return a new {@code Repository}
198      */
199     @Nonnull
200     public static Repository newInstance( boolean withDefaults )
201     {
202         return newBuilder( withDefaults ).build();
203     }
204 
205     /**
206      * Creates a new {@code Repository} builder instance.
207      * Equivalent to {@code newBuilder( true )}.
208      * @see #newBuilder(boolean)
209      *
210      * @return a new {@code Builder}
211      */
212     @Nonnull
213     public static Builder newBuilder()
214     {
215         return newBuilder( true );
216     }
217 
218     /**
219      * Creates a new {@code Repository} builder instance using default values or not.
220      *
221      * @param withDefaults the boolean indicating whether default values should be used
222      * @return a new {@code Builder}
223      */
224     @Nonnull
225     public static Builder newBuilder( boolean withDefaults )
226     {
227         return new Builder( withDefaults );
228     }
229 
230     /**
231      * Creates a new {@code Repository} builder instance using the specified object as a basis.
232      * Equivalent to {@code newBuilder( from, false )}.
233      *
234      * @param from the {@code Repository} instance to use as a basis
235      * @return a new {@code Builder}
236      */
237     @Nonnull
238     public static Builder newBuilder( Repository from )
239     {
240         return newBuilder( from, false );
241     }
242 
243     /**
244      * Creates a new {@code Repository} builder instance using the specified object as a basis.
245      *
246      * @param from the {@code Repository} instance to use as a basis
247      * @param forceCopy the boolean indicating if a copy should be forced
248      * @return a new {@code Builder}
249      */
250     @Nonnull
251     public static Builder newBuilder( Repository from, boolean forceCopy )
252     {
253         return new Builder( from, forceCopy );
254     }
255 
256     /**
257      * Builder class used to create Repository instances.
258      * @see #with()
259      * @see #newBuilder()
260      */
261     @NotThreadSafe
262     public static class Builder
263         extends RepositoryBase.Builder
264     {
265         Repository base;
266         RepositoryPolicy releases;
267         RepositoryPolicy snapshots;
268 
269         Builder( boolean withDefaults )
270         {
271             super( withDefaults );
272             if ( withDefaults )
273             {
274             }
275         }
276 
277         Builder( Repository base, boolean forceCopy )
278         {
279             super( base, forceCopy );
280             if ( forceCopy )
281             {
282                 this.releases = base.releases;
283                 this.snapshots = base.snapshots;
284             }
285             else
286             {
287                 this.base = base;
288             }
289         }
290 
291         @Nonnull
292         public Builder id( String id )
293         {
294             this.id = id;
295             return this;
296         }
297 
298         @Nonnull
299         public Builder name( String name )
300         {
301             this.name = name;
302             return this;
303         }
304 
305         @Nonnull
306         public Builder url( String url )
307         {
308             this.url = url;
309             return this;
310         }
311 
312         @Nonnull
313         public Builder layout( String layout )
314         {
315             this.layout = layout;
316             return this;
317         }
318 
319         @Nonnull
320         public Builder releases( RepositoryPolicy releases )
321         {
322             this.releases = releases;
323             return this;
324         }
325 
326         @Nonnull
327         public Builder snapshots( RepositoryPolicy snapshots )
328         {
329             this.snapshots = snapshots;
330             return this;
331         }
332 
333 
334         @Nonnull
335         public Repository build()
336         {
337             if ( base != null
338                     && ( id == null || id == base.id )
339                     && ( name == null || name == base.name )
340                     && ( url == null || url == base.url )
341                     && ( layout == null || layout == base.layout )
342                     && ( releases == null || releases == base.releases )
343                     && ( snapshots == null || snapshots == base.snapshots )
344             )
345             {
346                 return base;
347             }
348             return new Repository(
349                 id != null ? id : ( base != null ? base.id : null ),
350                 name != null ? name : ( base != null ? base.name : null ),
351                 url != null ? url : ( base != null ? base.url : null ),
352                 layout != null ? layout : ( base != null ? base.layout : null ),
353                 releases != null ? releases : ( base != null ? base.releases : null ),
354                 snapshots != null ? snapshots : ( base != null ? base.snapshots : null )
355             );
356         }
357     }
358 
359 }