Skip to content

Published on Maven repository this plugin imitates the tryParse method in C# within Java, useful tools for parsing user inputs without the trouble of getting exceptions.

License

Notifications You must be signed in to change notification settings

alpha-mo/maven-plugin-tryParse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java tryParse

version: 1.0.1

_Ref Class:

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.

_Parser Class:

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.

Injecting dependency:

<dependency>
    <groupId>io.github.mohamadojail</groupId>
    <artifactId>Java-tryParse-maven-plugin</artifactId>
    <version>1.0.0</version>
  </dependency>

Suggested usage:

	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());

About

Published on Maven repository this plugin imitates the tryParse method in C# within Java, useful tools for parsing user inputs without the trouble of getting exceptions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages