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:net.orpiske.sdm.engine.GroovyEngine.java
public void run(final File file, String... phases) throws EngineException { long total = 0; GroovyObject groovyObject = getObject(file); Object url = groovyObject.getProperty("url"); if (phases.length == 0) { return;//from w ww .j a v a 2 s . c o m } if (ArrayUtils.contains(phases, "fetch")) { total += runPhase(groovyObject, "fetch", url); } String artifactName = null; try { if (url != null && !url.toString().isEmpty()) { artifactName = URLUtils.getFilename(url.toString()); artifactName = WorkdirUtils.getWorkDir() + File.separator + artifactName; } } catch (MalformedURLException e) { String urlString = url.toString(); if (!ScmUrlUtils.isValid(urlString)) { throw new EngineException("The package URL is invalid: " + e.getMessage(), e); } } catch (URISyntaxException e) { throw new EngineException("The URL syntax is invalid: " + e.getMessage(), e); } if (ArrayUtils.contains(phases, "extract")) { total += runPhase(groovyObject, "extract", artifactName); } if (ArrayUtils.contains(phases, "build")) { total += runPhase(groovyObject, "build", (Object[]) null); } if (ArrayUtils.contains(phases, "verify")) { total += runPhase(groovyObject, "verify", (Object[]) null); } if (ArrayUtils.contains(phases, "prepare")) { total += runPhase(groovyObject, "prepare", (Object[]) null); } if (ArrayUtils.contains(phases, "install")) { total += runPhase(groovyObject, "install", (Object[]) null); } if (ArrayUtils.contains(phases, "finish")) { total += runPhase(groovyObject, "finish", (Object[]) null); } if (ArrayUtils.contains(phases, "cleanup")) { total += runPhase(groovyObject, "cleanup", (Object[]) null); } printPhaseHeader("install completed"); logger.info("Installation completed in " + total + " ms"); }
From source file:com.cloudera.impala.extdatasource.ExternalDataSourceExecutor.java
/** * @param jarPath The local path to the jar containing the ExternalDataSource. * @param className The name of the class implementing the ExternalDataSource. * @param apiVersionStr The API version the ExternalDataSource implements. * Must be a valid value of {@link ApiVersion}. *//*w w w. j av a 2 s . c o m*/ public ExternalDataSourceExecutor(String jarPath, String className, String apiVersionStr) throws ImpalaException { Preconditions.checkNotNull(jarPath); apiVersion_ = ApiVersion.valueOf(apiVersionStr); if (apiVersion_ == null) { throw new ImpalaRuntimeException("Invalid API version: " + apiVersionStr); } jarPath_ = jarPath; className_ = className; try { URL url = new File(jarPath).toURI().toURL(); URLClassLoader loader = URLClassLoader.newInstance(new URL[] { url }, getClass().getClassLoader()); Class<?> c = Class.forName(className, true, loader); if (!ArrayUtils.contains(c.getInterfaces(), apiVersion_.getApiInterface())) { throw new ImpalaRuntimeException( String.format("Class '%s' does not implement interface '%s' required for API version %s", className, apiVersion_.getApiInterface().getName(), apiVersionStr)); } Constructor<?> ctor = c.getConstructor(); dataSource_ = (ExternalDataSource) ctor.newInstance(); } catch (Exception ex) { throw new ImpalaRuntimeException(String.format( "Unable to load external data " + "source library from path=%s className=%s apiVersion=%s", jarPath, className, apiVersionStr), ex); } }
From source file:com.hubspot.utils.circuitbreaker.CircuitBreakerInvocationHandler.java
/** * Called from a Proxy instance to invoke a method on the realObj stored by this handler. * //ww w. j a v a 2 s. com * If a "blacklisted" exception is thrown, we inform our CircuitBreakerPolicy let it * tell us whether we should move states. */ @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { getLog().debug("circuit breaker wrapped method invocation = " + method.toGenericString()); Throwable fromInvocation = null; Object ret = null; try { if (blacklist.containsKey(method) && policy.getCurrentState() == CircuitBreakerState.OPEN && !policy.shouldAttemptReset()) { // breaker is open, just throw our standard CircuitBreakerException throw new CircuitBreakerException(); } // circuit breaker is either open or half-open, do our invocation ret = method.invoke(realObj, args); } catch (InvocationTargetException e) { // The underlying method was called successfully, but threw an exception. // we want to pass that exception on. fromInvocation = e.getCause(); } catch (IllegalArgumentException e) { // "In a properly constructed proxy, this should never happen." getLog().debug("Illegal argument exception in circuit breaker handler" + e); throw e; } catch (IllegalAccessException e) { // "In a properly constructed proxy, this should never happen." getLog().debug("Illegal access exception in circuit breaker handler" + e); throw e; } // exception was thrown, determine if it was blacklisted and if we should trip if (fromInvocation != null) { if (blacklist.containsKey(method)) { Class[] blacklistedExceptionTypes = blacklist.get(method); if (ArrayUtils.contains(blacklistedExceptionTypes, fromInvocation.getClass())) { policy.failedBlacklistedCall(method); } } else { policy.successfulCall(method); } throw fromInvocation; } if (blacklist.containsKey(method)) policy.successfulCall(method); return ret; }
From source file:de.ingrid.admin.Utils.java
public static void addDatatypeToIndex(String index, String type) { Config config = JettyStarter.getInstance().config; if (config.datatypesOfIndex != null) { String[] types = config.datatypesOfIndex.get(index); if (types != null) { if (!ArrayUtils.contains(types, type)) { config.datatypesOfIndex.put(index, (String[]) ArrayUtils.add(types, type)); if (!config.datatypes.contains(type)) { config.datatypes.add(type); }//from w w w .j a v a2s .co m } } } }
From source file:com.kibana.multitenancy.plugin.acl.SearchGuardACLRequestActionFilter.java
private boolean includesProperyValue(final IndicesRequest request, final String property, final String expValue) { try {/*from ww w .j a va 2 s . co m*/ final Method method = request.getClass().getDeclaredMethod(property); method.setAccessible(true); final String value = (String) method.invoke(request); return expValue.equals(value); } catch (final Exception e) { try { final Method method = request.getClass().getDeclaredMethod(property + "s"); method.setAccessible(true); final String[] types = (String[]) method.invoke(request); return ArrayUtils.contains(types, expValue); } catch (final Exception e1) { logger.warn("Cannot determine {} for {} due to {}[s]() method not found", property, request, property); } } return false; }
From source file:com.dp2345.template.directive.BaseDirective.java
/** * ?//from w w w. j a va2 s. c o m * * @param params * ? * @param type * ? * @param ignoreProperties * * @return */ protected List<Filter> getFilters(Map<String, TemplateModel> params, Class<?> type, String... ignoreProperties) throws TemplateModelException { List<Filter> filters = new ArrayList<Filter>(); PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(type); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String propertyName = propertyDescriptor.getName(); Class<?> propertyType = propertyDescriptor.getPropertyType(); if (!ArrayUtils.contains(ignoreProperties, propertyName) && params.containsKey(propertyName)) { Object value = FreemarkerUtils.getParameter(propertyName, propertyType, params); filters.add(Filter.eq(propertyName, value)); } } return filters; }
From source file:de.alpharogroup.random.RandomExtensionsTest.java
/** * Test method for {@link RandomExtensions#getRandomEnum(Enum)} . *//*from ww w. j a v a2s. c o m*/ @Test public void testGetRandomEnum() { final Gender enumEntry = Gender.FEMALE; final Gender randomEnumEntry = RandomExtensions.getRandomEnum(enumEntry); final Gender[] genders = Gender.values(); AssertJUnit.assertTrue("Enum value should contain the random value.", ArrayUtils.contains(genders, randomEnumEntry)); }
From source file:alpha.portal.model.AdornmentTypeTest.java
/** * Test valid strings.//from www. j a va 2s . co m */ @Test public void testValidStrings() { final String[] t = AdornmentType.Visibility.getValueRange().getValidStrings(); Assert.assertEquals(2, t.length); Assert.assertTrue(ArrayUtils.contains(t, AdornmentTypeVisibility.PRIVATE.value())); Assert.assertTrue(ArrayUtils.contains(t, AdornmentTypeVisibility.PUBLIC.value())); }
From source file:net.shopxx.plugin.LoginPlugin.java
protected String joinKeyValue(Map<String, Object> map, String prefix, String suffix, String separator, boolean ignoreEmptyValue, String... ignoreKeys) { List<String> list = new ArrayList<String>(); if (map != null) { for (Map.Entry<String, Object> entry : map.entrySet()) { String key = entry.getKey(); String value = ConvertUtils.convert(entry.getValue()); if (StringUtils.isNotEmpty(key) && !ArrayUtils.contains(ignoreKeys, key) && (!ignoreEmptyValue || StringUtils.isNotEmpty(value))) { list.add(key + "=" + (value != null ? value : "")); }//from w ww .jav a 2s . c o m } } return (prefix != null ? prefix : "") + StringUtils.join(list, separator) + (suffix != null ? suffix : ""); }
From source file:com.hs.mail.container.config.Config.java
public static boolean isLocal(String domain) { return ArrayUtils.contains(domains, domain); }