forked from apache/commons-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConverter.java.html
More file actions
90 lines (77 loc) · 4.7 KB
/
Copy pathConverter.java.html
File metadata and controls
90 lines (77 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>Converter.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Commons CLI</a> > <a href="index.source.html" class="el_package">org.apache.commons.cli</a> > <span class="el_source">Converter.java</span></div><h1>Converter.java</h1><pre class="source lang-java linenums">/*
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
https://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.MalformedURLException;
import java.net.URL;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
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.
* @param <E> The kind of thrown exception or error.
* @since 1.7.0
*/
@FunctionalInterface
public interface Converter<T, E extends Exception> {
// See also Apache Commons Lang FailableFunction
/**
* The default converter. Does nothing.
*/
<span class="fc" id="L42"> Converter<?, RuntimeException> DEFAULT = s -> s;</span>
/**
* Class name converter. Calls {@link Class#forName(String)}.
*/
<span class="fc" id="L47"> Converter<Class<?>, ClassNotFoundException> CLASS = Class::forName;</span>
/**
* File name converter. Calls {@link File#File(String)}.
*/
<span class="fc" id="L52"> Converter<File, NullPointerException> FILE = File::new;</span>
/**
* Path converter. Calls {@link Paths#get(java.net.URI)}.
*/
<span class="fc" id="L57"> Converter<Path, InvalidPathException> PATH = Paths::get;</span>
/**
* Number converter. Converts to a Double if a decimal point ('.') is in the string or a Long otherwise.
*/
<span class="fc bfc" id="L62" title="All 2 branches covered."> Converter<Number, NumberFormatException> NUMBER = s -> s.indexOf('.') != -1 ? (Number) Double.valueOf(s) : (Number) Long.valueOf(s);</span>
/**
* 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
*/
<span class="fc" id="L69"> Converter<Object, ReflectiveOperationException> OBJECT = s -> CLASS.apply(s).getConstructor().newInstance();</span>
/**
* Creates a URL. Calls {@link URL#URL(String)}.
*/
<span class="fc" id="L74"> Converter<URL, MalformedURLException> URL = URL::new;</span>
/**
* Converts to a date using the format string Form "EEE MMM dd HH:mm:ss zzz yyyy".
*/
<span class="fc" id="L79"> Converter<Date, java.text.ParseException> DATE = s -> new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(s);</span>
/**
* Applies the conversion function to the String argument.
*
* @param string the String to convert
* @return the Object from the conversion.
* @throws E on error.
*/
T apply(String string) throws E;
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>