List of usage examples for java.util Set isEmpty
boolean isEmpty();
From source file:Main.java
public static Set<BluetoothDevice> findPaired() { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); Set<BluetoothDevice> devices = bluetoothAdapter.getBondedDevices(); if (devices == null || devices.isEmpty()) { return null; } else {/*w w w . j av a2s . c om*/ return devices; } }
From source file:Main.java
/** * Check if set isn't empty./*ww w. j av a 2 s . c om*/ * * @param set * The set to be tested. * @return <code>true</code> is not empty, <code>false</code> otherwise. */ public static <E> boolean isNotEmpty(Set<E> set) { return set != null && !set.isEmpty(); }
From source file:cn.hxh.springside.utils.validator.ValidatorUtils.java
/** * JSR303validate, ?ConstraintViolationException. *//*ww w .j a v a 2 s.c o m*/ public static void validateWithException(Validator validator, Object object, Class<?>... groups) throws ConstraintViolationException { Set constraintViolations = validator.validate(object, groups); if (!constraintViolations.isEmpty()) { throw new ConstraintViolationException(constraintViolations); } }
From source file:org.mashupmedia.util.AdminHelper.java
public static boolean isAdministrator(User user) { if (user == null) { return false; }//from w w w . ja v a 2 s .c om Set<Role> roles = user.getRoles(); if (roles == null || roles.isEmpty()) { return false; } for (Role role : roles) { if (role.getIdName().equalsIgnoreCase(ROLE_ADMIN_IDNAME)) { return true; } } return false; }
From source file:Main.java
/** * @param sa a set/*from w w w .j a v a 2s . c o m*/ * @param sb anotehr set * @return the intersection of <code>sa</code> and <code>sb</code> */ public static <E> Set<E> intersection(Set<E> sa, Set<E> sb) { Set<E> result = new HashSet<E>(); if (sa == null || sb == null || sa.isEmpty() || sb.isEmpty()) return result; Set<E> smallest = sa.size() < sb.size() ? sa : sb; Set<E> biggest = smallest == sa ? sb : sa; for (E entry : smallest) { if (biggest.contains(entry)) result.add(entry); } return result; }
From source file:com.google.mr4c.config.ConfigUtils.java
public static boolean containsVariables(String content) { Set<String> vars = extractVariables(content); return !vars.isEmpty(); }
From source file:Main.java
/** * Removes the value from the set of values mapped by key. If this value was the last value in the set of values * mapped by key, the complete key/values entry is removed. * //from w w w .j a va 2 s . c om * @param key * The key for which to remove a value. * @param value * The value for which to remove the key. * @param map * The object that maps the key to a set of values, on which the operation should occur. */ public static <K, V> void deleteAndRemove(final K key, final V value, final Map<K, Set<V>> map) { if (key == null) { throw new IllegalArgumentException("Argument 'key' cannot be null."); } if (value == null) { throw new IllegalArgumentException("Argument 'value' cannot be null."); } if (map == null) { throw new IllegalArgumentException("Argument 'map' cannot be null."); } if (map.isEmpty() || !map.containsKey(key)) { return; } final Set<V> values = map.get(key); values.remove(value); if (values.isEmpty()) { map.remove(key); } }
From source file:Main.java
/** * Creates an unmodifiable shallow copy of the given original {@link Set}. <p> While the copy returns an immutable * copy of the {@link Set} the content is not cloned in any way. Unless the content is immutable by itself the * result is not fully immutable. In the shallow copy all references are the same as in the original {@link Set}! * </p>/*from w w w.j av a 2 s . c o m*/ * * @param original The {@link Set} to copy the elements fro. * @param <E> The type of the elements * * @return Returns an immutable (unmodifiable) copy of the original {@link Set} with all the elements added but not * cloned! */ public static <E> Set<E> createUnmodifiableShallowCopy(final Set<E> original) { if (original == null || original.isEmpty()) { return Collections.emptySet(); } else { return Collections.unmodifiableSet(new HashSet<E>(original)); } }
From source file:guru.nidi.ramlproxy.report.ReportFormat.java
private static void addIfNonempty(StringBuilder base, String desc, Set<String> s) { if (!s.isEmpty()) { base.append(desc + ": " + s + "\n"); }/*from w ww .j av a 2 s . co m*/ }
From source file:io.fabric8.vertx.maven.plugin.utils.GroovyExtensionCombiner.java
private static byte[] read(Set<String> lines) { if (lines == null || lines.isEmpty()) { return new byte[0]; }/*from www . java 2 s . c o m*/ StringBuilder buffer = new StringBuilder(); for (String l : lines) { buffer.append(l).append("\n"); } return buffer.toString().getBytes(); }