001// SPDX-License-Identifier: GPL-3.0-or-later 002 003package es.uvigo.esei.sing.textproc.step.xml.definition; 004 005import javax.xml.bind.annotation.XmlRootElement; 006import javax.xml.bind.annotation.XmlValue; 007 008/** 009 * Contains common logic to all processing step parameters, keeping their code 010 * DRY. 011 * 012 * @author Alejandro González García 013 * @see ProcessingStepParameter 014 */ 015public abstract class AbstractProcessingStepParameter implements ProcessingStepParameter { 016 @XmlValue 017 private String value; 018 019 @Override 020 public final String getValue() { 021 return value; 022 } 023 024 @Override 025 public final String getName() { 026 try { 027 return getClass().getDeclaredAnnotation(XmlRootElement.class).name(); 028 } catch (final NullPointerException exc) { 029 throw new AssertionError("Missing XmlRootElement annotation"); 030 } 031 } 032 033 /** 034 * Converts the value of a parameter to a boolean value. Currently, the value is 035 * assumed to be {@code true} if and only if it equals the strings "true" or 036 * "1", ignoring case differences. Therefore, a {@code null} value is treated as 037 * {@code false}. 038 * 039 * @param value The value for the processing step parameter. 040 * @return The value of the processing step parameter, converted to a boolean 041 * value. 042 */ 043 public static boolean convertValueToBoolean(final String value) { 044 return "true".equalsIgnoreCase(value) || "1".equals(value); 045 } 046}