- Timestamp:
- 2020-11-29T10:33:58+01:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
r17358 r17374 708 708 // see #9599 709 709 if (discardedWays.stream().anyMatch(w -> !w.isNew())) { 710 for (int i = 0; i < boundaries.size(); i++) { 711 AssembledPolygon ring = boundaries.get(i); 710 for (AssembledPolygon ring : boundaries) { 712 711 for (int k = 0; k < ring.ways.size(); k++) { 713 712 WayInPolygon ringWay = ring.ways.get(k); -
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r17164 r17374 1124 1124 1125 1125 if (cyclePrims && shift) { 1126 for ( Iterator<OsmPrimitive> i =cycleList.iterator(); i.hasNext();) {1127 nxt = i.next();1126 for (OsmPrimitive osmPrimitive : cycleList) { 1127 nxt = osmPrimitive; 1128 1128 if (!nxt.isSelected()) { 1129 1129 break; // take first primitive in cycleList not in sel -
trunk/src/org/openstreetmap/josm/data/cache/HostLimitQueue.java
r15525 r17374 4 4 import java.io.IOException; 5 5 import java.net.URL; 6 import java.util.Iterator;7 6 import java.util.Map; 8 7 import java.util.concurrent.ConcurrentHashMap; … … 53 52 54 53 private JCSCachedTileLoaderJob<?, ?> findJob() { 55 for (Iterator<Runnable> it = iterator(); it.hasNext();) { 56 Runnable r = it.next(); 54 for (Runnable r : this) { 57 55 if (r instanceof JCSCachedTileLoaderJob) { 58 56 JCSCachedTileLoaderJob<?, ?> job = (JCSCachedTileLoaderJob<?, ?>) r; -
trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFile.java
r17333 r17374 263 263 private static NTV2SubGrid getSubGrid(NTV2SubGrid[] topLevelSubGrid, double lon, double lat) { 264 264 NTV2SubGrid sub = null; 265 for ( int i = 0; i <topLevelSubGrid.length; i++) {266 sub = topLevel SubGrid[i].getSubGridForCoord(lon, lat);265 for (NTV2SubGrid topLevel : topLevelSubGrid) { 266 sub = topLevel.getSubGridForCoord(lon, lat); 267 267 if (sub != null) { 268 268 break; … … 274 274 @Override 275 275 public String toString() { 276 return new StringBuilder(256) 277 .append("Headers : ") 278 .append(overviewHeaderCount) 279 .append("\nSub Hdrs : ") 280 .append(subGridHeaderCount) 281 .append("\nSub Grids: ") 282 .append(subGridCount) 283 .append("\nType : ") 284 .append(shiftType) 285 .append("\nVersion : ") 286 .append(version) 287 .append("\nFr Ellpsd: ") 288 .append(fromEllipsoid) 289 .append("\nTo Ellpsd: ") 290 .append(toEllipsoid) 291 .append("\nFr Maj Ax: ") 292 .append(fromSemiMajorAxis) 293 .append("\nFr Min Ax: ") 294 .append(fromSemiMinorAxis) 295 .append("\nTo Maj Ax: ") 296 .append(toSemiMajorAxis) 297 .append("\nTo Min Ax: ") 298 .append(toSemiMinorAxis) 299 .toString(); 276 char endl = '\n'; 277 return "Headers : " + overviewHeaderCount + endl + 278 "Sub Hdrs : " + subGridHeaderCount + endl + 279 "Sub Grids: " + subGridCount + endl + 280 "Type : " + shiftType + endl + 281 "Version : " + version + endl + 282 "Fr Ellpsd: " + fromEllipsoid + endl + 283 "To Ellpsd: " + toEllipsoid + endl + 284 "Fr Maj Ax: " + fromSemiMajorAxis + endl + 285 "Fr Min Ax: " + fromSemiMinorAxis + endl + 286 "To Maj Ax: " + toSemiMajorAxis + endl + 287 "To Min Ax: " + toSemiMinorAxis; 300 288 } 301 289 -
trunk/src/org/openstreetmap/josm/data/validation/routines/UrlValidator.java
r13590 r17374 276 276 } 277 277 allowedSchemes = new HashSet<>(schemes.length); 278 for ( int i = 0; i <schemes.length; i++) {279 allowedSchemes.add(scheme s[i].toLowerCase(Locale.ENGLISH));278 for (String scheme : schemes) { 279 allowedSchemes.add(scheme.toLowerCase(Locale.ENGLISH)); 280 280 } 281 281 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/ConnectivityRelations.java
r16643 r17374 80 80 final String joined = cnTag.replace("bw", Integer.toString(BW)); 81 81 82 83 82 final Map<Integer, Map<Integer, Boolean>> result = new HashMap<>(); 84 83 String[] lanes = joined.split("\\|", -1); 85 84 for (int i = 0; i < lanes.length; i++) { 86 String[] lane = lanes[i].split(":", -1); 85 final String[] lane = lanes[i].split(":", -1); 87 86 int laneNumber; 88 87 //Ignore connections from bw, since we cannot derive a lane number from bw -
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java
r17096 r17374 156 156 * Returns the list of "duplicate nodes" errors for the given selection of node and parent test 157 157 * @param parentTest The parent test of returned errors 158 * @param nodes The nodes selction to look into 158 * @param nodes The nodes selection to look into 159 159 * @return the list of "duplicate nodes" errors 160 160 */ … … 187 187 Way w = (Way) sp; 188 188 Map<String, String> keys = w.getKeys(); 189 for (Iterator<Entry<String, Boolean>> itt = typeMap.entrySet().iterator(); itt.hasNext();) { 190 Entry<String, Boolean> e = itt.next(); 189 for (Entry<String, Boolean> e : typeMap.entrySet()) { 191 190 if (keys.containsKey(e.getKey())) { 192 191 e.setValue(Boolean.TRUE); -
trunk/src/org/openstreetmap/josm/data/validation/tests/SimilarNamedWays.java
r15079 r17374 220 220 StringBuilder expression = new StringBuilder(); 221 221 int maxLength = 0; 222 for ( int i = 0; i < words.length; i++) {223 if (word s[i].length() > maxLength) {224 maxLength = word s[i].length();222 for (String word : words) { 223 if (word.length() > maxLength) { 224 maxLength = word.length(); 225 225 } 226 226 if (expression.length() > 0) { 227 227 expression.append('|'); 228 228 } 229 expression.append(Pattern.quote(word s[i]));229 expression.append(Pattern.quote(word)); 230 230 } 231 231 this.regExpr = Pattern.compile(expression.toString(), CASE_INSENSITIVE + UNICODE_CASE); … … 243 243 // which word matches? 244 244 String part = ""; 245 for (int i = 0; i < words.length; i++) { 246 String word = words[i]; 245 for (String word : words) { 247 246 if (start + word.length() <= name.length()) { 248 247 part = name.substring(start, start + word.length()); -
trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
r17347 r17374 277 277 List<Command> undoCommands = UndoRedoHandler.getInstance().getUndoCommands(); 278 278 undoRoot = new DefaultMutableTreeNode(); 279 for ( int i = 0; i <undoCommands.size(); ++i) {280 undoRoot.add(getNodeForCommand(undoCommand s.get(i)));279 for (Command undoCommand : undoCommands) { 280 undoRoot.add(getNodeForCommand(undoCommand)); 281 281 } 282 282 undoTreeModel.setRoot(undoRoot); … … 286 286 List<Command> redoCommands = UndoRedoHandler.getInstance().getRedoCommands(); 287 287 redoRoot = new DefaultMutableTreeNode(); 288 for ( int i = 0; i <redoCommands.size(); ++i) {289 redoRoot.add(getNodeForCommand(redoCommand s.get(i)));288 for (Command redoCommand : redoCommands) { 289 redoRoot.add(getNodeForCommand(redoCommand)); 290 290 } 291 291 redoTreeModel.setRoot(redoRoot); … … 341 341 if (c.getChildren() != null) { 342 342 List<PseudoCommand> children = new ArrayList<>(c.getChildren()); 343 for ( int i = 0; i <children.size(); ++i) {344 node.add(getNodeForCommand(child ren.get(i)));343 for (PseudoCommand child : children) { 344 node.add(getNodeForCommand(child)); 345 345 } 346 346 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/DialogsPanel.java
r16438 r17374 194 194 */ 195 195 if (action == Action.RESTORE_SAVED || action == Action.ELEMENT_SHRINKS) { 196 for (int i = 0; i < n; ++i) { 197 final ToggleDialog dlg = allDialogs.get(i); 196 for (final ToggleDialog dlg : allDialogs) { 198 197 if (dlg.isDialogInDefaultView()) { 199 198 final int ph = action == Action.RESTORE_SAVED ? dlg.getLastHeight() : dlg.getPreferredHeight(); … … 251 250 int dm = 0; // additional space needed by the small dialogs 252 251 int dp = 0; // available space from the large dialogs 253 for (int i = 0; i < n; ++i) { 254 final ToggleDialog dlg = allDialogs.get(i); 252 for (final ToggleDialog dlg : allDialogs) { 255 253 if (dlg != triggeredBy && dlg.isDialogInDefaultView()) { 256 254 final int ha = dlg.getSize().height; // current … … 266 264 } 267 265 /** adjust, without changing the sum */ 268 for (int i = 0; i < n; ++i) { 269 final ToggleDialog dlg = allDialogs.get(i); 266 for (final ToggleDialog dlg : allDialogs) { 270 267 if (dlg != triggeredBy && dlg.isDialogInDefaultView()) { 271 268 final int ha = dlg.getHeight(); … … 276 273 dlg.setPreferredSize(new Dimension(Integer.MAX_VALUE, hn)); 277 274 } else { 278 int d = dp == 0 ? 0 : ((h0 -he) * dm / dp);275 int d = dp == 0 ? 0 : ((h0 - he) * dm / dp); 279 276 dlg.setPreferredSize(new Dimension(Integer.MAX_VALUE, h0 - d)); 280 277 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/placement/CompletelyInsideAreaStrategy.java
r16488 r17374 40 40 // Centroids are not optimal either, just imagine a U-shaped house. 41 41 42 Rectangle pb = path.getBounds(); 42 final Rectangle pb = path.getBounds(); 43 43 44 44 // quick check to see if label box is smaller than primitive box … … 56 56 final int nbh = (int) nb.getHeight(); 57 57 58 Rectangle centeredNBounds = new Rectangle(x2, y2, nbw, nbh); 58 final Rectangle centeredNBounds = new Rectangle(x2, y2, nbw, nbh); 59 59 60 60 // slower check to see if label is displayed inside primitive shape … … 85 85 // Dumb algorithm to find a better placement. We could surely find a smarter one but it should 86 86 // solve most of building issues with only few calculations (8 at most) 87 for (int i = 0; i < candidates.length; i++) { 88 centeredNBounds = candidates[i]; 89 if (path.contains(centeredNBounds)) { 90 return centerOf(path.getMapViewState(), centeredNBounds); 87 for (Rectangle candidate : candidates) { 88 if (path.contains(candidate)) { 89 return centerOf(path.getMapViewState(), candidate); 91 90 } 92 91 } -
trunk/src/org/openstreetmap/josm/tools/ListenerList.java
r15726 r17374 5 5 import java.text.MessageFormat; 6 6 import java.util.HashMap; 7 import java.util.Iterator;8 7 import java.util.Objects; 9 8 import java.util.concurrent.CopyOnWriteArrayList; … … 156 155 eventFirerer.fire(l); 157 156 } 158 for (Iterator<WeakListener<T>> iterator = weakListeners.iterator(); iterator.hasNext();) { 159 WeakListener<T> weakLink = iterator.next(); 157 for (WeakListener<T> weakLink : weakListeners) { 160 158 T l = weakLink.listener.get(); 161 159 if (l != null) { -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r16955 r17374 1510 1510 } 1511 1511 Bidi.reorderVisually(levels, 0, dirStrings, 0, levels.length); 1512 for ( int i = 0; i <dirStrings.length; ++i) {1513 char[] chars = dirString s[i].str.toCharArray();1514 gvs.add(font.layoutGlyphVector(frc, chars, 0, chars.length, dirString s[i].direction));1512 for (DirectionString dirString : dirStrings) { 1513 char[] chars = dirString.str.toCharArray(); 1514 gvs.add(font.layoutGlyphVector(frc, chars, 0, chars.length, dirString.direction)); 1515 1515 } 1516 1516 return gvs; -
trunk/test/unit/org/openstreetmap/josm/data/validation/routines/DomainValidatorTestIT.java
r17275 r17374 348 348 private static boolean isInIanaList(String name, String[] array, Set<String> ianaTlds) { 349 349 boolean ok = true; 350 for ( int i = 0; i < array.length; i++) {351 if (!ianaTlds.contains( array[i])) {352 Logging.error(name + " contains unexpected value: " + array[i]);350 for (String element : array) { 351 if (!ianaTlds.contains(element)) { 352 Logging.error(name + " contains unexpected value: " + element); 353 353 ok = false; 354 354 } -
trunk/test/unit/org/openstreetmap/josm/data/validation/routines/EmailValidatorTest.java
r17275 r17374 493 493 @Test 494 494 void testEmailFromPerl() { 495 for ( int index = 0; index <testEmailFromPerl.length; index++) {496 String item = testEmailFromPerl[index].item;497 if ( testEmailFromPerl[index].valid) {498 assertTrue("Should be OK: " +item, validator.isValid(item));495 for (ResultPair resultPair : testEmailFromPerl) { 496 String item = resultPair.item; 497 if (resultPair.valid) { 498 assertTrue("Should be OK: " + item, validator.isValid(item)); 499 499 } else { 500 assertFalse("Should fail: " +item, validator.isValid(item));500 assertFalse("Should fail: " + item, validator.isValid(item)); 501 501 } 502 502 } -
trunk/test/unit/org/openstreetmap/josm/data/validation/routines/UrlValidatorTest.java
r17275 r17374 31 31 class UrlValidatorTest { 32 32 33 private static final boolean printStatus = false; 34 private static final boolean printIndex = false; //print index that indicates current scheme,host,port,path, query test were using. 35 36 /** 37 * Setup 38 */ 39 @BeforeEach 40 public void setUp() { 41 for (int index = 0; index < testPartsIndex.length - 1; index++) { 42 testPartsIndex[index] = 0; 43 } 44 } 45 46 /** 47 * Test is valid 48 */ 49 @Test 50 public void testIsValid() { 33 private static final boolean printStatus = false; 34 private static final boolean printIndex = false; //print index that indicates current scheme,host,port,path, query test were using. 35 36 /** 37 * Setup 38 */ 39 @BeforeEach 40 public void setUp() { 41 for (int index = 0; index < testPartsIndex.length - 1; index++) { 42 testPartsIndex[index] = 0; 43 } 44 } 45 46 /** 47 * Test is valid 48 */ 49 @Test 50 public void testIsValid() { 51 51 testIsValid(testUrlParts, UrlValidator.ALLOW_ALL_SCHEMES); 52 52 setUp(); 53 53 long options = 54 UrlValidator.ALLOW_2_SLASHES 55 + UrlValidator.ALLOW_ALL_SCHEMES 56 + UrlValidator.NO_FRAGMENTS; 54 UrlValidator.ALLOW_2_SLASHES 55 + UrlValidator.ALLOW_ALL_SCHEMES 56 + UrlValidator.NO_FRAGMENTS; 57 57 58 58 testIsValid(testUrlPartsOptions, options); 59 } 60 61 /** 62 * Test is valid scheme 63 */ 64 @Test 65 public void testIsValidScheme() { 66 if (printStatus) { 67 System.out.print("\n testIsValidScheme() "); 68 } 69 //UrlValidator urlVal = new UrlValidator(schemes,false,false,false); 70 UrlValidator urlVal = new UrlValidator(schemes, 0); 71 for (int sIndex = 0; sIndex <testScheme.length; sIndex++) {72 ResultPairtestPair= testScheme[sIndex];73 boolean result = urlVal.isValidScheme(testPair.item);74 assertEquals(testPair.item, testPair.valid, result);75 if (printStatus) {76 if (result == testPair.valid) {77 System.out.print('.');78 } else {79 System.out.print('X');59 } 60 61 /** 62 * Test is valid scheme 63 */ 64 @Test 65 public void testIsValidScheme() { 66 if (printStatus) { 67 System.out.print("\n testIsValidScheme() "); 68 } 69 //UrlValidator urlVal = new UrlValidator(schemes,false,false,false); 70 UrlValidator urlVal = new UrlValidator(schemes, 0); 71 for (ResultPair testPair : testScheme) { 72 boolean result = urlVal.isValidScheme(testPair.item); 73 assertEquals(testPair.item, testPair.valid, result); 74 if (printStatus) { 75 if (result == testPair.valid) { 76 System.out.print('.'); 77 } else { 78 System.out.print('X'); 79 } 80 80 } 81 } 82 } 83 if (printStatus) { 84 System.out.println(); 85 } 86 } 87 88 /** 89 * Create set of tests by taking the testUrlXXX arrays and 90 * running through all possible permutations of their combinations. 91 * 92 * @param testObjects Used to create a url. 93 * @param options options 94 */ 95 private void testIsValid(Object[] testObjects, long options) { 96 UrlValidator urlVal = new UrlValidator(null, null, options); 97 assertTrue(urlVal.isValid("http://www.google.com")); 98 assertTrue(urlVal.isValid("http://www.google.com/")); 99 int statusPerLine = 60; 100 int printed = 0; 101 if (printIndex) { 102 statusPerLine = 6; 103 } 104 do { 105 StringBuilder testBuffer = new StringBuilder(); 106 boolean expected = true; 107 for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) { 108 int index = testPartsIndex[testPartsIndexIndex]; 109 ResultPair[] part = (ResultPair[]) testObjects[testPartsIndexIndex]; 110 testBuffer.append(part[index].item); 111 expected &= part[index].valid; 112 } 113 String url = testBuffer.toString(); 114 boolean result = urlVal.isValid(url); 115 assertEquals(url, expected, result); 116 if (printStatus) { 117 if (printIndex) { 118 System.out.print(testPartsIndextoString()); 119 } else { 120 if (result == expected) { 121 System.out.print('.'); 122 } else { 123 System.out.print('X'); 124 } 81 } 82 if (printStatus) { 83 System.out.println(); 84 } 85 } 86 87 /** 88 * Create set of tests by taking the testUrlXXX arrays and 89 * running through all possible permutations of their combinations. 90 * 91 * @param testObjects Used to create a url. 92 * @param options options 93 */ 94 private void testIsValid(Object[] testObjects, long options) { 95 UrlValidator urlVal = new UrlValidator(null, null, options); 96 assertTrue(urlVal.isValid("http://www.google.com")); 97 assertTrue(urlVal.isValid("http://www.google.com/")); 98 int statusPerLine = 60; 99 int printed = 0; 100 if (printIndex) { 101 statusPerLine = 6; 102 } 103 do { 104 StringBuilder testBuffer = new StringBuilder(); 105 boolean expected = true; 106 for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) { 107 int index = testPartsIndex[testPartsIndexIndex]; 108 ResultPair[] part = (ResultPair[]) testObjects[testPartsIndexIndex]; 109 testBuffer.append(part[index].item); 110 expected &= part[index].valid; 125 111 } 126 printed++; 127 if (printed == statusPerLine) { 128 System.out.println(); 129 printed = 0; 112 String url = testBuffer.toString(); 113 boolean result = urlVal.isValid(url); 114 assertEquals(url, expected, result); 115 if (printStatus) { 116 if (printIndex) { 117 System.out.print(testPartsIndextoString()); 118 } else { 119 if (result == expected) { 120 System.out.print('.'); 121 } else { 122 System.out.print('X'); 123 } 124 } 125 printed++; 126 if (printed == statusPerLine) { 127 System.out.println(); 128 printed = 0; 129 } 130 130 } 131 } 132 } while (incrementTestPartsIndex(testPartsIndex, testObjects)); 133 if (printStatus) { 134 System.out.println(); 135 } 136 } 131 } while (incrementTestPartsIndex(testPartsIndex, testObjects)); 132 if (printStatus) { 133 System.out.println(); 134 } 135 } 137 136 138 137 /** … … 144 143 UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.NO_FRAGMENTS); 145 144 assertTrue(urlValidator.isValid( 146 "http://l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.org")); 145 "http://l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.org")); 147 146 } 148 147 … … 164 163 UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES); 165 164 assertTrue("parentheses should be valid in URLs", 166 validator.isValid("http://somewhere.com/pathxyz/file(1).html")); 165 validator.isValid("http://somewhere.com/pathxyz/file(1).html")); 167 166 } 168 167 … … 191 190 @Test 192 191 void testValidator248() { 193 RegexValidator regex = new RegexValidator( new String[] {"localhost", ".*\\.my-testing"});192 RegexValidator regex = new RegexValidator("localhost", ".*\\.my-testing"); 194 193 UrlValidator validator = new UrlValidator(regex, 0); 195 194 … … 211 210 212 211 assertTrue("localhost URL should validate", 213 validator.isValid("http://localhost/test/index.html")); 212 validator.isValid("http://localhost/test/index.html")); 214 213 215 214 assertTrue("machinename URL should validate", 216 validator.isValid("http://machinename/test/index.html")); 215 validator.isValid("http://machinename/test/index.html")); 217 216 218 217 assertTrue("www.apache.org should still validate", 219 validator.isValid("http://www.apache.org/test/index.html")); 218 validator.isValid("http://www.apache.org/test/index.html")); 220 219 } 221 220 … … 267 266 268 267 assertTrue("http://apache.org/ should be allowed by default", 269 268 validator.isValid("http://www.apache.org/test/index.html")); 270 269 271 270 assertFalse("file:///c:/ shouldn't be allowed by default", 272 271 validator.isValid("file:///C:/some.file")); 273 272 274 273 assertFalse("file:///c:\\ shouldn't be allowed by default", 275 validator.isValid("file:///C:\\some.file")); 274 validator.isValid("file:///C:\\some.file")); 276 275 277 276 assertFalse("file:///etc/ shouldn't be allowed by default", 278 validator.isValid("file:///etc/hosts")); 277 validator.isValid("file:///etc/hosts")); 279 278 280 279 assertFalse("file://localhost/etc/ shouldn't be allowed by default", 281 validator.isValid("file://localhost/etc/hosts")); 280 validator.isValid("file://localhost/etc/hosts")); 282 281 283 282 assertFalse("file://localhost/c:/ shouldn't be allowed by default", 284 validator.isValid("file://localhost/c:/some.file")); 283 validator.isValid("file://localhost/c:/some.file")); 285 284 286 285 // Turn it on, and check 287 286 // Note - we need to enable local urls when working with file: 288 validator = new UrlValidator(new String[] 287 validator = new UrlValidator(new String[]{"http", "file"}, UrlValidator.ALLOW_LOCAL_URLS); 289 288 290 289 assertTrue("http://apache.org/ should be allowed by default", 291 290 validator.isValid("http://www.apache.org/test/index.html")); 292 291 293 292 assertTrue("file:///c:/ should now be allowed", 294 293 validator.isValid("file:///C:/some.file")); 295 294 296 295 // Currently, we don't support the c:\ form 297 296 assertFalse("file:///c:\\ shouldn't be allowed", 298 validator.isValid("file:///C:\\some.file")); 297 validator.isValid("file:///C:\\some.file")); 299 298 300 299 assertTrue("file:///etc/ should now be allowed", 301 validator.isValid("file:///etc/hosts")); 300 validator.isValid("file:///etc/hosts")); 302 301 303 302 assertTrue("file://localhost/etc/ should now be allowed", 304 validator.isValid("file://localhost/etc/hosts")); 303 validator.isValid("file://localhost/etc/hosts")); 305 304 306 305 assertTrue("file://localhost/c:/ should now be allowed", 307 validator.isValid("file://localhost/c:/some.file")); 306 validator.isValid("file://localhost/c:/some.file")); 308 307 309 308 // These are never valid 310 309 assertFalse("file://c:/ shouldn't ever be allowed, needs file:///c:/", 311 validator.isValid("file://C:/some.file")); 310 validator.isValid("file://C:/some.file")); 312 311 313 312 assertFalse("file://c:\\ shouldn't ever be allowed, needs file:///c:/", 314 validator.isValid("file://C:\\some.file")); 313 validator.isValid("file://C:\\some.file")); 315 314 } 316 315 … … 324 323 assertTrue(urlValidator.isValid("hTtP://sample.ondemand.CoM/")); 325 324 assertTrue(urlValidator.isValid("httpS://SAMPLE.ONEMAND.COM/")); 326 urlValidator = new UrlValidator( new String[] {"HTTP", "HTTPS"});325 urlValidator = new UrlValidator("HTTP", "HTTPS"); 327 326 assertTrue(urlValidator.isValid("http://sample.ondemand.com/")); 328 327 assertTrue(urlValidator.isValid("hTtP://sample.ondemand.CoM/")); … … 367 366 368 367 static boolean incrementTestPartsIndex(int[] testPartsIndex, Object[] testParts) { 369 boolean carry = true; //add 1 to lowest order part. 370 boolean maxIndex = true; 371 for (int testPartsIndexIndex = testPartsIndex.length - 1; testPartsIndexIndex >= 0; --testPartsIndexIndex) { 372 int index = testPartsIndex[testPartsIndexIndex]; 373 ResultPair[] part = (ResultPair[]) testParts[testPartsIndexIndex]; 374 if (carry) { 375 if (index < part.length - 1) { 376 index++; 377 testPartsIndex[testPartsIndexIndex] = index; 378 carry = false; 368 boolean carry = true; //add 1 to lowest order part. 369 boolean maxIndex = true; 370 for (int testPartsIndexIndex = testPartsIndex.length - 1; testPartsIndexIndex >= 0; --testPartsIndexIndex) { 371 int index = testPartsIndex[testPartsIndexIndex]; 372 ResultPair[] part = (ResultPair[]) testParts[testPartsIndexIndex]; 373 if (carry) { 374 if (index < part.length - 1) { 375 index++; 376 testPartsIndex[testPartsIndexIndex] = index; 377 carry = false; 378 } else { 379 testPartsIndex[testPartsIndexIndex] = 0; 380 carry = true; 381 } 382 } 383 maxIndex &= (index == (part.length - 1)); 384 } 385 386 return (!maxIndex); 387 } 388 389 private String testPartsIndextoString() { 390 StringBuilder carryMsg = new StringBuilder("{"); 391 for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) { 392 carryMsg.append(testPartsIndex[testPartsIndexIndex]); 393 if (testPartsIndexIndex < testPartsIndex.length - 1) { 394 carryMsg.append(','); 379 395 } else { 380 testPartsIndex[testPartsIndexIndex] = 0; 381 carry = true; 396 carryMsg.append('}'); 382 397 } 383 } 384 maxIndex &= (index == (part.length - 1)); 385 } 386 387 return (!maxIndex); 388 } 389 390 private String testPartsIndextoString() { 391 StringBuilder carryMsg = new StringBuilder("{"); 392 for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) { 393 carryMsg.append(testPartsIndex[testPartsIndexIndex]); 394 if (testPartsIndexIndex < testPartsIndex.length - 1) { 395 carryMsg.append(','); 396 } else { 397 carryMsg.append('}'); 398 } 399 } 400 return carryMsg.toString(); 401 } 402 403 /** 404 * Non-regression test for VALIDATOR-290 405 */ 406 @Test 407 public void testValidator290() { 398 } 399 return carryMsg.toString(); 400 } 401 402 /** 403 * Non-regression test for VALIDATOR-290 404 */ 405 @Test 406 public void testValidator290() { 408 407 UrlValidator validator = new UrlValidator(); 409 408 assertTrue(validator.isValid("http://xn--h1acbxfam.idn.icann.org/")); … … 442 441 } 443 442 444 /** 445 * Non-regression test for VALIDATOR-361 446 */ 447 @Test 448 public void testValidator361() { 449 UrlValidator validator = new UrlValidator(); 450 assertTrue(validator.isValid("http://hello.tokyo/")); 451 } 452 453 /** 454 * Non-regression test for VALIDATOR-363 455 */ 456 @Test 457 public void testValidator363() { 443 /** 444 * Non-regression test for VALIDATOR-361 445 */ 446 @Test 447 public void testValidator361() { 448 UrlValidator validator = new UrlValidator(); 449 assertTrue(validator.isValid("http://hello.tokyo/")); 450 } 451 452 /** 453 * Non-regression test for VALIDATOR-363 454 */ 455 @Test 456 public void testValidator363() { 458 457 UrlValidator urlValidator = new UrlValidator(); 459 458 assertTrue(urlValidator.isValid("http://www.example.org/a/b/hello..world")); … … 475 474 } 476 475 477 /** 478 * Non-regression test for VALIDATOR-375 479 */ 480 @Test 481 public void testValidator375() { 482 UrlValidator validator = new UrlValidator(); 483 String url = "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html"; 484 assertTrue("IPv6 address URL should validate: " + url, validator.isValid(url)); 485 url = "http://[::1]:80/index.html"; 486 assertTrue("IPv6 address URL should validate: " + url, validator.isValid(url)); 487 url = "http://FEDC:BA98:7654:3210:FEDC:BA98:7654:3210:80/index.html"; 488 assertFalse("IPv6 address without [] should not validate: " + url, validator.isValid(url)); 489 } 490 491 /** 492 * Non-regression test for VALIDATOR-353 493 */ 494 @Test 495 public void testValidator353() { // userinfo 496 UrlValidator validator = new UrlValidator(); 497 assertTrue(validator.isValid("http://www.apache.org:80/path")); 498 assertTrue(validator.isValid("http://user:pass@www.apache.org:80/path")); 499 assertTrue(validator.isValid("http://user:@www.apache.org:80/path")); 500 assertTrue(validator.isValid("http://us%00er:-._~!$&'()*+,;=@www.apache.org:80/path")); 501 assertFalse(validator.isValid("http://:pass@www.apache.org:80/path")); 502 assertFalse(validator.isValid("http://:@www.apache.org:80/path")); 503 assertFalse(validator.isValid("http://user:pa:ss@www.apache.org/path")); 504 assertFalse(validator.isValid("http://user:pa@ss@www.apache.org/path")); 505 } 506 507 /** 508 * Non-regression test for VALIDATOR-382 509 */ 510 @Test 511 public void testValidator382() { 512 UrlValidator validator = new UrlValidator(); 513 assertTrue(validator.isValid("ftp://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose")); 514 } 515 516 /** 517 * Non-regression test for VALIDATOR-380 518 */ 519 @Test 520 public void testValidator380() { 521 UrlValidator validator = new UrlValidator(); 522 assertTrue(validator.isValid("http://www.apache.org:80/path")); 523 assertTrue(validator.isValid("http://www.apache.org:8/path")); 524 assertTrue(validator.isValid("http://www.apache.org:/path")); 525 } 526 527 /** 528 * Unit test of {@link UrlValidator#getValidatorName}. 529 */ 530 @Test 531 public void testValidatorName() { 532 assertEquals("URL validator", UrlValidator.getInstance().getValidatorName()); 533 } 534 535 //-------------------- Test data for creating a composite URL 536 /** 537 * The data given below approximates the 4 parts of a URL 538 * {@code <scheme>://<authority><path>?<query>} except that the port number 539 * is broken out of authority to increase the number of permutations. 540 * A complete URL is composed of a scheme+authority+port+path+query, 541 * all of which must be individually valid for the entire URL to be considered 542 * valid. 543 */ 544 ResultPair[] testUrlScheme = {new ResultPair("http://", true), 545 new ResultPair("ftp://", true), 546 new ResultPair("h3t://", true), 547 new ResultPair("3ht://", false), 548 new ResultPair("http:/", false), 549 new ResultPair("http:", false), 550 new ResultPair("http/", false), 551 new ResultPair("://", false), 552 new ResultPair("", true)}; 553 554 ResultPair[] testUrlAuthority = {new ResultPair("www.google.com", true), 555 new ResultPair("go.com", true), 556 new ResultPair("go.au", true), 557 new ResultPair("0.0.0.0", true), 558 new ResultPair("255.255.255.255", true), 559 new ResultPair("256.256.256.256", false), 560 new ResultPair("255.com", true), 561 new ResultPair("1.2.3.4.5", false), 562 new ResultPair("1.2.3.4.", false), 563 new ResultPair("1.2.3", false), 564 new ResultPair(".1.2.3.4", false), 565 new ResultPair("go.a", false), 566 new ResultPair("go.a1a", false), 567 new ResultPair("go.cc", true), 568 new ResultPair("go.1aa", false), 569 new ResultPair("aaa.", false), 570 new ResultPair(".aaa", false), 571 new ResultPair("aaa", false), 572 new ResultPair("", false) 573 }; 574 ResultPair[] testUrlPort = {new ResultPair(":80", true), 575 new ResultPair(":65535", true), 576 new ResultPair(":0", true), 577 new ResultPair("", true), 578 new ResultPair(":-1", false), 579 new ResultPair(":65636", true), 580 new ResultPair(":65a", false) 581 }; 582 ResultPair[] testPath = {new ResultPair("/test1", true), 583 new ResultPair("/t123", true), 584 new ResultPair("/$23", true), 585 new ResultPair("/..", false), 586 new ResultPair("/../", false), 587 new ResultPair("/test1/", true), 588 new ResultPair("", true), 589 new ResultPair("/test1/file", true), 590 new ResultPair("/..//file", false), 591 new ResultPair("/test1//file", false) 592 }; 593 //Test allow2slash, noFragment 594 ResultPair[] testUrlPathOptions = {new ResultPair("/test1", true), 595 new ResultPair("/t123", true), 596 new ResultPair("/$23", true), 597 new ResultPair("/..", false), 598 new ResultPair("/../", false), 599 new ResultPair("/test1/", true), 600 new ResultPair("/#", false), 601 new ResultPair("", true), 602 new ResultPair("/test1/file", true), 603 new ResultPair("/t123/file", true), 604 new ResultPair("/$23/file", true), 605 new ResultPair("/../file", false), 606 new ResultPair("/..//file", false), 607 new ResultPair("/test1//file", true), 608 new ResultPair("/#/file", false) 609 }; 610 611 ResultPair[] testUrlQuery = {new ResultPair("?action=view", true), 612 new ResultPair("?action=edit&mode=up", true), 613 new ResultPair("", true) 614 }; 615 616 Object[] testUrlParts = {testUrlScheme, testUrlAuthority, testUrlPort, testPath, testUrlQuery}; 617 Object[] testUrlPartsOptions = {testUrlScheme, testUrlAuthority, testUrlPort, testUrlPathOptions, testUrlQuery}; 618 int[] testPartsIndex = {0, 0, 0, 0, 0}; 619 620 //---------------- Test data for individual url parts ---------------- 621 private final String[] schemes = {"http", "gopher", "g0-To+.", 622 "not_valid" // TODO this will need to be dropped if the ctor validates schemes 623 }; 624 625 ResultPair[] testScheme = {new ResultPair("http", true), 626 new ResultPair("ftp", false), 627 new ResultPair("httpd", false), 628 new ResultPair("gopher", true), 629 new ResultPair("g0-to+.", true), 630 new ResultPair("not_valid", false), // underscore not allowed 631 new ResultPair("HtTp", true), 632 new ResultPair("telnet", false)}; 476 /** 477 * Non-regression test for VALIDATOR-375 478 */ 479 @Test 480 public void testValidator375() { 481 UrlValidator validator = new UrlValidator(); 482 String url = "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html"; 483 assertTrue("IPv6 address URL should validate: " + url, validator.isValid(url)); 484 url = "http://[::1]:80/index.html"; 485 assertTrue("IPv6 address URL should validate: " + url, validator.isValid(url)); 486 url = "http://FEDC:BA98:7654:3210:FEDC:BA98:7654:3210:80/index.html"; 487 assertFalse("IPv6 address without [] should not validate: " + url, validator.isValid(url)); 488 } 489 490 /** 491 * Non-regression test for VALIDATOR-353 492 */ 493 @Test 494 public void testValidator353() { // userinfo 495 UrlValidator validator = new UrlValidator(); 496 assertTrue(validator.isValid("http://www.apache.org:80/path")); 497 assertTrue(validator.isValid("http://user:pass@www.apache.org:80/path")); 498 assertTrue(validator.isValid("http://user:@www.apache.org:80/path")); 499 assertTrue(validator.isValid("http://us%00er:-._~!$&'()*+,;=@www.apache.org:80/path")); 500 assertFalse(validator.isValid("http://:pass@www.apache.org:80/path")); 501 assertFalse(validator.isValid("http://:@www.apache.org:80/path")); 502 assertFalse(validator.isValid("http://user:pa:ss@www.apache.org/path")); 503 assertFalse(validator.isValid("http://user:pa@ss@www.apache.org/path")); 504 } 505 506 /** 507 * Non-regression test for VALIDATOR-382 508 */ 509 @Test 510 public void testValidator382() { 511 UrlValidator validator = new UrlValidator(); 512 assertTrue(validator.isValid("ftp://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose")); 513 } 514 515 /** 516 * Non-regression test for VALIDATOR-380 517 */ 518 @Test 519 public void testValidator380() { 520 UrlValidator validator = new UrlValidator(); 521 assertTrue(validator.isValid("http://www.apache.org:80/path")); 522 assertTrue(validator.isValid("http://www.apache.org:8/path")); 523 assertTrue(validator.isValid("http://www.apache.org:/path")); 524 } 525 526 /** 527 * Unit test of {@link UrlValidator#getValidatorName}. 528 */ 529 @Test 530 public void testValidatorName() { 531 assertEquals("URL validator", UrlValidator.getInstance().getValidatorName()); 532 } 533 534 //-------------------- Test data for creating a composite URL 535 /** 536 * The data given below approximates the 4 parts of a URL 537 * {@code <scheme>://<authority><path>?<query>} except that the port number 538 * is broken out of authority to increase the number of permutations. 539 * A complete URL is composed of a scheme+authority+port+path+query, 540 * all of which must be individually valid for the entire URL to be considered 541 * valid. 542 */ 543 ResultPair[] testUrlScheme = { 544 new ResultPair("http://", true), 545 new ResultPair("ftp://", true), 546 new ResultPair("h3t://", true), 547 new ResultPair("3ht://", false), 548 new ResultPair("http:/", false), 549 new ResultPair("http:", false), 550 new ResultPair("http/", false), 551 new ResultPair("://", false), 552 new ResultPair("", true) 553 }; 554 555 ResultPair[] testUrlAuthority = { 556 new ResultPair("www.google.com", true), 557 new ResultPair("go.com", true), 558 new ResultPair("go.au", true), 559 new ResultPair("0.0.0.0", true), 560 new ResultPair("255.255.255.255", true), 561 new ResultPair("256.256.256.256", false), 562 new ResultPair("255.com", true), 563 new ResultPair("1.2.3.4.5", false), 564 new ResultPair("1.2.3.4.", false), 565 new ResultPair("1.2.3", false), 566 new ResultPair(".1.2.3.4", false), 567 new ResultPair("go.a", false), 568 new ResultPair("go.a1a", false), 569 new ResultPair("go.cc", true), 570 new ResultPair("go.1aa", false), 571 new ResultPair("aaa.", false), 572 new ResultPair(".aaa", false), 573 new ResultPair("aaa", false), 574 new ResultPair("", false) 575 }; 576 577 ResultPair[] testUrlPort = { 578 new ResultPair(":80", true), 579 new ResultPair(":65535", true), 580 new ResultPair(":0", true), 581 new ResultPair("", true), 582 new ResultPair(":-1", false), 583 new ResultPair(":65636", true), 584 new ResultPair(":65a", false) 585 }; 586 587 ResultPair[] testPath = { 588 new ResultPair("/test1", true), 589 new ResultPair("/t123", true), 590 new ResultPair("/$23", true), 591 new ResultPair("/..", false), 592 new ResultPair("/../", false), 593 new ResultPair("/test1/", true), 594 new ResultPair("", true), 595 new ResultPair("/test1/file", true), 596 new ResultPair("/..//file", false), 597 new ResultPair("/test1//file", false) 598 }; 599 600 //Test allow2slash, noFragment 601 ResultPair[] testUrlPathOptions = { 602 new ResultPair("/test1", true), 603 new ResultPair("/t123", true), 604 new ResultPair("/$23", true), 605 new ResultPair("/..", false), 606 new ResultPair("/../", false), 607 new ResultPair("/test1/", true), 608 new ResultPair("/#", false), 609 new ResultPair("", true), 610 new ResultPair("/test1/file", true), 611 new ResultPair("/t123/file", true), 612 new ResultPair("/$23/file", true), 613 new ResultPair("/../file", false), 614 new ResultPair("/..//file", false), 615 new ResultPair("/test1//file", true), 616 new ResultPair("/#/file", false) 617 }; 618 619 ResultPair[] testUrlQuery = { 620 new ResultPair("?action=view", true), 621 new ResultPair("?action=edit&mode=up", true), 622 new ResultPair("", true) 623 }; 624 625 Object[] testUrlParts = {testUrlScheme, testUrlAuthority, testUrlPort, testPath, testUrlQuery}; 626 Object[] testUrlPartsOptions = {testUrlScheme, testUrlAuthority, testUrlPort, testUrlPathOptions, testUrlQuery}; 627 int[] testPartsIndex = {0, 0, 0, 0, 0}; 628 629 //---------------- Test data for individual url parts ---------------- 630 private final String[] schemes = { 631 "http", 632 "gopher", 633 "g0-To+.", 634 "not_valid" // TODO this will need to be dropped if the ctor validates schemes 635 }; 636 637 ResultPair[] testScheme = { 638 new ResultPair("http", true), 639 new ResultPair("ftp", false), 640 new ResultPair("httpd", false), 641 new ResultPair("gopher", true), 642 new ResultPair("g0-to+.", true), 643 new ResultPair("not_valid", false), // underscore not allowed 644 new ResultPair("HtTp", true), 645 new ResultPair("telnet", false) 646 }; 633 647 } -
trunk/test/unit/org/openstreetmap/josm/gui/conflict/pair/nodes/NodeListMergeModelTest.java
r17275 r17374 76 76 protected void ensureSelected(DefaultListSelectionModel model, Object... idx) { 77 77 if (idx == null) return; 78 for ( int i = 0; i < idx.length; i++) {79 if ( idx[i]instanceof Integer) {80 int j = (Integer) idx[i];78 for (Object object : idx) { 79 if (object instanceof Integer) { 80 int j = (Integer) object; 81 81 assertTrue(model.isSelectedIndex(j), "expected row " + j + " to be selected"); 82 82 break; 83 83 } 84 int[] rows = (int[]) idx[i];84 int[] rows = (int[]) object; 85 85 if (rows.length != 2) { 86 86 fail("illegal selection range. Either null or not length 2: " + Arrays.toString(rows));
Note:
See TracChangeset
for help on using the changeset viewer.