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 java.text.ParsePosition;
19 import java.util.Optional;
20
21 import io.jenetics.jpx.Longitude;
22
23 /**
24 * This field allows to access the absolute value of the second part of the
25 * longitude of a given location.
26 *
27 * @version 2.2
28 * @since 2.2
29 */
30 final class LongitudeSecond extends Field {
31
32 LongitudeSecond(final String pattern) {
33 super(pattern, 's');
34 }
35
36 @Override
37 public void parse(
38 final CharSequence in,
39 final ParsePosition pos,
40 final LocationBuilder builder
41 ) {
42 double d = parse(in, pos);
43 builder.addLongitudeSecond(d);
44 }
45
46 @Override
47 public Optional<String> format(final Location loc) {
48 return loc.longitude()
49 .map(Longitude::toDegrees)
50 .map(Field::toSeconds)
51 .map(this::format);
52 }
53
54 }
|