
org.opentripplanner.transit.model.framework.AbstractEntityBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
The newest version!
package org.opentripplanner.transit.model.framework;
import java.util.Objects;
public abstract class AbstractEntityBuilder<
E extends AbstractTransitEntity, B extends AbstractEntityBuilder
>
extends AbstractBuilder
implements TransitEntityBuilder {
@SuppressWarnings("rawtypes")
private static final EntityContext, ?> NOOP = new EntityContext() {};
private FeedScopedId id;
private final EntityContext context;
public AbstractEntityBuilder(FeedScopedId id, EntityContext context) {
super(null);
this.id = id;
this.context = Objects.requireNonNull(context);
}
public AbstractEntityBuilder(FeedScopedId id) {
this(id, noopContext());
}
public AbstractEntityBuilder(E original, EntityContext context) {
super(original);
this.id = original.getId();
this.context = context;
}
public AbstractEntityBuilder(E original) {
this(original, noopContext());
}
public final FeedScopedId getId() {
return id;
}
public final B withId(FeedScopedId id) {
this.id = id;
//noinspection unchecked
return (B) this;
}
@SuppressWarnings("unchecked")
@Override
public E save() {
return context.save((B) this);
}
@SuppressWarnings("unchecked")
private static <
E extends AbstractTransitEntity, B extends AbstractEntityBuilder
> EntityContext noopContext() {
return (EntityContext) NOOP;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy