All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.transit.model.framework.AbstractBuilder Maven / Gradle / Ivy

The newest version!
package org.opentripplanner.transit.model.framework;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public abstract class AbstractBuilder<
  E extends TransitObject, B extends AbstractBuilder
>
  implements TransitBuilder {

  private final E original;

  public AbstractBuilder(@Nullable E original) {
    this.original = original;
  }

  E original() {
    return original;
  }

  /**
   * Create a new instance, following the pattern (from the Agency class):
   * 
   * protected Agency buildFromValues() {
   *   return new Agency(this);
   * }
   * 
*/ protected abstract E buildFromValues(); @Override public final @Nonnull E build() { var b = buildFromValues(); if (original == null) { return b; } // Make sure we only make a new object if it is changed. // Another approach is also to use the Deduplicator, but that is a hassle without DI in place. return original.sameAs(b) ? original : b; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy