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

io.sphere.sdk.shippingmethods.ShippingMethod Maven / Gradle / Ivy

There is a newer version: 1.0.0-M12
Show newest version
package io.sphere.sdk.shippingmethods;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.sphere.sdk.models.DefaultModel;
import io.sphere.sdk.models.Reference;
import io.sphere.sdk.models.Referenceable;
import io.sphere.sdk.taxcategories.TaxCategory;
import io.sphere.sdk.zones.Zone;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

import static java.util.stream.Collectors.toList;


@JsonDeserialize(as = ShippingMethodImpl.class)
public interface ShippingMethod extends DefaultModel {
    String getName();

    Optional getDescription();

    Reference getTaxCategory();

    List getZoneRates();

    default List getShippingRatesForZone(final Referenceable zone) {
        final Optional zoneRateOptional = getZoneRates().stream()
                .filter(rate -> rate.getZone().hasSameIdAs(zone.toReference()))
                .findFirst();
        return zoneRateOptional
                .map(rate -> rate.getShippingRates())
                .orElse(Collections.emptyList());
    }

    default List> getZones() {
        return getZoneRates().stream().map(rate -> rate.getZone()).collect(toList());
    }

    boolean isDefault();

    @Override
    default Reference toReference() {
        return Reference.of(typeId(), getId(), this);
    }

    public static String typeId(){
        return "shipping-method";
    }

    public static TypeReference typeReference(){
        return new TypeReference() {
            @Override
            public String toString() {
                return "TypeReference";
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy