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

at.gridgears.held.internal.parser.LocationReferenceParser Maven / Gradle / Ivy

package at.gridgears.held.internal.parser;

import at.gridgears.held.LocationReference;
import at.gridgears.schemas.held.LocationResponseType;
import at.gridgears.schemas.held.ReturnLocationType;
import org.apache.commons.lang3.mutable.MutableObject;

import java.net.URI;
import java.time.Instant;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;

import static at.gridgears.held.internal.parser.ParseUtils.toInstant;

class LocationReferenceParser {
    List parse(LocationResponseType locationResponseType) {
        MutableObject expires = new MutableObject<>();

        List result = new LinkedList<>();
        Optional.ofNullable(locationResponseType.getLocationUriSet())
                .map(storeExpires(expires))
                .map(ReturnLocationType::getLocationURI)
                .map(List::stream)
                .ifPresent(stream ->
                        stream.forEach(uri -> result.add(new LocationReference(URI.create(uri.trim()), expires.getValue())))
                );
        return result;
    }

    private Function storeExpires(MutableObject expires) {
        return returnLocationType -> {
            expires.setValue(toInstant(returnLocationType.getExpires()));
            return returnLocationType;
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy