com.github.TKnudsen.ComplexDataObject.model.io.parsers.objects.BooleanParser 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: BooleanParser
*
*
*
* Description:
*
*
*
* Copyright: Copyright (c) 2016
*
*
* @author Juergen Bernard
* @version 1.0
*/
public class BooleanParser implements IObjectParser {
@Override
public Boolean apply(Object object) {
final String stringRepresentation = String.valueOf(object).toLowerCase();
switch (stringRepresentation) {
case "false":
case "FALSE":
case "nein":
case "Nein":
case "0":
case "0.0":
case "n":
case "no":
case "No":
return Boolean.FALSE;
case "true":
case "TRUE":
case "j":
case "ja":
case "Ja":
case "1":
case "1.0":
case "y":
case "yes":
case "Yes":
return Boolean.TRUE;
default:
System.out.println("Object" + object + " could not be parsed to Boolean");
return null;
}
}
}