List of usage examples for java.util Set size
int size();
From source file:Main.java
public static <E> boolean areDisjoint(Set<E> setOne, Set<E> setTwo) { if (setOne == null || setTwo == null) { return true; }// ww w.j a v a 2 s.c o m Set<E> smallerSet = setOne; Set<E> largerSet = setTwo; if (setOne.size() > setTwo.size()) { smallerSet = setTwo; largerSet = setOne; } for (E el : smallerSet) { if (largerSet.contains(el)) { return false; } } return true; }
From source file:com.ace.erp.common.inject.support.InjectBaseDependencyHelper.java
public static void findAndInjectBaseRepositoryDependency(GenericService<?, ?> genericService) { final Set<Object> candidates = findDependencies(genericService, BaseComponent.class); if (candidates.size() == 0 || candidates.size() > 1) { throw new IllegalStateException( "expect 1 @BaseComponent anntation BaseRepository subclass bean, but found " + candidates.size() + ", please check class [" + genericService.getClass() + "] @BaseComponent annotation."); }/* w w w .j a va2s . c o m*/ Object baserMapper = candidates.iterator().next(); if (baserMapper.getClass().isAssignableFrom(BaseComponent.class)) { throw new IllegalStateException("[" + genericService.getClass() + "] @BaseComponent annotation bean " + "must be BaseRepository subclass"); } genericService.setBaseMapper((BaseMapper) baserMapper); }
From source file:com.bruce.intellijplugin.generatesetter.utils.PsiToolUtils.java
public static void addImportToFile(PsiDocumentManager psiDocumentManager, PsiJavaFile containingFile, Document document, Set<String> newImportList) { if (newImportList.size() > 0) { Iterator<String> iterator = newImportList.iterator(); while (iterator.hasNext()) { String u = iterator.next(); if (u.startsWith("java.lang")) { iterator.remove();//from ww w . j a v a 2 s .c o m } } } if (newImportList.size() > 0) { PsiJavaFile javaFile = containingFile; PsiImportStatement[] importStatements = javaFile.getImportList().getImportStatements(); Set<String> containedSet = new HashSet<>(); for (PsiImportStatement s : importStatements) { containedSet.add(s.getQualifiedName()); } StringBuilder newImportText = new StringBuilder(); for (String newImport : newImportList) { if (!containedSet.contains(newImport)) { newImportText.append("\nimport " + newImport + ";"); } } PsiPackageStatement packageStatement = javaFile.getPackageStatement(); int start = 0; if (packageStatement != null) { start = packageStatement.getTextLength() + packageStatement.getTextOffset(); } String insertText = newImportText.toString(); if (StringUtils.isNotBlank(insertText)) { document.insertString(start, insertText); PsiDocumentUtils.commitAndSaveDocument(psiDocumentManager, document); } } }
From source file:edu.wpi.checksims.algorithm.AlgorithmRunner.java
/** * Run a pairwise similarity detection algorithm. * * @param submissions Pairs to run on/*from w ww .ja v a 2 s. c o m*/ * @param algorithm Algorithm to use * @return Collection of AlgorithmResults, one for each input pair */ public static Set<AlgorithmResults> runAlgorithm(Set<Pair<Submission, Submission>> submissions, SimilarityDetector algorithm) { checkNotNull(submissions); checkArgument(submissions.size() > 0, "Must provide at least one pair of submissions to run on!"); checkNotNull(algorithm); Logger logs = LoggerFactory.getLogger(AlgorithmRunner.class); long startTime = System.currentTimeMillis(); logs.info("Performing similarity detection on " + submissions.size() + " pairs using algorithm " + algorithm.getName()); // Perform parallel analysis of all submission pairs to generate a results list Set<AlgorithmResults> results = ParallelAlgorithm.parallelSimilarityDetection(algorithm, submissions); long endTime = System.currentTimeMillis(); long timeElapsed = endTime - startTime; logs.info("Finished similarity detection in " + timeElapsed + " ms"); return results; }
From source file:com.ace.erp.common.inject.support.InjectBaseDependencyHelper.java
public static void findAndInjectGenericServiceDependency(BaseController<?, ?> baseController) { final Set<Object> candidates = findDependencies(baseController, BaseComponent.class); if (candidates.size() > 1) { throw new IllegalStateException( "expect 1 @BaseComponent anntation AbstractService subclass bean, but found " + candidates.size() + ", please check class [" + baseController.getClass() + "] @BaseComponent annotation."); }//from w w w .ja v a 2 s .c o m Object genericService = candidates.iterator().next(); if (genericService.getClass().isAssignableFrom(BaseComponent.class)) { throw new IllegalStateException("[" + baseController.getClass() + "] @BaseComponent annotation bean " + "must be AbstractService subclass"); } baseController.setGenericService((GenericService) genericService); }
From source file:Main.java
/** * Return a sorted array of holidays for a given year. * * @param year/* ww w .ja v a 2 s. c om*/ * The year to get holidays for. * @return The array of holidays, sorted by date. */ public static Date[] getHolidays(int year) { Set<Date> days = getHolidaySet(year); Date[] dates = days.toArray(new Date[days.size()]); Arrays.sort(dates); return dates; }
From source file:de.metas.ui.web.window.datatypes.json.JSONLookupValue.java
public static final StringLookupValue stringLookupValueFromJsonMap(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 av a 2s.co m final Map.Entry<String, String> e = entrySet.iterator().next(); final String id = e.getKey(); final String name = e.getValue(); return StringLookupValue.of(id, name); }
From source file:com.bstek.dorado.core.io.ResourceUtils.java
/** * ??????// w w w . ja va2s .com * * @param resourceLocations * ? * @return ??? * @throws IOException */ public static Resource[] getResources(String[] resourceLocations) throws IOException { Set<Resource> resourceSet = getResourceSet(resourceLocations); Resource[] resources = new Resource[resourceSet.size()]; resourceSet.toArray(resources); return resources; }
From source file:com.titilink.camel.rest.util.ValidationUtil.java
/** * ??JSR-303bean// www. java 2 s .c o m * * @param instance * @return */ public static <T> Set<String> validate(T instance, Class<?>... groups) { Set<ConstraintViolation<T>> set = validateBean(instance, groups); Set<String> errorCodeSet = new HashSet<String>(set.size()); for (ConstraintViolation<T> c : set) { errorCodeSet.add(c.getMessage()); } return errorCodeSet; }
From source file:ke.co.tawi.babblesms.server.utils.StringUtil.java
/** * Eliminate repetitions from an array of Strings. * // w w w .ja va2s . c o m * @param strArray * @return an array of Strings where there are no duplicates */ public static String[] removeDuplicates(String[] strArray) { List<String> list = Arrays.asList(strArray); Set<String> set = new HashSet<String>(list); String[] result = new String[set.size()]; set.toArray(result); return result; }