001package org.apache.archiva.checksum; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.ArrayList; 023import java.util.List; 024import java.util.Map; 025import java.util.TreeMap; 026 027/** 028 * Container for a list of update status objects. 029 * 030 * If there is a overall error that is not specific to a algorithm, the total status 031 * flag is set to error. 032 */ 033public class UpdateStatusList { 034 035 private int totalStatus = UpdateStatus.NONE; 036 private Throwable error; 037 private Map<ChecksumAlgorithm, UpdateStatus> statusList = new TreeMap<>(); 038 039 public UpdateStatusList() { 040 041 } 042 043 public void addStatus(UpdateStatus status) { 044 statusList.put(status.getAlgorithm(), status); 045 } 046 047 public static UpdateStatusList INITIALIZE(List<ChecksumAlgorithm> algorithms) { 048 final UpdateStatusList list = new UpdateStatusList(); 049 for(ChecksumAlgorithm algorithm : algorithms) { 050 list.addStatus(new UpdateStatus(algorithm)); 051 } 052 return list; 053 } 054 055 public int getTotalStatus() { 056 return totalStatus; 057 } 058 059 public void setTotalError(Throwable e) { 060 this.error = e; 061 this.totalStatus = UpdateStatus.ERROR; 062 } 063 064 public Throwable getTotalError() { 065 return error; 066 } 067 068 public List<UpdateStatus> getStatusList() { 069 return new ArrayList(statusList.values()); 070 } 071 072 public void setStatus(ChecksumAlgorithm algorithm, UpdateStatus status) { 073 statusList.put(algorithm, status); 074 } 075 076 public void setStatus(ChecksumAlgorithm algorithm, int status) { 077 statusList.put(algorithm, new UpdateStatus(algorithm, status)); 078 } 079 080 public void setErrorStatus(ChecksumAlgorithm algorithm, Throwable e) { 081 statusList.put(algorithm, new UpdateStatus(algorithm,e)); 082 } 083 084 public UpdateStatus getStatus(ChecksumAlgorithm algorithm) { 085 return statusList.get(algorithm); 086 } 087}