-
Notifications
You must be signed in to change notification settings - Fork 249
[CLI-321] Add and use a Converter interface and implementations without using BeanUtils #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
a7426a4
Fixes for CLI-321
Claudenw 7ae9b1c
Fixed issues with date parsing
Claudenw ad8466c
Switched to ConvertUtilsBean2 for conversions.
Claudenw e02c36c
Implementation with tests
Claudenw 9ae4c99
fixed checkstyle issues
Claudenw b5d2212
fixed spotbugs error & some javadoc
Claudenw e36f282
Updated spotbugs to 4.8.2.0
Claudenw 1787859
added javadocs and tests
Claudenw 037550d
fixed breaking changes and javadoc
Claudenw e081e56
added since annotation to Converter and Verifier
Claudenw 942364a
Added an Enum Validator implementation
Claudenw f365872
fixed formatting issues
Claudenw 3ec932d
fixed checkstyle error
Claudenw 6d5a916
Converted Verifier to Predicate<String>
Claudenw 9b93936
Moved Converter, Verifier and their respective tests to base cli pack…
Claudenw 2ec9d4d
Merge branch 'apache:master' into Functional_Converters
Claudenw a8d7c89
Removed verifier management and rebased to master
Claudenw d588a86
moved param <T> tags
Claudenw 0eee294
updated numberic tests
Claudenw 658aa2b
Updated documentation, added Supplier<String> as a default provider f…
Claudenw b68633a
fixed checkstyle issues
Claudenw 1ca90bb
Added Path to TypeHandler and updated documentation
Claudenw 4d4f52c
removed verifier
Claudenw 30d26f5
removed verifier
Claudenw 2d6ff50
updated javadoc and site documentation
Claudenw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,78 @@ | ||
| /* | ||
| Licensed to the Apache Software Foundation (ASF) under one or more | ||
| contributor license agreements. See the NOTICE file distributed with | ||
| this work for additional information regarding copyright ownership. | ||
| The ASF licenses this file to You 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.apache.commons.cli; | ||
|
|
||
| import java.io.File; | ||
| import java.net.URL; | ||
| import java.nio.file.Path; | ||
| import java.text.SimpleDateFormat; | ||
| import java.util.Date; | ||
|
|
||
| /** | ||
| * The definition of the functional interface to call when doing a conversion. | ||
| * Like {@code Function<String,T>} but can throw an Exception. | ||
| * | ||
| * @param <T> The return type for the function. | ||
| * @since 1.7.0 | ||
| */ | ||
| @FunctionalInterface | ||
| public interface Converter<T> { | ||
|
|
||
| /** The default converter. Does nothing. */ | ||
| Converter<?> DEFAULT = s -> s; | ||
|
|
||
| /** Class name converter. Calls {@code Class.forName}. */ | ||
| Converter<Class<?>> CLASS = s -> Class.forName(s); | ||
|
|
||
| /** File name converter. Calls @{code new File(s)} */ | ||
| Converter<File> FILE = s -> new File(s); | ||
|
|
||
| /** Path converter. Calls @{code new Path(s)} */ | ||
| Converter<Path> PATH = s -> new File(s).toPath(); | ||
|
|
||
| /** | ||
| * Number converter. Converts to a Double if a decimal point ('.') is in the | ||
| * string or a Long otherwise. | ||
| */ | ||
| Converter<Number> NUMBER = s -> { | ||
| if (s.indexOf('.') != -1) { | ||
| return Double.valueOf(s); | ||
| } | ||
| return Long.valueOf(s); | ||
| }; | ||
|
|
||
| /** | ||
| * Converts a class name to an instance of the class. Uses the Class converter | ||
| * to find the class and then call the default constructor. | ||
| * @see #CLASS | ||
| */ | ||
| Converter<Object> OBJECT = s -> CLASS.apply(s).getConstructor().newInstance(); | ||
|
|
||
| /** Creates a URL. Calls {@code new URL(s)}. */ | ||
| Converter<URL> URL = s -> new URL(s); | ||
|
|
||
| /** Converts to a date using the format string Form "EEE MMM dd HH:mm:ss zzz yyyy". */ | ||
| Converter<Date> DATE = s -> new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(s); | ||
|
|
||
| /** | ||
| * Applies the conversion function to the String argument. | ||
| * @param str the String to convert | ||
| * @return the Object from the conversion. | ||
| * @throws Exception on error. | ||
| */ | ||
| T apply(String str) throws Exception; | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.