From 93c6ae71dc384e55b5c27330a8f445c27775b0f3 Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Thu, 19 May 2016 08:41:28 +0000 Subject: [PATCH] SSDM-3027: Helper class to create Map instances. SVN: 36551 --- .../cisd/common/collection/MapBuilder.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 common/source/java/ch/systemsx/cisd/common/collection/MapBuilder.java diff --git a/common/source/java/ch/systemsx/cisd/common/collection/MapBuilder.java b/common/source/java/ch/systemsx/cisd/common/collection/MapBuilder.java new file mode 100644 index 00000000000..9a1e242d51f --- /dev/null +++ b/common/source/java/ch/systemsx/cisd/common/collection/MapBuilder.java @@ -0,0 +1,51 @@ +/* + * Copyright 2016 ETH Zuerich, SIS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.common.collection; + +import java.util.HashMap; +import java.util.Map; + +/** + * Helper class to fill {@link Map} instances in fluid api style. + * + * @author Franz-Josef Elmer + */ +public class MapBuilder<K, T> +{ + private final Map<K, T> map; + + public MapBuilder() + { + this(new HashMap<K, T>()); + } + + public MapBuilder(Map<K, T> map) + { + this.map = map; + } + + public Map<K, T> getMap() + { + return map; + } + + public MapBuilder<K, T> entry(K key, T value) + { + map.put(key, value); + return this; + } +} -- GitLab