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

it.tidalwave.geo.geocoding.GeoCoderEntitySet Maven / Gradle / Ivy

The newest version!
/***********************************************************************************************************************
 *
 * forceTen - open source geography
 * Copyright (C) 2007-2012 by Tidalwave s.a.s. (http://www.tidalwave.it)
 *
 ***********************************************************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations under the License.
 *
 ***********************************************************************************************************************
 *
 * WWW: http://forceten.tidalwave.it
 * SCM: https://bitbucket.org/tidalwave/forceten-src
 *
 **********************************************************************************************************************/
package it.tidalwave.geo.geocoding;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.io.Serializable;
import it.tidalwave.geo.Coordinate;
import it.tidalwave.geo.CoordinateSet;
import it.tidalwave.geo.Sector;

/***********************************************************************************************************************
 *
 * @author Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
@Immutable
public final class GeoCoderEntitySet implements Serializable, Iterable
  {
    private static final long serialVersionUID = -34534064049604L;

    private final List geoEntities = new ArrayList(); // Collection is not serializable

    private final CoordinateSet coordinateSet;

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public GeoCoderEntitySet()
      {
        coordinateSet = new CoordinateSet();
      }
    
    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public GeoCoderEntitySet (@Nonnull final GeoCoderEntity ... geoEntities)
      {
        this(Arrays.asList(geoEntities));
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public GeoCoderEntitySet (@Nonnull final Collection geoEntities)
      {
        final List coordinates = new ArrayList();
        
        for (final GeoCoderEntity geoEntity : geoEntities)
          {
            coordinates.add(geoEntity.getCoordinate());
          }

        this.geoEntities.addAll(geoEntities);
        this.coordinateSet = new CoordinateSet(coordinates);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override
    @Nonnull
    public Iterator iterator()
      {
        return Collections.unmodifiableCollection(geoEntities).iterator();
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Nonnegative
    public int size()
      {
        return geoEntities.size();
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Nonnull
    public Sector getSector()
      {
        return coordinateSet.getSector();
      }

    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    @Override
    public boolean equals (@CheckForNull final Object object)
      {
        if (object == null)
          {
            return false;
          }

        if (getClass() != object.getClass())
          {
            return false;
          }

        final GeoCoderEntitySet other = (GeoCoderEntitySet)object;

        return this.geoEntities.equals(other.geoEntities) && this.coordinateSet.equals(other.coordinateSet);
      }

    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    @Override
    public int hashCode()
      {
        int hash = 5;
        hash = 97 * hash + geoEntities.hashCode();
        hash = 97 * hash + coordinateSet.hashCode();
        return hash;
      }

    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    @Override
    public String toString()
      {
        return String.format("GeoEntitySet@%x[%d entities, %s]",
                             System.identityHashCode(this), geoEntities.size(), coordinateSet.getSector());
      }
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy