BagInfoRequirement.java

  1. /*
  2.  * Copyright (C) 2023 DANS - Data Archiving and Networked Services (info@dans.knaw.nl)
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  * http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package nl.knaw.dans.bagit.conformance.profile;

  17. import java.util.ArrayList;
  18. import java.util.List;
  19. import java.util.Objects;

  20. /**
  21.  * This class is used to define elements in a bag-info.txt file used by a bagit-profile.
  22.  */
  23. public class BagInfoRequirement {
  24.   private boolean required;
  25.   private List<String> acceptableValues = new ArrayList<>();
  26.   private boolean repeatable = true;
  27.  
  28.   @Override
  29.   public boolean equals(final Object other) {
  30.     if (!(other instanceof BagInfoRequirement)) {
  31.       return false;
  32.     }
  33.     final BagInfoRequirement castOther = (BagInfoRequirement) other;
  34.     return Objects.equals(required, castOther.required)
  35.         && Objects.equals(acceptableValues, castOther.acceptableValues)
  36.         && Objects.equals(repeatable, castOther.repeatable);
  37.   }

  38.   @Override
  39.   public int hashCode() {
  40.     return Objects.hash(required, acceptableValues, repeatable);
  41.   }

  42.   public BagInfoRequirement(){
  43.     //intentionally left empty
  44.   }
  45.   /**
  46.    * Constructs a new BagInfoRequirement setting {@link #repeatable} to true (default).
  47.    * @param required Indicates whether or not the tag is required.
  48.    * @param acceptableValues List of acceptable values.
  49.    */
  50.   public BagInfoRequirement(final boolean required, final List<String> acceptableValues){
  51.     this.required = required;
  52.     this.acceptableValues = acceptableValues;
  53.   }
  54.  
  55.   /**
  56.    * Constructs a new BagInfoRequirement.
  57.    * @param required Indicates whether or not the tag is required.
  58.    * @param acceptableValues List of acceptable values.
  59.    * @param repeatable Indicates whether or not the tag is repeatable.
  60.    */
  61.   public BagInfoRequirement(final boolean required, final List<String> acceptableValues, final boolean repeatable){
  62.     this.required = required;
  63.     this.acceptableValues = acceptableValues;
  64.     this.repeatable = repeatable;
  65.   }
  66.  
  67.   @Override
  68.   public String toString() {
  69.     return "[required=" + required + ", acceptableValues=" + acceptableValues + ", repeatable=" + repeatable + "]";
  70.   }
  71.  
  72.   public boolean isRequired() {
  73.     return required;
  74.   }
  75.   public void setRequired(final boolean required) {
  76.     this.required = required;
  77.   }
  78.   public List<String> getAcceptableValues() {
  79.     return acceptableValues;
  80.   }
  81.   public void setAcceptableValues(final List<String> acceptableValues) {
  82.     this.acceptableValues = acceptableValues;
  83.   }
  84.   public boolean isRepeatable() {
  85.     return repeatable;
  86.   }
  87.   public void setRepeatable(final boolean repeatable) {
  88.     this.repeatable = repeatable;
  89.   }
  90. }