1 /* 2 * Copyright 2012 Olivier Godineau 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * the License at http://www.apache.org/licenses/LICENSE-2.0 7 * 8 * Unless required by applicable law or agreed to in writing, software 9 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 10 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 11 * License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 package olg.csv.bean.parser.impl; 15 16 import olg.csv.bean.parser.AbstractParser; 17 import olg.csv.bean.parser.ParseException; 18 19 /** 20 * Parser dedicated in parsing String into character. 21 * 22 * @author Olivier Godineau 23 * 24 */ 25 public class CharacterParser extends AbstractParser<Character> { 26 27 @Override 28 public Character parse(String str) { 29 Character retour = null; 30 if (str != null) { 31 if (str.trim().length() != 1) { 32 throw new ParseException("Parsing char only with argument String as char[" + str + "]"); 33 } 34 retour = str.trim().charAt(0); 35 } 36 return retour; 37 38 } 39 40 /** 41 * Constructor. 42 */ 43 public CharacterParser() { 44 super(); 45 46 } 47 48 }