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

com.targomo.client.api.response.TimeVectorResponse Maven / Gradle / Ivy

The newest version!
package com.targomo.client.api.response;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.targomo.client.api.TravelOptions;
import com.targomo.client.api.geo.Coordinate;
import com.targomo.client.api.response.parsingpojos.ElementWithTargets;
import com.targomo.client.api.response.parsingpojos.TransitTravelTimes;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class TimeVectorResponse extends DefaultResponse>, List>>{

    @JsonIgnore
    private Map> travelTimeVectors = null;

    @Override
    protected List> parseData(List> jacksonData) {
        return jacksonData;
    }

    public Map> getTravelTimeVectors(){
        if(travelTimeVectors != null)
            return travelTimeVectors;

        travelTimeVectors = new HashMap<>();
        if(data != null) {
            final TravelOptions travelOptions = this.getTravelOptions();
            for (ElementWithTargets travelTimesOfSource : data) {

                Map mapOfTravelTimesOfSource =
                        travelTimesOfSource.getTargets().stream().collect(Collectors.toMap(
                                tTO -> travelOptions.getTarget(tTO.getId()), //key becomes coordinate
                                Function.identity() )); //value is the travel time vector result

                //adding the targets to the map
                travelTimeVectors.put(travelOptions.getSource(travelTimesOfSource.getId()), mapOfTravelTimesOfSource);
            }
        }
        return travelTimeVectors;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy