code
stringlengths
73
34.1k
label
stringclasses
1 value
public Method findMethod (String methodName, Class<?>[] parameterTypes) throws NoSuchMethodException { // make sure the constructor list is loaded maybeLoadMethods(); List<Member> methodList = _methodMap.get(methodName); if (methodList == null) { throw new NoSuch...
java
protected void maybeLoadConstructors () { if (_ctorList == null) { _ctorList = new ArrayList<Member>(); Constructor<?>[] ctors = _clazz.getConstructors(); for (int i = 0; i < ctors.length; ++i) { _ctorList.add(ctors[i]); _paramMap.put(ctors...
java
protected void maybeLoadMethods () { if (_methodMap == null) { _methodMap = new HashMap<String,List<Member>>(); Method[] methods = _clazz.getMethods(); for (int i = 0; i < methods.length; ++i) { Method m = methods[i]; String methodName = m...
java
public static <A, B> B foldLeft (F<B,A> func, B zero, Iterable<? extends A> values) { for (A value : values) { zero = func.apply(zero, value); } return zero; }
java
public static <A> A reduceLeft (F<A,A> func, Iterable<? extends A> values) { Iterator<? extends A> iter = values.iterator(); A zero = iter.next(); while (iter.hasNext()) { zero = func.apply(zero, iter.next()); } return zero; }
java
public static int sum (int zero, Iterable<? extends Number> values) { for (Number value : values) { zero += value.intValue(); } return zero; }
java
public static long sum (long zero, Iterable<? extends Number> values) { for (Number value : values) { zero += value.longValue(); } return zero; }
java
public static float sum (float zero, Iterable<? extends Number> values) { for (Number value : values) { zero += value.floatValue(); } return zero; }
java
public static double sum (double zero, Iterable<? extends Number> values) { for (Number value : values) { zero += value.doubleValue(); } return zero; }
java
public static BigInteger sum (BigInteger zero, Iterable<? extends BigInteger> values) { for (BigInteger value : values) { zero = zero.add(value); } return zero; }
java
public static String truncate (String text, int length, String append) { return StringUtil.truncate(text, length, append); }
java
public static String join (String[] values, String sep) { return StringUtil.join(values, sep); }
java
public static String copyright (String holder, int startYear) { Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); return "&copy; " + holder + " " + startYear + "-" + year; }
java
public void render (Component host, RadialMenu menu, Graphics2D gfx, int x, int y) { paint(gfx, x, y, menu); }
java
public void addObject (int x, int y, Object object) { Record record = new Record(x, y, object); // if this is the very first element, we have to insert it // straight away because our binary search algorithm doesn't work // on empty arrays if (_size == 0) { _reco...
java
public static int distance (int x1, int y1, int x2, int y2) { int dx = x1-x2, dy = y1-y2; return (int)Math.sqrt(dx*dx+dy*dy); }
java
protected int binarySearch (int x) { // copied from java.util.Arrays which I wouldn't have to have done had the provided a // means by which to binarySearch in a subset of an array. alas. int low = 0; int high = _size-1; while (low <= high) { int mid = (low + hig...
java
public static String compose (String key, Object... args) { StringBuilder buf = new StringBuilder(); buf.append(key); buf.append('|'); for (int i = 0; i < args.length; i++) { if (i > 0) { buf.append('|'); } // escape the string whil...
java
public static String unescape (String value) { int bsidx = value.indexOf('\\'); if (bsidx == -1) { return value; } StringBuilder buf = new StringBuilder(); int vlength = value.length(); for (int ii = 0; ii < vlength; ii++) { char ch = value.ch...
java
public static String[] decompose (String compoundKey) { String[] args = compoundKey.split("\\|"); for (int ii = 0; ii < args.length; ii++) { args[ii] = unescape(args[ii]); } return args; }
java
public static String qualify (String bundle, String key) { // sanity check if (bundle.indexOf(QUAL_PREFIX) != -1 || bundle.indexOf(QUAL_SEP) != -1) { String errmsg = "Message bundle may not contain '" + QUAL_PREFIX + "' or '" + QUAL_SEP + "' [bundle=" + bundle...
java
public static String getBundle (String qualifiedKey) { if (!qualifiedKey.startsWith(QUAL_PREFIX)) { throw new IllegalArgumentException( qualifiedKey + " is not a fully qualified message key."); } int qsidx = qualifiedKey.indexOf(QUAL_SEP); if (qsidx == -1...
java
public static String getUnqualifiedKey (String qualifiedKey) { if (!qualifiedKey.startsWith(QUAL_PREFIX)) { throw new IllegalArgumentException( qualifiedKey + " is not a fully qualified message key."); } int qsidx = qualifiedKey.indexOf(QUAL_SEP); if (qsi...
java
public int createUser ( Username username, Password password, String realname, String email, int siteId) throws UserExistsException, PersistenceException { // create a new user object... User user = new User(); user.setDirtyMask(_utable.getFieldMask()); // ...configu...
java
public User loadUserBySession (String sessionKey) throws PersistenceException { User user = load(_utable, "sessions", "where authcode = '" + sessionKey + "' " + "AND sessions.userId = users.userId"); if (user != null) { user.setDirtyMask(_utable.getFieldM...
java
public HashIntMap<User> loadUsersFromId (int[] userIds) throws PersistenceException { HashIntMap<User> data = new HashIntMap<User>(); if (userIds.length > 0) { String query = "where userId in (" + genIdString(userIds) + ")"; for (User user : loadAll(_utable, query)) {...
java
public ArrayList<User> lookupUsersByEmail (String email) throws PersistenceException { return loadAll(_utable, "where email = " + JDBCUtil.escape(email)); }
java
public ArrayList<User> lookupUsersWhere (final String where) throws PersistenceException { ArrayList<User> users = loadAll(_utable, where); for (User user : users) { // configure the user record with its field mask user.setDirtyMask(_utable.getFieldMask()); } ...
java
public boolean updateUser (final User user) throws PersistenceException { if (!user.getDirtyMask().isModified()) { // nothing doing! return false; } update(_utable, user, user.getDirtyMask()); return true; }
java
public void deleteUser (final User user) throws PersistenceException { if (user.isDeleted()) { return; } executeUpdate(new Operation<Object>() { public Object invoke (Connection conn, DatabaseLiaison liaison) throws PersistenceException, SQLEx...
java
public String registerSession (User user, int expireDays) throws PersistenceException { // look for an existing session for this user final String query = "select authcode from sessions where userId = " + user.userId; String authcode = execute(new Operation<String>() { pu...
java
public boolean refreshSession (String sessionKey, int expireDays) throws PersistenceException { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, expireDays); Date expires = new Date(cal.getTime().getTime()); // attempt to update an existing session row, returnin...
java
public String[] loadAllRealNames () throws PersistenceException { final ArrayList<String> names = new ArrayList<String>(); // do the query execute(new Operation<Object>() { public Object invoke (Connection conn, DatabaseLiaison liaison) throws Persistence...
java
protected void populateUser ( User user, Username name, Password pass, String realname, String email, int siteId) { user.username = name.getUsername(); user.setPassword(pass); user.setRealName(realname); user.setEmail(email); user.created = new Date(System.currentTime...
java
protected int insertUser (final User user) throws UserExistsException, PersistenceException { executeUpdate(new Operation<Object>() { public Object invoke (Connection conn, DatabaseLiaison liaison) throws PersistenceException, SQLException { tr...
java
protected User loadUserWhere (String where) throws PersistenceException { User user = load(_utable, where); if (user != null) { user.setDirtyMask(_utable.getFieldMask()); } return user; }
java
public static synchronized void setToggling (AbstractButton b) { if (_toggler == null) { _toggler = new ActionListener () { public void actionPerformed (ActionEvent event) { AbstractButton but = (AbstractButton) event.getSource(); ...
java
public static ActionListener cycleToProperty ( final String property, final PrefsConfig config, AbstractButton button, final int[] values) { ActionListener al = new ActionListener() { public void actionPerformed (ActionEvent event) { // get the current...
java
@Override // from DatabaseLiaison public boolean createTableIfMissing (Connection conn, String table, List<String> columns, List<ColumnDefinition> defns, List<List<String>> uniqueColumns, List<String> pkColumns) throws SQLExce...
java
private boolean canAddTableToFromClause(Table table, Map<Table, List<JoinCriteria>> destMap, List<Table> allTables) { if ((table == null) || allTables.contains(table)) { return false; } if ((destMap.get(table) != null) && (destMap.get(table).size() > 0)) { List<JoinCriteria> list = destMap.ge...
java
public static <T> void sort (T[] a, Comparator<? super T> comp) { sort(a, 0, a.length - 1, comp); }
java
public static <T extends Comparable<? super T>> void sort (T[] a) { sort(a, 0, a.length - 1); }
java
public static <T> void rsort (T[] a, Comparator<? super T> comp) { rsort(a, 0, a.length - 1, comp); }
java
public static <T extends Comparable<? super T>> void rsort (T[] a) { rsort(a, 0, a.length - 1); }
java
public static <T> void sort (T[] a, int lo0, int hi0, Comparator<? super T> comp) { // bail out if we're already done if (hi0 <= lo0) { return; } T t; // if this is a two element file, do a simple sort on it if (hi0 - lo0 == 1) { // if they'r...
java
public static <T extends Comparable<? super T>> void sort (T[] a, int lo0, int hi0) { // bail out if we're already done if (hi0 <= lo0) { return; } T t; // if this is a two element file, do a simple sort on it if (hi0 - lo0 == 1) { // if they...
java
public static <T extends Comparable<? super T>> void sort (List<T> a) { sort(a, new Comparator<T>() { public int compare (T o1, T o2) { if (o1 == o2) { // catches null == null return 0; } else if (o1 == null) { return 1; ...
java
public static <T> void sort (List<T> a, Comparator<? super T> comp) { sort(a, 0, a.size() - 1, comp); }
java
public static <T> void rsort (List<T> a, Comparator<? super T> comp) { sort(a, Collections.reverseOrder(comp)); }
java
public static <T> void sort (List<T> a, int lo0, int hi0, Comparator<? super T> comp) { // bail out if we're already done if (hi0 <= lo0) { return; } T e1, e2; // if this is a two element file, do a simple sort on it if (hi0 - lo0 == 1) { // ...
java
@ReplacedBy("com.google.common.collect.Iterators#concat() or com.google.common.collect.Iterables#concat()") public static <T> Iterator<T> getMetaIterator (Iterable<Iterator<T>> metaIterable) { return new MetaIterator<T>(metaIterable); }
java
public static <T extends Comparable<? super T>> Iterator<T> getSortedIterator (Iterable<T> coll) { return getSortedIterator(coll.iterator(), new Comparator<T>() { public int compare (T o1, T o2) { if (o1 == o2) { // catches null == null return 0; ...
java
public static <T> Iterator<T> getSortedIterator (Iterable<T> coll, Comparator<T> comparator) { return getSortedIterator(coll.iterator(), comparator); }
java
public static <T extends Comparable<? super T>> Iterator<T> getSortedIterator (Iterator<T> itr) { return getSortedIterator(itr, new Comparator<T>() { public int compare (T o1, T o2) { if (o1 == o2) { // catches null == null return 0; } else if ...
java
public static <T> Iterator<T> getSortedIterator (Iterator<T> itr, Comparator<T> comparator) { SortableArrayList<T> list = new SortableArrayList<T>(); CollectionUtil.addAll(list, itr); list.sort(comparator); return getUnmodifiableIterator(list); }
java
public static <T> Iterator<T> getRandomIterator (Iterable<T> c) { return getRandomIterator(c.iterator()); }
java
public static <T> Iterator<T> getRandomIterator (Iterator<T> itr) { ArrayList<T> list = new ArrayList<T>(); CollectionUtil.addAll(list, itr); java.util.Collections.shuffle(list); return getUnmodifiableIterator(list); }
java
public static <T> Iterator<T> getUnmodifiableIterator (Iterable<T> c) { return getUnmodifiableIterator(c.iterator()); }
java
@ReplacedBy("com.google.common.collect.Iterators#unmodifiableIterator()") public static <T> Iterator<T> getUnmodifiableIterator (final Iterator<T> itr) { return new Iterator<T>() { public boolean hasNext () { return itr.hasNext(); } public T next () { ...
java
public static Object unmarshal (Class<?> type, String source) throws Exception { if (type.isEnum()) { // we need to use a dummy enum type here as there's no way to ask Enum.valueOf to // execute on an existentially typed enum; it all works out under the hood @Supp...
java
protected final void rangeCheck (int index, boolean insert) { if ((index < 0) || (insert ? (index > _size) : (index >= _size))) { throw new IndexOutOfBoundsException( "Index: " + index + ", Size: " + _size); } }
java
public Class getValueClass() { if (valueClass == null) { if (valueClassName != null) { try { valueClass = Class.forName(valueClassName); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } } return valueClass; }
java
public void setPreviewValue(String previewValue) { if (!isProcedureParameter && (previewValue != null)) { throw new IllegalArgumentException("Parameter '" + name + "' is not a procedure parameter."); } this.previewValue = previewValue; }
java
public String getValue (String name, String defval) { return _props.getProperty(name, defval); }
java
public Object instantiateValue (String name, String defcname) throws Exception { return Class.forName(getValue(name, defcname)).newInstance(); }
java
public Iterator<String> keys () { HashSet<String> matches = new HashSet<String>(); enumerateKeys(matches); return matches.iterator(); }
java
private void put(PrintStream p, String s, int column, int colSpan, BandElement bandElement) { if (s == null) { // nl(); put(p, "", column, colSpan, bandElement); return; } int size = 0; if (colSpan > 1) { for (int i=column; i<c...
java
protected static PropRecord parseMetaData (String path, URL sourceURL) throws IOException { InputStream input = sourceURL.openStream(); BufferedReader bin = new BufferedReader(new InputStreamReader(input)); try { PropRecord record = new PropRecord(path, sourceURL); ...
java
public static InputStream getStream (String path, ClassLoader loader) { // first try the supplied class loader InputStream in = getResourceAsStream(path, loader); if (in != null) { return in; } // if that didn't work, try the system class loader (but only if it's...
java
public boolean waitForResponse () throws TimeoutException { if (_success == 0) { synchronized (this) { try { // wait for the response, timing out after a while if (_timeout == NO_TIMEOUT) { wait(); ...
java
public static final <T> T silenceDeepCopy(T object) { try { return deepCopy(object); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
java
public final boolean isModified () { int mcount = _modified.length; for (int ii = 0; ii < mcount; ii++) { if (_modified[ii]) { return true; } } return false; }
java
public final boolean isModified (String fieldName) { Integer index = _descripMap.get(fieldName); if (index == null) { throw new IllegalArgumentException("Field not in mask: " + fieldName); } return _modified[index.intValue()]; }
java
public final boolean onlySubsetModified (Set<String> fieldSet) { for (String field : _descripMap.keySet()) { if (isModified(field) && (!fieldSet.contains(field))) { return false; } } return true; }
java
public void setModified (String fieldName) { Integer index = _descripMap.get(fieldName); if (index == null) { throw new IllegalArgumentException("Field not in mask: " + fieldName); } _modified[index.intValue()] = true; }
java
public void addValue (int value) { if (value < _minValue) { _buckets[0]++; } else if (value >= _maxValue) { _buckets[_buckets.length-1]++; } else { _buckets[(value-_minValue)/_bucketWidth]++; } _count++; }
java
public String summarize () { StringBuilder buf = new StringBuilder(); buf.append(_count).append(":"); for (int ii = 0; ii < _buckets.length; ii++) { if (ii > 0) { buf.append(","); } buf.append(_buckets[ii]); } return buf.toS...
java
public <E extends T> Iterator<E> filter (final Iterator<E> input) { return new Iterator<E>() { // from Iterator public boolean hasNext () { return _found || findNext(); } // from Iterator public E next () { ...
java
public <E extends T> void filter (Collection<E> coll) { for (Iterator<E> itr = coll.iterator(); itr.hasNext(); ) { if (!isMatch(itr.next())) { itr.remove(); } } }
java
public <E extends T> Iterable<E> createView (final Iterable<E> input) { return new Iterable<E>() { public Iterator<E> iterator() { return filter(input.iterator()); } }; }
java
public <E extends T> Collection<E> createView (final Collection<E> input) { // TODO: create a collection of the same type? return new AbstractCollection<E>() { @Override public int size () { // oh god, oh god: we iterate and count int size = 0;...
java
public static Builder at (long millis) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(millis); return with(calendar); }
java
public static Builder at (int year, int month, int day) { Calendar calendar = Calendar.getInstance(); calendar.set(year, month, day); return with(calendar).zeroTime(); }
java
public static Builder in (TimeZone zone, Locale locale) { return with(Calendar.getInstance(zone, locale)); }
java
public RadialMenuItem addMenuItem (String command, String label, Image icon, Predicate predicate) { RadialMenuItem item = new RadialMenuItem(command, label, new ImageIcon(icon), predicate); addMenuItem(item); return item; }
java
public boolean removeMenuItem (String command) { int icount = _items.size(); for (int i = 0; i < icount; i++) { RadialMenuItem item = _items.get(i); if (item.command.equals(command)) { _items.remove(i); return true; } } ...
java
public void deactivate () { if (_host != null) { // unwire ourselves from the host component Component comp = _host.getComponent(); comp.removeMouseListener(this); comp.removeMouseMotionListener(this); // reinstate the previous mouse listeners ...
java
public void render (Graphics2D gfx) { Component host = _host.getComponent(); int x = _bounds.x, y = _bounds.y; if (_centerLabel != null) { // render the centerpiece label _centerLabel.paint(gfx, x + _centerLabel.closedBounds.x, y + _ce...
java
protected void repaint () { // only repaint the area that we overlap _host.repaintRect(_bounds.x, _bounds.y, _bounds.width+1, _bounds.height+1); }
java
public static String currency (double value, Locale locale) { return currency(value, NumberFormat.getCurrencyInstance(locale)); }
java
protected <T> int update (final Table<T> table, final T object, final FieldMask mask) throws PersistenceException { return executeUpdate(new Operation<Integer>() { public Integer invoke (Connection conn, DatabaseLiaison liaison) throws SQLExc...
java
protected <T> ArrayList<T> loadAll (final Table<T> table, final String query) throws PersistenceException { return execute(new Operation<ArrayList<T>>() { public ArrayList<T> invoke ( Connection conn, DatabaseLiaison liaison) ...
java
protected <T> ArrayList<T> loadAllByExample ( final Table<T> table, final T example) throws PersistenceException { return execute(new Operation<ArrayList<T>>() { public ArrayList<T> invoke ( Connection conn, DatabaseLiaison liaison) throws SQLExcep...
java
protected <T> int store (final Table<T> table, final T object) throws PersistenceException { return executeUpdate(new Operation<Integer>() { public Integer invoke (Connection conn, DatabaseLiaison liaison) throws SQLException, PersistenceException { ...
java
public String fixedText (String name, String extra, Object value) { return fixedInput("text", name, value, extra); }
java
public String submitExtra (String name, String text, String extra) { return fixedInput("submit", name, text, extra); }
java
public String imageSubmit (String name, String value, String imagePath) { return fixedInput("image", name, value, "src=\"" + imagePath + "\""); }
java
public String button (String name, String text, String extra) { return fixedInput("button", name, text, extra); }
java
public String hidden (String name, Object defaultValue) { return fixedHidden(name, getValue(name, defaultValue)); }
java
public String checkbox (String name, boolean defaultValue) { String value = getParameter(name); return fixedCheckbox( name, (value == null) ? defaultValue : !value.equals("")); }
java