All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.TKnudsen.ComplexDataObject.model.io.parsers.objects.LongParser Maven / Gradle / Ivy

Go to download

A library that models real-world objects in Java, referred to as ComplexDataObjects. Other features: IO and preprocessing of ComplexDataObjects.

The newest version!
package com.github.TKnudsen.ComplexDataObject.model.io.parsers.objects;

/**
 * 

* Copyright: Copyright (c) 2018-2020 *

* * @author Juergen Bernard * @version 1.03 */ public class LongParser implements IObjectParser { @Override public Long apply(Object object) { if (object == null) return null; if (object instanceof Long) return new Long((long) object); if (object instanceof Number) { Number n = (Number) object; if (Double.isNaN(n.doubleValue())) return null; else return new Long(((Number) object).longValue()); } if (object instanceof Boolean) return ((boolean) object) ? 1L : 0L; if (object.toString().contains("E")) { try { return Double.valueOf(object.toString()).longValue(); } catch (Exception e) { } } String stringValue = String.valueOf(object).toLowerCase(); stringValue = stringValue.trim(); stringValue = stringValue.replace(",", "."); if (stringValue.contains(" ")) stringValue = stringValue.substring(0, stringValue.indexOf(" ")); try { return Long.parseLong(stringValue); } catch (Exception e) { return null; } } @Override public Class getOutputClassType() { return Long.class; } @Override public String toString() { return this.getClass().getSimpleName(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy