| 253 | | protected OsmDataLayer createNewLayer(String layerName) { |
| 254 | | if (layerName == null || layerName.isEmpty()) { |
| 255 | | layerName = settings.getLayerName(); |
| 256 | | } |
| 257 | | if (layerName == null || layerName.isEmpty()) { |
| 258 | | layerName = OsmDataLayer.createNewName(); |
| | 255 | /** |
| | 256 | * Creates a name for a new layer by utilizing the settings ({@link DownloadParams#getLayerName()}) or |
| | 257 | * {@link OsmDataLayer#createNewName()} if the former option is {@code null}. |
| | 258 | * |
| | 259 | * @return a name for a new layer |
| | 260 | */ |
| | 261 | protected String generateLayerName() { |
| | 262 | return Optional.ofNullable(settings.getLayerName()) |
| | 263 | .filter(layerName -> !Utils.isStripEmpty(layerName)) |
| | 264 | .orElse(OsmDataLayer.createNewName()); |
| | 265 | } |
| | 266 | |
| | 267 | /** |
| | 268 | * Can be overridden (e.g. by plugins) if a subclass of {@link OsmDataLayer} is needed. |
| | 269 | * If you want to change how the name is determined, consider overriding |
| | 270 | * {@link #generateLayerName()} instead. |
| | 271 | * |
| | 272 | * @param dataset the dataset on which the layer is based, must be non-null |
| | 273 | * @param layerName the name of the new layer, must be either non-blank or non-present |
| | 274 | * @return a new instance of {@link OsmDataLayer} constructed with the given arguments |
| | 275 | */ |
| | 276 | protected OsmDataLayer createNewLayer(final DataSet dataset, final Optional<String> layerName) { |
| | 277 | if (layerName.filter(Utils::isStripEmpty).isPresent()) { |
| | 278 | throw new IllegalArgumentException("Blank layer name!"); |
| 260 | | if (settings.getDownloadPolicy() != null) { |
| 261 | | dataSet.setDownloadPolicy(settings.getDownloadPolicy()); |
| 262 | | } |
| 263 | | if (settings.getUploadPolicy() != null) { |
| 264 | | dataSet.setUploadPolicy(settings.getUploadPolicy()); |
| 265 | | } |
| | 280 | return new OsmDataLayer( |
| | 281 | Objects.requireNonNull(dataset, "dataset parameter"), |
| | 282 | layerName.orElseGet(this::generateLayerName), |
| | 283 | null |
| | 284 | ); |
| | 285 | } |
| | 286 | |
| | 287 | /** |
| | 288 | * Convenience method for {@link #createNewLayer(DataSet, Optional)}, uses the dataset |
| | 289 | * from field {@link #dataSet} and applies the settings from field {@link #settings}. |
| | 290 | * |
| | 291 | * @param layerName an optional layer name, must be non-blank if the [Optional] is present |
| | 292 | * @return a newly constructed layer |
| | 293 | */ |
| | 294 | protected final OsmDataLayer createNewLayer(final Optional<String> layerName) { |
| | 295 | Optional.ofNullable(settings.getDownloadPolicy()) |
| | 296 | .ifPresent(dataSet::setDownloadPolicy); |
| | 297 | Optional.ofNullable(settings.getUploadPolicy()) |
| | 298 | .ifPresent(dataSet::setUploadPolicy); |