@Override public void handleEvent(final PersonArrivalEvent arrivalEvent) { this.doReset(); PersonDepartureEvent departureEvent = this.pendantDepartures.remove(arrivalEvent.getPersonId()); String mode = arrivalEvent.getLegMode(); Frequency frequency; ResizableDoubleArray rawDataElement; // Consistency check... if (departureEvent == null) { log.warn( "One arrival do not correspond to any departure for agent " + arrivalEvent.getPersonId()); return; } else if (!mode.equals(departureEvent.getLegMode())) { log.warn("Departure and arrival have uncompatible modes!"); return; } // consistency check... DONE if (this.frequencies.containsKey(mode)) { frequency = this.frequencies.get(mode); rawDataElement = this.rawData.get(mode); } else { frequency = new Frequency(); rawDataElement = new ResizableDoubleArray(); this.frequencies.put(mode, frequency); this.rawData.put(mode, rawDataElement); } double xyVal = 0.0; if (this.xy.equals("times")) { xyVal = this.computeTimes(arrivalEvent, departureEvent); } else { xyVal = this.computeDistances(arrivalEvent, departureEvent); } // remember data frequency.addValue(xyVal); rawDataElement.addElement(xyVal); }
/** * Copies source to dest, copying the underlying data, so dest is a new, independent copy of * source. Does not contract before the copy. * * <p>Obtains synchronization locks on both source and dest (in that order) before performing the * copy. * * <p>Neither source nor dest may be null; otherwise a NullPointerException is thrown * * @param source ResizableDoubleArray to copy * @param dest ResizableArray to replace with a copy of the source array * @since 2.0 */ public static void copy(ResizableDoubleArray source, ResizableDoubleArray dest) { synchronized (source) { synchronized (dest) { dest.initialCapacity = source.initialCapacity; dest.contractionCriteria = source.contractionCriteria; dest.expansionFactor = source.expansionFactor; dest.expansionMode = source.expansionMode; dest.internalArray = new double[source.internalArray.length]; System.arraycopy(source.internalArray, 0, dest.internalArray, 0, dest.internalArray.length); dest.numElements = source.numElements; dest.startIndex = source.startIndex; } } }