1 /*
2  *  Copyright 2001-2014 Stephen Colebourne
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */

16 package org.joda.time.format;
17
18
19 /**
20  * Adapter between old and new printer interface.
21  *
22  * @author Stephen Colebourne
23  * @since 2.4
24  */

25 class InternalParserDateTimeParser implements DateTimeParser, InternalParser {
26     
27     private final InternalParser underlying;
28
29     static DateTimeParser of(InternalParser underlying) {
30         if (underlying instanceof DateTimeParserInternalParser) {
31             return ((DateTimeParserInternalParser) underlying).getUnderlying();
32         }
33         if (underlying instanceof DateTimeParser) {
34             return (DateTimeParser) underlying;
35         }
36         if (underlying == null) {
37             return null;
38         }
39         return new InternalParserDateTimeParser(underlying);
40     }
41
42     private InternalParserDateTimeParser(InternalParser underlying) {
43         this.underlying = underlying;
44     }
45
46     //-------------------------------------------------------------------------
47     public int estimateParsedLength() {
48         return underlying.estimateParsedLength();
49     }
50
51     public int parseInto(DateTimeParserBucket bucket, CharSequence text, int position) {
52         return underlying.parseInto(bucket, text, position);
53     }
54
55     public int parseInto(DateTimeParserBucket bucket, String text, int position) {
56         return underlying.parseInto(bucket, text, position);
57     }
58
59     //-----------------------------------------------------------------------
60     @Override
61     public boolean equals(Object obj) {
62         if (obj == this) {
63             return true;
64         }
65         if (obj instanceof InternalParserDateTimeParser) {
66             InternalParserDateTimeParser other = (InternalParserDateTimeParser) obj;
67             return underlying.equals(other.underlying);
68         }
69         return false;
70     }
71
72 }
73