BerthStepIdentifier extends TrackIdentifier { public boolean isDirectlyLinked(BerthStepIdentifier next) { if (toBerthId.equals(next.getFromBerthId())) { return true; } Id fromA = parseId(fromBerthId); Id fromB = parseId(toBerthId); Id toA = parseId(next.fromBerthId); Id toB = parseId(next.toBerthId); if (fromA.areaId.equals(toA.areaId)) { return false; } String fromASubId = fromA.berthId.substring(1); String fromBSubId = fromB.berthId.substring(1); String toASubId = toA.berthId.substring(1); String toBSubId = toB.berthId.substring(1); if (fromASubId.equals(toASubId) && fromBSubId.equals(toBSubId)) { return true; } return false; } BerthStepIdentifier(String fromBerthId, String toBerthId);  BerthStepIdentifier(String areaId, String fromBerthId, String toBerthId); String getFromBerthId(); String getToBerthId(); boolean isDirectlyLinked(BerthStepIdentifier next); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testIsLinked01() { BerthStepIdentifier a = new BerthStepIdentifier("TB_0677", "TB_N001"); BerthStepIdentifier b = new BerthStepIdentifier("LA_T677", "LA_0001"); assertTrue(a.isDirectlyLinked(b)); assertTrue(b.isDirectlyLinked(a)); }
@Test public void testIsLinked02() { BerthStepIdentifier a = new BerthStepIdentifier("TB_0677", "TB_0679"); BerthStepIdentifier b = new BerthStepIdentifier("TB_0679", "TB_0681"); assertTrue(a.isDirectlyLinked(b)); assertFalse(b.isDirectlyLinked(a)); }