
ru.d_shap.conditionalvalues.ValueSet 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.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Class represents a distinct condition with a corresponding values for this condition.
*
* @param generic type for the value.
*
* @author Dmitry Shapovalov
*/
public final class ValueSet {
private final String _id;
private final Predicate _predicate;
private final Map _predicates;
private final Map> _conditions;
private final Set _conditionNames;
private final List _values;
ValueSet(final String id, final Predicate predicate, final Map predicates, final Map> conditions, final List values) {
super();
_id = id;
_predicate = predicate;
_predicates = createPredicates(predicates);
_conditions = createConditions(conditions);
_conditionNames = createConditionNames();
_values = createValues(values);
}
private Map createPredicates(final Map predicates) {
Map result = new HashMap<>();
if (predicates != null) {
for (Map.Entry entry : predicates.entrySet()) {
String key = entry.getKey();
Predicate predicate = entry.getValue();
if (key != null && predicate != null) {
result.put(key, predicate);
}
}
}
return result;
}
private Map> createConditions(final Map> conditions) {
Map> result = new HashMap<>();
if (conditions != null) {
for (Map.Entry> entry : conditions.entrySet()) {
String key = entry.getKey();
Set
© 2015 - 2025 Weber Informatics LLC | Privacy Policy