1 package org.apache.archiva.checksum;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 /**
23 * Status of checksum update for specific algorithm.
24 */
25 public class UpdateStatus {
26
27 /**
28 * Checksum file did not exist before and was created
29 */
30 public static final int CREATED = 1;
31 /**
32 * Checksum file existed, but content differed
33 */
34 public static final int UPDATED = 2;
35 /**
36 * Nothing changed
37 */
38 public static final int NONE = 0;
39 /**
40 * Error occured during update/creation of the checksum file
41 */
42 public static final int ERROR = -1;
43
44 private final ChecksumAlgorithm algorithm;
45 private final int status;
46 private final Throwable error;
47
48 public UpdateStatus(ChecksumAlgorithm algorithm) {
49 this.algorithm = algorithm;
50 status = NONE;
51 error = null;
52 }
53
54 public UpdateStatus(ChecksumAlgorithm algorithm, int status) {
55 this.algorithm = algorithm;
56 this.status = status;
57 error = null;
58 }
59
60 public UpdateStatus(ChecksumAlgorithm algorithm, Throwable error) {
61 this.algorithm = algorithm;
62 this.status = ERROR;
63 this.error = error;
64 }
65
66 /**
67 * Return the status value.
68 * @return The value
69 */
70 public int getValue() {
71 return status;
72 }
73
74 /**
75 * Return error, if exists, otherwise <code>null</code> will be returned.
76 * @return
77 */
78 public Throwable getError() {
79 return error;
80 }
81
82 /**
83 * Return the algorithm, this status is assigned to.
84 * @return The checksum algorithm
85 */
86 public ChecksumAlgorithm getAlgorithm() {
87 return algorithm;
88 }
89 }