Example usage for java.util Set size

List of usage examples for java.util Set size

Introduction

In this page you can find the example usage for java.util Set size.

Prototype

int size();

Source Link

Document

Returns the number of elements in this set (its cardinality).

Usage

From source file:de.vandermeer.skb.commons.Predicates.java

/**
 * Returns a predicate that evaluates to true if the set contains strings starting with a given character sequence.
 * @param nodes set of strings as base/*w  w  w . j  av a2 s. c  o m*/
 * @return predicate that returns true if set contains strings starting with it, false otherwise
 */
final public static Predicate<StrBuilder> CONTAINS_STRINGS_STARTING_WITH(final Set<String> nodes) {
    return new Predicate<StrBuilder>() {
        @Override
        public boolean test(final StrBuilder fqpn) {
            if (fqpn == null) {
                return false;
            }
            String key = fqpn.toString();
            if (!nodes.contains(key)) {
                return false;
            }

            Set<String> tail = new TreeSet<String>(nodes).tailSet(key, false);
            if (tail.size() == 0) {
                return false;
            }

            String child = tail.iterator().next();
            if (child.startsWith(key)) {
                return true;
            }
            return false;
        }
    };
}

From source file:de.metas.ui.web.window.datatypes.json.JSONLookupValue.java

public static final IntegerLookupValue integerLookupValueFromJsonMap(final Map<String, String> map) {
    final Set<Map.Entry<String, String>> entrySet = map.entrySet();
    if (entrySet.size() != 1) {
        throw new IllegalArgumentException("Invalid JSON lookup value: map=" + map);
    }/*w  w  w.  j a  v  a 2  s . c o m*/
    final Map.Entry<String, String> e = entrySet.iterator().next();

    String idStr = e.getKey();
    if (idStr == null) {
        return null;
    }
    idStr = idStr.trim();
    if (idStr.isEmpty()) {
        return null;
    }

    final int id = Integer.parseInt(idStr);
    final String name = e.getValue();

    return IntegerLookupValue.of(id, name);
}

From source file:misc.TestUtils.java

private static char[] toCharArray(Set<Character> set) {
    char[] ret = new char[set.size()];
    int ind = 0;/*from w  ww  .j a va2  s .  c  o m*/
    for (Character c : set) {
        ret[ind++] = c;
    }
    return ret;
}

From source file:Main.java

public static CharSequence[] getDeviceNames(@Nullable Set<BluetoothDevice> bluetoothDevices) {
    if (bluetoothDevices == null) {
        return new CharSequence[0];
    }//from w ww. j  av a 2s .  c  o  m

    BluetoothDevice[] devices = bluetoothDevices.toArray(new BluetoothDevice[bluetoothDevices.size()]);
    CharSequence[] deviceNames = new CharSequence[devices.length];

    for (int i = 0; i < deviceNames.length; i++) {
        deviceNames[i] = devices[i].getName();
    }

    return deviceNames;
}

From source file:com.h6ah4i.android.compat.utils.SharedPreferencesJsonStringSetWrapperUtils.java

public static boolean putStringSet(SharedPreferences.Editor editor, String key, Set<String> values) {
    try {//w  w  w . j ava  2  s .  c  om
        final JSONArray a = new JSONArray();
        final String[] strValues = (String[]) values.toArray(new String[values.size()]);

        for (int i = 0; i < values.size(); i++) {
            a.put(strValues[i]);
        }

        if (!values.isEmpty()) {
            editor.putString(key, a.toString());
        } else {
            editor.putString(key, null);
        }

        return editor.commit();
    } catch (RuntimeException e) {
        Log.e(TAG, "putStringSet()", e);

        return false;
    }
}

From source file:edu.wpi.checksims.util.PairGeneratorTest.java

public static void checkPairsAreInSet(Set<Pair<Submission, Submission>> toCheck,
        Set<Pair<Submission, Submission>> expected) {
    assertNotNull(toCheck);//from   w ww .  j a  va2s.  c o m
    assertNotNull(expected);

    assertEquals(expected.size(), toCheck.size());

    expected.stream().forEach((pair) -> assertTrue(
            toCheck.contains(pair) || toCheck.contains(Pair.of(pair.getRight(), pair.getLeft()))));
}

From source file:com.googlesource.gerrit.plugins.motd.MotdFileBasedConfig.java

private static List<SubnetConfig> allSubnets(FileBasedConfig cfg) {
    Set<String> names = cfg.getSubsections("subnet");
    List<SubnetConfig> result = Lists.newArrayListWithCapacity(names.size());
    for (String name : names) {
        result.add(new SubnetConfig(cfg, name));
    }/*from   ww  w  . j  a  va 2  s.c o  m*/
    return result;
}

From source file:org.springmodules.util.Strings.java

/**
 * Removes duplicates from the given String array.
 * /* w w w .jav  a  2s .c o m*/
 * @param array
 *          the given array
 * @return a new String array without duplicated entries
 */
public static String[] removeDuplicates(String[] array) {
    if (ObjectUtils.isEmpty(array)) {
        return array;
    }
    Set set = new TreeSet();

    int arraySize = array.length;
    for (int i = 0; i < arraySize; i++) {
        set.add(array[i]);
    }
    return (String[]) set.toArray(new String[set.size()]);
}

From source file:com.espertech.esper.epl.core.ResultSetProcessorHandThrough.java

/**
 * Applies the select-clause to the given events returning the selected events. The number of events stays the
 * same, i.e. this method does not filter it just transforms the result set.
 * @param exprProcessor - processes each input event and returns output event
 * @param events - input events/*from  w  w w .ja v a2  s .  c  o m*/
 * @param isNewData - indicates whether we are dealing with new data (istream) or old data (rstream)
 * @param isSynthesize - set to true to indicate that synthetic events are required for an iterator result set
 * @return output events, one for each input event
 */
protected static EventBean[] getSelectEventsNoHaving(SelectExprProcessor exprProcessor,
        Set<MultiKey<EventBean>> events, boolean isNewData, boolean isSynthesize) {
    int length = events.size();
    if (length == 0) {
        return null;
    }

    EventBean[] result = new EventBean[length];
    int count = 0;
    for (MultiKey<EventBean> key : events) {
        EventBean[] eventsPerStream = key.getArray();
        result[count] = exprProcessor.process(eventsPerStream, isNewData, isSynthesize);
        count++;
    }

    return result;
}

From source file:fr.paris.lutece.plugins.extend.util.ExtendUtils.java

/**
* Validate./*from  www  .j av a 2 s . c o  m*/
*
* @param <A> the generic type
* @param request the request
* @param bean the resource type
* @return the JSP error
*/
public static <A> String validate(HttpServletRequest request, A bean) {
    // Check mandatory fields
    Set<ConstraintViolation<A>> constraintViolations = BeanValidationUtil.validate(bean);

    if (constraintViolations.size() > 0) {
        Object[] params = { buildStopMessage(constraintViolations) };

        return AdminMessageService.getMessageUrl(request, MESSAGE_STOP_GENERIC_MESSAGE, params,
                AdminMessage.TYPE_STOP);
    }

    return StringUtils.EMPTY;
}