001: /*
002: * Created on 28.06.2005 for PIROL
003: *
004: * SVN header information:
005: * $Author: javamap $
006: * $Rev: 856 $
007: * $Date: 2007-06-18 21:15:27 -0700 (Mon, 18 Jun 2007) $
008: * $Id: FeatureSchemaTools.java 856 2007-06-19 04:15:27Z javamap $
009: */
010: package de.fho.jump.pirol.utilities.apiTools;
011:
012: import java.util.ArrayList;
013:
014: import com.vividsolutions.jump.feature.AttributeType;
015: import com.vividsolutions.jump.feature.FeatureSchema;
016:
017: import de.fho.jump.pirol.utilities.attributes.AttributeInfo;
018:
019: /**
020: * Class for easier handling of featureSchema objects.
021: *
022: * @author Ole Rahn
023: * <br>
024: * <br>FH Osnabrück - University of Applied Sciences Osnabrück,
025: * <br>Project: PIROL (2005),
026: * <br>Subproject: Daten- und Wissensmanagement
027: *
028: * @version $Rev: 856 $
029: *
030: */
031: public class FeatureSchemaTools extends ToolToMakeYourLifeEasier {
032:
033: /**
034: * Extracts information of all attributes with one of the given types from the given FeatureSchema
035: *@param fs FeatureSchema to get information from
036: *@param allowedTypes array with AttributeTypes, that specify which attribute to get information about
037: *@return array with information on matching attributes
038: */
039: public static AttributeInfo[] getAttributesWithTypes(
040: FeatureSchema fs, AttributeType[] allowedTypes) {
041: ArrayList<AttributeInfo> attrInfosList = new ArrayList<AttributeInfo>();
042: AttributeInfo[] attrInfoArray = AttributeInfo
043: .schema2AttributeInfoArray(fs);
044: int numInfos = attrInfoArray.length;
045:
046: for (int i = 0; i < numInfos; i++) {
047: if (FeatureSchemaTools.isAttributeTypeAllowed(
048: attrInfoArray[i].getAttributeType(), allowedTypes)) {
049: attrInfosList.add(attrInfoArray[i]);
050: }
051: }
052:
053: numInfos = attrInfosList.size();
054: AttributeInfo[] attrInfoRaw = (AttributeInfo[]) attrInfosList
055: .toArray(new AttributeInfo[0]);
056:
057: return attrInfoRaw;
058: }
059:
060: /**
061: * Extracts information on the attribute at the given index from the feature schema.
062: *@param fs FeatureSchema to get information from
063: *@param attrIndex index of the attribute in the given featureSchema to get information about
064: *@return information about the attribute
065: */
066: public static AttributeInfo getAttributesInfoFor(FeatureSchema fs,
067: int attrIndex) {
068: AttributeInfo attrInfo = new AttributeInfo(fs
069: .getAttributeName(attrIndex), fs
070: .getAttributeType(attrIndex));
071:
072: attrInfo.setIndex(attrIndex);
073:
074: return attrInfo;
075: }
076:
077: /**
078: * Extracts information on the attribute with the given name from the feature schema.
079: *@param fs FeatureSchema to get information from
080: *@param attrName name of the attribute in the given featureSchema to get information about
081: *@return information about the attribute
082: */
083: public static AttributeInfo getAttributesInfoFor(FeatureSchema fs,
084: String attrName) {
085: return FeatureSchemaTools.getAttributesInfoFor(fs, fs
086: .getAttributeIndex(attrName));
087: }
088:
089: /**
090: * Checks if the given attribute type is contained in the given array of allowed attribute types.
091: *@param at attribute type to be checked
092: *@param allowedTypes array of allowed attribute types
093: *@return true if <code>at</code> is contained in <code>allowedTypes</code>, else false
094: */
095: public static boolean isAttributeTypeAllowed(AttributeType at,
096: AttributeType[] allowedTypes) {
097: int numTypes = allowedTypes.length;
098: for (int i = 0; i < numTypes; i++) {
099: if (allowedTypes[i].equals(at))
100: return true;
101: }
102: return false;
103: }
104:
105: }
|