
ru.d_shap.conditionalvalues.ValueSetUniqueCondition Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of conditional-values Show documentation
Show all versions of conditional-values Show documentation
Conditional values simplify conditional logic and get rid of if-statements in the code
The newest version!
///////////////////////////////////////////////////////////////////////////////////////////////////
// Conditional values simplify conditional logic and get rid of if-statements in the code.
// Copyright (C) 2016 Dmitry Shapovalov.
//
// This file is part of conditional values.
//
// Conditional values is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Conditional values 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see .
///////////////////////////////////////////////////////////////////////////////////////////////////
package ru.d_shap.conditionalvalues;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
/**
* Class represents a unique combination of conditions in the {@link ru.d_shap.conditionalvalues.ValueSet} object.
*
* @author Dmitry Shapovalov
*/
public final class ValueSetUniqueCondition {
private final String _id;
private final Map _conditions;
ValueSetUniqueCondition(final String id) {
super();
_id = id;
_conditions = Collections.unmodifiableMap(new TreeMap());
}
ValueSetUniqueCondition(final ValueSetUniqueCondition valueSetUniqueCondition, final String conditionName, final Object conditionValue) {
super();
_id = valueSetUniqueCondition._id;
Map map = new TreeMap<>(valueSetUniqueCondition._conditions);
if (conditionName != null && conditionValue != null) {
if (map.containsKey(conditionName)) {
throw new DuplicateConditionNameException(conditionName);
} else {
map.put(conditionName, conditionValue);
}
}
_conditions = Collections.unmodifiableMap(map);
}
/**
* Get the ID.
*
* @return the ID.
*/
public String getId() {
return _id;
}
/**
* Get a combination of conditions.
*
* @return combination of conditions.
*/
public Map getConditions() {
return _conditions;
}
@Override
public String toString() {
String conditions = _conditions.toString();
if (_id != null) {
conditions = _id + "=" + conditions;
}
return conditions;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy