org.bbottema.javareflection.valueconverter.converters.StringConverters Maven / Gradle / Ivy
/*
* Copyright (C) 2011 Benny Bottema ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bbottema.javareflection.valueconverter.converters;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.experimental.UtilityClass;
import org.bbottema.javareflection.util.Function;
import org.bbottema.javareflection.util.Function.Functions;
import org.bbottema.javareflection.util.commonslang25.NumberUtils;
import org.bbottema.javareflection.valueconverter.IncompatibleTypeException;
import org.bbottema.javareflection.valueconverter.ValueFunction;
import org.bbottema.javareflection.valueconverter.ValueFunction.ValueFunctionImpl;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import java.io.File;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Conversions are as follows:
* FIXME add non-Number conversions
*
* - Integer (or primitive int):
Integer.parseInt(value)
* - Character:
value.getCharAt(0)
*
new BigDecimal(value)
(simply attempt the widest number type)Byte.parseByte(value)
Short.parseShort(value)
Long.parseLong(value)
Float.parseFloat(value)
Double.parseDouble(value)
BigInteger.valueOf(Long.parseLong(value))
new BigDecimal(value)
UUID.fromString(value)
String
to an Enum instance, by mapping to the enum's name using
* {@link Enum#valueOf(Class, String)}.
*/
public static