001: /*
002: * Copyright 2001-2005 Stephen Colebourne
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.joda.time.convert;
017:
018: import org.joda.time.Chronology;
019: import org.joda.time.DateTimeUtils;
020: import org.joda.time.Period;
021: import org.joda.time.ReadWritableInterval;
022: import org.joda.time.ReadWritablePeriod;
023:
024: /**
025: * NullConverter converts null to an instant, partial, duration, period
026: * or interval. Null means now for instant/partial, zero for duration/period
027: * and from now to now for interval.
028: *
029: * @author Stephen Colebourne
030: * @author Brian S O'Neill
031: * @since 1.0
032: */
033: class NullConverter extends AbstractConverter implements
034: InstantConverter, PartialConverter, DurationConverter,
035: PeriodConverter, IntervalConverter {
036:
037: /**
038: * Singleton instance.
039: */
040: static final NullConverter INSTANCE = new NullConverter();
041:
042: /**
043: * Restricted constructor.
044: */
045: protected NullConverter() {
046: super ();
047: }
048:
049: //-----------------------------------------------------------------------
050: /**
051: * Gets the millisecond duration, which is zero.
052: *
053: * @param object the object to convert, which is null
054: * @return the millisecond duration
055: */
056: public long getDurationMillis(Object object) {
057: return 0L;
058: }
059:
060: //-----------------------------------------------------------------------
061: /**
062: * Sets the given ReadWritableDuration to zero milliseconds.
063: *
064: * @param duration duration to get modified
065: * @param object the object to convert, which is null
066: * @param chrono the chronology to use
067: * @throws NullPointerException if the duration is null
068: */
069: public void setInto(ReadWritablePeriod duration, Object object,
070: Chronology chrono) {
071: duration.setPeriod((Period) null);
072: }
073:
074: //-----------------------------------------------------------------------
075: /**
076: * Extracts interval endpoint values from an object of this converter's
077: * type, and sets them into the given ReadWritableInterval.
078: *
079: * @param writableInterval interval to get modified, not null
080: * @param object the object to convert, which is null
081: * @param chrono the chronology to use, may be null
082: * @throws NullPointerException if the interval is null
083: */
084: public void setInto(ReadWritableInterval writableInterval,
085: Object object, Chronology chrono) {
086: writableInterval.setChronology(chrono);
087: long now = DateTimeUtils.currentTimeMillis();
088: writableInterval.setInterval(now, now);
089: }
090:
091: //-----------------------------------------------------------------------
092: /**
093: * Returns null.
094: *
095: * @return null
096: */
097: public Class getSupportedType() {
098: return null;
099: }
100:
101: }
|