1 package org.sonatype.aether.repository;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 public final class RepositoryPolicy
18 {
19
20
21
22
23 public static final String UPDATE_POLICY_NEVER = "never";
24
25
26
27
28 public static final String UPDATE_POLICY_ALWAYS = "always";
29
30
31
32
33 public static final String UPDATE_POLICY_DAILY = "daily";
34
35
36
37
38 public static final String UPDATE_POLICY_INTERVAL = "interval";
39
40
41
42
43 public static final String CHECKSUM_POLICY_FAIL = "fail";
44
45
46
47
48 public static final String CHECKSUM_POLICY_WARN = "warn";
49
50
51
52
53 public static final String CHECKSUM_POLICY_IGNORE = "ignore";
54
55 private final boolean enabled;
56
57 private final String updatePolicy;
58
59 private final String checksumPolicy;
60
61
62
63
64 public RepositoryPolicy()
65 {
66 this( true, UPDATE_POLICY_DAILY, CHECKSUM_POLICY_WARN );
67 }
68
69
70
71
72
73
74
75
76
77 public RepositoryPolicy( boolean enabled, String updatePolicy, String checksumPolicy )
78 {
79 this.enabled = enabled;
80 this.updatePolicy = ( updatePolicy != null ) ? updatePolicy : "";
81 this.checksumPolicy = ( checksumPolicy != null ) ? checksumPolicy : "";
82 }
83
84
85
86
87
88
89 public boolean isEnabled()
90 {
91 return enabled;
92 }
93
94
95
96
97
98
99
100 public RepositoryPolicy setEnabled( boolean enabled )
101 {
102 if ( this.enabled == enabled )
103 {
104 return this;
105 }
106 return new RepositoryPolicy( enabled, updatePolicy, checksumPolicy );
107 }
108
109
110
111
112
113
114 public String getUpdatePolicy()
115 {
116 return updatePolicy;
117 }
118
119
120
121
122
123
124
125
126
127 public RepositoryPolicy setUpdatePolicy( String updatePolicy )
128 {
129 if ( this.updatePolicy.equals( updatePolicy ) )
130 {
131 return this;
132 }
133 return new RepositoryPolicy( enabled, updatePolicy, checksumPolicy );
134 }
135
136
137
138
139
140
141 public String getChecksumPolicy()
142 {
143 return checksumPolicy;
144 }
145
146
147
148
149
150
151
152
153 public RepositoryPolicy setChecksumPolicy( String checksumPolicy )
154 {
155 if ( this.checksumPolicy.equals( checksumPolicy ) )
156 {
157 return this;
158 }
159 return new RepositoryPolicy( enabled, updatePolicy, checksumPolicy );
160 }
161
162 @Override
163 public String toString()
164 {
165 StringBuilder buffer = new StringBuilder( 256 );
166 buffer.append( "enabled=" ).append( isEnabled() );
167 buffer.append( ", checksums=" ).append( getChecksumPolicy() );
168 buffer.append( ", updates=" ).append( getUpdatePolicy() );
169 return buffer.toString();
170 }
171
172 @Override
173 public boolean equals( Object obj )
174 {
175 if ( this == obj )
176 {
177 return true;
178 }
179
180 if ( obj == null || !getClass().equals( obj.getClass() ) )
181 {
182 return false;
183 }
184
185 RepositoryPolicy that = (RepositoryPolicy) obj;
186
187 return enabled == that.enabled && updatePolicy.equals( that.updatePolicy )
188 && checksumPolicy.equals( that.checksumPolicy );
189 }
190
191 @Override
192 public int hashCode()
193 {
194 int hash = 17;
195 hash = hash * 31 + ( enabled ? 1 : 0 );
196 hash = hash * 31 + updatePolicy.hashCode();
197 hash = hash * 31 + checksumPolicy.hashCode();
198 return hash;
199 }
200
201 }