001/*
002 * Copyright (c) 2007-2013, Stephen Colebourne & Michael Nascimento Santos
003 *
004 * All rights reserved.
005 *
006 * Redistribution and use in source and binary forms, with or without
007 * modification, are permitted provided that the following conditions are met:
008 *
009 *  * Redistributions of source code must retain the above copyright notice,
010 *    this list of conditions and the following disclaimer.
011 *
012 *  * Redistributions in binary form must reproduce the above copyright notice,
013 *    this list of conditions and the following disclaimer in the documentation
014 *    and/or other materials provided with the distribution.
015 *
016 *  * Neither the name of JSR-310 nor the names of its contributors
017 *    may be used to endorse or promote products derived from this software
018 *    without specific prior written permission.
019 *
020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
024 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031 */
032package org.threeten.bp.jdk8;
033
034import org.threeten.bp.temporal.Temporal;
035import org.threeten.bp.temporal.TemporalAdder;
036import org.threeten.bp.temporal.TemporalAdjuster;
037import org.threeten.bp.temporal.TemporalSubtractor;
038import org.threeten.bp.temporal.TemporalUnit;
039
040/**
041 * A temporary class providing implementations that will become default interface
042 * methods once integrated into JDK 8.
043 */
044public abstract class DefaultInterfaceTemporal
045        extends DefaultInterfaceTemporalAccessor
046        implements Temporal {
047
048    @Override
049    public Temporal with(TemporalAdjuster adjuster) {
050        return adjuster.adjustInto(this);
051    }
052
053    @Override
054    public Temporal plus(TemporalAdder adjuster) {
055        return adjuster.addTo(this);
056    }
057
058    @Override
059    public Temporal minus(TemporalSubtractor adjuster) {
060        return adjuster.subtractFrom(this);
061    }
062
063    @Override
064    public Temporal minus(long amountToSubtract, TemporalUnit unit) {
065        return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
066    }
067
068}