Example usage for com.liferay.portal.kernel.util GetterUtil getDouble

List of usage examples for com.liferay.portal.kernel.util GetterUtil getDouble

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util GetterUtil getDouble.

Prototype

public static double getDouble(String value, Locale locale) 

Source Link

Document

Returns the String value as a double.

Usage

From source file:com.liferay.events.global.mobile.Utils.java

License:Open Source License

public static double getLikeness(EventContact me, EventContact targetContact, Map<String, String> eventConfig)
        throws JSONException {

    double percentInterestMatch = getInterestLikeness(me, targetContact);
    double percentExpertiseMatch = getExpertiseMatch(me, targetContact);
    double industrySimilarity = getJaroWinklerDistance(me.getIndustry(), targetContact.getIndustry());
    double jobTitleSimilarity = getJaroWinklerDistance(me.getJobTitle(), targetContact.getJobTitle());

    double locationDistance;

    if (me.getLat() == 0 || me.getLng() == 0 || targetContact.getLat() == 0 || targetContact.getLng() == 0) {
        locationDistance = 100000;//  ww  w  . j a va  2s .c o m
    } else {
        locationDistance = getDistanceBetween(me.getLat(), me.getLng(), targetContact.getLat(),
                targetContact.getLng());
    }

    double locationSimilarity = 1 - (locationDistance / 500);
    if (locationSimilarity < 0)
        locationSimilarity = 0;

    double finalMatch = GetterUtil.getDouble(eventConfig.get("expertise_match_weight"), 0.50)
            * percentExpertiseMatch
            + GetterUtil.getDouble(eventConfig.get("interest_match_weight"), 0.30) * percentInterestMatch
            + GetterUtil.getDouble(eventConfig.get("location_match_weight"), 0.05) * locationSimilarity
            + GetterUtil.getDouble(eventConfig.get("job_title_match_weight"), 0.05) * jobTitleSimilarity
            + GetterUtil.getDouble(eventConfig.get("industry_match_weight"), 0.10) * industrySimilarity;

    String bonusStr = eventConfig.get("bonus_match_map");
    String attendeeType = targetContact.getAttendeeType();

    if (Validator.isNotNull(bonusStr) && Validator.isNotNull(attendeeType)) {
        JSONArray arr = JSONFactoryUtil.createJSONArray(bonusStr);
        for (int i = 0; i < arr.length(); i++) {
            String bonusType = arr.getJSONObject(i).getString("type");
            Double bonus = arr.getJSONObject(i).getDouble("bonus");
            if (attendeeType.contains(bonusType)) {
                finalMatch += bonus;
            }
        }
    }

    if (finalMatch > 1.0) {
        finalMatch = 1.0;
    }

    return finalMatch;
}