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

com.wwm.indexer.internal.random.PostcodeConverter Maven / Gradle / Ivy

The newest version!
/******************************************************************************
 * Copyright (c) 2005-2008 Whirlwind Match Limited. All rights reserved.
 *
 * This is open source software; you can use, redistribute and/or modify
 * it under the terms of the Open Software Licence v 3.0 as published by the 
 * Open Source Initiative.
 *
 * You should have received a copy of the Open Software Licence along with this
 * application. if not, contact the Open Source Initiative (www.opensource.org)
 *****************************************************************************/
package com.wwm.indexer.internal.random;


import org.fuzzydb.attrs.location.EcefVector;
import org.fuzzydb.core.whirlwind.internal.IAttribute;
import org.fuzzydb.dto.attributes.LocationAttribute;
import org.fuzzydb.util.geo.GeoInformation;
import org.springframework.core.convert.converter.Converter;

import com.wwm.indexer.db.converters.TempFactory;
import com.wwm.indexer.exceptions.AttributeException;


public class PostcodeConverter {

    private static final Converter converter = TempFactory.getPostcodeConverter();

    public Class getIAttributeClass() {
        return EcefVector.class;
    }

    public Class getObjectClass() {
        return LocationAttribute.class;
    }

    public EcefVector convert(String name, IAttribute attribute) {
        return (EcefVector) attribute;
    }

    synchronized public EcefVector convertToInternal(int attrid, Object object) throws AttributeException {
        // FIXME: a bodge to work with either
        String name, postcode;
        if (object instanceof LocationAttribute){
            LocationAttribute attr = (LocationAttribute) object;
            postcode = attr.getPostcode();
            name = attr.getName();
        } else {
            postcode = (String)object;
            name = String.valueOf(attrid);
        }
        GeoInformation result = converter.convert(postcode);

        if (result == null){
            throw new AttributeException("Unable to lookup postcode for: " + name + "=" + postcode);
        }

        return EcefVector.fromDegs(attrid, result.getLatitude(), result.getLongitude());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy