List of usage examples for java.util Collection isEmpty
boolean isEmpty();
From source file:hrytsenko.csv.IO.java
/** * Saves records into CSV file./* w w w. j a va 2 s . c o m*/ * * <p> * If file already exists, then it will be overridden. * * @param args * the named arguments {@link IO}. * * @throws IOException * if file could not be written. */ public static void save(Map<String, ?> args) throws IOException { Path path = getPath(args); LOGGER.info("Save: {}.", path.getFileName()); @SuppressWarnings("unchecked") Collection<Record> records = (Collection<Record>) args.get("records"); if (records.isEmpty()) { LOGGER.info("No records to save."); return; } try (Writer dataWriter = newBufferedWriter(path, getCharset(args), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { Set<String> columns = new LinkedHashSet<>(); List<Map<String, String>> rows = new ArrayList<>(); for (Record record : records) { Map<String, String> values = record.values(); columns.addAll(values.keySet()); rows.add(values); } CsvSchema.Builder csvSchema = getSchema(args).setUseHeader(true); for (String column : columns) { csvSchema.addColumn(column); } CsvMapper csvMapper = new CsvMapper(); ObjectWriter csvWriter = csvMapper.writer().withSchema(csvSchema.build()); csvWriter.writeValue(dataWriter, rows); } }
From source file:ipLock.ProcessHandle.java
private static String determineJavaExecutablePath() { File javaHome = new File(System.getProperty("java.home")); Collection<File> files = FileUtils.listFiles(javaHome, new NameFileFilter("java"), new NameFileFilter("bin")); if (files.isEmpty()) { throw new RuntimeException("No java executable found at java home '" + javaHome + "'"); }// w w w .j a v a 2s .c om if (files.size() > 1) { throw new RuntimeException("Multiple java executables found at java home '" + javaHome + "': " + StringUtils.join(files, "; ")); } return Collections.min(files).getAbsolutePath(); }
From source file:maltcms.ui.fileHandles.properties.tools.PropertyLoader.java
private static Tuple2D<Configuration, Configuration> loadPropertiesFromClass(Class<?> c) { PropertiesConfiguration ret = new PropertiesConfiguration(); PropertiesConfiguration var = new PropertiesConfiguration(); String requiredVariables = ""; String optionalVariables = ""; String providedVariables = ""; Collection<String> reqVars = AnnotationInspector.getRequiredVariables(c); for (String rv : reqVars) { requiredVariables += rv + ","; }/*from w w w .jav a 2 s .c o m*/ if (requiredVariables.length() > 0) { requiredVariables = requiredVariables.substring(0, requiredVariables.length() - 1); } var.setProperty(REQUIRED_VARS, requiredVariables); Collection<String> optVars = AnnotationInspector.getOptionalRequiredVariables(c); for (String rv : optVars) { optionalVariables += rv + ","; } if (optionalVariables.length() > 0) { optionalVariables = optionalVariables.substring(0, optionalVariables.length() - 1); } var.setProperty(OPTIONAL_VARS, optionalVariables); Collection<String> provVars = AnnotationInspector.getProvidedVariables(c); for (String rv : provVars) { providedVariables += rv + ","; } if (providedVariables.length() > 0) { providedVariables = providedVariables.substring(0, providedVariables.length() - 1); } var.setProperty(PROVIDED_VARS, providedVariables); Collection<String> keys = AnnotationInspector.getRequiredConfigKeys(c); if (!keys.isEmpty()) { for (String key : keys) { ret.setProperty(key, AnnotationInspector.getDefaultValueFor(c, key)); } } return new Tuple2D<Configuration, Configuration>(ret, var); }
From source file:com.mtgi.analytics.servlet.BehaviorTrackingListener.java
private static void addRequestAdapters(Collection<ServletRequestBehaviorTrackingAdapter> accum, ListableBeanFactory beanFactory, boolean hasFilter) { @SuppressWarnings("unchecked") Collection<ServletRequestBehaviorTrackingAdapter> beans = beanFactory .getBeansOfType(ServletRequestBehaviorTrackingAdapter.class, false, false).values(); if (!beans.isEmpty()) { if (hasFilter) throw new IllegalStateException( "You have configured both BehaviorTrackingFilters and BehaviorTrackingListeners in the same web application. Only one of these methods may be used in a single application."); accum.addAll(beans);// w w w . j a v a 2s.co m } }
From source file:com.centeractive.ws.builder.DefinitionSaveTest.java
public static File findFile(File folder, String name) { final boolean RECURSIVE = true; String[] extensions = new String[] { FilenameUtils.getExtension(name) }; Collection<File> files = FileUtils.listFiles(folder, extensions, RECURSIVE); if (files.isEmpty() == false) { return files.iterator().next(); }/*www . j a v a 2s. c o m*/ throw new RuntimeException("File not found " + name); }
From source file:ru.org.linux.tag.TagService.java
public static String toString(Collection<String> tags) { if (tags.isEmpty()) { return ""; }/* ww w . j a v a 2 s . com*/ StringBuilder str = new StringBuilder(); for (String tag : tags) { str.append(str.length() > 0 ? "," : "").append(tag); } return str.toString(); }
From source file:de.pawlidi.openaletheia.generator.KeyGenerator.java
public static String readKeyFile(final String directory, final boolean privateKeyFile) { if (!StringUtils.isBlank(directory)) { File rootDir = new File(directory); if (rootDir.exists() && rootDir.isDirectory()) { Collection<File> files = FileUtils.listFiles(rootDir, new String[] { KEY_FILE_EXTENSION }, false); if (!files.isEmpty()) { for (File file : files) { if (file.getName().endsWith((privateKeyFile ? PRIVATE_KEY_FILE : PUBLIC_KEY_FILE))) { try { return FileUtils.readFileToString(file, Converter.UTF_8); } catch (IOException e) { e.printStackTrace(); }//w w w . j a v a 2s . c o m } } } } } return null; }
From source file:br.com.suricattus.surispring.spring.security.util.SecurityUtil.java
/** * List user authorities./* w w w . j a va 2s .c om*/ * * @return user authorities */ @SuppressWarnings("unchecked") public static Set<String> getUserAuthorities() { if (SecurityContextHolder.getContext() == null) return Collections.EMPTY_SET; Authentication currentUser = SecurityContextHolder.getContext().getAuthentication(); if (currentUser == null) return Collections.EMPTY_SET; Collection<? extends GrantedAuthority> grantedAauthorities = currentUser.getAuthorities(); if (grantedAauthorities == null || grantedAauthorities.isEmpty()) return Collections.EMPTY_SET; Set<String> authorities = new TreeSet<String>(); for (GrantedAuthority ga : grantedAauthorities) authorities.add(ga.getAuthority()); return authorities; }
From source file:net.ontopia.utils.TestFileUtils.java
public static List<String[]> getTestInputFiles(ResourcesDirectoryReader directoryReader, String resourcesDirectory) { Collection<String> resources = directoryReader.getResourcesAsStrings(); if (resources.isEmpty()) throw new RuntimeException("No resources found in directory " + resourcesDirectory); List<String[]> tests = new ArrayList<String[]>(); for (String resource : resources) { int slashPos = resource.lastIndexOf('/') + 1; String root = resource.substring(0, slashPos); String filename = resource.substring(slashPos); tests.add(new String[] { root, filename }); }/*from w ww. jav a 2s .c om*/ return tests; }
From source file:com.acc.storefront.tags.Functions.java
/** * JSP EL Function to get a primary Image for a Product in a specific format * /*ww w. ja va2s . c o m*/ * @param product * the product * @param format * the desired format * @return the image */ public static ImageData getPrimaryImageForProductAndFormat(final ProductData product, final String format) { if (product != null && format != null) { final Collection<ImageData> images = product.getImages(); if (images != null && !images.isEmpty()) { for (final ImageData image : images) { if (ImageDataType.PRIMARY.equals(image.getImageType()) && format.equals(image.getFormat())) { return image; } } } } return null; }