Class GPX.Builder

java.lang.Object
io.jenetics.jpx.GPX.Builder
Enclosing class:
GPX

public static final class GPX.Builder extends Object
Builder class for creating immutable GPX objects.

Creating a GPX object with one track-segment and 3 track-points:

final GPX gpx = GPX.builder() .addTrack(track -> track .addSegment(segment -> segment .addPoint(p -> p.lat(48.2081743).lon(16.3738189).ele(160)) .addPoint(p -> p.lat(48.2081743).lon(16.3738189).ele(161)) .addPoint(p -> p.lat(48.2081743).lon(16.3738189).ele(162)))) .build();
  • Method Details

    • creator

      public GPX.Builder creator(String creator)
      Set the GPX creator.
      Parameters:
      creator - the GPX creator
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if the given argument is null
    • creator

      public String creator()
      Return the current creator value.
      Returns:
      the current creator value
      Since:
      1.1
    • version

      public GPX.Builder version(GPX.Version version)
      Set the GPX version.
      Parameters:
      version - the GPX version
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if the given argument is null
      Since:
      1.3
    • version

      public String version()
      Return the current version value.
      Returns:
      the current version value
      Since:
      1.1
    • metadata

      public GPX.Builder metadata(Metadata metadata)
      Set the GPX metadata.
      Parameters:
      metadata - the GPX metadata
      Returns:
      this Builder for method chaining
    • metadata

      public GPX.Builder metadata(Consumer<? super Metadata.Builder> metadata)
      Allows setting partial metadata without messing up with the Metadata.Builder class.
      final GPX gpx = GPX.builder() .metadata(md -> md.author("Franz Wilhelmstötter")) .addTrack(...) .build();
      Parameters:
      metadata - the metadata consumer
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if the given argument is null
    • metadata

      Return the current metadata value.
      Returns:
      the current metadata value
      Since:
      1.1
    • wayPoints

      public GPX.Builder wayPoints(List<WayPoint> wayPoints)
      Sets the way-points of the GPX object. The list of way-points may be null.
      Parameters:
      wayPoints - the GPX way-points
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if one of the way-points in the list is null
    • addWayPoint

      public GPX.Builder addWayPoint(WayPoint wayPoint)
      Add one way-point to the GPX object.
      Parameters:
      wayPoint - the way-point to add
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if the given wayPoint is null
    • addWayPoint

      public GPX.Builder addWayPoint(Consumer<? super WayPoint.Builder> wayPoint)
      Add a way-point to the GPX object using a WayPoint.Builder.
      final GPX gpx = GPX.builder() .addWayPoint(wp -> wp.lat(23.6).lon(13.5).ele(50)) .build();
      Parameters:
      wayPoint - the way-point to add, configured by the way-point builder
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if the given argument is null
    • wayPoints

      public List<WayPoint> wayPoints()
      Return the current way-points. The returned list is mutable.
      Returns:
      the current, mutable way-point list
      Since:
      1.1
    • routes

      public GPX.Builder routes(List<Route> routes)
      Sets the routes of the GPX object. The list of routes may be null.
      Parameters:
      routes - the GPX routes
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if one of the routes is null
    • addRoute

      public GPX.Builder addRoute(Route route)
      Add a route the GPX object.
      Parameters:
      route - the route to add
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if the given route is null
    • addRoute

      public GPX.Builder addRoute(Consumer<? super Route.Builder> route)
      Add a route the GPX object.
      final GPX gpx = GPX.builder() .addRoute(route -> route .addPoint(p -> p.lat(48.2081743).lon(16.3738189).ele(160)) .addPoint(p -> p.lat(48.2081743).lon(16.3738189).ele(161))) .build();
      Parameters:
      route - the route to add, configured by the route builder
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if the given argument is null
    • routes

      public List<Route> routes()
      Return the current routes. The returned list is mutable.
      Returns:
      the current, mutable route list
      Since:
      1.1
    • tracks

      public GPX.Builder tracks(List<Track> tracks)
      Sets the tracks of the GPX object. The list of tracks may be null.
      Parameters:
      tracks - the GPX tracks
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if one of the tracks is null
    • addTrack

      public GPX.Builder addTrack(Track track)
      Add a track the GPX object.
      Parameters:
      track - the track to add
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if the given track is null
    • addTrack

      public GPX.Builder addTrack(Consumer<? super Track.Builder> track)
      Add a track the GPX object.
      final GPX gpx = GPX.builder() .addTrack(track -> track .addSegment(segment -> segment .addPoint(p -> p.lat(48.2081743).lon(16.3738189).ele(160)) .addPoint(p -> p.lat(48.2081743).lon(16.3738189).ele(161)) .addPoint(p -> p.lat(48.2081743).lon(16.3738189).ele(162)))) .build();
      Parameters:
      track - the track to add, configured by the track builder
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if the given argument is null
    • tracks

      public List<Track> tracks()
      Return the current tracks. The returned list is mutable.
      Returns:
      the current, mutable track list
      Since:
      1.1
    • extensions

      public GPX.Builder extensions(Document extensions)
      Sets the extensions object, which may be null. The root element of the extensions document must be extensions.
      <extensions> ... </extensions>
      Parameters:
      extensions - the extensions document
      Returns:
      this Builder for method chaining
      Throws:
      IllegalArgumentException - if the root element is not the an extensions node
      Since:
      1.5
    • extensions

      Return the current extensions
      Returns:
      the extensions document
      Since:
      1.5
    • build

      public GPX build()
      Create an immutable GPX object from the current builder state.
      Returns:
      an immutable GPX object from the current builder state
    • wayPointFilter

      Return a new WayPoint filter.
      final GPX filtered = gpx.toBuilder() .wayPointFilter() .filter(wp -> wp.getTime().isPresent()) .build()) .build();
      Returns:
      a new WayPoint filter
      Since:
      1.1
    • routeFilter

      Return a new Route filter.
      final GPX filtered = gpx.toBuilder() .routeFilter() .filter(Route::nonEmpty) .build()) .build();
      Returns:
      a new Route filter
      Since:
      1.1
    • trackFilter

      Return a new Track filter.
      final GPX merged = gpx.toBuilder() .trackFilter() .map(track -> track.toBuilder() .listMap(Filters::mergeSegments) .filter(TrackSegment::nonEmpty) .build()) .build() .build();
      Returns:
      a new Track filter
      Since:
      1.1