| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.preferences; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| import java.util.Map; |
| |
| /** |
| * Abstract dependencies for all relevant OSBP product & model bundle configuration files. |
| * <br> |
| * There are three types of dependencies for each type of configuration file |
| * <ul> |
| * <li>required dependencies - these are essential for the OSBP product & model bundle</li> |
| * <li>recommended dependencies - these are not essential for the OSBP product & model bundle</li> |
| * <li>deprecated dependencies - these are dependencies, which existed in the past, but have been removed later on</li> |
| * </ul> |
| */ |
| public abstract class AbstractConfigurationFileBase { |
| |
| /** |
| * @return map of required dependencies; with the id as map key and attributes map as map value |
| */ |
| abstract Map<String,Map<String,String>> getRequiredAsMap(); |
| |
| /** |
| * @return string with required dependencies separated by newline characters |
| */ |
| abstract String getRequiredAsString(); |
| |
| /** |
| * @return map of recommended dependencies; with the id as map key and attributes map as map value |
| */ |
| abstract Map<String,Map<String,String>> getRecommendedAsMap(); |
| |
| /** |
| * @return string with recommended dependencies separated by newline characters |
| */ |
| abstract String getRecommendedAsString(); |
| |
| /** |
| * @return map of deprecated dependencies; with the id as map key and attributes map as map value |
| */ |
| abstract Map<String,Map<String,String>> getDeprecatedAsMap(); |
| |
| /** |
| * @return string with deprecated dependencies separated by newline characters |
| */ |
| abstract String getDeprecatedAsString(); |
| |
| /** |
| * @param asString the <i>pure</i> string, which has to be prepared |
| * @return the prepared string, the preparation may be different for the different types of configuration files |
| */ |
| abstract String prepareSerialized(String asString); |
| |
| /** |
| * @param asString serialized string with dependencies separated by newline characters |
| * @return deserialized as map of dependencies; with the id as map key and attributes map as map value |
| */ |
| abstract Map<String,Map<String,String>> deserialize(String asString); |
| |
| /** |
| * @param attributes deserialized map of dependencies; with the id as map key and attributes map as map value |
| * @return serialized as string with dependencies separated by newline characters |
| */ |
| abstract String serialize(String id, Map<String,String> attributes); |
| |
| /** |
| * @param asString list of configurations as string separated by newline characters |
| * @return string with any duplicate lines removed |
| */ |
| protected String removeDuplicates(String asString) { |
| String[] lines = asString.split("\n"); |
| List<String> items = new ArrayList<String>(); |
| for (String line : lines) { |
| if (!items.contains(line.trim())) { |
| items.add(line.trim()); |
| } |
| } |
| return String.join("\n", items); |
| } |
| } |