/** * @return the ObjectKey2 in the STATIONS table of the station owned by player p within the city * radius, or -1 if there is no station */ public ObjectKey2 hasStation(FreerailsPrincipal p) { int xmin = cityModel.getCityX() - cityModel.getCityRadius(); int xmax = cityModel.getCityX() + cityModel.getCityRadius(); int ymin = cityModel.getCityY() - cityModel.getCityRadius(); int ymax = cityModel.getCityY() + cityModel.getCityRadius(); xmin = xmin < 0 ? 0 : xmin; ymin = ymin < 0 ? 0 : ymin; xmax = xmax >= world.getMapWidth() ? world.getMapWidth() - 1 : xmax; ymax = ymax >= world.getMapHeight() ? world.getMapHeight() - 1 : ymax; Iterator i = world.getIterator(KEY.STATIONS, p); while (i.hasNext()) { StationModel sm = (StationModel) i.next(); int x = sm.getStationX(); int y = sm.getStationY(); if (x >= xmin && x <= xmax && y >= ymin && y <= ymax) { return new ObjectKey2(KEY.STATIONS, p, sm.getUUID()); } } return null; }
@Override public void run() { NamedCache cache = Utility.getCache(Constants.SHIPMENT_CACHE); LikeFilter likeCity = new LikeFilter("getToAddress.getCity", (String) model.getSelectedItem()); GreaterEqualsFilter greaterEqualParcel = new GreaterEqualsFilter("getParcels.size", (Integer) parcelCount.getValue()); AndFilter andFilter = new AndFilter(likeCity, greaterEqualParcel); Map<String, Object> result = (Map<String, Object>) cache.aggregate(andFilter, new CalculateWeightAggregrator()); resultArea.append( "Total entries processed: " + result.get(Constants.TOTAL_ENTRY) + Constants.NEWLINE); resultArea.append("Total weight: " + result.get(Constants.TOTAL_WEIGHT)); }