it.tidalwave.geo.location.elmo.impl.ElmoGeoPath Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* 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.location.elmo.impl;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.ThreadSafe;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.CopyOnWriteArrayList;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.geo.location.GeoLocation;
import it.tidalwave.geo.location.GeoPath;
import it.tidalwave.geo.location.GeoSchema;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
@Immutable
@ThreadSafe
public class ElmoGeoPath implements GeoPath
{
private final List list;
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
protected ElmoGeoPath (@Nonnull final List geolocations)
{
list = Collections.unmodifiableList(geolocations);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
@Nonnull
public GeoLocation findByType (@Nonnull final GeoSchema geoSchema,
@Nonnull final Object type)
throws NotFoundException
{
for (final ListIterator i = list.listIterator(list.size()); i.hasPrevious(); )
{
final GeoLocation geoLocation = i.previous();
if (geoLocation.findType(geoSchema) == type)
{
return geoLocation;
}
}
throw new NotFoundException(String.format("No ancestor of type %s", type));
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
@Nonnull
public List asList()
{
return new CopyOnWriteArrayList(list);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
@Nonnegative
public int size()
{
return list.size();
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
@Nonnull
public GeoLocation get (@Nonnegative final int index)
{
return list.get(index);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
@Nonnull
public Iterator iterator()
{
return Collections.unmodifiableCollection(list).iterator();
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public boolean equals (final @CheckForNull Object object)
{
if (object == null)
{
return false;
}
if (getClass() != object.getClass())
{
return false;
}
final ElmoGeoPath other = (ElmoGeoPath)object;
return this.list.equals(other.list);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public int hashCode()
{
return list.hashCode();
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
@Nonnull
public String toString()
{
return String.format("ElmoGeoPath@%x[%s]", System.identityHashCode(this), list);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy