com.github.TKnudsen.ComplexDataObject.model.io.parsers.objects.IntegerParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of complex-data-object Show documentation
Show all versions of complex-data-object Show documentation
A library that models real-world objects in Java, referred to as ComplexDataObjects. Other features: IO and preprocessing of ComplexDataObjects.
package com.github.TKnudsen.ComplexDataObject.model.io.parsers.objects;
/**
*
* Title: IntegerParser
*
*
*
* Description:
*
*
*
* Copyright: Copyright (c) 2016
*
*
* @author Juergen Bernard
* @version 1.0
*/
public class IntegerParser implements IObjectParser {
@Override
public Integer apply(Object object) {
String stringValue = String.valueOf(object).toLowerCase();
stringValue = stringValue.trim();
stringValue = stringValue.replace(",", ".");
if (stringValue.contains(" "))
stringValue = stringValue.substring(0, stringValue.indexOf(" "));
try {
return Integer.parseInt(stringValue);
} catch (Exception e) {
return null;
}
}
}