All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jgrasstools.gears.io.grasslegacy.map.attribute.AttributeTable Maven / Gradle / Ivy

The newest version!
/*
 * JGrass - Free Open Source Java GIS http://www.jgrass.org 
 * (C) HydroloGIS - www.hydrologis.com 
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see .
 */
/*******************************************************************************
           FILE:  AttributeTable.java
    DESCRIPTION:  
          NOTES:  ---
         AUTHOR:  John Preston,
                  Andrea Antonello
          EMAIL:  [email protected]
                  [email protected]
        COMPANY:  University of the West Indies
                  University of Trento / CUDAM
      COPYRIGHT:  ICENS, University of the West Indies
                  Engineering Department, University of Trento / CUDAM
        VERSION:  
        CREATED:  August 11, 2004, 2004
       REVISION:  ---

 ******************************************************************************

   This library is free software; you can redistribute it and/or 
   modify it under the terms of the GNU Library General Public 
   License as published by the Free Software Foundation; either 
   version 2 of the License, or (at your option) any later version. 

   This library is distributed in the hope that it will be useful, 
   but WITHOUT ANY WARRANTY; without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
   Library General Public License for more details. 

   You should have received a copy of the GNU Library General Public 
   License along with this library; if not, write to the Free 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 
   USA 

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:
   1. Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
   2. Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.

 ******************************************************************************

     CHANGE LOG:

        version: 
       comments: changes
         author: 
        created:  
 *****************************************************************************/
package org.jgrasstools.gears.io.grasslegacy.map.attribute;

import java.util.Enumeration;
import java.util.Vector;

/**
 *
 */
public class AttributeTable {
    private Vector atts = null;

    /** Creates a new instance of AttributeTable */
    public AttributeTable() {
        atts = new Vector();
    }

    /**
     *
     */
    public int size() {
        return atts.size();
    }

    /**
     *
     */
    public Enumeration getCategories() {
        return atts.elements();
    }

    /**
     *
     */
    public void addAttribute( float cat, String value ) {
        // System.out.println("##############################################");
        // for (int i=0; i cat0) {
                low = cat0;
                range = cat1 - cat0;
            } else {
                low = cat1;
                range = cat0 - cat1;
            }
            catText = text;
        }

        /**
         * Compare a value to the range of values in this attribute
         * If the cat is below the renage then return -1, if it
         * is aboove the ramge then return +1, if it is equal return 0
         */
        public int compare( float cat ) {
            float diff = cat - low;
            if (diff < 0)
                return -1;
            else if (diff > range)
                return 1;

            return 0;
        }

        public String getText() {
            return catText;
        }

        public float getLowcategoryValue() {
            return low;
        }

        public float getCategoryRange() {
            return range;
        }

        /**
         *
         */
        public String toString() {
            if (range == 0f)
                return String.valueOf(low) + ":" + catText;
            else
                return String.valueOf(low) + "-" + String.valueOf(low + range) + ":" + catText;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy