version: 1.0.1
you can create a variable using this class and setting the type to either Integer or Double.
to get the value of the variable use the get method out.getValue()
the class also has a built in toString()
method.
this class has two public methods:
tryParseInt( incomingData, _RefObj out )
.tryParseDouble( incomingData, _RefObj out )
.
as expected from simulating the C# method .tryParse()
the methods would try to parse the incoming data to the desired data type and set the value to the _Ref object provided in the method parameters.
in case of failure the value of _Ref object will be set to null.
<dependency>
<groupId>io.github.mohamadojail</groupId>
<artifactId>Java-tryParse-maven-plugin</artifactId>
<version>1.0.0</version>
</dependency>
String incomingData = "101";
_Ref<Integer> out = new _Ref<>();
boolean check = _Parser.tryParseInt(incomingData, out);
loop check example:
Scanner scanner = new Scanner(System.in);
System.out.println("Enter an Integer");
_Ref<Integer> out = new _Ref<>();
boolean check = _Parser.tryParseInt(scanner.nextLine(), out);
while (!check){
System.out.println("invalid input try again");
check = _Parser.tryParseInt(scanner.nextLine(), out);
}
System.out.println("Success! you entered a valid Integer: " + out.getValue());