001/* 002 * #%L 003 * Netarchivesuite - archive 004 * %% 005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library, 006 * the National Library of France and the Austrian National Library. 007 * %% 008 * This program is free software: you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation, either version 2.1 of the 011 * License, or (at your option) any later version. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Lesser Public License for more details. 017 * 018 * You should have received a copy of the GNU General Lesser Public 019 * License along with this program. If not, see 020 * <http://www.gnu.org/licenses/lgpl-2.1.html>. 021 * #L% 022 */ 023package dk.netarkivet.archive.arcrepositoryadmin; 024 025import java.util.Date; 026 027import dk.netarkivet.common.distribute.arcrepository.ReplicaStoreState; 028import dk.netarkivet.common.exceptions.ArgumentNotValid; 029 030/** 031 * This class contains a storestate, and the time, when it was last set. 032 */ 033public class ArchiveStoreState { 034 035 /** The state for a specific archive, or overall state. */ 036 private ReplicaStoreState storestate; 037 038 /** Time of last state change. */ 039 private Date lastchanged; 040 041 /** 042 * Constructor for this class. This sets the lastchanged value to Now. 043 * 044 * @param storestate A BitArchiveStoreState 045 */ 046 public ArchiveStoreState(ReplicaStoreState storestate) { 047 setState(storestate); 048 } 049 050 /** 051 * Constructor for this class. 052 * 053 * @param storestate A BitArchiveStoreState 054 * @param lastchanged Time for when this state was set 055 */ 056 public ArchiveStoreState(ReplicaStoreState storestate, Date lastchanged) { 057 setState(storestate, lastchanged); 058 } 059 060 /** 061 * Return the current BitArchiveStoreState. 062 * 063 * @return the current BitArchiveStoreState 064 */ 065 public ReplicaStoreState getState() { 066 return storestate; 067 } 068 069 /** 070 * Sets the current ReplicaStoreState. 071 * 072 * @param state The ReplicaStoreState. 073 * @param lastDate The lastchanged date. 074 * @throws ArgumentNotValid If the state or the lastDate is null. 075 */ 076 public void setState(ReplicaStoreState state, Date lastDate) throws ArgumentNotValid { 077 ArgumentNotValid.checkNotNull(state, "ReplicaStoreState state"); 078 ArgumentNotValid.checkNotNull(lastDate, "Date lastDate"); 079 080 this.storestate = state; 081 this.lastchanged = lastDate; 082 } 083 084 /** 085 * Sets the current ReplicaStoreState. As a sideeffect lastchanged is set to NOW. 086 * 087 * @param state the ReplicaStoreState. 088 * @throws ArgumentNotValid If the state is null. 089 */ 090 public void setState(ReplicaStoreState state) throws ArgumentNotValid { 091 ArgumentNotValid.checkNotNull(state, "ReplicaStoreState state"); 092 this.storestate = state; 093 this.lastchanged = new Date(); 094 } 095 096 /** 097 * Get the Date for when the state was lastchanged. 098 * 099 * @return the Date for when the state was lastchanged 100 */ 101 public Date getLastChanged() { 102 return this.lastchanged; 103 104 } 105 106 /** 107 * Creates an string representation of this instance. 108 * 109 * @return The string representation of this instance. 110 */ 111 public String toString() { 112 String stringRepresentation = getState() + " " + getLastChanged().getTime(); 113 return stringRepresentation; 114 } 115}