Changeset 10299 in josm for trunk/src/org
- Timestamp:
- 2016-05-29T16:33:08+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java
r10208 r10299 319 319 defaultExtension, 320 320 description + (!extensionsForDescription.isEmpty() 321 ? (" (" + Utils.join(", ", extensionsForDescription) + ")")321 ? (" (" + Utils.join(", ", extensionsForDescription) + ')') 322 322 : "") 323 323 ); -
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r10220 r10299 244 244 245 245 public interface BinaryMatchFactory extends MatchFactory { 246 BinaryMatch get(String keyword, Match lhs, Match rhs, PushbackTokenizer tokenizer) throws ParseError;246 AbstractBinaryMatch get(String keyword, Match lhs, Match rhs, PushbackTokenizer tokenizer) throws ParseError; 247 247 } 248 248 … … 337 337 * A binary search operator which may take data parameters. 338 338 */ 339 public abstract static class BinaryMatch extends Match {339 public abstract static class AbstractBinaryMatch extends Match { 340 340 341 341 protected final Match lhs; 342 342 protected final Match rhs; 343 343 344 public BinaryMatch(Match lhs, Match rhs) { 344 /** 345 * Constructs a new {@code BinaryMatch}. 346 * @param lhs Left hand side 347 * @param rhs Right hand side 348 */ 349 public AbstractBinaryMatch(Match lhs, Match rhs) { 345 350 this.lhs = lhs; 346 351 this.rhs = rhs; 347 352 } 348 353 349 public Match getLhs() { 354 /** 355 * Returns left hand side. 356 * @return left hand side 357 */ 358 public final Match getLhs() { 350 359 return lhs; 351 360 } 352 361 353 public Match getRhs() { 362 /** 363 * Returns right hand side. 364 * @return right hand side 365 */ 366 public final Match getRhs() { 354 367 return rhs; 355 368 } … … 438 451 * Matches if both left and right expressions match. 439 452 */ 440 public static class And extends BinaryMatch { 453 public static class And extends AbstractBinaryMatch { 454 /** 455 * Constructs a new {@code And} match. 456 * @param lhs left hand side 457 * @param rhs right hand side 458 */ 441 459 public And(Match lhs, Match rhs) { 442 460 super(lhs, rhs); … … 455 473 @Override 456 474 public String toString() { 457 return (lhs instanceof BinaryMatch && !(lhs instanceof And) ? "(" + lhs + ")": lhs) + " && "458 + (rhs instanceof BinaryMatch && !(rhs instanceof And) ? "(" + rhs + ")": rhs);475 return (lhs instanceof AbstractBinaryMatch && !(lhs instanceof And) ? ("(" + lhs + ')') : lhs) + " && " 476 + (rhs instanceof AbstractBinaryMatch && !(rhs instanceof And) ? ("(" + rhs + ')') : rhs); 459 477 } 460 478 } … … 463 481 * Matches if the left OR the right expression match. 464 482 */ 465 public static class Or extends BinaryMatch { 483 public static class Or extends AbstractBinaryMatch { 484 /** 485 * Constructs a new {@code Or} match. 486 * @param lhs left hand side 487 * @param rhs right hand side 488 */ 466 489 public Or(Match lhs, Match rhs) { 467 490 super(lhs, rhs); … … 480 503 @Override 481 504 public String toString() { 482 return (lhs instanceof BinaryMatch && !(lhs instanceof Or) ? "(" + lhs + ")": lhs) + " || "483 + (rhs instanceof BinaryMatch && !(rhs instanceof Or) ? "(" + rhs + ")": rhs);505 return (lhs instanceof AbstractBinaryMatch && !(lhs instanceof Or) ? ("(" + lhs + ')') : lhs) + " || " 506 + (rhs instanceof AbstractBinaryMatch && !(rhs instanceof Or) ? ("(" + rhs + ')') : rhs); 484 507 } 485 508 } … … 488 511 * Matches if the left OR the right expression match, but not both. 489 512 */ 490 public static class Xor extends BinaryMatch { 513 public static class Xor extends AbstractBinaryMatch { 514 /** 515 * Constructs a new {@code Xor} match. 516 * @param lhs left hand side 517 * @param rhs right hand side 518 */ 491 519 public Xor(Match lhs, Match rhs) { 492 520 super(lhs, rhs); … … 505 533 @Override 506 534 public String toString() { 507 return (lhs instanceof BinaryMatch && !(lhs instanceof Xor) ? "(" + lhs + ")": lhs) + " ^ "508 + (rhs instanceof BinaryMatch && !(rhs instanceof Xor) ? "(" + rhs + ")": rhs);535 return (lhs instanceof AbstractBinaryMatch && !(lhs instanceof Xor) ? ("(" + lhs + ')') : lhs) + " ^ " 536 + (rhs instanceof AbstractBinaryMatch && !(rhs instanceof Xor) ? ("(" + rhs + ')') : rhs); 509 537 } 510 538 } … … 1755 1783 final String forKey = '"' + escapeStringForSearch(key) + '"' + '='; 1756 1784 if (value == null || value.isEmpty()) { 1757 return forKey + "*";1785 return forKey + '*'; 1758 1786 } else { 1759 1787 return forKey + '"' + escapeStringForSearch(value) + '"'; -
trunk/src/org/openstreetmap/josm/data/AutosaveTask.java
r10212 r10299 13 13 import java.nio.charset.StandardCharsets; 14 14 import java.nio.file.Files; 15 import java.nio.file.Path; 15 16 import java.util.ArrayList; 16 17 import java.util.Date; … … 73 74 public static final BooleanProperty PROP_NOTIFICATION = new BooleanProperty("autosave.notification", false); 74 75 75 pr ivate staticclass AutosaveLayerInfo {76 private OsmDataLayer layer;76 protected static final class AutosaveLayerInfo { 77 private final OsmDataLayer layer; 77 78 private String layerName; 78 79 private String layerFileName; 79 80 private final Deque<File> backupFiles = new LinkedList<>(); 81 82 AutosaveLayerInfo(OsmDataLayer layer) { 83 this.layer = layer; 84 } 80 85 } 81 86 … … 89 94 private final File autosaveDir = new File(Main.pref.getUserDataDirectory(), AUTOSAVE_DIR); 90 95 private final File deletedLayersDir = new File(Main.pref.getUserDataDirectory(), DELETED_LAYERS_DIR); 96 97 /** 98 * Replies the autosave directory. 99 * @return the autosave directory 100 * @since 10299 101 */ 102 public final Path getAutosaveDir() { 103 return autosaveDir.toPath(); 104 } 91 105 92 106 public void schedule() { … … 153 167 } 154 168 155 private File getNewLayerFile(AutosaveLayerInfo layer) { 156 int index = 0; 157 Date now = new Date(); 169 protected File getNewLayerFile(AutosaveLayerInfo layer, Date now, int startIndex) { 170 int index = startIndex; 158 171 while (true) { 159 172 String filename = String.format("%1$s_%2$tY%2$tm%2$td_%2$tH%2$tM%2$tS%2$tL%3$s", 160 layer.layerFileName, now, index == 0 ? "" : '_' + index);161 File result = new File(autosaveDir, filename + "."+ Main.pref.get("autosave.extension", "osm"));173 layer.layerFileName, now, index == 0 ? "" : ("_" + index)); 174 File result = new File(autosaveDir, filename + '.' + Main.pref.get("autosave.extension", "osm")); 162 175 try { 176 if (index > PROP_INDEX_LIMIT.get()) 177 throw new IOException("index limit exceeded"); 163 178 if (result.createNewFile()) { 164 File pidFile = new File(autosaveDir, filename+".pid"); 165 try (PrintStream ps = new PrintStream(pidFile, "UTF-8")) { 166 ps.println(ManagementFactory.getRuntimeMXBean().getName()); 167 } catch (IOException | SecurityException t) { 168 Main.error(t); 169 } 179 createNewPidFile(autosaveDir, filename); 170 180 return result; 171 181 } else { 172 182 Main.warn(tr("Unable to create file {0}, other filename will be used", result.getAbsolutePath())); 173 if (index > PROP_INDEX_LIMIT.get())174 throw new IOException("index limit exceeded");175 183 } 176 184 } catch (IOException e) { … … 179 187 } 180 188 index++; 189 } 190 } 191 192 private static void createNewPidFile(File autosaveDir, String filename) { 193 File pidFile = new File(autosaveDir, filename+".pid"); 194 try (PrintStream ps = new PrintStream(pidFile, "UTF-8")) { 195 ps.println(ManagementFactory.getRuntimeMXBean().getName()); 196 } catch (IOException | SecurityException t) { 197 Main.error(t); 181 198 } 182 199 } … … 188 205 } 189 206 if (changedDatasets.remove(info.layer.data)) { 190 File file = getNewLayerFile(info );207 File file = getNewLayerFile(info, new Date(), 0); 191 208 if (file != null) { 192 209 info.backupFiles.add(file); … … 240 257 synchronized (layersLock) { 241 258 layer.data.addDataSetListener(datasetAdapter); 242 AutosaveLayerInfo info = new AutosaveLayerInfo(); 243 info.layer = layer; 244 layersInfo.add(info); 259 layersInfo.add(new AutosaveLayerInfo(layer)); 245 260 } 246 261 } … … 287 302 } 288 303 289 pr ivateFile getPidFile(File osmFile) {304 protected File getPidFile(File osmFile) { 290 305 return new File(autosaveDir, osmFile.getName().replaceFirst("[.][^.]+$", ".pid")); 291 306 }
Note:
See TracChangeset
for help on using the changeset viewer.