List of usage examples for org.apache.commons.lang ArrayUtils contains
public static boolean contains(boolean[] array, boolean valueToFind)
Checks if the value is in the given array.
From source file:com.kylinolap.metadata.model.cube.CubeDesc.java
public DimensionDesc findDimensionByColumn(TblColRef col) { for (DimensionDesc dim : dimensions) { if (ArrayUtils.contains(dim.getColumnRefs(), col)) return dim; }// w w w . ja va2 s .com return null; }
From source file:at.tuwien.ifs.somtoolbox.apps.SOMToolboxMain.java
/** * @param cls the class to search the main in. * @param args command line args for the main class invoked. * @param useGUI <code>true</code> if the {@link GenericGUI} should be launched. * @return <code>true</code> if the class contains a <code>static main(String[])</code> that was invoked, * <code>false</code> otherwise. * @see GenericGUI/*ww w. j a v a 2 s .c o m*/ */ private static boolean tryInvokeMain(Class<?> cls, String[] args, boolean useGUI) { try { if (useGUI) { @SuppressWarnings("unchecked") Class<SOMToolboxApp> sta = (Class<SOMToolboxApp>) cls; new GenericGUI(sta, args).setVisible(true); return true; } } catch (ClassCastException cce) { // Nop, continue... } try { Method main = cls.getMethod("main", String[].class); // special handling - if the parameter "--help" is present, also print the description if (ArrayUtils.contains(args, "--help")) { Object description = null; try { // try to get the LONG_DESCRIPTION field description = cls.getField("LONG_DESCRIPTION").get(null) + "\n"; } catch (Exception e) { try { // fall back using the DESCRIPTION field description = cls.getField("DESCRIPTION").get(null) + "\n"; } catch (Exception e1) { // nothing found => write nothing... description = ""; } } System.out.println(description); try { Parameter[] options = (Parameter[]) cls.getField("OPTIONS").get(null); JSAP jsap = AbstractOptionFactory.registerOptions(options); JSAPResult jsapResult = OptionFactory.parseResults(args, jsap, cls.getName()); AbstractOptionFactory.printUsage(jsap, cls.getName(), jsapResult, null); return true; } catch (Exception e1) { // we didn't find the options => let the class be invoked ... } } main.invoke(null, new Object[] { args }); return true; } catch (InvocationTargetException e) { // If main throws an error, print it e.getCause().printStackTrace(); return true; } catch (Exception e) { // Everything else is hidden... return false; } }
From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReflectionUtil.java
/** * Returns a {@link Method} with a certain name and parameter types declared in the given class or any subclass * (except {@link Object})./*from ww w . ja v a 2s. com*/ * <p/> * If no parameter types are specified i.e., {@code paramTypes} is {@code null} the parameter types are ignored * for signature comparison.<br/> * If a parameter type is not known i.e., it is {@code null}, all declared methods are checked whether their * parameter types conform to the known parameter types i.e., if every known type is assignable to the parameter * type of the method and if exactly one was found, it is returned.<br/> * Otherwise a {@link NoSuchMethodException} is thrown indicating that no or several methods were found. * * @param type the class * @param methodName the name of the method to find * @param clazzes the full-qualified class names of the parameters * @return the accessible method resolved * @throws ClassNotFoundException if a class cannot be located by the specified class loader */ public static Method findMethod(final Class<?> type, String methodName, Class<?>... clazzes) throws ClassNotFoundException { Method method = null; // If all parameter types are known, find the method that exactly matches the signature if (clazzes != null && !ArrayUtils.contains(clazzes, null)) { for (Class<?> clazz = type; clazz != Object.class; clazz = clazz.getSuperclass()) { try { method = type.getDeclaredMethod(methodName, clazzes); break; } catch (NoSuchMethodException e) { // Ignore } } } // If no method was found, find all possible candidates if (method == null) { List<Method> candidates = new ArrayList<>(); for (Class<?> clazz = type; clazz != null; clazz = clazz.getSuperclass()) { for (Method declaredMethod : clazz.getDeclaredMethods()) { if (declaredMethod.getName().equals(methodName) && (clazzes == null || ClassUtils.isAssignable(clazzes, declaredMethod.getParameterTypes()))) { // Check if there is already a overridden method with the same signature for (Method candidate : candidates) { if (candidate.getName().equals(declaredMethod.getName())) { /** * If there is at least one parameters in the method of the super type, which is a * sub type of the corresponding parameter of the sub type, remove the method declared * in the sub type. */ if (!Arrays.equals(declaredMethod.getParameterTypes(), candidate.getParameterTypes()) && ClassUtils.isAssignable(declaredMethod.getParameterTypes(), candidate.getParameterTypes())) { candidates.remove(candidate); } else { declaredMethod = null; } break; } } // If the method has a different signature matching the given types, add it to the candidates if (declaredMethod != null) { candidates.add(declaredMethod); } } } } if (candidates.size() != 1) { throw new JCloudScaleException( String.format("Cannot find distinct method '%s.%s()' with parameter types %s", type, methodName, Arrays.toString(clazzes))); } method = candidates.get(0); } //do we really need this dependency? //ReflectionUtils.makeAccessible(method); if (method != null && !method.isAccessible()) method.setAccessible(true); return method; }
From source file:net.navasoft.madcoin.backend.services.vo.request.SuccessRequestVOWrapper.java
/** * Gets the processing values./*www . ja va 2 s .co m*/ * * @param service * the service * @since 27/07/2014, 06:49:08 PM */ @Override public void processValues(IService service) { if (isValidService(service)) { for (ProcessedField annotatedField : getTarget(service)) { for (Method accessor : filterMethods()) { Annotation annot = accessor.getAnnotation(ProcessingField.class); if (annot != null) { ProcessingField expectedReal = ((ProcessingField) annot); if (!ArrayUtils.contains(alreadyProcessed, expectedReal.expectedVariable())) { try { if (validateProcessAnnotations(annotatedField, expectedReal)) { Object requestValue = null; switch (expectedReal.precedence()) { case BASIC_OPTIONAL: requestValue = accessor.invoke(hidden, ArrayUtils.EMPTY_OBJECT_ARRAY); processed.put(expectedReal.expectedVariable(), requestValue); alreadyProcessed = (String[]) ArrayUtils.add(alreadyProcessed, expectedReal.expectedVariable()); break; case BASIC_REQUIRED: requestValue = accessor.invoke(this.hidden, ArrayUtils.EMPTY_OBJECT_ARRAY); processed.put(expectedReal.expectedVariable(), requestValue); alreadyProcessed = (String[]) ArrayUtils.add(alreadyProcessed, expectedReal.expectedVariable()); break; case COMPLEX_OPTIONAL: requestValue = expectedReal.helperClass().newInstance(); processed.put(expectedReal.expectedVariable(), expectedReal.helperClass() .getMethod(expectedReal.converterMethod(), ArrayUtils.EMPTY_CLASS_ARRAY) .invoke(requestValue, ArrayUtils.EMPTY_OBJECT_ARRAY)); alreadyProcessed = (String[]) ArrayUtils.add(alreadyProcessed, expectedReal.expectedVariable()); break; case COMPLEX_REQUIRED: requestValue = expectedReal.helperClass().newInstance(); processed.put(expectedReal.expectedVariable(), expectedReal.helperClass() .getMethod(expectedReal.converterMethod(), ArrayUtils.EMPTY_CLASS_ARRAY) .invoke(requestValue, ArrayUtils.EMPTY_OBJECT_ARRAY)); alreadyProcessed = (String[]) ArrayUtils.add(alreadyProcessed, expectedReal.expectedVariable()); break; default: break; } } } catch (IllegalAccessException e1) { } catch (IllegalArgumentException e1) { } catch (InvocationTargetException e1) { } catch (NoSuchMethodException e) { } catch (SecurityException e) { } catch (InstantiationException e) { } } } } } } }
From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.TestPluginConfigurationServiceDefault.java
@Test public void testGetAllSharedBuildNumberIds01() { final ConfigurationEntity configuration = this.getConfiguration(); SharedBuildNumberEntity sharedBuildNumber1 = new SharedBuildNumberEntity(); sharedBuildNumber1.setId(5);//from ww w . ja v a 2s. com configuration.addOrUpdateBuildNumber(sharedBuildNumber1); SharedBuildNumberEntity sharedBuildNumber2 = new SharedBuildNumberEntity(); sharedBuildNumber2.setId(22); configuration.addOrUpdateBuildNumber(sharedBuildNumber2); SharedBuildNumberEntity sharedBuildNumber3 = new SharedBuildNumberEntity(); sharedBuildNumber3.setId(1); configuration.addOrUpdateBuildNumber(sharedBuildNumber3); replay(this.service); int[] ids = this.service.getAllSharedBuildNumberIds(); assertNotNull("The list of IDs should not be null.", ids); assertTrue("The list of IDs should contain 1.", ArrayUtils.contains(ids, 1)); assertTrue("The list of IDs should contain 5.", ArrayUtils.contains(ids, 5)); assertTrue("The list of IDs should contain 22.", ArrayUtils.contains(ids, 22)); verify(this.service); }
From source file:com.adobe.acs.commons.util.impl.UrlFilter.java
private boolean check(String value, String allowedArrayPropertyName, String allowedPatternPropertyName, ValueMap properties) {// w ww .jav a 2 s.c o m if (value == null) { // no value is always allowed return true; } String[] allowedValues = properties.get(allowedArrayPropertyName, String[].class); if (allowedValues != null) { if (allowedValues.length == 0) { log.debug("{} was empty, therefore not allowing any value.", allowedArrayPropertyName); return false; } else if (!ArrayUtils.contains(allowedValues, value)) { log.debug("{} did not contain our string {}. checking the pattern.", allowedArrayPropertyName, value); String allowedPattern = properties.get(allowedPatternPropertyName, String.class); if (allowedPattern == null || !Pattern.matches(allowedPattern, value)) { log.debug("allowedPattern ({}) did not match our string {}", allowedPattern, value); return false; } else { log.debug("allowedPattern ({}) did match our string {}", allowedPattern, value); return true; } } else { return true; } } else { String allowedPattern = properties.get(allowedPatternPropertyName, String.class); if (allowedPattern != null && !Pattern.matches(allowedPattern, value)) { log.debug("allowedPattern ({}) did not match our string {}", allowedPattern, value); return false; } else { return true; } } }
From source file:io.fabric8.elasticsearch.plugin.OpenshiftRequestContextFactory.java
private boolean isBlacklistProject(String project) { return ArrayUtils.contains(operationsProjects, project.toLowerCase()); }
From source file:edu.cornell.med.icb.clustering.TestMCLClusterer.java
@Test public void fourInstanceClusteringInOneCluster() { // put one instance in each cluster, total two instances final Clusterer clusterer = new MCLClusterer(4); final SimilarityDistanceCalculator distanceCalculator = new MaxLinkageDistanceCalculator() { public double distance(final int i, final int j) { // instances 0 and 1 belong to same cluster if (i == 0 && j == 1 || i == 1 && j == 0) { return 0; } else { return 10; }/*w w w. ja va 2 s . c om*/ } }; // instances 0,1,2,3 go to cluster 1 (distance(0,1)=0; distance(2,0)=10<=threshold) assertEquals(0d, distanceCalculator.distance(0, 1), DELTA); assertEquals(0d, distanceCalculator.distance(1, 0), DELTA); assertEquals(10d, distanceCalculator.distance(0, 0), DELTA); assertEquals(10d, distanceCalculator.distance(1, 1), DELTA); assertEquals(10d, distanceCalculator.distance(0, 2), DELTA); assertEquals(10d, distanceCalculator.distance(2, 0), DELTA); assertEquals(10d, distanceCalculator.distance(2, 3), DELTA); final List<int[]> clusters = clusterer.cluster(distanceCalculator, 11); assertNotNull(clusters); assertEquals("Expected one cluster", 1, clusters.size()); final int[] cluster = clusters.get(0); assertEquals("First cluster must have size 4", 4, cluster.length); assertTrue("Instance 0 in cluster 0", ArrayUtils.contains(cluster, 0)); assertTrue("Instance 1 in cluster 0", ArrayUtils.contains(cluster, 1)); assertTrue("Instance 2 in cluster 0", ArrayUtils.contains(cluster, 2)); assertTrue("Instance 3 in cluster 0", ArrayUtils.contains(cluster, 3)); }
From source file:com.icantrap.collections.dawg.Dawg.java
/** * Given a subset of source letters and a possible pattern, find words that would satisfy the conditions. * * @param letters Confining set of letters to choose from. Use ? for wildcards * @param pattern Pattern for words. Use '?' for single letter wildcard. Use '*' for multiple letter wildcard. * @return An array of letters.//www . j a v a2s.c o m */ public Result[] subwords(String letters, String pattern) // yes, there's a lot of repeated code here. it might get cleaned up at the end. { if (!lettersValid(letters)) return null; if (!patternValid(pattern)) return null; List<PatternToken> patternTokens = processPattern(pattern); int tokenCount = patternTokens.size(); Set<Result> results = new HashSet<Result>(); // the running list of subwords Stack<StackEntry> stack = new Stack<StackEntry>(); // a stack of paths to traverse. This prevents the StackOverflowException. stack.push(new StackEntry(nodes[0], letters.toUpperCase().toCharArray(), "", 0)); while (!stack.empty()) { StackEntry entry = stack.pop(); int patternIndex = entry.patternIndex; char[] chars = entry.chars; int node = entry.node; char nodeValue = getChar(node); if (patternIndex < tokenCount) // match the pattern { PatternToken patternToken = patternTokens.get(patternIndex); if (patternToken.required) { StringBuilder nextSubwordBuilder = new StringBuilder(entry.subword.length() + 1) .append(entry.subword); List<Integer> nextWildcardPositions = entry.wildcardPositions; switch (patternToken.letter) { case '?': // the node value needs to be in the letters if (ArrayUtils.contains(chars, nodeValue)) chars = ArrayUtils.removeElement(chars, nodeValue); else if (ArrayUtils.contains(chars, '?')) { chars = ArrayUtils.removeElement(chars, '?'); if (nextWildcardPositions == null) nextWildcardPositions = new ArrayList<Integer>(); else nextWildcardPositions = new ArrayList<Integer>(entry.wildcardPositions); nextWildcardPositions.add(entry.subword.length()); } else continue; nextSubwordBuilder.append(nodeValue); break; case (char) -1: if (canTerminate(node)) results.add(new Result(entry.subword, nextWildcardPositions)); continue; default: if (nodeValue != patternToken.letter) continue; if (0 != nodeValue) nextSubwordBuilder.append(nodeValue); break; } ++patternIndex; // if we just fulfilled the last token, see if the subword can terminate if ((patternIndex == tokenCount) && canTerminate(node)) results.add(new Result(nextSubwordBuilder.toString(), nextWildcardPositions)); // lookahead to the next token and put a candidate on the stack addCandidates(stack, patternTokens, patternIndex, node, chars, nextSubwordBuilder.toString(), nextWildcardPositions); } else // optional pattern match { if (node == nodes[0]) { addCandidates(stack, patternTokens, patternIndex, node, chars, entry.subword, entry.wildcardPositions); } else if ('?' == patternToken.letter) { // whether we match the pattern or not, it must be in the letters List<Integer> nextWildcardPositions = entry.wildcardPositions; StringBuilder nextSubwordBuilder = new StringBuilder(entry.subword.length() + 1) .append(entry.subword).append(nodeValue); char[] nextChars; if (ArrayUtils.contains(chars, nodeValue)) nextChars = ArrayUtils.removeElement(chars, nodeValue); else if (ArrayUtils.contains(chars, '?')) { nextChars = ArrayUtils.removeElement(chars, '?'); if (nextWildcardPositions == null) nextWildcardPositions = new ArrayList<Integer>(); else nextWildcardPositions = new ArrayList<Integer>(entry.wildcardPositions); nextWildcardPositions.add(entry.subword.length()); } else continue; // match the pattern { int nextPatternIndex = patternIndex + 1; // if we just fulfilled the last token, see if the subword can terminate if ((nextPatternIndex == tokenCount) && canTerminate(node)) results.add(new Result(nextSubwordBuilder.toString(), nextWildcardPositions)); // lookahead to the next token and put a candidate on the stack addCandidates(stack, patternTokens, nextPatternIndex, node, nextChars, nextSubwordBuilder.toString(), nextWildcardPositions); } // don't match the pattern // lookahead to the next token and put a candidate on the stack addCandidates(stack, patternTokens, patternIndex, node, nextChars, nextSubwordBuilder.toString(), nextWildcardPositions); } else { StringBuilder nextSubwordBuilder = new StringBuilder(entry.subword.length() + 1) .append(entry.subword).append(nodeValue); // match the letters, not the pattern { List<Integer> nextWildcardPositions = entry.wildcardPositions; char[] nextChars = null; boolean found = true; if (ArrayUtils.contains(chars, nodeValue)) nextChars = ArrayUtils.removeElement(chars, nodeValue); else if (ArrayUtils.contains(chars, '?')) { nextChars = ArrayUtils.removeElement(chars, '?'); if (nextWildcardPositions == null) nextWildcardPositions = new ArrayList<Integer>(); else nextWildcardPositions = new ArrayList<Integer>(entry.wildcardPositions); nextWildcardPositions.add(entry.subword.length()); } else found = false; if (found) // lookahead to the next token and put a candidate on the stack addCandidates(stack, patternTokens, patternIndex, node, nextChars, nextSubwordBuilder.toString(), nextWildcardPositions); } // match the pattern, not the letters if (nodeValue == patternToken.letter) { int nextPatternIndex = patternIndex + 1; // if we just fulfilled the last token, see if the subword can terminate if ((nextPatternIndex == tokenCount) && canTerminate(node)) results.add(new Result(nextSubwordBuilder.toString(), entry.wildcardPositions)); // lookahead to the next token and put a candidate on the stack addCandidates(stack, patternTokens, nextPatternIndex, node, chars, nextSubwordBuilder.toString(), entry.wildcardPositions); } } } } else // no pattern to match { StringBuilder nextSubwordBuilder = new StringBuilder(entry.subword.length() + 1) .append(entry.subword); List<Integer> nextWildcardPositions = entry.wildcardPositions; char[] nextChars = entry.chars; if (node != nodes[0]) { if (ArrayUtils.contains(chars, nodeValue)) nextChars = ArrayUtils.removeElement(chars, nodeValue); else if (ArrayUtils.contains(chars, '?')) { nextChars = ArrayUtils.removeElement(chars, '?'); if (nextWildcardPositions == null) nextWildcardPositions = new ArrayList<Integer>(); else nextWildcardPositions = new ArrayList<Integer>(entry.wildcardPositions); nextWildcardPositions.add(entry.subword.length()); } else continue; if (0 != nodeValue) nextSubwordBuilder.append(nodeValue); if (canTerminate(node)) results.add(new Result(nextSubwordBuilder.toString(), nextWildcardPositions)); } // find the next candidate from the letters addCandidatesFromLetters(stack, node, nextChars, nextSubwordBuilder.toString(), nextWildcardPositions, patternIndex); } } return results.toArray(new Result[results.size()]); }
From source file:com.adobe.acs.commons.workflow.bulk.execution.model.Workspace.java
public boolean isActive(PayloadGroup payloadGroup) { return ArrayUtils.contains(activePayloadGroups, payloadGroup.getDereferencedPath()); }