1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.ancientprogramming.fixedformat4j.format.impl;
17
18 import com.ancientprogramming.fixedformat4j.format.AbstractFixedFormatter;
19 import com.ancientprogramming.fixedformat4j.format.FormatInstructions;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.commons.lang.StringUtils;
23
24
25
26
27
28
29
30 public class CharacterFormatter extends AbstractFixedFormatter<Character> {
31
32 private static final Log LOG = LogFactory.getLog(CharacterFormatter.class);
33
34 public Character asObject(String string, FormatInstructions instructions) {
35 Character result = null;
36 if (!StringUtils.isEmpty(string)) {
37 result = string.charAt(0);
38 if (string.length() > 1) {
39 LOG.warn("found more than one character[" + string + "] after reading instructions from record. Will return first character[" + result + "]");
40 }
41 }
42 return result;
43 }
44
45 public String asString(Character obj, FormatInstructions instructions) {
46 String result = "";
47 if (obj != null) {
48 result = Character.toString(obj);
49 }
50 return result;
51 }
52 }