Changeset 19695 in josm for trunk/src


Ignore:
Timestamp:
2026-11-20T12:53:15+01:00 (4 days ago)
Author:
stoecker
Message:

fix #25021 - Fix Sonar issues in VectorDataSet and added test cases - patch by DanProgs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/vector/VectorDataSet.java

    r19519 r19695  
    253253    @Override
    254254    public <T extends VectorPrimitive> Collection<T> getPrimitives(Predicate<? super VectorPrimitive> predicate) {
    255         Collection<VectorPrimitive> primitives = tryRead(this.readWriteLock, () -> {
     255        final Collection<VectorPrimitive> primitives = tryRead(this.readWriteLock, () -> {
    256256            final Storage<MVTTile> dataStore = this.getBestZoomDataStore().orElse(null);
    257257            final Stream<VectorDataStore> dataStoreStream = dataStore != null ? dataStore.stream().map(MVTTile::getData) : Stream.empty();
    … …  
    364364        return tryRead(this.readWriteLock, () -> {
    365365            final Storage<MVTTile> dataStore = this.getBestZoomDataStore().orElse(null);
    366             Stream<VectorDataStore> dataStoreStream = dataStore != null ? dataStore.stream().map(MVTTile::getData) : Stream.empty();
    367                 return Stream.concat(dataStoreStream, Stream.of(this.customDataStore)).map(VectorDataStore::getPrimitivesMap)
    368                   .flatMap(dataMap -> {
    369                     // Synchronize on dataMap to avoid concurrent modification errors
    370                     synchronized (dataMap) {
    371                         return this.currentSelectedPrimitives.stream().map(dataMap::get).filter(Objects::nonNull);
    372                     }
    373                 }).collect(Collectors.toList());
     366            final Stream<VectorDataStore> dataStoreStream = dataStore != null
     367                    ? dataStore.stream().map(MVTTile::getData)
     368                    : Stream.empty();
     369
     370            return Stream.concat(dataStoreStream, Stream.ofNullable(this.customDataStore))
     371                    .map(VectorDataStore::getPrimitivesMap)
     372                    .filter(Objects::nonNull)
     373                    .flatMap(dataMap -> {
     374                        final Map<PrimitiveId, VectorPrimitive> lockObject = dataMap;
     375                        synchronized (lockObject) {
     376                            final List<VectorPrimitive> selectedInMap = new ArrayList<>();
     377                            for (PrimitiveId id : this.currentSelectedPrimitives) {
     378                                final VectorPrimitive primitive = lockObject.get(id);
     379                                if (primitive != null) {
     380                                    selectedInMap.add(primitive);
     381                                }
     382                            }
     383                            return selectedInMap.stream();
     384                        }
     385                    })
     386                    .collect(Collectors.toList());
    374387        }).orElseGet(Collections::emptyList);
    375388    }
    … …  
    491504            SelectionChangeEvent<VectorPrimitive, VectorNode, VectorWay, VectorRelation, VectorDataSet>> command) {
    492505        synchronized (this.selectionLock) {
    493             SelectionChangeEvent<VectorPrimitive, VectorNode, VectorWay, VectorRelation, VectorDataSet> event =
     506            final SelectionChangeEvent<VectorPrimitive, VectorNode, VectorWay, VectorRelation, VectorDataSet> event =
    494507                    command.apply(currentSelectedPrimitives.stream().map(this::getPrimitiveById).collect(Collectors.toSet()));
    495508            if (event.isNop()) {
    … …  
    636649     */
    637650    public void setInvisibleLayers(Collection<String> invisibleLayers) {
    638         String[] currentInvisibleLayers = invisibleLayers.stream().filter(Objects::nonNull).toArray(String[]::new);
    639         List<String> temporaryList = Arrays.asList(currentInvisibleLayers);
     651        final String[] currentInvisibleLayers = invisibleLayers.stream().filter(Objects::nonNull).toArray(String[]::new);
     652        final List<String> temporaryList = Arrays.asList(currentInvisibleLayers);
    640653        this.dataStoreMap.values().stream().flatMap(Collection::stream).map(MVTTile::getData)
    641654          .forEach(dataStore -> dataStore.getAllPrimitives().parallelStream()
Note: See TracChangeset for help on using the changeset viewer.