001/* 002 * #%L 003 * Netarchivesuite - common 004 * %% 005 * Copyright (C) 2005 - 2018 The Royal Danish 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.common.distribute.arcrepository; 024 025import dk.netarkivet.common.exceptions.ArgumentNotValid; 026 027/** 028 * Enumeration of the possible replica types used for replicas. 029 */ 030public enum ReplicaType { 031 032 /** If no replica type has been set. */ 033 NO_REPLICA_TYPE, 034 /** bitarchive replica which contain files stored in repository. */ 035 BITARCHIVE, 036 /** Checksum replica which contains checksums of files in repository. */ 037 CHECKSUM; 038 039 /** String representation of the ReplicaType.BITARCHIVE. */ 040 public static final String BITARCHIVE_REPLICATYPE_AS_STRING = "bitarchive"; 041 042 /** String representation of the ReplicaType.CHECKSUM. */ 043 public static final String CHECKSUM_REPLICATYPE_AS_STRING = "checksum"; 044 045 /** 046 * Helper method that gives a proper object from e.g. settings. 047 * 048 * @param ordinal a certain integer for a replica type 049 * @return the ReplicaType related to a certain integer 050 * @throws ArgumentNotValid If argument rt does not correspond to a ReplicaType 051 */ 052 public static ReplicaType fromOrdinal(int ordinal) { 053 switch (ordinal) { 054 case 0: 055 return NO_REPLICA_TYPE; 056 case 1: 057 return BITARCHIVE; 058 case 2: 059 return CHECKSUM; 060 default: 061 throw new ArgumentNotValid("Invalid replica type with number " + ordinal); 062 } 063 } 064 065 /** 066 * Helper method that gives a proper object from e.g. settings. 067 * 068 * @param s A string representing a ReplicaType. 069 * @return the ReplicaType related to a certain string; if the string does not correspond to a known replicatype, it 070 * returns NO_REPLICA_TYPE 071 * @throws ArgumentNotValid If argument s is null 072 */ 073 public static ReplicaType fromSetting(String s) { 074 ArgumentNotValid.checkNotNull(s, "s"); 075 String t = s.toLowerCase(); 076 if (t.equals(BITARCHIVE_REPLICATYPE_AS_STRING)) { 077 return BITARCHIVE; 078 } else { 079 if (t.equals(CHECKSUM_REPLICATYPE_AS_STRING)) { 080 return CHECKSUM; 081 } else { 082 return NO_REPLICA_TYPE; 083 } 084 } 085 } 086 087}