-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added methods to parse to Optional using exceptions. Upgraded to JUnit 5
- Loading branch information
Showing
13 changed files
with
893 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/github/robtimus/tryparse/ExceptionBasedParsing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* ExceptionBasedParsing.java | ||
* Copyright 2019 Rob Spoor | ||
* | ||
* 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 com.github.robtimus.tryparse; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Indicates that a method delegates to an existing method and catches its exceptions. | ||
* | ||
* @author Rob Spoor | ||
* @since 1.1 | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.SOURCE) | ||
@Documented | ||
public @interface ExceptionBasedParsing { | ||
// marker annotation | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/github/robtimus/tryparse/NativeParsing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* NativeParsing.java | ||
* Copyright 2019 Rob Spoor | ||
* | ||
* 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 com.github.robtimus.tryparse; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Indicates that a method uses native parsing instead of delegating to an existing method and catching its exceptions. | ||
* | ||
* @author Rob Spoor | ||
* @since 1.1 | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.SOURCE) | ||
@Documented | ||
public @interface NativeParsing { | ||
// marker annotation | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/github/robtimus/tryparse/ParseFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* ParseFunction.java | ||
* Copyright 2019 Rob Spoor | ||
* | ||
* 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 com.github.robtimus.tryparse; | ||
|
||
/** | ||
* A function that parses one object into another. | ||
* | ||
* @author Rob Spoor | ||
* @param <T> The type of object to parse. | ||
* @param <R> The type of the parse result. | ||
* @param <X> The type of exception that occurs if parsing fails. | ||
* @since 1.1 | ||
*/ | ||
public interface ParseFunction<T, R, X extends Exception> { | ||
|
||
/** | ||
* Parses an object. | ||
* | ||
* @param input The object to parse. | ||
* @return The parsed object. | ||
* @throws X If parsing fails. | ||
*/ | ||
R parse(T input) throws X; | ||
} |
Oops, something went wrong.