@Override public boolean hasNext() { try { next = reader.readLine(); if (next == null) { reader.close(); return false; } return true; }catch(IOException e) { throw X_Util.rethrow(e); } }
@Override public boolean findRemove(E value, boolean all) { ListIterator<E> iter = list.listIterator(); boolean removed = false; while (iter.hasNext()) { E next = iter.next(); if (X_Util.equal(next, value)) { iter.remove(); if (!all) return true; removed = true; } } return removed; }
@Override public Iterator<String> iterator() { try { // reader is closed by StringReader BufferedReader reader = new BufferedReader(new InputStreamReader(open())); return new StringReader(reader); } catch (IOException e) { throw X_Util.rethrow(e); } } };
@Override public boolean equals(Object obj) { if (obj == this)return true; if (obj instanceof Pair){ Pair<?, ?> that = (Pair<?, ?>) obj; if (X_Util.equal(x, that.get0())){ return X_Util.equal(y, that.get1()); } } if (obj instanceof Entry){ Entry<?, ?> that = (Entry<?, ?>) obj; if (X_Util.equal(x, that.getKey())){ return X_Util.equal(y, that.getValue()); } } return false; }
@Override public Model loadPomString(String pomString) throws XmlPullParserException { try { return new MavenXpp3Reader().read(new StringReader(pomString)); } catch (IOException ignored) { throw X_Util.rethrow(ignored); } }
@Override public final boolean contains(final E value) { for (final E e : forEach()) { if (X_Util.equal(value, e)) { return true; } } return false; }
static ResourceCollection fromUrl(URL url, String pkg) { String path = url.toExternalForm(); File file; boolean jarUrl = path.startsWith("jar:"); if (jarUrl) path = path.substring("jar:".length()); boolean fileUrl = path.startsWith("file:"); if (fileUrl) path = path.substring("file:".length()); boolean jarFile = path.contains(".jar!"); if (jarFile) path = path.substring(0, path.indexOf(".jar!") + ".jar".length()); if (!(file = new java.io.File(path)).exists()) { path = path.replace("%20", " "); if (!(file = new java.io.File(path)).exists()) { //should be impossible since we get these urls from classloader throw X_Util.rethrow(new FileNotFoundException()); } } try { //TODO getOrMake; use an InitWithParamMap if (url.getProtocol().equals("jar")) { return new ResourceCollection(pkg, ((JarURLConnection)url.openConnection()).getJarFile()); } assert url.getProtocol().equals("file") : "ResourceCollection only handles url and file protocols"; if (jarFile) { return new ResourceCollection(pkg, new JarFile(file)); } return new ResourceCollection(file); }catch (IOException e) { throw X_Util.rethrow(e); } }
public boolean ifNext(K position) { if (equal(todo[this.position], position)) { bump(); return true; } return false; }
protected <X> X create(Class<? extends X> renderer) { try { return renderer.newInstance(); } catch (InstantiationException e) { throw X_Debug.rethrow(e.getCause() == null ? e : e.getCause()); } catch (IllegalAccessException e) { throw X_Util.rethrow(e); } }
@Override public final int indexOf(final E value) { for (int i = 0, m = size(); i < m; i++) { if (X_Util.equal(getValue(i), value)) { return i; } } return -1; }
public static synchronized File getXApiHome() { // We purposely don't cache this value so users can change it at runtime. String loc = X_Properties.getProperty(X_Namespace.PROPERTY_XAPI_HOME); try { if (loc == null) { // use a temporary directory instead File f = File.createTempFile("xapi", "home"); loc = f.getAbsolutePath(); X_Properties.setProperty(X_Namespace.PROPERTY_XAPI_HOME, loc); return f; } File home = new File(loc); if (!home.exists()) { X_Log.info("XApi home @ "+home.getCanonicalPath()+" does not exist."); if (home.mkdirs()) { X_Log.info("Successfully created home directory"); } else { X_Log.warn("Unable to create home directory; using temp file."); X_Properties.setProperty(X_Namespace.PROPERTY_XAPI_HOME, null); return getXApiHome(); } } return home; } catch (Throwable e) { throw X_Util.rethrow(e); } }
@Override public final boolean findRemove(final E value, final boolean all) { boolean removed = false; for (int i = 0, m = size(); i < m; i++) { final E next = getValue(i); if (X_Util.equal(next, value)) { remove(i--); if (!all) { return true; } removed = true; } } return removed; }