| 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(); |
| | 254 | /** |
| | 255 | * Creates a name for a new layer by utilizing the settings ({@link DownloadParams#getLayerName()}) or |
| | 256 | * {@link OsmDataLayer#createNewName()} if the former option is {@code null}. |
| | 257 | * |
| | 258 | * @return a name for a new layer |
| | 259 | */ |
| | 260 | protected String generateLayerName() { |
| | 261 | return Optional.ofNullable(settings.getLayerName()) |
| | 262 | .orElse(OsmDataLayer.createNewName()); |
| | 263 | } |
| | 264 | |
| | 265 | /** |
| | 266 | * Can be overridden (e.g. by plugins) if a subclass of {@link OsmDataLayer} is needed. |
| | 267 | * If you want to change how the name is determined, consider overriding |
| | 268 | * {@link #generateLayerName()} instead. |
| | 269 | * |
| | 270 | * @param dataset the dataset on which the layer is based, must be non-null |
| | 271 | * @param layerName the name of the new layer, must be non-blank |
| | 272 | * @return a new instance of {@link OsmDataLayer} constructed with the given arguments |
| | 273 | */ |
| | 274 | protected OsmDataLayer createNewLayer(final DataSet dataset, final String layerName) { |
| | 275 | if (Utils.isStripEmpty(layerName)) { |
| | 276 | 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 | | } |
| | 278 | return new OsmDataLayer( |
| | 279 | Objects.requireNonNull(dataset, "dataset parameter"), |
| | 280 | Objects.requireNonNull(layerName, "layerName parameter"), |
| | 281 | null |
| | 282 | ); |
| | 283 | } |
| | 284 | |
| | 285 | //TODO: Make final as soon as this method is no longer overridden by plugins, change param type to Optional<String> |
| | 286 | protected OsmDataLayer createNewLayer(final String layerName) { |
| | 287 | Optional.ofNullable(settings.getDownloadPolicy()) |
| | 288 | .ifPresent(dataSet::setDownloadPolicy); |
| | 289 | Optional.ofNullable(settings.getUploadPolicy()) |
| | 290 | .ifPresent(dataSet::setUploadPolicy); |