View Javadoc

1   /*
2    * Copyright 2004 the original author or authors.
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 com.ancientprogramming.fixedformat4j.format;
17  
18  /**
19   * Contains context for loading and exporting fixedformat data.
20   * The context describes what kind of formatter to use, what datatype to convert and what offset to fetch data from.
21   *
22   * @author Jacob von Eyben - http://www.ancientprogramming.com
23   * @since 1.0.0
24   */
25  public class FormatContext<T> {
26  
27    private int offset;
28    private Class<T> dataType;
29    private Class<? extends FixedFormatter> formatter;
30  
31    public FormatContext(int offset, Class<T> dataType, Class<? extends FixedFormatter> formatter) {
32      this.offset = offset;
33      this.dataType = dataType;
34      this.formatter = formatter;
35    }
36  
37    public int getOffset() {
38      return offset;
39    }
40  
41    public Class<T> getDataType() {
42      return dataType;
43    }
44  
45    public Class<? extends FixedFormatter> getFormatter() {
46      return formatter;
47    }
48  
49  
50    public String toString() {
51      return "FormatContext{" +
52          "offset=" + offset +
53          ", dataType=" + dataType.getName() +
54          ", formatter=" + formatter.getName() +
55          '}';
56    }
57  }