1 /* 2 * dpkg - Debian Package library and the Debian Package Maven plugin 3 * (c) Copyright 2016 Gerrit Hohl 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 */ 19 package net.sourceforge.javadpkg.field.impl; 20 21 import net.sourceforge.javadpkg.field.Field; 22 23 /** 24 * <p> 25 * A {@link Field} implementation. 26 * </p> 27 * 28 * @author Gerrit Hohl (gerrit-hohl@users.sourceforge.net) 29 * @version <b>1.0</b>, 28.04.2016 by Gerrit Hohl 30 */ 31 public class FieldImpl extends AbstractField { 32 33 34 /** The name. */ 35 private String name; 36 /** The value. */ 37 private StringBuilder value; 38 39 40 /** 41 * <p> 42 * Creates a field. 43 * </p> 44 * <p> 45 * The value won't be formatted. 46 * </p> 47 * 48 * @param name 49 * The name. 50 * @param value 51 * The value. 52 * @throws IllegalArgumentException 53 * If any of the parameters is <code>null</code>. 54 */ 55 public FieldImpl(String name, String value) { 56 this(name, value, false); 57 } 58 59 60 /** 61 * <p> 62 * Creates a field. 63 * </p> 64 * 65 * @param name 66 * The name. 67 * @param value 68 * The value. 69 * @param formatValue 70 * The flag if the value should be stored as formatted. A 71 * formatted value contains "." instead of empty lines. 72 * @throws IllegalArgumentException 73 * If any of the parameters is <code>null</code>. 74 */ 75 public FieldImpl(String name, String value, boolean formatValue) { 76 super(false, false); 77 78 if (name == null) 79 throw new IllegalArgumentException("Argument name is null."); 80 if (value == null) 81 throw new IllegalArgumentException("Argument value is null."); 82 83 this.name = name; 84 this.value = new StringBuilder(); 85 if (formatValue) { 86 this.value.append(this.formatValue(value)); 87 } else { 88 this.value.append(value); 89 } 90 } 91 92 93 /** 94 * <p> 95 * Returns the name. 96 * </p> 97 * 98 * @return The name. 99 */ 100 @Override 101 public String getName() { 102 return this.name; 103 } 104 105 106 /** 107 * <p> 108 * Returns the value. 109 * </p> 110 * 111 * @return The value. 112 */ 113 @Override 114 public String getValue() { 115 return this.value.toString(); 116 } 117 118 119 /** 120 * <p> 121 * Sets the specified value as the value of the field. 122 * </p> 123 * 124 * @param value 125 * The value. 126 * @throws IllegalArgumentException 127 * If the value is <code>null</code>. 128 */ 129 public void setValue(String value) { 130 if (value == null) 131 throw new IllegalArgumentException("Argument value is null."); 132 133 this.value = new StringBuilder(); 134 this.value.append(value); 135 } 136 137 138 /** 139 * <p> 140 * Adds the specified value to the value of the field. 141 * </p> 142 * 143 * @param value 144 * The value which should be added to the field value. 145 */ 146 public void addValue(String value) { 147 if (value == null) 148 throw new IllegalArgumentException("Argument value is null."); 149 150 this.value.append(value); 151 } 152 153 154 }