it.tidalwave.geo.geocoding.GeoCoderSupport 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.Nonnull;
import javax.annotation.concurrent.ThreadSafe;
import java.util.HashMap;
import java.util.Map;
import java.io.Serializable;
import org.openide.util.Lookup;
import it.tidalwave.netbeans.capabilitiesprovider.LookupFactory;
import it.tidalwave.geo.Coordinate;
import it.tidalwave.geo.geocoding.impl.DefaultGeoCoderEntity;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
@ThreadSafe
public abstract class GeoCoderSupport implements GeoCoder
{
// FIXME: weak
private final Map FLYWEIGHT_MAP = new HashMap();
@CheckForNull
private Lookup lookup;
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override @Nonnull
public synchronized Lookup getLookup()
{
if (lookup == null)
{
lookup = LookupFactory.createLookup(this);
}
return lookup;
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@CheckForNull
protected GeoCoderEntity findCachedGeoEntityById (final @Nonnull String id,
final @CheckForNull GeoCoderEntity parent)
{
final DefaultGeoCoderEntity geoEntity = FLYWEIGHT_MAP.get(id);
if ((geoEntity != null) && (parent != null))
{
geoEntity.setParent(parent);
}
return geoEntity;
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
protected synchronized GeoCoderEntity createGeoEntity (final @CheckForNull GeoCoderEntity parent,
final @Nonnull String id,
final @Nonnull String name,
final @Nonnull Coordinate coordinates,
final @Nonnull String code,
final @Nonnull String typeAsString,
final @Nonnull Serializable[] capabilities)
{
GeoCoderEntity geoEntity = findCachedGeoEntityById(id, parent);
if (geoEntity == null)
{
geoEntity = new DefaultGeoCoderEntity(this, parent, id, name, coordinates, code, typeAsString, capabilities);
FLYWEIGHT_MAP.put(id, (DefaultGeoCoderEntity)geoEntity);
}
return geoEntity;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy