List of usage examples for java.util Set isEmpty
boolean isEmpty();
From source file:com.gargoylesoftware.htmlunit.general.HostExtractor.java
private static void ensure(final File file, final Set<String> set) throws IOException { final Set<String> unusedNames = new HashSet<>(set); final List<String> lines = FileUtils.readLines(file); for (final String line : lines) { for (final Iterator<String> it = unusedNames.iterator(); it.hasNext();) { if (line.contains("(\"" + it.next() + "\")")) { it.remove();/* w w w .ja v a 2 s.com*/ } } } unusedNames.remove("this"); unusedNames.remove("Boolean"); unusedNames.remove("null"); if (!unusedNames.isEmpty()) { for (final String name : unusedNames) { if (name.contains(" ")) { continue; } System.out.println(""); System.out.println(" /**"); System.out.println(" * @throws Exception if the test fails"); System.out.println(" */"); System.out.println(" @Test"); System.out.println(" @Alerts(\"exception\")"); String methodName = name; for (final String prefix : PREFIXES_) { if (methodName.startsWith(prefix)) { methodName = prefix.toLowerCase(Locale.ROOT) + methodName.substring(prefix.length()); break; } } if (Character.isUpperCase(methodName.charAt(0))) { methodName = Character.toLowerCase(methodName.charAt(0)) + methodName.substring(1); } methodName = methodName.replace(".", "_"); System.out.println(" public void " + methodName + "() throws Exception {"); System.out.println(" test(\"" + name + "\");"); System.out.println(" }"); } } for (final String name : unusedNames) { if (name.contains(" ")) { System.out.println("Ignoring: " + name); } } }
From source file:edu.wpi.checksims.ChecksimsCommandLine.java
/** * Build the collection of submissions Checksims will be run on. * * TODO add unit tests/*from w w w .j a v a 2 s . c o m*/ * * @param cli Parsed command line options * @param glob Glob matcher to use when building submissions * @param tokenizer Tokenizer to use when building submissions * @param recursive Whether to recursively traverse when building submissions * @return Collection of submissions which will be used to run Checksims * @throws IOException Thrown on issue reading files or traversing directories to build submissions */ static Set<Submission> getSubmissions(CommandLine cli, String glob, Tokenizer tokenizer, boolean recursive) throws IOException, ChecksimsException { checkNotNull(cli); checkNotNull(glob); String[] unusedArgs = cli.getArgs(); List<File> submissionDirs = new ArrayList<>(); if (unusedArgs.length < 2) { throw new ChecksimsException("Expected at least 2 arguments: glob pattern and a submission directory!"); } // The first element in args should be the glob matcher, so start at index 1 for (int i = 1; i < unusedArgs.length; i++) { logs.debug("Adding directory " + unusedArgs[i]); submissionDirs.add(new File(unusedArgs[i])); } // Generate submissions to work on Set<Submission> submissions = new HashSet<>(); for (File dir : submissionDirs) { submissions.addAll(Submission.submissionListFromDir(dir, glob, tokenizer, recursive)); } if (submissions.isEmpty()) { throw new ChecksimsException("Did not obtain any submissions to operate on!"); } return submissions; }
From source file:com.delicious.deliciousfeeds4J.DeliciousUtil.java
public static UserInfo deserializePublicUserInformationFromJson(String username, String json) throws Exception { logger.debug("Trying to deserialize JSON to UserInfo..."); logger.trace("Deserializing JSON: " + json); //Check if empty or null if (json == null || json.isEmpty()) { logger.debug("Nothing to deserialize. JSON-string was empty!"); return null; }/*www.ja v a 2 s. c o m*/ //Actually deserialize final Set<UserInfoDetail> userInfoDetails = ((Set<UserInfoDetail>) objectMapper.readValue(json, new TypeReference<Set<UserInfoDetail>>() { })); if (userInfoDetails == null || userInfoDetails.isEmpty()) { logger.debug("No userInfoDetails found. Collection was empty."); return null; } logger.info("Successfully deserialized {} userInfoDetails!", userInfoDetails.size()); //Now build a UserInfo-object final UserInfo userInfo = new UserInfo(); userInfo.setUser(username); for (UserInfoDetail userInfoDetail : userInfoDetails) { if (userInfoDetail.getId().equals(UserInfoDetail.ITEMS_ID)) userInfo.setItems(userInfoDetail.getCount()); else if (userInfoDetail.getId().equals(UserInfoDetail.FOLLOWERS_ID)) userInfo.setFollowers(userInfoDetail.getCount()); else if (userInfoDetail.getId().equals(UserInfoDetail.FOLLOWING_ID)) userInfo.setFollowing(userInfoDetail.getCount()); userInfo.getUserInfoDetailSet().add(userInfoDetail); } return userInfo; }
From source file:ch.uzh.ifi.attempto.acewiki.gf.GfSentence.java
private static GfWikiEntry createGfWikiEntry(GfGrammar grammar, String language, String text) { try {//from w w w .jav a 2s . c om Set<String> trees = grammar.parse(text, language); if (trees == null) { throw new RuntimeException("No such language: " + language); } if (trees.isEmpty()) { // TODO this should be done properly; see GfTextOperator // If parsing fails: first char to lower case text = DefaultTextOperator.firstCharToLowerCase(text); trees = grammar.parse(text, language); } return new GfWikiEntry(language, text, new TreeList(trees)); } catch (GfServiceException e) { throw new RuntimeException(e.getMessage()); } }
From source file:bioLockJ.Config.java
/** * Get property as list (must be comma dlimited in prop file) * @param propertyName//from ww w . j a va 2s . c om * @return */ public static Set<String> requireSet(final String propertyName) throws Exception { final Set<String> val = getSet(propertyName); if ((val == null) || val.isEmpty()) { throwPropNotFoundException(propertyName); } return val; }
From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtil.java
private static void writeMaterialTypes(Set<Extract> extracts, Set<LabeledExtract> les, PrintWriter out) { final Set<Term> all = new TreeSet<Term>(ENTITY_COMPARATOR); for (final Extract e : extracts) { addIgnoreNull(all, e.getMaterialType()); }/* w ww. j a v a 2 s . co m*/ if (all.isEmpty()) { for (final LabeledExtract e : les) { addIgnoreNull(all, e.getMaterialType()); } } for (final Term mt : all) { out.print("!Sample_molecule="); final String m = translateMaterial(mt); out.println(m); } }
From source file:ListAlgorithms.java
public static void printSet(String setName, Set algorithms) { System.out.println(setName + ":"); if (algorithms.isEmpty()) { System.out.println(" None available."); } else {/*from w w w. j a v a2 s . c o m*/ Iterator it = algorithms.iterator(); while (it.hasNext()) { String name = (String) it.next(); System.out.println(" " + name); } } }
From source file:com.tech.utils.CustomCollectionUtil.java
/** * Method to calculate standard set difference operation. Example : Consider * set1 = {1,2,3,4,5} set2 = {1,2,3} then, the output of this method will be * setDifference = {4,5}/*from ww w . j a v a2 s. com*/ * * @param set1 * @param set2 * @return setDifference */ public static Set<Long> setDifference(Set<Long> itemSet1, Set<Long> itemSet2) { Set<Long> setDifference = new HashSet<Long>(); /* * Perform set difference operation only if the set1 are not empty. */ if (itemSet1 != null && !itemSet1.isEmpty()) { if (itemSet2 != null && !itemSet2.isEmpty()) { for (Long item : itemSet1) { if (!itemSet2.contains(item)) { setDifference.add(item); } } } else { for (Long item : itemSet1) { setDifference.add(item); } } } return setDifference; }
From source file:com.reactivetechnologies.platform.utils.EntityFinder.java
/** * //from w w w . j av a 2 s. com * @param basePkg * @return * @throws ClassNotFoundException */ public static Collection<Class<?>> findMapEntityClasses(String basePkg) throws ClassNotFoundException { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider( false); provider.addIncludeFilter(new TypeFilter() { @Override public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException { AnnotationMetadata aMeta = metadataReader.getAnnotationMetadata(); return aMeta.hasAnnotation(HzMapConfig.class.getName()); } }); //consider the finder class to be in the root package Set<BeanDefinition> beans = null; try { beans = provider.findCandidateComponents(StringUtils.hasText(basePkg) ? basePkg : EntityFinder.class.getName().substring(0, EntityFinder.class.getName().lastIndexOf("."))); } catch (Exception e) { throw new IllegalArgumentException("Unable to scan for entities under base package", e); } Set<Class<?>> classes = new HashSet<>(); if (beans != null && !beans.isEmpty()) { classes = new HashSet<>(beans.size()); for (BeanDefinition bd : beans) { classes.add(Class.forName(bd.getBeanClassName())); } } else { log.warn(">> Did not find any key value entities under the given base scan package [" + basePkg + "]"); } return classes; }
From source file:com.silverpeas.util.StringUtil.java
private static String reencode(byte[] data, Set<String> encodings, String declaredEncoding) throws UnsupportedEncodingException { if (!encodings.isEmpty()) { String encoding = encodings.iterator().next(); String value = new String(data, encoding); if (!checkEncoding(value)) { encodings.remove(encoding); return reencode(data, encodings, declaredEncoding); }/* w w w. j a v a2 s . c o m*/ return encoding; } return declaredEncoding; }