net.sourceforge.javadpkg.control.impl.PackageVersionRelationOperatorParserImpl 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.control.impl;
import java.util.Map;
import java.util.TreeMap;
import net.sourceforge.javadpkg.ParseException;
import net.sourceforge.javadpkg.control.PackageVersionRelationOperator;
import net.sourceforge.javadpkg.control.PackageVersionRelationOperatorParser;
/**
*
* A {@link PackageVersionRelationOperatorParser} implementation.
*
*
* @author Gerrit Hohl ([email protected])
* @version 1.0, 01.01.2016 by Gerrit Hohl
*/
public class PackageVersionRelationOperatorParserImpl implements PackageVersionRelationOperatorParser {
/** The relational operators. */
private Map relationOperators;
/**
*
* Creates a parser.
*
*/
public PackageVersionRelationOperatorParserImpl() {
super();
this.relationOperators = new TreeMap<>();
this.addRelationOperator("<<");
this.addRelationOperator("<=");
this.addRelationOperator("=");
this.addRelationOperator(">=");
this.addRelationOperator(">>");
}
/**
*
* Adds a relation operator to the internal map.
*
*
* @param text
* The text.
*/
private void addRelationOperator(String text) {
this.relationOperators.put(text, new PackageVersionRelationOperatorImpl(text));
}
@Override
public PackageVersionRelationOperator parsePackageVersionRelationOperator(String value) throws ParseException {
PackageVersionRelationOperator relationOperator;
if (value == null)
throw new IllegalArgumentException("Argument value is null.");
relationOperator = this.relationOperators.get(value);
if (relationOperator == null)
throw new ParseException("The relational operator |" + value + "| is not a supported relational operator.");
return relationOperator;
}
/* **********************************************************************
* **********************************************************************
* **********************************************************************
* **********************************************************************
* **********************************************************************
*/
/**
*
* The {@link PackageVersionRelationOperator} implementation of this class.
*
*
* @author Gerrit Hohl ([email protected])
* @version 1.0, 01.01.2016 by Gerrit Hohl
*/
private class PackageVersionRelationOperatorImpl implements PackageVersionRelationOperator {
/** The text. */
private String text;
/**
*
* Creates a relation operator.
*
*
* @param text
* The text.
*/
public PackageVersionRelationOperatorImpl(String text) {
super();
this.text = text;
}
@Override
public String getText() {
return this.text;
}
}
}