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

org.opentripplanner.netex.loader.mapping.DayOfWeekMapper Maven / Gradle / Ivy

package org.opentripplanner.netex.loader.mapping;

import org.rutebanken.netex.model.DayOfWeekEnumeration;

import java.time.DayOfWeek;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Set;

/**
 * Map between NeTEx {@link DayOfWeekEnumeration} to Java {@link DayOfWeek}. The NeTEx version have
 * "collection" type elements like WEEKDAYS, WEEKEND, EVERYDAY and NONE. Beacuse of this, the
 * mapping is not ono-to-one, but rather one-to-many.
 */
class DayOfWeekMapper {

    /** Utility class with static methods, prevent instantiation with private constructor */
    private DayOfWeekMapper() {}

    /**
     * Return a set Java DayOfWeek representing a union of all input values given. Each value is
     * mapped to a set of Java DayOfWeek, which is merged into one set.
     * 

* [MONDAY, SATURDAY, WEEKEND] => [MONDAY, SATURDAY, SUNDAY] */ static Set mapDayOfWeek(Collection values) { EnumSet result = EnumSet.noneOf(DayOfWeek.class); for (DayOfWeekEnumeration it : values) { result.addAll(mapDayOfWeek(it)); } return result; } /** * Maps given {@code value} into a set of Java DayOfWeek. *

    *
  • MONDAY to SUNDAY is mapped to a Set with one element *
  • NONE is mapped to an empty set *
  • WEEKDAYS is mapped to a set of MONDAY..FRIDAY *
  • WEEKEND is mapped to a set of SATURDAY..SUNDAY *
  • EVERYDAY is mapped to a set of MONDAY..SUNDAY *
*/ static Set mapDayOfWeek(DayOfWeekEnumeration value) { switch (value) { case MONDAY : return EnumSet.of(DayOfWeek.MONDAY); case TUESDAY: return EnumSet.of(DayOfWeek.TUESDAY); case WEDNESDAY: return EnumSet.of(DayOfWeek.WEDNESDAY); case THURSDAY : return EnumSet.of(DayOfWeek.THURSDAY); case FRIDAY: return EnumSet.of(DayOfWeek.FRIDAY); case SATURDAY : return EnumSet.of(DayOfWeek.SATURDAY); case SUNDAY: return EnumSet.of(DayOfWeek.SUNDAY); case WEEKDAYS : return EnumSet.range(DayOfWeek.MONDAY, DayOfWeek.FRIDAY); case WEEKEND : return EnumSet.range(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY); case EVERYDAY : return EnumSet.range(DayOfWeek.MONDAY, DayOfWeek.SUNDAY); case NONE: return EnumSet.noneOf(DayOfWeek.class); } throw new IllegalArgumentException("Day of week enum mapping missing: " + value); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy