public static void addAll(Vector to, Vector all) { synchronized (to) { for (int i = 0; i < all.size(); ++i) { to.addElement(all.elementAt(i)); } } }
public static void addNew(Vector to, Vector all) { synchronized (to) { for (int i = 0; i < all.size(); ++i) { if (0 <= Util.getIndex(to, all.elementAt(i))) continue; to.addElement(all.elementAt(i)); } } }
/* Divide text to array of parts using serparator charaster */ public static String[] explode(String text, char separator) { if (StringUtils.isEmpty(text)) { return new String[0]; } Vector<String> tmp = new Vector<String>(); int start = 0; int end = text.indexOf(separator, start); while (end >= start) { tmp.addElement(text.substring(start, end)); start = end + 1; end = text.indexOf(separator, start); } tmp.addElement(text.substring(start)); String[] result = new String[tmp.size()]; tmp.copyInto(result); return result; }
private static void putUrl(Vector<String> urls, String url) { final String skip = "?!;:,."; final String openDelemiters = "{[(«"; final String delemiters = "}])»"; int cutIndex = url.length() - 1; for (; cutIndex >= 0; --cutIndex) { char lastChar = url.charAt(cutIndex); if (-1 != skip.indexOf(lastChar)) { continue; } int delemiterIndex = delemiters.indexOf(lastChar); if (-1 != delemiterIndex) { if (-1 == url.indexOf(openDelemiters.charAt(delemiterIndex))) { continue; } } break; } if (cutIndex <= 0) { return; } else if (cutIndex != url.length() - 1) { url = url.substring(0, cutIndex + 1); } if (-1 == url.indexOf(':')) { boolean isPhone = ('+' == url.charAt(0)); boolean hasDot = false; boolean nonDigit = false; for (int i = isPhone ? 1 : 0; i < url.length(); ++i) { char ch = url.charAt(i); if ('.' == ch) { hasDot = true; } else if (!Character.isDigit(ch)) { nonDigit = true; break; } } if (isPhone) { if (!nonDigit && !hasDot && (7 <= url.length())) { url = "tel:" + url; } else { return; } } else { if (nonDigit) { if (-1 == url.indexOf('/')) { if (-1 == url.indexOf('@')) return; // jid or email } else { url = "http:\57\57" + url; } } else { return; } } } int protoEnd = url.indexOf(':'); if (-1 != protoEnd) { if (url.length() <= protoEnd + 5) { return; } for (int i = 0; i < protoEnd; ++i) { if (!isURLChar(url.charAt(i), URL_CHAR_PROTOCOL)) { return; } } } if (!urls.contains(url)) { urls.addElement(url); } }