| /** |
| * |
| * 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.LinkedHashMap; |
| import java.util.Map; |
| |
| public class ItemDescription { |
| |
| private final String fRowName; |
| private final Map<String, Type> fColumns; |
| |
| public enum Type { |
| DatabaseType, // NOSONAR |
| Integer, // NOSONAR |
| String, // NOSONAR |
| Boolean, // NOSONAR |
| }; |
| |
| public ItemDescription(String rowName, Object... columnAttributes) { |
| fRowName = rowName; |
| fColumns = new LinkedHashMap<>(); |
| for (int idx = 0; idx < columnAttributes.length/2; idx++) { |
| fColumns.put((String)columnAttributes[idx*2], (Type)columnAttributes[idx*2+1]); |
| } |
| } |
| |
| public static boolean parseBoolean(String text, boolean deflt) { |
| try { |
| return Boolean.parseBoolean(text); |
| } |
| catch (Exception e) { // NOSONAR |
| return deflt; |
| } |
| } |
| |
| public static int parseInt(String text, int deflt) { |
| try { |
| return Integer.parseInt(text); |
| } |
| catch (Exception e) { // NOSONAR |
| return deflt; |
| } |
| |
| } |
| |
| public String getRowName() { |
| return fRowName; |
| } |
| |
| public String[] getColumnNames() { |
| return fColumns.keySet().toArray(new String[0]); |
| } |
| |
| public Type getColumnType(String columnName) { |
| return fColumns.get(columnName); |
| } |
| } |