View Javadoc
1   /*
2    * Copyright (c) 2001-2017, Zoltan Farkas All Rights Reserved.
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this program; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17   *
18   * Additionally licensed with:
19   *
20   * Licensed under the Apache License, Version 2.0 (the "License");
21   * you may not use this file except in compliance with the License.
22   * You may obtain a copy of the License at
23   *
24   *      http://www.apache.org/licenses/LICENSE-2.0
25   *
26   * Unless required by applicable law or agreed to in writing, software
27   * distributed under the License is distributed on an "AS IS" BASIS,
28   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29   * See the License for the specific language governing permissions and
30   * limitations under the License.
31   */
32  package org.spf4j.text;
33  
34  import java.io.Serializable;
35  import java.text.Format;
36  import java.util.Objects;
37  import javax.annotation.Nullable;
38  
39  /**
40   * @author zoly
41   */
42  final class FormatInfo implements Serializable, Cloneable {
43  
44    private static final long serialVersionUID = 1L;
45    private final Format format;
46  
47    private final int offset;
48  
49    private final int argumentNumber;
50  
51    FormatInfo(@Nullable final Format format, final int offset, final int argumentNumber) {
52      this.format = format;
53      this.offset = offset;
54      this.argumentNumber = argumentNumber;
55    }
56  
57    @Nullable
58    public Format getFormat() {
59      return format;
60    }
61  
62    public int getOffset() {
63      return offset;
64    }
65  
66    public int getArgumentNumber() {
67      return argumentNumber;
68    }
69  
70    @Override
71    public int hashCode() {
72      int hash = Objects.hashCode(this.format);
73      hash = 31 * hash + this.offset;
74      return 31 * hash + this.argumentNumber;
75    }
76  
77  
78  
79    @Override
80    public boolean equals(final Object obj) {
81      if (this == obj) {
82        return true;
83      }
84      if (obj == null) {
85        return false;
86      }
87      if (getClass() != obj.getClass()) {
88        return false;
89      }
90      final FormatInfo other = (FormatInfo) obj;
91      if (this.offset != other.offset) {
92        return false;
93      }
94      if (this.argumentNumber != other.argumentNumber) {
95        return false;
96      }
97      return Objects.equals(this.format, other.format);
98    }
99  
100   @Override
101   public String toString() {
102     return "FormatInfo{" + "format=" + format + ", offset=" + offset + ", argumentNumber=" + argumentNumber + '}';
103   }
104 
105   @Override
106   protected FormatInfo clone() {
107     return new FormatInfo((Format) format.clone(), offset, argumentNumber);
108   }
109 
110 
111 
112 }