/** * Given the current name, append a long until a unique is found, starting at the given starting * num. */ public static String getNextUniqueValue(String name, long startingNum, String[] listOfNames) { boolean valid = true; for (int i = 0; i < Long.MAX_VALUE; i++) { StringBuffer newBuffer = new StringBuffer(name); newBuffer.append(startingNum); String test = newBuffer.toString(); if (listOfNames != null) { for (int x = 0; x < listOfNames.length; x++) { String currName = listOfNames[x]; if (StringUtil.equals(currName, test)) { valid = false; } } } if (!valid) { valid = true; startingNum++; } else { return test; } } return name; }
public boolean isAuthenticatedUser() { Principal p = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal(); if (p != null) { return StringUtil.equals(getId(), p.getName()); } return false; }
private String findUniqueUrl(CategoryNode cat, String unid, String jspUrl) { List<AbstractNode> children = cat.getChildren(); int childrenCount = children.size(); for (int i = 0; i < childrenCount; i++) { if (StringUtil.equals(children.get(i).getJspUrl(), jspUrl)) { return unid; } } return jspUrl; }
/** * Counts occurance of character in a provided string * * @param source * @param match * @return */ public static int countMatch(String source, char match) { int count = 0; if (isNotEmpty(source)) { for (int i = 0; i < source.length(); i++) { if (StringUtil.equals(source.charAt(i), match)) { count++; } } } return count; }
public static int indexOf(String[] arr, String item) { if (arr != null) { int i = 0; for (String string : arr) { if (StringUtil.equals(string, item)) { return i; } i++; } } return -1; }
/** * This is mostly for dump/debug capability * * @param key * @return */ @Override public Object getFieldByProvider(String provider, String key) { PeopleDataProvider[] dataProviders = (PeopleDataProvider[]) getService().getResourceDataProviders(); for (int i = 0; i < dataProviders.length; i++) { PeopleDataProvider pd = dataProviders[i]; if (StringUtil.equals(pd.getName(), provider)) { if (pd instanceof AbstractPeopleDataProvider) { Object value = ((AbstractPeopleDataProvider) pd).getValue(this, key); return value; } } } return null; }
private CategoryNode findCategory(CategoryNode parent, String[] cats, int level) { List<AbstractNode> children = parent.getChildren(); CategoryNode found = null; for (int i = 0; i < children.size(); i++) { AbstractNode c = children.get(i); if (c instanceof CategoryNode) { if (StringUtil.equals(cats[level], c.getName())) { found = (CategoryNode) c; break; } } } if (found == null) { found = new CategoryNode(parent, cats[level]); parent.getChildren().add(found); } if (level < cats.length - 1) { return findCategory(found, cats, level + 1); } return found; }
public boolean isViewer() { UserBean b = UserBean.get(); return StringUtil.equals(b.getId(), getId()); }