Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 2001-2005 Stephen Colebourne
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
 package org.joda.time.base;
 
 
BaseInterval is an abstract implementation of ReadableInterval that stores data in two long millisecond fields.

This class should generally not be used directly by API users. The org.joda.time.ReadableInterval interface should be used when different kinds of interval objects are to be referenced.

BaseInterval subclasses may be mutable and not thread-safe.

Author(s):
Brian S O'Neill
Sean Geoghegan
Stephen Colebourne
Since:
1.0
 
 public abstract class BaseInterval
         extends AbstractInterval
         implements ReadableIntervalSerializable {

    
Serialization version
 
     private static final long serialVersionUID = 576586928732749278L;

    
The chronology of the interval
 
     private Chronology iChronology;
    
The start of the interval
 
     private long iStartMillis;
    
The end of the interval
 
     private long iEndMillis;

    
Constructs an interval from a start and end instant.

Parameters:
startInstant start of this interval, as milliseconds from 1970-01-01T00:00:00Z.
endInstant end of this interval, as milliseconds from 1970-01-01T00:00:00Z.
chrono the chronology to use, null is ISO default
Throws:
java.lang.IllegalArgumentException if the end is before the start
 
     protected BaseInterval(long startInstantlong endInstantChronology chrono) {
         super();
          = DateTimeUtils.getChronology(chrono);
         checkInterval(startInstantendInstant);
          = startInstant;
          = endInstant;
     }

    
Constructs an interval from a start and end instant.

Parameters:
start start of this interval, null means now
end end of this interval, null means now
Throws:
java.lang.IllegalArgumentException if the end is before the start
 
     protected BaseInterval(ReadableInstant startReadableInstant end) {
         super();
         if (start == null && end == null) {
              =  = DateTimeUtils.currentTimeMillis();
              = ISOChronology.getInstance();
         } else {
              = DateTimeUtils.getInstantChronology(start);
              = DateTimeUtils.getInstantMillis(start);
              = DateTimeUtils.getInstantMillis(end);
             checkInterval();
         }
     }

    
Constructs an interval from a start instant and a duration.

Parameters:
start start of this interval, null means now
duration the duration of this interval, null means zero length
Throws:
java.lang.IllegalArgumentException if the end is before the start
java.lang.ArithmeticException if the end instant exceeds the capacity of a long
    protected BaseInterval(ReadableInstant startReadableDuration duration) {
        super();
         = DateTimeUtils.getInstantChronology(start);
         = DateTimeUtils.getInstantMillis(start);
        long durationMillis = DateTimeUtils.getDurationMillis(duration);
         = FieldUtils.safeAdd(durationMillis);
    }

    
Constructs an interval from a millisecond duration and an end instant.

Parameters:
duration the duration of this interval, null means zero length
end end of this interval, null means now
Throws:
java.lang.IllegalArgumentException if the end is before the start
java.lang.ArithmeticException if the start instant exceeds the capacity of a long
    protected BaseInterval(ReadableDuration durationReadableInstant end) {
        super();
         = DateTimeUtils.getInstantChronology(end);
         = DateTimeUtils.getInstantMillis(end);
        long durationMillis = DateTimeUtils.getDurationMillis(duration);
         = FieldUtils.safeAdd(, -durationMillis);
    }

    
Constructs an interval from a start instant and a time period.

When forming the interval, the chronology from the instant is used if present, otherwise the chronology of the period is used.

Parameters:
start start of this interval, null means now
period the period of this interval, null means zero length
Throws:
java.lang.IllegalArgumentException if the end is before the start
java.lang.ArithmeticException if the end instant exceeds the capacity of a long
    protected BaseInterval(ReadableInstant startReadablePeriod period) {
        super();
        Chronology chrono = DateTimeUtils.getInstantChronology(start);
         = chrono;
         = DateTimeUtils.getInstantMillis(start);
        if (period == null) {
             = ;
        } else {
             = chrono.add(period, 1);
        }
    }

    
Constructs an interval from a time period and an end instant.

When forming the interval, the chronology from the instant is used if present, otherwise the chronology of the period is used.

Parameters:
period the period of this interval, null means zero length
end end of this interval, null means now
Throws:
java.lang.IllegalArgumentException if the end is before the start
java.lang.ArithmeticException if the start instant exceeds the capacity of a long
    protected BaseInterval(ReadablePeriod periodReadableInstant end) {
        super();
        Chronology chrono = DateTimeUtils.getInstantChronology(end);
         = chrono;
         = DateTimeUtils.getInstantMillis(end);
        if (period == null) {
             = ;
        } else {
             = chrono.add(period, -1);
        }
    }

    
Constructs a time interval converting or copying from another object that describes an interval.

Parameters:
interval the time interval to copy
chrono the chronology to use, null means let converter decide
Throws:
java.lang.IllegalArgumentException if the interval is invalid
    protected BaseInterval(Object intervalChronology chrono) {
        super();
        IntervalConverter converter = ConverterManager.getInstance().getIntervalConverter(interval);
        if (converter.isReadableInterval(intervalchrono)) {
            ReadableInterval input = (ReadableIntervalinterval;
             = (chrono != null ? chrono : input.getChronology());
             = input.getStartMillis();
             = input.getEndMillis();
        } else if (this instanceof ReadWritableInterval) {
            converter.setInto((ReadWritableIntervalthisintervalchrono);
        } else {
            MutableInterval mi = new MutableInterval();
            converter.setInto(miintervalchrono);
             = mi.getChronology();
             = mi.getStartMillis();
             = mi.getEndMillis();
        }
    }
    //-----------------------------------------------------------------------
    
Gets the chronology of this interval.

Returns:
the chronology
    public Chronology getChronology() {
        return ;
    }

    
Gets the start of this time interval which is inclusive.

Returns:
the start of the time interval, millisecond instant from 1970-01-01T00:00:00Z
    public long getStartMillis() {
        return ;
    }

    
Gets the end of this time interval which is exclusive.

Returns:
the end of the time interval, millisecond instant from 1970-01-01T00:00:00Z
    public long getEndMillis() {
        return ;
    }
    //-----------------------------------------------------------------------
    
Sets this interval from two millisecond instants and a chronology.

Parameters:
startInstant the start of the time interval
endInstant the start of the time interval
chrono the chronology, not null
Throws:
java.lang.IllegalArgumentException if the end is before the start
    protected void setInterval(long startInstantlong endInstantChronology chrono) {
        checkInterval(startInstantendInstant);
         = startInstant;
         = endInstant;
         = DateTimeUtils.getChronology(chrono);
    }
New to GrepCode? Check out our FAQ X