01 /*
02 * Java GPX Library (jpx-3.1.0).
03 *
04 * Licensed under the Apache License, Version 2.0 (the "License");
05 * you may not use this file except in compliance with the License.
06 * You may obtain a copy of the License at
07 *
08 * http://www.apache.org/licenses/LICENSE-2.0
09 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package io.jenetics.jpx.format;
17
18 import static io.jenetics.jpx.Length.Unit.METER;
19
20 import java.text.ParsePosition;
21 import java.util.Optional;
22
23 /**
24 * This field allows to access the elevation (in meter) of a given location.
25 *
26 * @version 2.2
27 * @since 2.2
28 */
29 final class Elevation extends Field {
30
31 Elevation(final String pattern) {
32 super(pattern, 'E');
33 }
34
35 @Override
36 public void parse(
37 final CharSequence in,
38 final ParsePosition pos,
39 final LocationBuilder builder
40 ) {
41 builder.setElevation(parse(in, pos));
42 }
43
44 @Override
45 public Optional<String> format(final Location loc) {
46 return loc.elevation()
47 .map(l -> l.to(METER))
48 .map(this::format);
49 }
50
51 @Override
52 public String toPattern() {
53 return isPrefixSign() ? "+" + super.toPattern() : super.toPattern();
54 }
55
56 }
|