Android Open Source - cloudmine-android Locally Savable C M Geo Point






From Project

Back to project page cloudmine-android.

License

The source code is released under:

Copyright (c) 2012 CloudMine LLC, http://cloudmine.me Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software")...

If you think the Android project cloudmine-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.cloudmine.api.db;
/*  w w w  .ja  va  2  s . c  om*/
import com.cloudmine.api.CMGeoPointInterface;
import com.cloudmine.api.SimpleCMObject;
import com.cloudmine.api.rest.TransportableString;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A {@link CMGeoPointInterface} that can be saved locally/synced to server eventually.
 * <br>
 * Copyright CloudMine LLC. All rights reserved<br>
 * See LICENSE file included with SDK for details.
 */
public class LocallySavableCMGeoPoint extends com.cloudmine.api.db.LocallySavableCMObject implements CMGeoPointInterface {

    private static final Logger LOG = LoggerFactory.getLogger(LocallySavableCMGeoPoint.class);
    private static final String[] LATITUDE_KEYS = {"latitude", "lat", "y"};
    private static final String[] LONGITUDE_KEYS = {"longitude", "lon", "lng", "x"};

    private double latitude;
    private double longitude;
    private static final String __type__ = "geopoint";

    protected LocallySavableCMGeoPoint() {

    }

    public LocallySavableCMGeoPoint(double longitude, double latitude) {
        this.latitude = latitude;
        this.longitude = longitude;
    }

    public LocallySavableCMGeoPoint(TransportableString transportableString) {
        //is this hacky? yes it is!
        SimpleCMObject object = new SimpleCMObject(transportableString);
        this.latitude = getValueFromKey(object, LATITUDE_KEYS);
        this.longitude = getValueFromKey(object, LONGITUDE_KEYS);
    }

    protected void setWithOtherKey(String key, double value) {
        if(is(LATITUDE_KEYS, key)) {
            setLatitude(value);
        } else if(is(LONGITUDE_KEYS, key)) {
            setLongitude(value);
        }
    }

    @JsonAnySetter
    protected void setWithOtherKey(String key, String value) {
        try {
            double asDouble = Double.parseDouble(value);
            setWithOtherKey(key, asDouble);
        }catch(NumberFormatException e) {

        }
    }

    private boolean is(String[] possibleKeys, String key) {
        for(String possibleKey : possibleKeys) {
            if(possibleKey.equals(key)) {
                return true;
            }
        }
        return false;
    }

    private double getValueFromKey(SimpleCMObject object, String[] keys) {
        for(String key : keys) {
            Double keyValue = object.getDouble(key);
            if(keyValue != null)
                return keyValue.doubleValue();
        }
        LOG.error("No value found for keys, using 0.0");
        return 0;
    }

    @Override
    public String getClassName() {
        return GEOPOINT_CLASS;
    }

    public String get__type__() {
        return __type__;
    }

    @Override public double getLatitude() {
        return latitude;
    }

    @Override public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    @Override public double getLongitude() {
        return longitude;
    }

    @Override public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        LocallySavableCMGeoPoint geoPoint = (LocallySavableCMGeoPoint) o;

        if (Double.compare(geoPoint.latitude, latitude) != 0) return false;
        if (Double.compare(geoPoint.longitude, longitude) != 0) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        temp = latitude != +0.0d ? Double.doubleToLongBits(latitude) : 0L;
        result = (int) (temp ^ (temp >>> 32));
        temp = longitude != +0.0d ? Double.doubleToLongBits(longitude) : 0L;
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }
}




Java Source Code List

com.cloudmine.api.AccessListController.java
com.cloudmine.api.BaseCMUser.java
com.cloudmine.api.BaseCacheableCMFile.java
com.cloudmine.api.CMAndroidSocial.java
com.cloudmine.api.CMCreditCard.java
com.cloudmine.api.CMSharedPreferencesConstants.java
com.cloudmine.api.CurrentHandlerHavers.java
com.cloudmine.api.DeviceIdentifier.java
com.cloudmine.api.HasHandler.java
com.cloudmine.api.LocallySavable.java
com.cloudmine.api.db.BaseLocallySavableCMAccessList.java
com.cloudmine.api.db.BaseLocallySavableCMObject.java
com.cloudmine.api.db.CMObjectDBOpenHelper.java
com.cloudmine.api.db.LocallySavableCMGeoPoint.java
com.cloudmine.api.db.RequestConstants.java
com.cloudmine.api.db.RequestDBObject.java
com.cloudmine.api.db.RequestDBOpenHelper.java
com.cloudmine.api.db.RequestPerformerService.java
com.cloudmine.api.gui.AuthenticationDialog.java
com.cloudmine.api.gui.VolleyAuthenticationDialog.java
com.cloudmine.api.loopj.AsyncHttpClient.java
com.cloudmine.api.loopj.AsyncHttpRequest.java
com.cloudmine.api.loopj.AsyncHttpResponseHandler.java
com.cloudmine.api.loopj.PersistentCookieStore.java
com.cloudmine.api.loopj.RequestParams.java
com.cloudmine.api.loopj.RetryHandler.java
com.cloudmine.api.loopj.SerializableCookie.java
com.cloudmine.api.loopj.SimpleMultipartEntity.java
com.cloudmine.api.rest.AndroidAsynchronousHttpClient.java
com.cloudmine.api.rest.AndroidBase64Encoder.java
com.cloudmine.api.rest.AndroidHeaderFactory.java
com.cloudmine.api.rest.AndroidUserCMWebService.java
com.cloudmine.api.rest.BaseAccessListCreateRequest.java
com.cloudmine.api.rest.BaseAccessListLoadRequest.java
com.cloudmine.api.rest.BaseAccessListModificationRequest.java
com.cloudmine.api.rest.BaseAddPaymentMethodRequest.java
com.cloudmine.api.rest.BaseChangeUserIdentifierRequest.java
com.cloudmine.api.rest.BaseChangeUserPasswordRequest.java
com.cloudmine.api.rest.BaseChargeCardRequest.java
com.cloudmine.api.rest.BaseFileCreationRequest.java
com.cloudmine.api.rest.BaseFileDeleteRequest.java
com.cloudmine.api.rest.BaseFileLoadRequest.java
com.cloudmine.api.rest.BaseImageLoadRequest.java
com.cloudmine.api.rest.BaseLoadPaymentMethodsRequest.java
com.cloudmine.api.rest.BaseLoadUserProfilesRequest.java
com.cloudmine.api.rest.BaseObjectDeleteRequest.java
com.cloudmine.api.rest.BaseObjectLoadRequest.java
com.cloudmine.api.rest.BaseObjectModificationRequest.java
com.cloudmine.api.rest.BaseProfileLoadRequest.java
com.cloudmine.api.rest.BaseProfileUpdateRequest.java
com.cloudmine.api.rest.BaseRemovePaymentMethodRequest.java
com.cloudmine.api.rest.BaseResetPasswordRequest.java
com.cloudmine.api.rest.BaseSnippetRequest.java
com.cloudmine.api.rest.BaseUserCreationRequest.java
com.cloudmine.api.rest.BaseUserLoginRequest.java
com.cloudmine.api.rest.BaseUserLogoutRequest.java
com.cloudmine.api.rest.CMImageLoader.java
com.cloudmine.api.rest.CMNetwork.java
com.cloudmine.api.rest.CloudMineRequest.java
com.cloudmine.api.rest.CompleteSocialLoginRequest.java
com.cloudmine.api.rest.DialogListener.java
com.cloudmine.api.rest.DiskBitmapCache.java
com.cloudmine.api.rest.ObjectLoadRequestBuilder.java
com.cloudmine.api.rest.OkHttpStack.java
com.cloudmine.api.rest.RequestBuilder.java
com.cloudmine.api.rest.SharedRequestQueueHolders.java
com.cloudmine.api.rest.VolleyAsynchronousHttpClient.java
com.cloudmine.api.rest.callbacks.AndroidCallback.java
com.cloudmine.api.rest.callbacks.PaymentResponseCallback.java
com.cloudmine.api.rest.response.PaymentResponse.java