1 package org.apache.archiva.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.Enumeration;
24 import java.util.List;
25 import java.util.Properties;
26
27
28
29
30
31
32 public class ArchivaModelCloner
33 {
34
35 public static ArtifactReference clone( ArtifactReference artifactReference )
36 {
37 if ( artifactReference == null )
38 {
39 return null;
40 }
41
42 ArtifactReference cloned = new ArtifactReference();
43
44 cloned.setGroupId( artifactReference.getGroupId() );
45 cloned.setArtifactId( artifactReference.getArtifactId() );
46 cloned.setVersion( artifactReference.getVersion() );
47 cloned.setClassifier( artifactReference.getClassifier() );
48 cloned.setType( artifactReference.getType() );
49
50 return cloned;
51 }
52
53 @SuppressWarnings( "unchecked" )
54 public static Properties clone( Properties properties )
55 {
56 if ( properties == null )
57 {
58 return null;
59 }
60
61 Properties cloned = new Properties();
62
63 Enumeration<String> keys = (Enumeration<String>) properties.propertyNames();
64 while ( keys.hasMoreElements() )
65 {
66 String key = (String) keys.nextElement();
67 String value = properties.getProperty( key );
68 cloned.setProperty( key, value );
69 }
70
71 return cloned;
72 }
73
74 public static SnapshotVersion clone( SnapshotVersion snapshotVersion )
75 {
76 if ( snapshotVersion == null )
77 {
78 return null;
79 }
80
81 SnapshotVersion cloned = new SnapshotVersion();
82
83 cloned.setTimestamp( snapshotVersion.getTimestamp() );
84 cloned.setBuildNumber( snapshotVersion.getBuildNumber() );
85
86 return cloned;
87 }
88
89 public static VersionedReference clone( VersionedReference versionedReference )
90 {
91 if ( versionedReference == null )
92 {
93 return null;
94 }
95
96 VersionedReference cloned = new VersionedReference();
97
98 cloned.setGroupId( versionedReference.getGroupId() );
99 cloned.setArtifactId( versionedReference.getArtifactId() );
100 cloned.setVersion( versionedReference.getVersion() );
101
102 return cloned;
103 }
104
105 public static List<ArtifactReference> cloneArtifactReferences( List<ArtifactReference> artifactReferenceList )
106 {
107 if ( artifactReferenceList == null )
108 {
109 return null;
110 }
111
112 List<ArtifactReference> ret = new ArrayList<>( artifactReferenceList.size() );
113
114 for ( ArtifactReference ref : artifactReferenceList )
115 {
116 ret.add( clone( ref ) );
117 }
118
119 return ret;
120 }
121
122 private static List<String> cloneSimpleStringList( List<String> simple )
123 {
124 if ( simple == null )
125 {
126 return null;
127 }
128
129 List<String> ret = new ArrayList<>( simple.size() );
130
131 for ( String txt : simple )
132 {
133 ret.add( txt );
134 }
135
136 return ret;
137 }
138
139 public static List<String> cloneAvailableVersions( List<String> availableVersions )
140 {
141 return cloneSimpleStringList( availableVersions );
142 }
143 }