
org.opentcs.virtualvehicle.Parsers Maven / Gradle / Ivy
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.virtualvehicle;
import com.google.common.primitives.Ints;
import jakarta.annotation.Nullable;
/**
* This class provides methods for parsing.
*/
public class Parsers {
/**
* Prevents instantiation of this utility class.
*/
private Parsers() {
}
/**
* Parses a String to an int. If toParse
could not be parsed successfully then the
* default value retOnFail
is returned.
*
* @param toParse the String
to be parsed.
* @param retOnFail default value that is returned if the String
could not be parsed.
* @return if the String
could be parsed then the int value of the
* String
is returned, else retOnFail
*/
public static int tryParseString(
@Nullable
String toParse,
int retOnFail
) {
if (toParse == null) {
return retOnFail;
}
Integer parseTry = Ints.tryParse(toParse);
if (parseTry == null) {
return retOnFail;
}
return parseTry;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy