List of usage examples for java.util Set size
int size();
From source file:com.hubrick.vertx.rest.converter.JacksonJsonHttpMessageConverter.java
private static Method getMethodIfAvailable(Class<?> clazz, String methodName, Class<?>... paramTypes) { checkNotNull(clazz, "Class must not be null"); checkNotNull(methodName, "Method name must not be null"); if (paramTypes != null) { try {//from w ww .j a v a 2s .c o m return clazz.getMethod(methodName, paramTypes); } catch (NoSuchMethodException ex) { return null; } } else { Set<Method> candidates = new HashSet<>(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:com.github.strawberry.guice.config.ConfigLoader.java
private static Option getFromProperties(Map properties, final Field field, final Config annotation) { Object value = null;//from w w w.ja v a 2 s .c om Class<?> fieldType = field.getType(); String pattern = annotation.value(); boolean allowNull = annotation.allowNull(); Set<String> matchingKeys = getKeys(properties, pattern); if (matchingKeys.size() == 1) { String matchingKey = Iterables.getOnlyElement(matchingKeys); if (fieldType.equals(char[].class)) { value = properties.get(matchingKey).toString().toCharArray(); } else if (fieldType.equals(Character[].class)) { value = ArrayUtils.toObject(properties.get(matchingKey).toString().toCharArray()); } else if (fieldType.equals(char.class) || fieldType.equals(Character.class)) { String toConvert = properties.get(matchingKey).toString(); if (toConvert.length() == 1) { value = properties.get(matchingKey).toString().charAt(0); } else { throw ConversionException.of(toConvert, matchingKey, fieldType); } } else if (fieldType.equals(String.class)) { value = properties.get(matchingKey); } else if (fieldType.equals(byte[].class)) { if (properties.containsKey(matchingKey)) { value = properties.get(matchingKey).toString().getBytes(); } else { value = null; } } else if (fieldType.equals(Byte[].class)) { value = ArrayUtils.toObject(properties.get(matchingKey).toString().getBytes()); } else if (fieldType.equals(boolean.class) || fieldType.equals(Boolean.class)) { String toConvert = properties.get(matchingKey).toString(); if (BOOLEAN.matcher(toConvert).matches()) { value = TRUE.matcher(toConvert).matches(); } else { throw ConversionException.of(toConvert, matchingKey, fieldType); } } else if (Map.class.isAssignableFrom(fieldType)) { value = mapOf(field, properties, matchingKey); } else if (Collection.class.isAssignableFrom(fieldType)) { value = collectionOf(field, properties, matchingKey); } else { String toConvert = properties.get(matchingKey).toString(); try { if (fieldType.equals(byte.class) || fieldType.equals(Byte.class)) { value = Byte.parseByte(properties.get(matchingKey).toString()); } else if (fieldType.equals(short.class) || fieldType.equals(Short.class)) { value = Short.parseShort(toConvert); } else if (fieldType.equals(int.class) || fieldType.equals(Integer.class)) { value = Integer.parseInt(toConvert); } else if (fieldType.equals(long.class) || fieldType.equals(Long.class)) { value = Long.parseLong(toConvert); } else if (fieldType.equals(BigInteger.class)) { value = new BigInteger(toConvert); } else if (fieldType.equals(float.class) || fieldType.equals(Float.class)) { value = Float.parseFloat(toConvert); } else if (fieldType.equals(double.class) || fieldType.equals(Double.class)) { value = Double.parseDouble(toConvert); } else if (fieldType.equals(BigDecimal.class)) { value = new BigDecimal(toConvert); } } catch (NumberFormatException exception) { throw ConversionException.of(exception, toConvert, matchingKey, fieldType); } } } else if (matchingKeys.size() > 1) { if (Map.class.isAssignableFrom(fieldType)) { value = nestedMapOf(field, properties, matchingKeys); } else if (Collection.class.isAssignableFrom(fieldType)) { value = nestedCollectionOf(field, properties, matchingKeys); } } else { if (!allowNull) { value = nonNullValueOf(fieldType); } } return Option.fromNull(value); }
From source file:com.mcleodmoores.mvn.natives.UnpackDependenciesMojo.java
public static boolean isIdentical(final Collection<Artifact> artifacts, final ArtifactQuery query) { final Set<String> values = new HashSet<String>(); for (final Artifact artifact : artifacts) { if (values.add(query.get(artifact)) && (values.size() > 1)) { return false; }//from ww w.j a va2s . c om } return true; }
From source file:org.cybercat.automation.annotations.AnnotationBuilder.java
@SuppressWarnings("unchecked") private final static <T extends IVersionControl> Class<T> versionControlPreprocessor(Class<T> providerzz) throws AutomationFrameworkException { Reflections refSearch;// ww w . j a va2s . c o m int version = 0; try { refSearch = getReflections(providerzz.getPackage().getName()); version = (int) AutomationMain.getPropertyLong("app.version"); if (refSearch == null || version < 0) return providerzz; } catch (Exception e) { return providerzz; } Set<Class<? extends T>> providers = refSearch.getSubTypesOf(providerzz); if (providers == null || providers.size() == 0) return providerzz; T candidate, caught = null; for (Class<? extends T> classProvider : providers) { try { Constructor<T> c = (Constructor<T>) classProvider.getConstructor(); candidate = c.newInstance(); if (candidate.getVersion() == version) return (Class<T>) candidate.getClass(); if (caught == null || (candidate.getVersion() < version && caught.getVersion() < candidate.getVersion())) { caught = candidate; } } catch (Exception e) { e.printStackTrace(); } } return (Class<T>) caught.getClass(); }
From source file:io.cloudslang.maven.compiler.CloudSlangMavenCompiler.java
protected static Set<String> getSourceFilesForSourceRoot(CompilerConfiguration config, String sourceLocation) { Path path = Paths.get(sourceLocation); if (!Files.exists(path)) { return emptySet(); }/*from www .j a v a 2 s . co m*/ DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(sourceLocation); Set<String> includes = config.getIncludes(); if (includes != null && !includes.isEmpty()) { String[] inclStrs = includes.toArray(new String[includes.size()]); scanner.setIncludes(inclStrs); } else { scanner.setIncludes(new String[] { "**/*.sl.yaml", "**/*.sl", "**/*.sl.yml" }); } Set<String> configExcludes = config.getExcludes(); if (configExcludes != null && !configExcludes.isEmpty()) { String[] exclStrs = configExcludes.toArray(new String[configExcludes.size()]); scanner.setExcludes(exclStrs); } else { scanner.setExcludes(new String[] { "**/*prop.sl" }); } scanner.scan(); String[] sourceDirectorySources = scanner.getIncludedFiles(); Set<String> sources = new HashSet<>(); for (String sourceDirectorySource : sourceDirectorySources) { sources.add(new File(sourceLocation, sourceDirectorySource).getPath()); } return sources; }
From source file:com.basp.trabajo_al_minuto.model.business.BusinessUtils.java
public static String rollbackValidation(ConstraintViolationException cve) { Set<ConstraintViolation<?>> constraintViolations = cve.getConstraintViolations(); if (constraintViolations.size() > 0) { Iterator<ConstraintViolation<?>> iterator = constraintViolations.iterator(); List<RollbackResult> rlb = new ArrayList(); while (iterator.hasNext()) { ConstraintViolation<?> cv = iterator.next(); rlb.add(new RollbackResult(cv.getRootBean().getClass().getCanonicalName(), cv.getMessage(), cv.getInvalidValue().toString())); }/* w ww.ja va 2s . c om*/ return new Gson().toJson(rlb); } return null; }
From source file:com.dungnv.utils.StringUtils.java
public static String[] convertSetToArray(Set<String> set) { if (set != null) { String[] result = new String[set.size()]; int i = 0; for (String s : set) { // System.out.println(i + ":" + s); result[i++] = s;/* ww w . ja v a 2s. co m*/ } return result; } else { return new String[0]; } }
From source file:hudson.plugins.trackplus.Updater.java
private static List<TrackplusIssue> getTrackplusIssues(Set<Integer> ids, TrackplusSession session, PrintStream logger) throws RemoteException { List<TrackplusIssue> issues = new ArrayList<TrackplusIssue>(ids.size()); for (Integer id : ids) { try {/*from ww w. j a v a 2 s .c o m*/ WSItemBean wsItem = session.getIssue(Integer.toString(id)); if (wsItem != null) { issues.add(new TrackplusIssue(wsItem)); } } catch (TCLFacadeException e) { String message = TrackplusSession.getMessage(e); LOGGER.log(Level.WARNING, "Error obtaining issue with id \"" + id + "\":" + message); } } return issues; }
From source file:modula.parser.io.ModelUpdater.java
/** * history//w w w.j a v a 2 s .c o m */ private static void updateHistory(final History history, final Map<String, TransitionTarget> targets, final TransitionalState parent) throws ModelException { SimpleTransition transition = history.getTransition(); if (transition == null || transition.getNext() == null) { logAndThrowModelError(ERR_HISTORY_NO_DEFAULT, new Object[] { history.getId(), getName(parent) }); } else { updateTransition(transition, targets); Set<TransitionTarget> historyStates = transition.getTargets(); if (historyStates.size() == 0) { logAndThrowModelError(ERR_STATE_NO_HIST, new Object[] { getName(parent) }); } for (TransitionTarget historyState : historyStates) { if (!history.isDeep()) { // Shallow history if (!parent.getChildren().contains(historyState)) { logAndThrowModelError(ERR_STATE_BAD_SHALLOW_HIST, new Object[] { getName(parent) }); } } else { // Deep history if (!historyState.isDescendantOf(parent)) { logAndThrowModelError(ERR_STATE_BAD_DEEP_HIST, new Object[] { getName(parent) }); } } } } }
From source file:com.createtank.payments.coinbase.RequestClient.java
public static String createRequestParams(Map<String, String> params) { if (params == null) return null; Set<Map.Entry<String, String>> entries = params.entrySet(); int size = entries.size(); int count = 0; StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> entry : entries) { sb.append(entry.getKey());/*from ww w . ja v a 2 s .c om*/ sb.append("="); sb.append(entry.getValue()); if (count < size - 1) { sb.append("&"); } count++; } return sb.toString(); }