001/*
002 * $Id: org.eclipse.jdt.ui.prefs 138 2006-09-10 12:29:15Z marchy $
003 *
004 * Copyright 2006 the original author or authors.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
007 * use this file except in compliance with the License. You may obtain a copy of
008 * the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015 * License for the specific language governing permissions and limitations under
016 * the License.
017 */
018package net.objectlab.kit.datecalc.common;
019
020import java.util.Set;
021
022/**
023 * This is an immutable holiday calendar, once given to a DateCalculator, a HolidayCalendar cannot be
024 * modified, it will throw {@link UnsupportedOperationException}.
025 *
026 * @author Benoit Xhenseval
027 * @since 1.1.0
028 */
029public class ImmutableHolidayCalendar<E> implements HolidayCalendar<E> {
030    private static final long serialVersionUID = 1287613980146071460L;
031
032    private final HolidayCalendar<E> delegate;
033
034    public ImmutableHolidayCalendar(final HolidayCalendar<E> delegate) {
035        super();
036        this.delegate = delegate;
037    }
038
039    /**
040     * @return the early (start) boundary of the holiday range
041     * @see net.objectlab.kit.datecalc.common.HolidayCalendar#getEarlyBoundary()
042     */
043    public E getEarlyBoundary() {
044        return delegate.getEarlyBoundary();
045    }
046
047    /**
048     * @return the set of holidays
049     * @see net.objectlab.kit.datecalc.common.HolidayCalendar#getHolidays()
050     */
051    public Set<E> getHolidays() {
052        return delegate.getHolidays();
053    }
054
055    /**
056     * @return the late (end) boundary of the holiday range
057     * @see net.objectlab.kit.datecalc.common.HolidayCalendar#getLateBoundary()
058     */
059    public E getLateBoundary() {
060        return delegate.getLateBoundary();
061    }
062
063    /**
064     * @param earlyBoundary
065     * @see net.objectlab.kit.datecalc.common.HolidayCalendar#setEarlyBoundary(java.lang.Object)
066     * @throws UnsupportedOperationException You cannot modify the early boundary, you need to use a new HolidayCalendar.
067     */
068    public HolidayCalendar<E> setEarlyBoundary(final E earlyBoundary) {
069        throw new UnsupportedOperationException("You cannot modify the early boundary, you need to use a new HolidayCalendar.");
070    }
071
072    /**
073     * @param holidays
074     * @see net.objectlab.kit.datecalc.common.HolidayCalendar#setHolidays(java.util.Set)
075     * @throws UnsupportedOperationException You cannot modify the holidays, you need to use a new HolidayCalendar.;
076     */
077    public HolidayCalendar<E> setHolidays(final Set<E> holidays) {
078        throw new UnsupportedOperationException("You cannot modify the holidays, you need to use a new HolidayCalendar.");
079    }
080
081    /**
082     * @param lateBoundary
083     * @see net.objectlab.kit.datecalc.common.HolidayCalendar#setLateBoundary(java.lang.Object)
084     * @throws UnsupportedOperationException You cannot modify the late boundary, you need to use a new HolidayCalendar.
085     */
086    public HolidayCalendar<E> setLateBoundary(final E lateBoundary) {
087        throw new UnsupportedOperationException("You cannot modify the late boundary, you need to use a new HolidayCalendar.");
088    }
089
090    /**
091     * @param date
092     * @return
093     * @see net.objectlab.kit.datecalc.common.HolidayCalendar#isHoliday(java.lang.Object)
094     */
095    public boolean isHoliday(final E date) {
096        return delegate.isHoliday(date);
097    }
098}