private void disturb(long pos, BlockState blockState, @Nullable ParticipantState disturber) { FallingBlocksRule rule = this.ruleWithShortestDelay(blockState); if(rule != null) { long tick = this.getMatch().getClock().now().tick + rule.delay; TLongObjectMap<ParticipantState> blockDisturbers = this.blockDisturbersByTick.get(tick); if(blockDisturbers == null) { blockDisturbers = new TLongObjectHashMap<>(); this.blockDisturbersByTick.put(tick, blockDisturbers); } Block block = blockState.getBlock(); if(!blockDisturbers.containsKey(pos)) { blockDisturbers.put(pos, disturber); } } }
@Override public void calculateAllReduceFactors(final TLongObjectMap<TLongArrayList> nodeSegmentTable, final TLongObjectMap<ISegment> segmentsTable, final TLongSet relevantLinks, TLongObjectMap<IPixelCut> pixelCuts) { TLongObjectMap<IRenderingSegment> renderingResults = new TLongObjectHashMap<>(); nodeSegmentTable.forEachEntry((nodeId, segmentIds) -> { if (segmentIds.size() > 1) { ISegment[] segments = new ISegment[segmentIds.size()]; for (int i = 0; i < segmentIds.size(); i++) { segments[i] = segmentsTable.get(segmentIds.get(i)); } investigateNode(nodeId, renderingResults, segments); } return true; }); adaptPixelCuts(pixelCuts, renderingResults); }
private void calculateRendering(IAzimuth currentAzimuth, List<IAzimuth> azimuthsToInvestigate, TLongObjectMap<IRenderingSegment> renderingResult) { IRenderingSegment rendering = renderingResult.get(currentAzimuth.getSegmentFrom().getId()); if (rendering == null) { rendering = new RenderingSegmentImpl(); } rendering.setId(currentAzimuth.getSegmentFrom().getId()); boolean connectedOnStartNode = currentAzimuth.getSegmentFrom().getFromNodeId() == currentAzimuth.getNodeId(); //Only consider azimuths from same origin for (IAzimuth azimuthToInvestigate : azimuthsToInvestigate) { if (currentAzimuth.getSegmentFrom().getId() == azimuthToInvestigate.getSegmentFrom().getId() && currentAzimuth.getSegmentFrom().getFuncRoadClassValue() >= azimuthToInvestigate.getSegmentTo().getFuncRoadClassValue() && azimuthToInvestigate.getSegmentTo().getFuncRoadClassValue() != 0) { if (connectedOnStartNode) { rendering.addStartCut(azimuthToInvestigate.getReduceFactor() * -1); } else { rendering.addEndCut(azimuthToInvestigate.getReduceFactor()); } } } renderingResult.put(currentAzimuth.getSegmentFrom().getId(), rendering); }
@Override public AudioManager getAudioManager() { if (!api.isAudioEnabled()) throw new IllegalStateException("Audio is disabled. Cannot retrieve an AudioManager while audio is disabled."); final TLongObjectMap<AudioManager> managerMap = api.getAudioManagerMap(); AudioManager mng = managerMap.get(id); if (mng == null) { // No previous manager found -> create one synchronized (managerMap) { mng = managerMap.get(id); if (mng == null) { mng = new AudioManagerImpl(this); managerMap.put(id, mng); } } } return mng; }
@Override public boolean compareAndSet(T expect, T update) { TLongObjectMap<Object> values = CURRENT_VALUES.get(); boolean matched; if (values != null) { Object actual = values.get(key); matched = Objects.equal(expect, actual); if (matched) { if (update != null) { values.put(key, update); } else { values.remove(key); } } } else { matched = expect == null; if (matched) { if (update != null) { initialize(update); } } } return matched; }
/** * Make any unsupported blocks fall that are disturbed for the current tick */ private void fallCheck() { this.visitsWorstTick = Math.max(this.visitsWorstTick, this.visitsThisTick); this.visitsThisTick = 0; World world = this.getMatch().getWorld(); TLongObjectMap<ParticipantState> blockDisturbers = this.blockDisturbersByTick.remove(this.getMatch().getClock().now().tick); if(blockDisturbers == null) return; TLongSet supported = new TLongHashSet(); TLongSet unsupported = new TLongHashSet(); TLongObjectMap<ParticipantState> fallsByBreaker = new TLongObjectHashMap<>(); try { while(!blockDisturbers.isEmpty()) { long pos = blockDisturbers.keySet().iterator().next(); ParticipantState breaker = blockDisturbers.remove(pos); // Search down for the first block that can actually fall for(;;) { long below = neighborPos(pos, BlockFace.DOWN); if(!Materials.isColliding(blockAt(world, below).getType())) break; blockDisturbers.remove(pos); // Remove all the blocks we find along the way pos = below; } // Check if the block needs to fall, if it isn't already falling if(!fallsByBreaker.containsKey(pos) && !this.isSupported(pos, supported, unsupported)) { fallsByBreaker.put(pos, breaker); } } } catch(MaxSearchVisitsExceeded ex) { this.logError(ex); } for(TLongObjectIterator<ParticipantState> iter = fallsByBreaker.iterator(); iter.hasNext();) { iter.advance(); this.fall(iter.key(), iter.value()); } }
/** {@inheritDoc} */ public boolean equals( Object other ) { if ( ! ( other instanceof TLongObjectMap ) ) { return false; } TLongObjectMap that = ( TLongObjectMap ) other; if ( that.size() != this.size() ) { return false; } try { TLongObjectIterator iter = this.iterator(); while ( iter.hasNext() ) { iter.advance(); long key = iter.key(); Object value = iter.value(); if ( value == null ) { if ( !( that.get( key ) == null && that.containsKey( key ) ) ) { return false; } } else { if ( !value.equals( that.get( key ) ) ) { return false; } } } } catch ( ClassCastException ex ) { // unused. } return true; }
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // MAP //noinspection unchecked _map = ( TLongObjectMap<V> ) in.readObject(); }
private TLongObjectMap<IPixelCut> adaptPixelCuts(TLongObjectMap<IPixelCut> pixelCuts, TLongObjectMap<IRenderingSegment> renderingResults) { for (Long key : renderingResults.keys()) { IRenderingSegment seg = renderingResults.get(key); pixelCuts.put(key, new PixelCut(seg.getId(), null, seg.getStartCutRight(), seg.getStartCutLeft(), seg.getEndCutRight(), seg.getEndCutLeft())); } return pixelCuts; }
private void investigateNode(long nodeId, TLongObjectMap<IRenderingSegment> renderingResult, ISegment... connectedSegments) { List<IAzimuth> azimuthList = new ArrayList<>(); for (ISegment segmentFrom : connectedSegments) { for (ISegment segmentTo : connectedSegments) { if (segmentFrom != null && segmentTo != null && (segmentFrom.getId() != segmentTo.getId())) { azimuthList.add(calculateAzimuth(nodeId, segmentFrom,segmentTo)); } } } calculateRendering(azimuthList, renderingResult); }
public AsyncGipLinkParser(String line, IGipModelFactory gipModelFactory, TLongObjectMap<IGipNode> nodes, Set<Integer> functionalRoadClasses, Set<Access> accessTypes, TObjectIntMap<String> atrPos) { this.line = line; this.modelFactory = gipModelFactory; this.nodes = nodes; this.functionalRoadClasses = functionalRoadClasses; this.accessTypes = accessTypes; this.atrPos = atrPos; }
public GipLinkSectionParser(IGipParser parserReference, IGipSectionParser<TLongObjectMap<IGipNode>> nodeParser, IImportConfig config, ImportStatistics statistics) { super(parserReference); this.links = new TSynchronizedLongObjectMap<>(new TLongObjectHashMap<>()); this.nodeParser = nodeParser; this.functionalRoadClasses = config.getFrcList(); this.accessTypes = config.getAccessTypes(); this.executor = Executors.newFixedThreadPool(15); this.statistics = statistics; }
private TLongObjectMap<IPixelCut> calculatePixelCutOffset(IImportConfig config, TLongSet linkIdsEnqueued, TLongObjectMap<IGipLink> links){ log.info("phase pixel cut calculation ...."); TLongObjectMap<IPixelCut> renderingResultPerSegment = new TLongObjectHashMap<>(); final TLongObjectHashMap<TLongArrayList> nodeLinksConnectionTable = new TLongObjectHashMap<>(); log.info("Link Ids Queued size: " + linkIdsEnqueued.size()); GipLinkFilter filter = new GipLinkFilter(config.getMaxFrc(),config.getMinFrc(),config.getIncludedGipIds(), config.getExcludedGipIds(),config.isEnableSmallConnections()); TLongSet filteredLinks = filter.filter(links); linkIdsEnqueued.forEach(value -> { //enqued Gip Links that after they have been filtered. if (filteredLinks.contains(value)) { IGipLink link = links.get(value); if (link != null) { if (link.getFromNodeId() != 0) { if (!nodeLinksConnectionTable.containsKey(link.getFromNodeId())) { nodeLinksConnectionTable.put(link.getFromNodeId(), new TLongArrayList()); } nodeLinksConnectionTable.get(link.getFromNodeId()).add(link.getId()); } if (link.getToNodeId() != 0) { if (!nodeLinksConnectionTable.containsKey(link.getToNodeId())) { nodeLinksConnectionTable.put(link.getToNodeId(), new TLongArrayList()); } nodeLinksConnectionTable.get(link.getToNodeId()).add(link.getId()); } } } return true; }); log.info("Filtered Links Size " + filteredLinks.size()); renderingResultPerSegment = new TLongObjectHashMap<>(); IRenderingCalculator renderingCalculator = new RenderingCalculatorImpl(); renderingCalculator.calculateAllReduceFactors(nodeLinksConnectionTable, adaptSegments(links), filteredLinks, renderingResultPerSegment); log.info("Rendering result size " + renderingResultPerSegment.size()); return renderingResultPerSegment; }
private TLongObjectMap<ISegment> adaptSegments(TLongObjectMap<IGipLink> links) { TLongObjectMap<ISegment> segments = new TLongObjectHashMap<>(links.size()); for (Long id : links.keys()) { IGipLink link = links.get(id); segments.put(id, new SegmentImpl(link.getId(), link.getFromNodeId(), link.getToNodeId(), link.getCoordinatesX(), link.getCoordinatesY(), link.getFuncRoadClassValue())); } return segments; }
protected void doUpdateConnections(IWaySegment current, TLongObjectMap<List<IGipTurnEdge>> turnEdges) { Set<IWaySegmentConnection> startNodeCons = new HashSet<>(); Set<IWaySegmentConnection> endNodeCons = new HashSet<>(); if (turnEdges.containsKey(current.getWayId())) { for (IGipTurnEdge turnEdge : turnEdges.get(current.getWayId())) { if (turnEdge.getViaNodeId() == current.getStartNodeId()) { startNodeCons.add(new WaySegmentConnection(turnEdge.getViaNodeId(), turnEdge.getFromLinkId(), turnEdge.getToLinkId(), ParserHelper.adaptAccess(turnEdge.getVehicleType()))); } else if (turnEdge.getViaNodeId() == current.getEndNodeId()) { endNodeCons.add(new WaySegmentConnection(turnEdge.getViaNodeId(), turnEdge.getFromLinkId(), turnEdge.getToLinkId(), ParserHelper.adaptAccess(turnEdge.getVehicleType()))); } else { log.error("ViaNode of TurnEdge is wheter start node nor end node!"); } } } if (!startNodeCons.isEmpty()) { current.setStartNodeCons(new ArrayList<>(startNodeCons)); } if (!endNodeCons.isEmpty()) { current.setEndNodeCons(new ArrayList<>(endNodeCons)); } }
public GipLinkTurnEdgesParser(IGipParser parserReference, IImportConfig config, IGipSectionParser<TLongObjectMap<IGipNode>> nodeParser, IGipSectionParser<TLongObjectMap<IGipLink>> linkParser, IGipSectionParser<TLongSet> linkCoordinateParser) { super(parserReference); this.config = config; this.nodeParser = nodeParser; this.linkParser = linkParser; this.linkCoordinateParser = linkCoordinateParser; this.turnEdges = new TLongObjectHashMap<>(); }
public GipLinkCoordinatesParser(IGipParser parserReference, IGipSectionParser<TLongObjectMap<IGipLink>> linkParser) { super(parserReference); this.linkParser = linkParser; this.linksToEnqueue = new TSynchronizedLongSet(new TLongHashSet()); this.executor = Executors.newFixedThreadPool(30); }
private CompletableFuture buildLinkAsync(final long currentLinkId, final Set<GipComparableLinkCoordinate> linkCoords, final TLongObjectMap<IGipLink> links, final TLongSet linksToEnqueue) { int[] linkCoordsX = new int[linkCoords.size() + 2]; int[] linkCoordsY = new int[linkCoords.size() + 2]; int i = 1; for (GipComparableLinkCoordinate linkCoordinate : linkCoords) { linkCoordsX[i] = linkCoordinate.getX(); linkCoordsY[i] = linkCoordinate.getY(); i++; } return CompletableFuture.supplyAsync(new AsyncGipLinkBuilder( links.get(currentLinkId), linkCoordsX, linkCoordsY), executor).thenAcceptAsync(gipLink -> { try { if (gipLink != null) { links.put(currentLinkId, gipLink); if (gipLink.isValid()) { linksToEnqueue.add(currentLinkId); } } } catch (Exception e) { log.error("Async Error ", e); } }); }
public static JSONArray arrayOf(TLongObjectMap<? extends CachedEntity> map) { JSONArray array = new JSONArray(); map.forEachValue(v->{ array.put(v.toJSON(0)); return true; }); return array; }
public static JSONArray arrayOf(long id, TLongObjectMap<? extends CachedEntity> map) { JSONArray array = new JSONArray(); map.forEachValue(v->{ array.put(v.toJSON(id)); return true; }); return array; }
public boolean equals( Object other ) { if ( ! ( other instanceof TLongObjectMap ) ) { return false; } TLongObjectMap that = ( TLongObjectMap ) other; if ( that.size() != this.size() ) { return false; } try { TLongObjectIterator iter = this.iterator(); while ( iter.hasNext() ) { iter.advance(); long key = iter.key(); Object value = iter.value(); if ( value == null ) { if ( !( that.get( key ) == null && that.containsKey( key ) ) ) { return false; } } else { if ( !value.equals( that.get( key ) ) ) { return false; } } } } catch ( ClassCastException ex ) { // unused. } return true; }
private void troveMapGet(Context context, TLongObjectMap map) { //Populates a map, makes 50% successful and 50% unsuccessful get() calls //Populate the map for (int i = 0; i < context.testValues.length; i++) map.put(context.testKeys[i], context.testValues[i]); for (int i = 0; i < context.testValues.length/2; i++) { map.get(context.testKeys[context.random.nextInt(context.testKeys.length)]); //Successful call map.get(Integer.MIN_VALUE+context.random.nextInt(Integer.MAX_VALUE)-1); //Unsuccessful call } }
private void troveMapPutUpdate(Context context, TLongObjectMap map) { //Populates a map, then repopulates it //Populate the map the first time for (int i = 0; i < context.testValues.length; i++) map.put(context.testKeys[i], context.testValues[i]); //Update every map pair for (int i = 0; i < context.testValues.length; i++) { map.put(context.testKeys[i], context.testValues2[i]); } }
private void troveMapPutRemove(Context context, TLongObjectMap map) { //Populates a map, then manually clears the contents of it //Populate the map the first time for (int i = 0; i < context.testValues.length; i++) map.put(context.testKeys[i], context.testValues[i]); //Remove every map pair for (int i = 0; i < context.testValues.length; i++) { map.remove(context.testKeys[i]); } }
@Override public ExchangeRate getRate(Currency fromCurrency, Currency toCurrency) { if (fromCurrency.id == toCurrency.id) { return ExchangeRate.ONE; } TLongObjectMap<ExchangeRate> rateMap = getMapFor(fromCurrency.id); ExchangeRate rate = rateMap.get(toCurrency.id); if (rate == null) { rate = ExchangeRate.NA; rateMap.put(toCurrency.id, rate); } return rate; }
private TLongObjectMap<ExchangeRate> getMapFor(long fromCurrencyId) { TLongObjectMap<ExchangeRate> m = rates.get(fromCurrencyId); if (m == null) { m = new TLongObjectHashMap<ExchangeRate>(); rates.put(fromCurrencyId, m); } return m; }
private TLongObjectMap<SortedSet<ExchangeRate>> getMapFor(long fromCurrencyId) { TLongObjectMap<SortedSet<ExchangeRate>> m = rates.get(fromCurrencyId); if (m == null) { m = new TLongObjectHashMap<SortedSet<ExchangeRate>>(); rates.put(fromCurrencyId, m); } return m; }
private SortedSet<ExchangeRate> getSetFor(TLongObjectMap<SortedSet<ExchangeRate>> rates, long date) { SortedSet<ExchangeRate> s = rates.get(date); if (s == null) { s = new TreeSet<ExchangeRate>(); rates.put(date, s); } return s; }
public TLongObjectMap<GuildMusicPlayer> getPlayers() { TLongObjectMap<GuildMusicPlayer> map = new TLongObjectHashMap<>(); for(Shard s : shards) { map.putAll(s.players()); } return map; }
/** {@inheritDoc} */ @Override @SuppressWarnings("rawtypes") public boolean equals( Object other ) { if ( ! ( other instanceof TLongObjectMap ) ) { return false; } TLongObjectMap that = ( TLongObjectMap ) other; if ( that.size() != this.size() ) { return false; } try { TLongObjectIterator iter = this.iterator(); while ( iter.hasNext() ) { iter.advance(); long key = iter.key(); Object value = iter.value(); if ( value == null ) { if ( !( that.get( key ) == null && that.containsKey( key ) ) ) { return false; } } else { if ( !value.equals( that.get( key ) ) ) { return false; } } } } catch ( ClassCastException ex ) { // unused. } return true; }
@Override @SuppressWarnings("unchecked") public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // MAP //noinspection unchecked _map = ( TLongObjectMap<V> ) in.readObject(); }
private TLongObjectMap<ExchangeRate> getMapFor(long fromCurrencyId) { TLongObjectMap<ExchangeRate> m = rates.get(fromCurrencyId); if (m == null) { m = new TLongObjectHashMap<>(); rates.put(fromCurrencyId, m); } return m; }