org.opentripplanner.model.TransitEntity 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
package org.opentripplanner.model;
import java.io.Serializable;
/**
* All OTP Transit entities should extend this class.
*
* @param The ID type - Some Entities uses String and others uses {@link FeedScopedId} so this
* need to be generic.
*/
public abstract class TransitEntity implements Serializable {
private static final long serialVersionUID = 1L;
public abstract T getId();
/**
* Override this method to allow the id to be set. The default implementation throw a
* {@link UnsupportedOperationException}.
*/
public void setId(T id) {
throw new UnsupportedOperationException(
"It is not allowed to change the id for this type: " + getClass().getSimpleName()
);
}
/**
* Uses the {@code id} for identity. We could use the {@link Object#equals(Object)} method,
* but this causes the equals to fail in cases were the same entity is created twice - for
* example after reloading a serialized instance.
*/
@Override
public boolean equals(Object obj) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
TransitEntity> other = (TransitEntity>) obj;
return getId().equals(other.getId());
}
@Override
public int hashCode() {
return getId().hashCode();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy