Changeset 4065 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2011-05-01T21:56:49+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r3979 r4065 3 3 4 4 import java.awt.Color; 5 import java.io.File; 6 import java.io.IOException; 7 import java.io.InputStream; 8 import java.io.OutputStream; 5 9 import java.util.Collection; 6 10 … … 15 19 } 16 20 17 public static <T> boolean exists(Iterable collection, Class<? extends T> klass) {21 public static <T> boolean exists(Iterable<T> collection, Class<? extends T> klass) { 18 22 for (Object item : collection) { 19 23 if (klass.isInstance(item)) … … 31 35 } 32 36 33 public static <T> T find(Iterable collection, Class<? extends T> klass) { 37 @SuppressWarnings("unchecked") 38 public static <T> T find(Iterable<? super T> collection, Class<? extends T> klass) { 34 39 for (Object item : collection) { 35 if (klass.isInstance(item)) { 36 @SuppressWarnings("unchecked") T res = (T) item; 37 return res; 38 } 40 if (klass.isInstance(item)) 41 return (T) item; 39 42 } 40 43 return null; … … 60 63 return b; 61 64 } else { 62 if (a < c) {65 if (a < c) 63 66 return a; 64 }65 67 return c; 66 68 } … … 160 162 } 161 163 164 165 public static int copyStream(InputStream source, OutputStream destination) throws IOException { 166 int count = 0; 167 byte[] b = new byte[512]; 168 int read; 169 while ((read = source.read(b)) != -1) { 170 count += read; 171 destination.write(b, 0, read); 172 } 173 return count; 174 } 175 176 177 162 178 public static Color complement(Color clr) { 163 179 return new Color(255 - clr.getRed(), 255 - clr.getGreen(), 255 - clr.getBlue(), clr.getAlpha()); 164 180 } 181 182 public static boolean deleteDirectory(File path) { 183 if( path.exists() ) { 184 File[] files = path.listFiles(); 185 for(int i=0; i<files.length; i++) { 186 if(files[i].isDirectory()) { 187 deleteDirectory(files[i]); 188 } 189 else { 190 files[i].delete(); 191 } 192 } 193 } 194 return( path.delete() ); 195 } 165 196 }
Note:
See TracChangeset
for help on using the changeset viewer.