List of usage examples for java.util Set isEmpty
boolean isEmpty();
From source file:io.wcm.dam.assetservice.impl.DamPathHandler.java
private static Set<String> validateDamPaths(String[] damPaths) { Set<String> paths = new HashSet<>(); if (damPaths != null) { for (String path : damPaths) { if (StringUtils.isNotBlank(path)) { paths.add(path);//from w ww. java 2 s.c o m } } } if (paths.isEmpty()) { paths.add(DEFAULT_DAM_PATH); } return ImmutableSet.copyOf(paths); }
From source file:com.enonic.cms.core.search.builder.ContentIndexDataFieldValueSetFactory.java
public static Set<ContentIndexDataFieldAndValue> create(ContentIndexDataElement element) { final Set<ContentIndexDataFieldAndValue> contentIndexDataFieldAndValues = Sets.newHashSet(); addStringFieldValue(element, contentIndexDataFieldAndValues); addNumericFieldValue(element, contentIndexDataFieldAndValues); addDateFieldValue(element, contentIndexDataFieldAndValues); if (!contentIndexDataFieldAndValues.isEmpty()) { addOrderbyValue(element, contentIndexDataFieldAndValues); }//www .j ava2s . c o m return contentIndexDataFieldAndValues; }
From source file:com.h6ah4i.android.compat.utils.SharedPreferencesJsonStringSetWrapperUtils.java
public static boolean putStringSet(SharedPreferences.Editor editor, String key, Set<String> values) { try {//from w ww . j ava 2s .c o m 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:com.qrmedia.commons.persistence.hibernate.clone.HibernateEntityBeanCloner.java
private static Collection<String> calculateTargetedFieldNames(Object entity, boolean preserveIdFields) { Collection<String> targetedFieldNames = new ArrayList<String>(); Class<?> entityClass = entity.getClass(); for (Field field : ClassUtils.getAllDeclaredFields(entityClass)) { String fieldName = field.getName(); // ignore static members and members without a valid getter and setter if (!Modifier.isStatic(field.getModifiers()) && PropertyUtils.isReadable(entity, fieldName) && PropertyUtils.isWriteable(entity, fieldName)) { targetedFieldNames.add(field.getName()); }/*from w w w . jav a 2 s . c o m*/ } /* * Assume that, in accordance with recommendations, entities are using *either* JPA property * *or* field access. Guess the access type from the location of the @Id annotation, as * Hibernate does. */ Set<Method> idAnnotatedMethods = ClassUtils.getAnnotatedMethods(entityClass, Id.class); boolean usingFieldAccess = idAnnotatedMethods.isEmpty(); // ignore fields annotated with @Version and, optionally, @Id targetedFieldNames.removeAll(usingFieldAccess ? getFieldNames(ClassUtils.getAllAnnotatedDeclaredFields(entityClass, Version.class)) : getPropertyNames(ClassUtils.getAnnotatedMethods(entityClass, Version.class))); if (!preserveIdFields) { targetedFieldNames.removeAll(usingFieldAccess ? getFieldNames(ClassUtils.getAllAnnotatedDeclaredFields(entityClass, Id.class)) : getPropertyNames(idAnnotatedMethods)); } return targetedFieldNames; }
From source file:com.flipkart.foxtrot.core.TestUtils.java
public static void registerActions(AnalyticsLoader analyticsLoader, ObjectMapper mapper) throws Exception { Reflections reflections = new Reflections("com.flipkart.foxtrot", new SubTypesScanner()); Set<Class<? extends Action>> actions = reflections.getSubTypesOf(Action.class); if (actions.isEmpty()) { throw new Exception("No analytics actions found!!"); }/* ww w . j ava2 s. c o m*/ List<NamedType> types = new Vector<NamedType>(); for (Class<? extends Action> action : actions) { AnalyticsProvider analyticsProvider = action.getAnnotation(AnalyticsProvider.class); if (null == analyticsProvider.request() || null == analyticsProvider.opcode() || analyticsProvider.opcode().isEmpty() || null == analyticsProvider.response()) { throw new Exception("Invalid annotation on " + action.getCanonicalName()); } if (analyticsProvider.opcode().equalsIgnoreCase("default")) { logger.warn("Action " + action.getCanonicalName() + " does not specify cache token. " + "Using default cache."); } analyticsLoader.register(new ActionMetadata(analyticsProvider.request(), action, analyticsProvider.cacheable(), analyticsProvider.opcode())); types.add(new NamedType(analyticsProvider.request(), analyticsProvider.opcode())); types.add(new NamedType(analyticsProvider.response(), analyticsProvider.opcode())); logger.info("Registered action: " + action.getCanonicalName()); } mapper.getSubtypeResolver().registerSubtypes(types.toArray(new NamedType[types.size()])); }
From source file:com.linkedin.pinot.controller.helix.core.PinotTableIdealStateBuilder.java
/** * Remove a segment is also required to recompute the ideal state. * * @param tableName//from ww w . j a va 2s. c o m * @param segmentId * @param helixAdmin * @param helixClusterName * @return */ public synchronized static IdealState dropSegmentFromIdealStateFor(String tableName, String segmentId, HelixAdmin helixAdmin, String helixClusterName) { final IdealState currentIdealState = helixAdmin.getResourceIdealState(helixClusterName, tableName); final Set<String> currentInstanceSet = currentIdealState.getInstanceSet(segmentId); if (!currentInstanceSet.isEmpty() && currentIdealState.getPartitionSet().contains(segmentId)) { for (String instanceName : currentIdealState.getInstanceSet(segmentId)) { currentIdealState.setPartitionState(segmentId, instanceName, "DROPPED"); } } else { throw new RuntimeException("Cannot found segmentId - " + segmentId + " in table - " + tableName); } return currentIdealState; }
From source file:com.github.gdfm.shobaidogu.StatsUtils.java
/** * Computes the fraction of source elements that are also in target. * //from ww w. j a v a 2 s .c om * @param source * the source set. * @param target * the target set. * @return the fraction. */ public static <T> double hitPercent(Set<T> source, Set<T> target) { checkNotNull(source); checkNotNull(target); if (source.isEmpty() || target.isEmpty()) return 0; double intersectSize = Sets.intersection(source, target).size(); return intersectSize / source.size(); }
From source file:net.sf.taverna.t2.maven.plugins.Utils.java
public static <T> List<Set<T>> getSubsets(Set<T> set) { List<Set<T>> subsets = new ArrayList<Set<T>>(); List<T> list = new ArrayList<T>(set); int numOfSubsets = 1 << set.size(); for (int i = 0; i < numOfSubsets; i++) { Set<T> subset = new HashSet<T>(); for (int j = 0; j < numOfSubsets; j++) { if (((i >> j) & 1) == 1) { subset.add(list.get(j)); }/*ww w .j av a2s . c om*/ } if (!subset.isEmpty()) { subsets.add(subset); } } Collections.sort(subsets, new Comparator<Set<T>>() { @Override public int compare(Set<T> o1, Set<T> o2) { return o1.size() - o2.size(); } }); return subsets; }
From source file:gov.nih.nci.caarray.security.SecurityPolicy.java
/** * Apply the given set of policies to the given entity. * @param entity the entity to apply policy * @param policies the set of policies to apply *//* w w w.j ava2 s. com*/ public static void applySecurityPolicies(Object entity, Set<SecurityPolicy> policies) { PropertyAccessor[] propAccessors = CaArrayUtils.createReflectionHelper(entity.getClass()).getAccessors(); if (!policies.isEmpty()) { for (PropertyAccessor propAccessor : propAccessors) { boolean disallowed = false; try { for (SecurityPolicy policy : policies) { if (!policy.allowProperty(propAccessor)) { clearDisallowedProperty(entity, propAccessor); disallowed = true; continue; } } if (!disallowed) { applyTransformations(policies, entity, propAccessor); } } catch (IllegalAccessException e) { LOG.warn("Could not apply security policies to property " + propAccessor.getter().getName(), e); } catch (InvocationTargetException e) { LOG.warn("Could not apply security policies to property " + propAccessor.getter().getName(), e); } } } }
From source file:com.linkedin.pinot.controller.helix.core.PinotTableIdealStateBuilder.java
/** * * @param brokerResourceName/*from w w w .j a v a 2 s.c o m*/ * @param helixAdmin * @param helixClusterName * @return */ public static IdealState removeBrokerResourceFromIdealStateFor(String brokerResourceName, HelixAdmin helixAdmin, String helixClusterName) { final IdealState currentIdealState = helixAdmin.getResourceIdealState(helixClusterName, CommonConstants.Helix.BROKER_RESOURCE_INSTANCE); final Set<String> currentInstanceSet = currentIdealState.getInstanceSet(brokerResourceName); if (!currentInstanceSet.isEmpty() && currentIdealState.getPartitionSet().contains(brokerResourceName)) { currentIdealState.getPartitionSet().remove(brokerResourceName); } else { throw new RuntimeException( "Cannot found broker resource - " + brokerResourceName + " in broker resource "); } return currentIdealState; }