private void writeSignalSystems(ByteBuffer out){ out.putInt(this.signalGroups.getSignalGroupDataBySignalSystemId().size()); for (Id<SignalSystem> systemId : this.signalGroups.getSignalGroupDataBySignalSystemId().keySet()){ ByteBufferUtils.putString(out, systemId.toString()); Map<Id<SignalGroup>, SignalGroupData> groups = this.signalGroups.getSignalGroupDataBySystemId(systemId); out.putInt(groups.size()); for (SignalGroupData group : groups.values()){ ByteBufferUtils.putString(out, group.getId().toString()); out.putInt(group.getSignalIds().size()); for (Id<Signal> signalId : group.getSignalIds()){ ByteBufferUtils.putString(out, signalId.toString()); SignalData signal = signalSystems.getSignalSystemData().get(systemId).getSignalData().get(signalId); ByteBufferUtils.putString(out, signal.getLinkId().toString()); if (signal.getLaneIds() == null || signal.getLaneIds().isEmpty()){ out.putInt(0); out.putInt(signal.getLaneIds().size()); for (Id<Lane> laneId : signal.getLaneIds()){ ByteBufferUtils.putString(out, laneId.toString()); out.putInt(signal.getTurningMoveRestrictions().size()); for (Id<Link> outLinkId : signal.getTurningMoveRestrictions()){ ByteBufferUtils.putString(out, outLinkId.toString());
private static void writeAgent(AgentSnapshotInfo agInfo, ByteBuffer out) { String id = agInfo.getId().toString(); ByteBufferUtils.putString(out, id); Point2D.Double point = OTFServerQuadTree.transform(new Coord(agInfo.getEasting(), agInfo.getNorthing())); out.putFloat((float) point.getX()); out.putFloat((float) point.getY()); out.putInt(agInfo.getAgentState().ordinal() ) ; out.putInt(agInfo.getUserDefined()); out.putFloat((float)agInfo.getColorValueBetweenZeroAndOne()); }
private void writeSignalGroupStates(ByteBuffer out){ out.putInt(this.signalTracker.getSignalGroupEvents().size()); for (SignalGroupStateChangedEvent e : this.signalTracker.getSignalGroupEvents()){ ByteBufferUtils.putString(out, e.getSignalSystemId().toString()); ByteBufferUtils.putString(out, e.getSignalGroupId().toString()); SignalGroupState state = e.getNewState(); if (state.equals(SignalGroupState.GREEN)){ out.putInt(1); } else if (state.equals(SignalGroupState.RED)){ out.putInt(0); } else if (state.equals(SignalGroupState.REDYELLOW)){ out.putInt(2); } else if (state.equals(SignalGroupState.YELLOW)){ out.putInt(3); } else if (state.equals(SignalGroupState.OFF)){ out.putInt(4); } } this.signalTracker.getSignalGroupEvents().clear(); }
private static void writeAgent(AgentSnapshotInfo pos, ByteBuffer out) { String id = pos.getId().toString(); ByteBufferUtils.putString(out, id); Point2D.Double point = OTFServerQuadTree.transform(new Coord(pos.getEasting(), pos.getNorthing())); out.putFloat((float) point.getX()); out.putFloat((float) point.getY()); out.putInt(pos.getUserDefined()); out.putFloat((float) pos.getColorValueBetweenZeroAndOne()); out.putInt(pos.getAgentState().ordinal()); }
@Override public void writeConstData(ByteBuffer out) throws IOException { out.putInt(this.schedule.getFacilities().size()); for (TransitStopFacility facility : this.schedule.getFacilities().values()) { ByteBufferUtils.putString(out, facility.getId().toString()); if (facility.getLinkId() != null) { // yyyy would most probably make sense to have something that generates coordinates for facilities Link link = this.network.getLinks().get( facility.getLinkId() ) ; if ( link==null ) { log.warn( " link not found; linkId: " + facility.getLinkId() ) ; ByteBufferUtils.putString(out,""); Point2D.Double point = OTFServerQuadTree.transform(facility.getCoord()); out.putDouble(point.getX()); out.putDouble(point.getY()); } else { ByteBufferUtils.putString(out, facility.getLinkId().toString()); AgentSnapshotInfo ps = agentSnapshotInfoFactory.createAgentSnapshotInfo(Id.create(facility.getId(), Person.class), link, 0.9*link.getLength(), 0) ; Point2D.Double point = OTFServerQuadTree.transform(new Coord(ps.getEasting(), ps.getNorthing())); out.putDouble(point.getX()) ; out.putDouble(point.getY()) ; } } else { ByteBufferUtils.putString(out,""); Point2D.Double point = OTFServerQuadTree.transform(facility.getCoord()); out.putDouble(point.getX()); out.putDouble(point.getY()); } } }
@Override public void writeConstData(ByteBuffer out) throws IOException { String id = this.src.getLink().getId().toString(); ByteBufferUtils.putString(out, id); //subtract minEasting/Northing somehow! Point2D.Double.Double linkStart = OTFServerQuadTree.transform(this.src.getLink().getFromNode().getCoord()); Point2D.Double.Double linkEnd = OTFServerQuadTree.transform(this.src.getLink().getToNode().getCoord()); out.putFloat((float) linkStart.x); out.putFloat((float) linkStart.y); out.putFloat((float) linkEnd.x); out.putFloat((float) linkEnd.y); if ( OTFVisConfigGroup.NUMBER_OF_LANES.equals(OTFClientControl.getInstance().getOTFVisConfig().getLinkWidthIsProportionalTo()) ) { out.putInt(NetworkUtils.getNumberOfLanesAsInt(0, this.src.getLink())); } else if ( OTFVisConfigGroup.CAPACITY.equals(OTFClientControl.getInstance().getOTFVisConfig().getLinkWidthIsProportionalTo()) ) { out.putInt( 1 + (int)(2.*this.src.getLink().getCapacity()/3600.) ) ; // yyyyyy 3600. is a magic number (the default of the capacity period attribute in Network) but I cannot get to the network (where "capacityPeriod" resides). // Please do better if you know better. kai, jun'11 } else { throw new RuntimeException("I do not understand. Aborting ..." ) ; } }
/** * Tests {@link ByteBufferUtils#putString(java.nio.ByteBuffer, String)} and * {@link ByteBufferUtils#getString(java.nio.ByteBuffer)}. */ public void testPutGetString() { final ByteBuffer buffer = ByteBuffer.allocate(100); buffer.putInt(5); ByteBufferUtils.putString(buffer, "foo bar"); buffer.putChar('?'); ByteBufferUtils.putString(buffer, "Hello World"); buffer.putChar('!'); buffer.flip(); assertEquals(5, buffer.getInt()); assertEquals("foo bar", ByteBufferUtils.getString(buffer)); assertEquals('?', buffer.getChar()); assertEquals("Hello World", ByteBufferUtils.getString(buffer)); assertEquals('!', buffer.getChar()); assertFalse(buffer.hasRemaining()); }