Mercurial > dive4elements > gnv-client
view geo-backend/src/main/java/de/intevation/gnv/geobackend/base/DefaultResultDescriptor.java @ 1145:dfe1ac687c7f tip
added tags
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:16:15 +0200 |
parents | ebeb56428409 |
children |
line wrap: on
line source
/* * Copyright (c) 2010 by Intevation GmbH * * This program is free software under the LGPL (>=v2.1) * Read the file LGPL.txt coming with the software for details * or visit http://www.gnu.org/licenses/ if it does not exist. */ package de.intevation.gnv.geobackend.base; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * This Class is the DefaultImplementation of the * Interface ResultDescriptor * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> * */ public class DefaultResultDescriptor implements ResultDescriptor { /** *The Uid of this Class */ private static final long serialVersionUID = 7016889733270716130L; /** * The Names of the Columns of one Result */ private List<String> columnNames = new ArrayList<String>(); /** * The Name of the Classes of the Values of one Result. */ private List<String> columnClassNames = new ArrayList<String>(); /** * The Lookup for the Columnindex of the Columnnames */ private Map<String, Integer> columnIndexLookup = new HashMap<String, Integer>(); /** * Constructor */ public DefaultResultDescriptor() { super(); } /** * @see de.intevation.gnv.geobackend.base.ResultDescriptor#getColumnClassName(int) */ public String getColumnClassName(int column) { return this.columnClassNames.get(column); } /** * @see de.intevation.gnv.geobackend.base.ResultDescriptor#getColumnCount() */ public int getColumnCount() { return this.columnClassNames.size(); } /** * @see de.intevation.gnv.geobackend.base.ResultDescriptor#getColumnName(int) */ public String getColumnName(int column) { return this.columnNames.get(column); } /** * @see de.intevation.gnv.geobackend.base.ResultDescriptor#addColumn(java.lang.String, java.lang.String) */ public void addColumn(String name, String className) { this.columnClassNames.add(className); this.columnNames.add(name); this.columnIndexLookup.put(name,this.columnNames.size()-1); } /** * @see de.intevation.gnv.geobackend.base.ResultDescriptor#getColumnIndices(java.lang.String[]) */ public int [] getColumnIndices(String [] columnNames) { if (columnNames == null) { return null; } int [] indices = new int[columnNames.length]; for (int i = 0; i < indices.length; ++i) { indices[i] = this.getColumnIndex(columnNames[i]); } return indices; } /** * @see de.intevation.gnv.geobackend.base.ResultDescriptor#getColumnIndex(java.lang.String) */ public int getColumnIndex(String columnName) { Integer value = this.columnIndexLookup.get(columnName); return value != null ? value.intValue() : -1; } /** * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder("["); int N = Math.min(columnNames.size(), columnClassNames.size()); for (int i = 0; i < N; ++i) { if (i > 0) { sb.append(", "); } sb.append(columnNames.get(i)) .append(": ") .append(columnClassNames.get(i)); } sb.append(']'); return sb.toString(); } }