net.sourceforge.javadpkg.field.impl.FieldImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dpkg Show documentation
Show all versions of dpkg Show documentation
The library for reading and writing Debian Packages.
/*
* dpkg - Debian Package library and the Debian Package Maven plugin
* (c) Copyright 2016 Gerrit Hohl
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package net.sourceforge.javadpkg.field.impl;
import net.sourceforge.javadpkg.field.Field;
/**
*
* A {@link Field} implementation.
*
*
* @author Gerrit Hohl ([email protected])
* @version 1.0, 28.04.2016 by Gerrit Hohl
*/
public class FieldImpl extends AbstractField {
/** The name. */
private String name;
/** The value. */
private StringBuilder value;
/**
*
* Creates a field.
*
*
* The value won't be formatted.
*
*
* @param name
* The name.
* @param value
* The value.
* @throws IllegalArgumentException
* If any of the parameters is null
.
*/
public FieldImpl(String name, String value) {
this(name, value, false);
}
/**
*
* Creates a field.
*
*
* @param name
* The name.
* @param value
* The value.
* @param formatValue
* The flag if the value should be stored as formatted. A
* formatted value contains "." instead of empty lines.
* @throws IllegalArgumentException
* If any of the parameters is null
.
*/
public FieldImpl(String name, String value, boolean formatValue) {
super(false, false);
if (name == null)
throw new IllegalArgumentException("Argument name is null.");
if (value == null)
throw new IllegalArgumentException("Argument value is null.");
this.name = name;
this.value = new StringBuilder();
if (formatValue) {
this.value.append(this.formatValue(value));
} else {
this.value.append(value);
}
}
/**
*
* Returns the name.
*
*
* @return The name.
*/
@Override
public String getName() {
return this.name;
}
/**
*
* Returns the value.
*
*
* @return The value.
*/
@Override
public String getValue() {
return this.value.toString();
}
/**
*
* Sets the specified value as the value of the field.
*
*
* @param value
* The value.
* @throws IllegalArgumentException
* If the value is null
.
*/
public void setValue(String value) {
if (value == null)
throw new IllegalArgumentException("Argument value is null.");
this.value = new StringBuilder();
this.value.append(value);
}
/**
*
* Adds the specified value to the value of the field.
*
*
* @param value
* The value which should be added to the field value.
*/
public void addValue(String value) {
if (value == null)
throw new IllegalArgumentException("Argument value is null.");
this.value.append(value);
}
}