package nl.ovapi.rid.model;

import java.util.ArrayList;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;

@ToString()
@EqualsAndHashCode()
public class JourneyPattern {

	@Getter
	@Setter
	/**
	 * DirectionType of JourneyPattern within Line. 1 or 2.
	 */
	public Integer directiontype;
	
	@ToString()
	public static class JourneyPatternPoint {
		@Getter
		@Setter
		@NonNull
		/**
		 * Sequential order in JourneyPattern and TimeDemandGroup
		 */
		private Integer pointorder;
		@Getter
		@Setter
		@NonNull
		/**
		 * Reference to this point in RID database.
		 */
		private Long pointref;
		@Getter
		@Setter
		@NonNull
		/**
		 * DataOwnerCode:UserStopCode of StopPoint.
		 */
		private String operatorpointref;
		@Getter
		@Setter
		@NonNull
		/**
		 * Whether this point is a WaitPoint/TimingPoint, if true a vehicle is not expected to depart early from this stop
		 */
		public boolean waitpoint;
		@Getter
		@Setter
		@NonNull
		/**
		 * Distance in meters from start of route. NOTE: does not have to start at 0.
		 */
		private Integer distancefromstartroute;
		@Getter
		@Setter
		@NonNull
		/**
		 * If stoppoint is not Scheduled, its a dummy not meant for passengers such as bridges and KAR points.
		 * Dummies are included in the case a KV6 messages arrives on a dummy.
		 */
		private boolean scheduled;

	}
	
	/**
	 * @param userstopcode DataOwnerCode':'UserStopCode
	 * @return false (JourneyPattern does not contain point), true (JourneyPattern contains point)
	 */
	public boolean contains(@NonNull String userstopcode) {
		for (JourneyPatternPoint pt : points) {
			if (userstopcode.equals(pt.getOperatorpointref())) {
				return true;
			}
		}
		return false;
	}
	
	/**
	 * 
	 * @param pointOrder Sequential order to be retrievd
	 * @return NULL: PointOrder not present in JourneyPattern
	 *         StopPoint with given PointOrder
	 */
	
	public JourneyPatternPoint getPoint(int pointOrder){
		for (JourneyPatternPoint pt : points){
			if (pt.pointorder.equals(pointOrder)){
				return pt;
			}
		}
		return null;
	}
	
	/**
	 * List with StopPoints in JourneyPattern
	 */
	@Getter private ArrayList<JourneyPatternPoint> points;
	
	/**
	 * Add point to JourneyPattern
	 * @param point
	 */
	public void add(JourneyPatternPoint point){
		points.add(point);
	}

	public JourneyPattern() {
		points = new ArrayList<JourneyPatternPoint>();
	}

}

package nl.ovapi.rid.model;

import java.util.ArrayList;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;

@ToString()
@EqualsAndHashCode()
public class JourneyPattern {

	@Getter
	@Setter
	/**
	 * DirectionType of JourneyPattern within Line. 1 or 2.
	 */
	public Integer directiontype;
	
	@ToString()
	public static class JourneyPatternPoint {
		@Getter
		@Setter
		@NonNull
		/**
		 * Sequential order in JourneyPattern and TimeDemandGroup
		 */
		private Integer pointorder;
		@Getter
		@Setter
		@NonNull
		/**
		 * Reference to this point in RID database.
		 */
		private Long pointref;
		@Getter
		@Setter
		@NonNull
		/**
		 * DataOwnerCode:UserStopCode of StopPoint.
		 */
		private String operatorpointref;
		@Getter
		@Setter
		@NonNull
		/**
		 * Whether this point is a WaitPoint/TimingPoint, if true a vehicle is not expected to depart early from this stop
		 */
		public boolean waitpoint;
		@Getter
		@Setter
		@NonNull
		/**
		 * Distance in meters from start of route. NOTE: does not have to start at 0.
		 */
		private Integer distancefromstartroute;
		@Getter
		@Setter
		@NonNull
		/**
		 * If stoppoint is not Scheduled, its a dummy not meant for passengers such as bridges and KAR points.
		 * Dummies are included in the case a KV6 messages arrives on a dummy.
		 */
		private boolean scheduled;

		@Getter
		@Setter
		@NonNull
		/**
		 * This point is skipped.
		 */
		private boolean skipped = false;

	}
	
	/**
	 * @param userstopcode DataOwnerCode':'UserStopCode
	 * @return false (JourneyPattern does not contain point), true (JourneyPattern contains point)
	 */
	public boolean contains(@NonNull String userstopcode) {
		for (JourneyPatternPoint pt : points) {
			if (userstopcode.equals(pt.getOperatorpointref())) {
				return true;
			}
		}
		return false;
	}
	
	/**
	 * 
	 * @param pointOrder Sequential order to be retrievd
	 * @return NULL: PointOrder not present in JourneyPattern
	 *         StopPoint with given PointOrder
	 */
	
	public JourneyPatternPoint getPoint(int pointOrder){
		for (JourneyPatternPoint pt : points){
			if (pt.pointorder.equals(pointOrder)){
				return pt;
			}
		}
		return null;
	}
	
	/**
	 * List with StopPoints in JourneyPattern
	 */
	@Getter private ArrayList<JourneyPatternPoint> points;
	
	/**
	 * Add point to JourneyPattern
	 * @param point
	 */
	public void add(JourneyPatternPoint point){
		points.add(point);
	}

	public JourneyPattern() {
		points = new ArrayList<JourneyPatternPoint>();
	}

}

Allow to define skipped journeypattern points