001/* 002 * The contents of this file are subject to the license and copyright detailed 003 * in the LICENSE and NOTICE files at the root of the source tree. 004 */ 005package org.duraspace.bagit; 006 007import java.util.Set; 008 009/** 010 * Rules which can be applied to the Bag-Info and Other-Info sections of a Bag Profile. Currently supports the 011 * parameters specified in version 1.3.0 of the bagit-profiles specification, in addition to the recommended parameter 012 * which is brought in from the Beyond the Repository bagit specification. 013 * 014 * @author mikejritter 015 * @since 2020-01-20 016 */ 017public class ProfileFieldRule { 018 019 private final boolean required; 020 private final boolean repeatable; 021 private final boolean recommended; 022 private final String description; 023 private final Set<String> values; 024 025 /** 026 * Constructor for a ProfileFieldRule. Takes the 4 possible json fields from a BagIt Profile *-Info field. 027 * 028 * @param required boolean value stating if this rule is required 029 * @param repeatable boolean value allowing a field to be repeated 030 * @param recommended boolean value stating if this rule is recommended 031 * @param description a text description of this rule 032 * @param values a set of string values which a field is allowed to be set to 033 */ 034 public ProfileFieldRule(final boolean required, 035 final boolean repeatable, 036 final boolean recommended, 037 final String description, 038 final Set<String> values) { 039 this.required = required; 040 this.repeatable = repeatable; 041 this.recommended = recommended; 042 this.description = description; 043 this.values = values; 044 } 045 046 /** 047 * 048 * @return if the field for this rule is required to exist 049 */ 050 public boolean isRequired() { 051 return required; 052 } 053 054 /** 055 * 056 * @return if the field is allowed to be repeated 057 */ 058 public boolean isRepeatable() { 059 return repeatable; 060 } 061 062 /** 063 * 064 * @return if the field for this rule is recommended to exist 065 */ 066 public boolean isRecommended() { 067 return recommended; 068 } 069 070 /** 071 * 072 * @return the description of this rule 073 */ 074 public String getDescription() { 075 return description; 076 } 077 078 /** 079 * 080 * @return the allowed values for fields matching this rule 081 */ 082 public Set<String> getValues() { 083 return values; 084 } 085 086 /** 087 * String representation of a ProfileFieldRule 088 * 089 * @return the string representation 090 */ 091 @Override 092 public String toString() { 093 return "ProfileFieldRule{" + 094 "\nrequired=" + required + 095 ",\nrecommended=" + recommended + 096 ",\ndescription='" + description + '\'' + 097 ",\nvalues=" + values + 098 "\n}"; 099 } 100}