Class Track.Builder

java.lang.Object
io.jenetics.jpx.Track.Builder
All Implemented Interfaces:
Filter<TrackSegment,Track>
Enclosing class:
Track

public static final class Track.Builder extends Object implements Filter<TrackSegment,Track>
Builder class for creating immutable Track objects.

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

final Track track = Track.builder() .name("Track 1") .description("Mountain bike tour.") .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)))) .addSegment(segment -> segment .addPoint(p -> p.lat(46.2081743).lon(16.3738189).ele(160)) .addPoint(p -> p.lat(47.2081743).lon(16.3738189).ele(161)) .addPoint(p -> p.lat(49.2081743).lon(16.3738189).ele(162)))) .build();
  • Method Details

    • name

      public Track.Builder name(String name)
      Set the name of the track.
      Parameters:
      name - the track name
      Returns:
      this Builder for method chaining
    • name

      public Optional<String> name()
      Return the current name value.
      Returns:
      the current name value
      Since:
      1.1
    • cmt

      public Track.Builder cmt(String comment)
      Set the comment of the track.
      Parameters:
      comment - the track comment
      Returns:
      this Builder for method chaining
    • cmt

      public Optional<String> cmt()
    • desc

      public Track.Builder desc(String description)
      Set the description of the track.
      Parameters:
      description - the track description
      Returns:
      this Builder for method chaining
    • desc

      public Optional<String> desc()
      Return the current description value.
      Returns:
      the current description value
      Since:
      1.1
    • src

      public Track.Builder src(String source)
      Set the source of the track.
      Parameters:
      source - the track source
      Returns:
      this Builder for method chaining
    • src

      public Optional<String> src()
      Return the current source value.
      Returns:
      the current source value
      Since:
      1.1
    • links

      public Track.Builder links(List<Link> links)
      Set the track links. The link list may be null.
      Parameters:
      links - the track links
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if one of the links in the list is null
    • addLink

      public Track.Builder addLink(Link link)
      Add the given link to the track
      Parameters:
      link - the link to add to the track
      Returns:
      this Builder for method chaining
    • addLink

      public Track.Builder addLink(String href)
      Add the given link to the track
      Parameters:
      href - the link to add to the track
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if the given href is null
      IllegalArgumentException - if the given href is not a valid URL
    • links

      public List<Link> links()
      Return the current links. The returned link list is mutable.
      Returns:
      the current links
      Since:
      1.1
    • number

      public Track.Builder number(UInt number)
      Set the track number.
      Parameters:
      number - the track number
      Returns:
      this Builder for method chaining
    • number

      public Track.Builder number(int number)
      Set the track number.
      Parameters:
      number - the track number
      Returns:
      this Builder for method chaining
      Throws:
      IllegalArgumentException - if the given value is smaller than zero
    • number

      public Optional<UInt> number()
      Return the current number value.
      Returns:
      the current number value
      Since:
      1.1
    • type

      public Track.Builder type(String type)
      Set the track type.
      Parameters:
      type - the track type
      Returns:
      this Builder for method chaining
    • type

      public Optional<String> type()
      Return the current type value.
      Returns:
      the current type value
      Since:
      1.1
    • extensions

      public Track.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 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
    • segments

      Set the track segments of the track. The list may be null.
      Parameters:
      segments - the track segments
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if one of the segments in the list is null
    • addSegment

      Add a track segment to the track.
      Parameters:
      segment - the track segment added to the track
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if the given argument is null
    • addSegment

      Add a track segment to the track, via the given builder.
      final Track track = Track.builder() .name("Track 1") .description("Mountain bike tour.") .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)))) .addSegment(segment -> segment .addPoint(p -> p.lat(46.2081743).lon(16.3738189).ele(160)) .addPoint(p -> p.lat(47.2081743).lon(16.3738189).ele(161)) .addPoint(p -> p.lat(49.2081743).lon(16.3738189).ele(162)))) .build();
      Parameters:
      segment - the track segment
      Returns:
      this Builder for method chaining
      Throws:
      NullPointerException - if the given argument is null
    • segments

      Return the current track segments. The returned segment list is mutable.
      Returns:
      the current track segments
      Since:
      1.1
    • filter

      public Track.Builder filter(Predicate<? super TrackSegment> predicate)
      Description copied from interface: Filter
      Return a filter consisting of the elements of this filter that matches the given predicate.
      Specified by:
      filter in interface Filter<TrackSegment,Track>
      Parameters:
      predicate - a non-interfering, stateless predicate to apply to each element to determine if it should be included
      Returns:
      a new filter
    • map

      public Track.Builder map(Function<? super TrackSegment,? extends TrackSegment> mapper)
      Description copied from interface: Filter
      Return a filter with the results of applying the given mapper function.
      Specified by:
      map in interface Filter<TrackSegment,Track>
      Parameters:
      mapper - a non-interfering, stateless function to apply to each element
      Returns:
      a new filter
    • flatMap

      public Track.Builder flatMap(Function<? super TrackSegment,? extends List<TrackSegment>> mapper)
      Description copied from interface: Filter
      Return a filter consisting of the results of replacing each element with the contents of the mapped elements.
      Specified by:
      flatMap in interface Filter<TrackSegment,Track>
      Parameters:
      mapper - a non-interfering, stateless function to apply to each element which produces a list of new values
      Returns:
      a new filter
    • listMap

      public Track.Builder listMap(Function<? super List<TrackSegment>,? extends List<TrackSegment>> mapper)
      Description copied from interface: Filter
      Return a filter with the results of the applying given mapper function.
      Specified by:
      listMap in interface Filter<TrackSegment,Track>
      Parameters:
      mapper - a non-interfering, stateless function to apply to the existing elements
      Returns:
      a new filter
    • build

      public Track build()
      Create a new GPX track from the current builder state.
      Specified by:
      build in interface Filter<TrackSegment,Track>
      Returns:
      a new GPX track from the current builder state