View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //  Generated by Modello Velocity from model-v3.vm
3   //  template, any modifications will be overwritten.
4   // ==============================================================
5   package org.apache.maven.artifact.repository.metadata;
6   
7   import java.io.Serializable;
8   import java.util.AbstractList;
9   import java.util.ArrayList;
10  import java.util.Collections;
11  import java.util.HashMap;
12  import java.util.List;
13  import java.util.Map;
14  import java.util.Objects;
15  import java.util.Set;
16  import java.util.stream.Collectors;
17  import java.util.stream.Stream;
18  import org.apache.maven.api.annotations.Generated;
19  import org.apache.maven.api.annotations.Nonnull;
20  
21  @Generated
22  public class Versioning
23      extends BaseObject
24  {
25  
26      public Versioning() {
27          this(org.apache.maven.api.metadata.Versioning.newInstance());
28      }
29  
30      public Versioning(org.apache.maven.api.metadata.Versioning delegate) {
31          this(delegate, null);
32      }
33  
34      public Versioning(org.apache.maven.api.metadata.Versioning delegate, BaseObject parent) {
35          super(delegate, parent);
36      }
37  
38      public Versioning clone(){
39          return new Versioning(getDelegate());
40      }
41  
42      public org.apache.maven.api.metadata.Versioning getDelegate() {
43          return (org.apache.maven.api.metadata.Versioning) super.getDelegate();
44      }
45  
46      @Override
47      public boolean equals(Object o) {
48          if (this == o) {
49              return true;
50          }
51          if (o == null || !(o instanceof Versioning)) {
52              return false;
53          }
54          Versioning that = (Versioning) o;
55          return Objects.equals(this.delegate, that.delegate);
56      }
57  
58      @Override
59      public int hashCode() {
60          return getDelegate().hashCode();
61      }
62  
63      public String getLatest() {
64          return getDelegate().getLatest();
65      }
66  
67      public void setLatest(String latest) {
68          if (!Objects.equals(latest, getLatest())) {
69              update(getDelegate().withLatest(latest));
70          }
71      }
72  
73      public String getRelease() {
74          return getDelegate().getRelease();
75      }
76  
77      public void setRelease(String release) {
78          if (!Objects.equals(release, getRelease())) {
79              update(getDelegate().withRelease(release));
80          }
81      }
82  
83      @Nonnull
84      public List<String> getVersions() {
85          return new WrapperList<String, String>(() -> getDelegate().getVersions(), this::setVersions, s -> s, s -> s);
86      }
87  
88      public void setVersions(List<String> versions) {
89          if (!Objects.equals(versions, getVersions())) {
90              update(getDelegate().withVersions(versions));
91          }
92      }
93  
94      public void addVersion(String version) {
95          update(getDelegate().withVersions(
96                 Stream.concat(getDelegate().getVersions().stream(), Stream.of(version))
97                          .collect(Collectors.toList())));
98      }
99  
100     public void removeVersion(String version) {
101         update(getDelegate().withVersions(
102                getDelegate().getVersions().stream()
103                         .filter(e -> !Objects.equals(e, version))
104                         .collect(Collectors.toList())));
105     }
106 
107     public String getLastUpdated() {
108         return getDelegate().getLastUpdated();
109     }
110 
111     public void setLastUpdated(String lastUpdated) {
112         if (!Objects.equals(lastUpdated, getLastUpdated())) {
113             update(getDelegate().withLastUpdated(lastUpdated));
114         }
115     }
116 
117     public Snapshot getSnapshot() {
118         return getDelegate().getSnapshot() != null ? new Snapshot(getDelegate().getSnapshot(), this) : null;
119     }
120 
121     public void setSnapshot(Snapshot snapshot) {
122         if (!Objects.equals(snapshot, getSnapshot())){
123             if (snapshot != null) {
124                 update(getDelegate().withSnapshot(snapshot.getDelegate()));
125                 snapshot.childrenTracking = this::replace;
126             } else {
127                 update(getDelegate().withSnapshot(null));
128             }
129         }
130     }
131 
132     @Nonnull
133     public List<SnapshotVersion> getSnapshotVersions() {
134         return new WrapperList<SnapshotVersion, org.apache.maven.api.metadata.SnapshotVersion>(
135                     () -> getDelegate().getSnapshotVersions(), l -> update(getDelegate().withSnapshotVersions(l)),
136                     d -> new SnapshotVersion(d, this), SnapshotVersion::getDelegate);
137     }
138 
139     public void setSnapshotVersions(List<SnapshotVersion> snapshotVersions) {
140         if (snapshotVersions == null) {
141             snapshotVersions = Collections.emptyList();
142         }
143         if (!Objects.equals(snapshotVersions, getSnapshotVersions())) {
144             update(getDelegate().withSnapshotVersions(
145                 snapshotVersions.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
146             snapshotVersions.forEach(e -> e.childrenTracking = this::replace);
147         }
148     }
149 
150     public void addSnapshotVersion(SnapshotVersion snapshotVersion) {
151         update(getDelegate().withSnapshotVersions(
152                Stream.concat(getDelegate().getSnapshotVersions().stream(), Stream.of(snapshotVersion.getDelegate()))
153                         .collect(Collectors.toList())));
154         snapshotVersion.childrenTracking = this::replace;
155     }
156 
157     public void removeSnapshotVersion(SnapshotVersion snapshotVersion) {
158         update(getDelegate().withSnapshotVersions(
159                getDelegate().getSnapshotVersions().stream()
160                         .filter(e -> !Objects.equals(e, snapshotVersion))
161                         .collect(Collectors.toList())));
162         snapshotVersion.childrenTracking = null;
163     }
164 
165     protected boolean replace(Object oldDelegate, Object newDelegate) {
166         if (super.replace(oldDelegate, newDelegate)) {
167             return true;
168         }
169         if (oldDelegate == getDelegate().getSnapshot()) {
170             update(getDelegate().withSnapshot((org.apache.maven.api.metadata.Snapshot) newDelegate));
171             return true;
172         }
173         if (getDelegate().getSnapshotVersions().contains(oldDelegate)) {
174             List<org.apache.maven.api.metadata.SnapshotVersion> list = new ArrayList<>(getDelegate().getSnapshotVersions());
175             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.metadata.SnapshotVersion) newDelegate : d);
176             update(getDelegate().withSnapshotVersions(list));
177             return true;
178         }
179         return false;
180     }
181 
182     public static List<org.apache.maven.api.metadata.Versioning> versioningToApiV4(List<Versioning> list) {
183         return list != null ? new WrapperList<>(list, Versioning::getDelegate, Versioning::new) : null;
184     }
185 
186     public static List<Versioning> versioningToApiV3(List<org.apache.maven.api.metadata.Versioning> list) {
187         return list != null ? new WrapperList<>(list, Versioning::new, Versioning::getDelegate) : null;
188     }
189 
190 
191     public void updateTimestamp()
192     {
193         setLastUpdatedTimestamp( new java.util.Date() );
194     }
195 
196     public void setLastUpdatedTimestamp( java.util.Date date )
197     {
198         java.util.TimeZone timezone = java.util.TimeZone.getTimeZone( "UTC" );
199         java.text.DateFormat fmt = new java.text.SimpleDateFormat( "yyyyMMddHHmmss" );
200         fmt.setTimeZone( timezone );
201         setLastUpdated( fmt.format( date ) );
202     }
203           
204 }