Format.java
01 /*
02  * Java GPX Library (jpx-3.1.0).
03  * Copyright (c) 2016-2023 Franz Wilhelmstötter
04  *
05  * Licensed under the Apache License, Version 2.0 (the "License");
06  * you may not use this file except in compliance with the License.
07  * You may obtain a copy of the License at
08  *
09  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * Author:
18  *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
19  */
20 package io.jenetics.jpx.format;
21 
22 import java.text.ParsePosition;
23 import java.util.Optional;
24 
25 /**
26  * Base interface for formatting and parsing a location.
27  *
28  @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
29  @version 2.2
30  @since 1.4
31  */
32 interface Format {
33 
34     /**
35      * Formats the given {@code value} to its string representation. If it is not
36      * possible to convert the {@code value} to a string, {@link Optional#empty()}
37      * is returned.
38      *
39      @param value the value which is converted to a string.
40      @return the converted value, or {@link Optional#empty()} if the format
41      *         fails
42      */
43     Optional<String> format(final Location value);
44 
45     /**
46      * Parses the given input value, {@code in}.
47      *
48      @param in the input string to parse
49      @param pos the current parse position
50      @param builder the location builder
51      @throws ParseException it the parsing fails
52      @throws NullPointerException if one of the given parameters is {@code null}
53      */
54     void parse(
55         final CharSequence in,
56         final ParsePosition pos,
57         final LocationBuilder builder
58     );
59 
60     /**
61      * Return a string representation of the format pattern.
62      *
63      @return a string representation of the format pattern
64      */
65     String toPattern();
66 
67 }