List of usage examples for java.util Set size
int size();
From source file:io.lavagna.service.PermissionService.java
private static MapSqlParameterSource[] fromUserIdAndRoleName(Role role, Set<Integer> userIds) { List<MapSqlParameterSource> ret = new ArrayList<>(userIds.size()); for (Integer userId : userIds) { ret.add(new MapSqlParameterSource("userId", userId).addValue("roleName", role.getName())); }//from w ww .ja v a 2 s. c om return ret.toArray(new MapSqlParameterSource[ret.size()]); }
From source file:net.audumla.climate.ClimateDataFactory.java
/** * Replaces the climate observation with a readonly version. * * @param cd the existing climate data bean * @return the climate data/*from ww w . ja va2 s . c om*/ */ public static WritableClimateObservation convertToWritableClimateObservation(ClimateObservation cd) { if (cd == null) { return null; } Set<Class<?>> interfaces = new LinkedHashSet<Class<?>>(); interfaces.addAll(ClassUtils.getAllInterfaces(cd.getClass())); return BeanUtils.convertBean(cd, WritableClimateObservation.class, interfaces.toArray(new Class<?>[interfaces.size()])); }
From source file:org.agiso.core.lang.util.ClassUtils.java
/** * Wyszukuje dla wskazanej klasy publiczn metod o okrelonej sygnaturze. Jeli * metoda nie zostanie naleziona zwraca {@code null}. * <p>W przypadku gdy nie jest okrelona tablica parametrw wywoania, zwraca metod * tylko gdy wynik wyszukiwania jest unikatowy, tj. istnieje tylko jedna publiczna * metoda o wskazanej nazwie./* w ww .ja v a2s. com*/ * * <p>Based on: * org.springframework.util.ClassUtils.getMethodIfAvailable(Class<?>, String, Class<?>...) * * @param clazz Klasa do sprawdzenia * @param methodName Nazwa wyszukiwanej metody * @param paramTypes Tablica typw parametrw wywoania metody * (moe by {@code null} w celu wyszukania dowolnej metody o wskazanej nazwie) * @return Znaleziona metoda lub @{code null} gdy nie istnieje lub nie jest unikatowa * @see Class#getMethod */ public static Method getMethodIfAvailable(Class<?> clazz, String methodName, Class<?>... paramTypes) { if (clazz == null) { throw new NullPointerException("Klasa musi by okrelona"); } if (methodName == null) { throw new NullPointerException("Nazwa metody musi by okrelona"); } if (paramTypes != null) { try { return clazz.getMethod(methodName, paramTypes); } catch (NoSuchMethodException ex) { return null; } } else { Set<Method> candidates = new HashSet<Method>(1); Method[] methods = clazz.getMethods(); for (Method method : methods) { if (methodName.equals(method.getName())) { candidates.add(method); } } if (candidates.size() == 1) { return candidates.iterator().next(); } return null; } }
From source file:org.web4thejob.util.CoreUtil.java
public static Set<Setting<?>> cloneSettings(Set<Setting<?>> source) { Set<Setting<?>> target = new HashSet<Setting<?>>(source.size()); for (Setting<?> setting : source) { target.add(setting.clone());//from w w w.j a v a 2 s. co m } return target; }
From source file:com.allinfinance.system.util.BeanUtils.java
/** * null??//from w w w.java 2 s.c om * @param source * @return */ public static String[] getNullPropertyNames(Object source) { final BeanWrapper src = new BeanWrapperImpl(source); java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors(); Set<String> emptyNames = new HashSet<String>(); for (java.beans.PropertyDescriptor pd : pds) { Object srcValue = src.getPropertyValue(pd.getName()); if (srcValue == null) emptyNames.add(pd.getName()); } String[] result = new String[emptyNames.size()]; return emptyNames.toArray(result); }
From source file:org.agiso.core.lang.util.ClassUtils.java
/** * Wyszukuje dla wskazanej klasy publiczn metod o okrelonej sygnaturze. Jeli * metoda nie zostanie naleziona wyrzuca wyjtek {@code IllegalStateException}. * <p>W przypadku gdy nie jest okrelona tablica parametrw wywoania, zwraca metod * tylko gdy wynik wyszukiwania jest unikatowy, tj. istnieje tylko jedna publiczna * metoda o wskazanej nazwie.//from w w w. j a va 2s . c o m * * <p>Based on: * org.springframework.util.ClassUtils.getMethod(Class<?>, String, Class<?>...) * * @param clazz Klasa do sprawdzenia * @param methodName Nazwa wyszukiwanej metody * @param paramTypes Tablica typw parametrw wywoania metody * (moe by {@code null} w celu wyszukania dowolnej metody o wskazanej nazwie) * @return Znaleziona metoda (niegdy {@code null}) * @throws IllegalStateException jeli nie znaleziono metody lub nie jest unikatowa * @see Class#getMethod */ public static Method getMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) { if (clazz == null) { throw new NullPointerException("Klasa musi by okrelona"); } if (methodName == null) { throw new NullPointerException("Nazwa metody musi by okrelona"); } if (paramTypes != null) { try { return clazz.getMethod(methodName, paramTypes); } catch (NoSuchMethodException ex) { throw new IllegalStateException("Expected method not found: " + ex); } } else { Set<Method> candidates = new HashSet<Method>(1); Method[] methods = clazz.getMethods(); for (Method method : methods) { if (methodName.equals(method.getName())) { candidates.add(method); } } if (candidates.size() == 1) { return candidates.iterator().next(); } else if (candidates.isEmpty()) { throw new IllegalStateException("Expected method not found: " + clazz + "." + methodName); } else { throw new IllegalStateException("No unique method found: " + clazz + "." + methodName); } } }
From source file:com.espertech.esper.event.vaevent.PropertyUtility.java
/** * Remove from values all removeValues and build a unique sorted result array. * @param values to consider/* w w w . j a v a 2 s . co m*/ * @param removeValues values to remove from values * @return sorted unique */ protected static String[] uniqueExclusiveSort(String[] values, String[] removeValues) { Set<String> unique = new HashSet<String>(); unique.addAll(Arrays.asList(values)); for (String removeValue : removeValues) { unique.remove(removeValue); } String[] uniqueArr = unique.toArray(new String[unique.size()]); Arrays.sort(uniqueArr); return uniqueArr; }
From source file:net.audumla.climate.ClimateDataFactory.java
/** * Replaces the climate data with a readonly version. * * @param cd the existing climate data bean * @return the climate data//from w w w . j av a 2 s .co m */ public static ClimateData convertToReadOnlyClimateData(ClimateData cd) { if (cd == null) { return null; } Set<Class<?>> interfaces = new LinkedHashSet<Class<?>>(); interfaces.addAll(ClassUtils.getAllInterfaces(cd.getClass())); interfaces.remove(WritableClimateData.class); return BeanUtils.convertBean(cd, interfaces.toArray(new Class<?>[interfaces.size()])); }
From source file:com.googlecode.psiprobe.Utils.java
public static boolean isThreadingEnabled() { try {/*from w ww . j ava2 s .co m*/ MBeanServer mBeanServer = new Registry().getMBeanServer(); ObjectName threadingOName = new ObjectName("java.lang:type=Threading"); Set s = mBeanServer.queryMBeans(threadingOName, null); return s != null && s.size() > 0; } catch (MalformedObjectNameException e) { return false; } }
From source file:common.Utilities.java
public static double getJaccardSim(Map<Integer, Integer> targetMap, Map<Integer, Integer> nMap) { Set<Integer> unionSet = new HashSet<Integer>(targetMap.keySet()); Set<Integer> intersectSet = new HashSet<Integer>(targetMap.keySet()); unionSet.addAll(nMap.keySet());/*w w w . j a va 2 s .c o m*/ intersectSet.retainAll(nMap.keySet()); return (double) intersectSet.size() / (double) unionSet.size(); }