This project has retired. For details please refer to its Attic page.
UpdateStatusList xref
View Javadoc
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  import java.util.ArrayList;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.TreeMap;
26  
27  /**
28   * Container for a list of update status objects.
29   *
30   * If there is a overall error that is not specific to a algorithm, the total status
31   * flag is set to error.
32   */
33  public class UpdateStatusList {
34  
35      private int totalStatus = UpdateStatus.NONE;
36      private Throwable error;
37      private Map<ChecksumAlgorithm, UpdateStatus> statusList = new TreeMap<>();
38  
39      public UpdateStatusList() {
40  
41      }
42  
43      public void addStatus(UpdateStatus status) {
44          statusList.put(status.getAlgorithm(), status);
45      }
46  
47      public static UpdateStatusList INITIALIZE(List<ChecksumAlgorithm> algorithms) {
48          final UpdateStatusListatusList.html#UpdateStatusList">UpdateStatusList list = new UpdateStatusList();
49          for(ChecksumAlgorithm algorithm : algorithms) {
50              list.addStatus(new UpdateStatus(algorithm));
51          }
52          return list;
53      }
54  
55      public int getTotalStatus() {
56          return totalStatus;
57      }
58  
59      public void setTotalError(Throwable e) {
60          this.error = e;
61          this.totalStatus = UpdateStatus.ERROR;
62      }
63  
64      public Throwable getTotalError() {
65          return error;
66      }
67  
68      public List<UpdateStatus> getStatusList() {
69          return new ArrayList(statusList.values());
70      }
71  
72      public void setStatus(ChecksumAlgorithm algorithm, UpdateStatus status) {
73          statusList.put(algorithm, status);
74      }
75  
76      public void setStatus(ChecksumAlgorithm algorithm, int status) {
77          statusList.put(algorithm, new UpdateStatus(algorithm, status));
78      }
79  
80      public void setErrorStatus(ChecksumAlgorithm algorithm, Throwable e) {
81          statusList.put(algorithm, new UpdateStatus(algorithm,e));
82      }
83  
84      public UpdateStatus getStatus(ChecksumAlgorithm algorithm) {
85          return statusList.get(algorithm);
86      }
87  }