Java Code Examples for org.apache.commons.lang3.ArrayUtils.contains()

The following are Jave code examples for showing how to use contains() of the org.apache.commons.lang3.ArrayUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: alexa-utterance-generator   File: WeightedSegmentsFormatter.java   View Source Code Vote up 6 votes
public WeightedSegmentsFormatter(final String[] args) {
    if (args != null) {
        prependPriority = ArrayUtils.contains(args, "-pp") || ArrayUtils.contains(args, "-prependPriority");

        int index1 = ArrayUtils.indexOf(args, "-weight");
        if (index1 < args.length - 1) {
            final String weightString = args[index1 + 1];
            Validate.isTrue(NumberUtils.isParsable(weightString), "Please provide a numeric value for weight.");
            this.weight = Integer.parseInt(weightString);
        }

        int index2 = ArrayUtils.indexOf(args, "-separator");
        if (index2 < args.length - 1) {
            valueSeparator = args[index2 + 1];
        }
    }
}
 
Example 2
Project: spark-project   File: PermissionInfo.java   View Source Code Vote up 6 votes
public PermissionInfo permitted() {
    Subject currentUser = SecurityUtils.getSubject();
    if (TYPE.ROLE.equals(this.type)) {
        // role based
        if (Logical.AND.equals(this.logical)) {
            isPermitted = currentUser.hasAllRoles(Arrays.asList(roles));
            return this;
        }
        isPermitted = ArrayUtils.contains(currentUser.hasRoles(Arrays.asList(roles)), true);
        return this;
    }
    // permission based
    if (Logical.AND.equals(this.logical)) {
        isPermitted = currentUser.isPermittedAll(permissions);
        return this;
    }
    isPermitted = ArrayUtils.contains(currentUser.isPermitted(permissions), true);
    return this;
}
 
Example 3
Project: java-debug   File: SetExceptionBreakpointsRequestHandler.java   View Source Code Vote up 6 votes
@Override
public CompletableFuture<Response> handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) {
    if (context.getDebugSession() == null) {
        return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.EMPTY_DEBUG_SESSION, "Empty debug session.");
    }

    String[] filters = ((SetExceptionBreakpointsArguments) arguments).filters;
    try {
        boolean notifyCaught = ArrayUtils.contains(filters, Types.ExceptionBreakpointFilter.CAUGHT_EXCEPTION_FILTER_NAME);
        boolean notifyUncaught = ArrayUtils.contains(filters, Types.ExceptionBreakpointFilter.UNCAUGHT_EXCEPTION_FILTER_NAME);

        context.getDebugSession().setExceptionBreakpoints(notifyCaught, notifyUncaught);
        return CompletableFuture.completedFuture(response);
    } catch (Exception ex) {
        return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.SET_EXCEPTIONBREAKPOINT_FAILURE,
                String.format("Failed to setExceptionBreakpoints. Reason: '%s'", ex.toString()));
    }
}
 
Example 4
Project: BaseClient   File: SoundHandler.java   View Source Code Vote up 6 votes
/**
 * Returns a random sound from one or more categories
 */
public SoundEventAccessorComposite getRandomSoundFromCategories(SoundCategory... categories)
{
    List<SoundEventAccessorComposite> list = Lists.<SoundEventAccessorComposite>newArrayList();

    for (ResourceLocation resourcelocation : this.sndRegistry.getKeys())
    {
        SoundEventAccessorComposite soundeventaccessorcomposite = (SoundEventAccessorComposite)this.sndRegistry.getObject(resourcelocation);

        if (ArrayUtils.contains(categories, soundeventaccessorcomposite.getSoundCategory()))
        {
            list.add(soundeventaccessorcomposite);
        }
    }

    if (list.isEmpty())
    {
        return null;
    }
    else
    {
        return (SoundEventAccessorComposite)list.get((new Random()).nextInt(list.size()));
    }
}
 
Example 5
Project: keti   File: AttributeCacheFactory.java   View Source Code Vote up 6 votes
private AttributeCache createAttributeCache(final String cacheType, final long maxCachedIntervalMinutes,
        final String zoneName, final RedisTemplate<String, String> cacheRedisTemplate,
        final BiFunction<String, String, String> getKey, final boolean enableAttributeCaching) {
    String[] profiles = environment.getActiveProfiles();

    if (!enableAttributeCaching) {
        LOGGER.info("Caching disabled for {} attributes.", cacheType);
        return new NonCachingAttributeCache();
    }
    if (ArrayUtils.contains(profiles, "redis") || ArrayUtils.contains(profiles, "cloud-redis")) {
        LOGGER.info("Redis caching enabled for {} attributes.", cacheType);
        return new RedisAttributeCache(maxCachedIntervalMinutes, zoneName, getKey, cacheRedisTemplate);
    }
    LOGGER.info("In-memory caching enabled for {} attributes.", cacheType);
    return new InMemoryAttributeCache(maxCachedIntervalMinutes, zoneName, getKey);
}
 
Example 6
Project: jvm-sandbox   File: CoreConfigure.java   View Source Code Vote up 5 votes
private static Map<String, String> propertiesToStringMap(final Properties properties) {
    final Map<String, String> map = new HashMap<String, String>();
    for (String key : properties.stringPropertyNames()) {

        // 过滤掉受保护的key
        if (ArrayUtils.contains(PROTECT_KEY_ARRAY, key)
                && map.containsKey(key)) {
            continue;
        }

        map.put(key, properties.getProperty(key));
    }
    return map;
}
 
Example 7
Project: zkAdmin   File: RegexpUtils.java   View Source Code Vote up 5 votes
/**
 * 将除了指定字符之外的所有正则元字符全部用转义符更改为字面含义
 * @param key
 * @param
 * @return
 */
public static String escapeRegChars(String key, char[] keeps) {
    for(char c:REGEXP_KEY_CHARS){
        if(!ArrayUtils.contains(keeps, c)){
            key=key.replace(String.valueOf(c),"\\"+c);
        }
    }
    return key;
}
 
Example 8
Project: lemon   File: StaticContentFilter.java   View Source Code Vote up 5 votes
/**
 * 创建Content基本信息.
 */
private ContentInfo getContentInfo(String contentPath) {
    ContentInfo contentInfo = new ContentInfo();

    String realFilePath = this.findRealFilePath(contentPath);
    logger.debug("realFilePath {}", realFilePath);

    File file = new File(realFilePath);

    contentInfo.setFile(file);
    contentInfo.setContentPath(contentPath);
    contentInfo.setFileName(file.getName());
    contentInfo.setLength((int) file.length());

    contentInfo.setLastModified(file.lastModified());
    contentInfo.setEtag("W/\"" + contentInfo.lastModified + "\"");

    contentInfo.setMimeType(mimetypesFileTypeMap
            .getContentType(contentInfo.fileName));

    if ((contentInfo.length >= GZIP_MINI_LENGTH)
            && ArrayUtils.contains(GZIP_MIME_TYPES,
                    contentInfo.getMimeType())) {
        contentInfo.setNeedGzip(true);
    } else {
        contentInfo.setNeedGzip(false);
    }

    return contentInfo;
}
 
Example 9
Project: bootstrap   File: BackendProxyServlet.java   View Source Code Vote up 5 votes
@Override
protected String filterServerResponseHeader(final HttpServletRequest clientRequest, final Response serverResponse, final String headerName,
		final String headerValue) {
	// Filter some headers
	final String lowerCase = StringUtils.lowerCase(headerName);
	return ArrayUtils.contains(INGNORE_HEADERS, lowerCase)
			|| INGORE_HEADER_VALUE.containsKey(lowerCase) && headerValue.startsWith(INGORE_HEADER_VALUE.get(lowerCase)) ? null : headerValue;
}
 
Example 10
Project: Wechat-Group   File: WxMpPayServiceImpl.java   View Source Code Vote up 5 votes
private void checkParameters(WxPayRefundRequest request) throws WxErrorException {
  BeanUtils.checkRequiredFields(request);

  if (StringUtils.isNotBlank(request.getRefundAccount())) {
    if (!ArrayUtils.contains(REFUND_ACCOUNT, request.getRefundAccount())) {
      throw new IllegalArgumentException("refund_account目前必须为" + Arrays.toString(REFUND_ACCOUNT) + "其中之一,实际值:" + request.getRefundAccount());
    }
  }

  if (StringUtils.isBlank(request.getOutTradeNo()) && StringUtils.isBlank(request.getTransactionId())) {
    throw new IllegalArgumentException("transaction_id 和 out_trade_no 不能同时为空,必须提供一个");
  }
}
 
Example 11
Project: Wechat-Group   File: WxMpPayServiceImpl.java   View Source Code Vote up 5 votes
private void checkParameters(WxPayUnifiedOrderRequest request) throws WxErrorException {
  BeanUtils.checkRequiredFields(request);

  if (!ArrayUtils.contains(TRADE_TYPES, request.getTradeType())) {
    throw new IllegalArgumentException("trade_type目前必须为" + Arrays.toString(TRADE_TYPES) + "其中之一,实际值:" + request.getTradeType());
  }

  if ("JSAPI".equals(request.getTradeType()) && request.getOpenid() == null) {
    throw new IllegalArgumentException("当 trade_type是'JSAPI'时未指定openid");
  }

  if ("NATIVE".equals(request.getTradeType()) && request.getProductId() == null) {
    throw new IllegalArgumentException("当 trade_type是'NATIVE'时未指定product_id");
  }
}
 
Example 12
Project: xtf   File: WaitUtil.java   View Source Code Vote up 5 votes
public static BooleanSupplier urlReturnsCode(String url, int... codes) {
	return () -> {
		try {
			int responseCode = HttpClient.get(url).code();
			return ArrayUtils.contains(codes, responseCode);
		} catch (IOException x) {
			return false;
		}
	};
}
 
Example 13
Project: featurea   File: NumericLocator.java   View Source Code Vote up 5 votes
private void validate() {
    super.validate(getRegisterCount());

    if (range == RegisterRange.COIL_STATUS || range == RegisterRange.INPUT_STATUS)
        throw new IllegalDataTypeException("Only binary values can be read from Coil and Input ranges");

    if (!ArrayUtils.contains(DATA_TYPES, dataType))
        throw new IllegalDataTypeException("Invalid data type");
}
 
Example 14
Project: PonySocks2   File: RecipeSockPaint.java   View Source Code Vote up 5 votes
@Override
protected boolean hasColor(ItemStack stack) {
	int[] ids = OreDictionary.getOreIDs(stack);
	for (int id : ids) {
		if (ArrayUtils.contains(PonySocks.dyeOreIds, id)) {
			return true;
		}
	}

	return false;
}
 
Example 15
Project: morefurnaces   File: ItemHandlerMoveStacks.java   View Source Code Vote up 5 votes
public void moveStacks()
{
    for (int i = 0; i < getSlots(); i++)
    {
        if (!ArrayUtils.contains(destSlots, i))
        {
            ItemStack src = getStackInSlot(i);
            if (!src.isEmpty())
            {
                ItemStack remainder = moveStackToFirstDest(src);
                setStackInSlot(i, remainder);
            }
        }
    }
}
 
Example 16
Project: customstuff4   File: TileEntityModuleInventory.java   View Source Code Vote up 4 votes
@Override
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing)
{
    return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY &&
           (facing == null || ArrayUtils.contains(supplier.sides, facing));
}
 
Example 17
Project: jvm-sandbox   File: SeparateImmediatelyEventListener.java   View Source Code Vote up 4 votes
@Override
public void onEvent(final Event event) throws Throwable {

    // 分离Immediately事件
    final Event replaceEvent;
    final Step step = stepRef.get();
    switch (step) {
        case STEP_IMMEDIATELY_RETURN_EVENT: {
            final ReturnEvent returnEvent = (ReturnEvent) event;
            replaceEvent = eventPool.borrowImmediatelyReturnEvent(returnEvent.processId, returnEvent.invokeId, returnEvent.object);
            break;
        }
        case STEP_IMMEDIATELY_THROWS_EVENT: {
            final ThrowsEvent throwsEvent = (ThrowsEvent) event;
            replaceEvent = eventPool.borrowImmediatelyThrowsEvent(throwsEvent.processId, throwsEvent.invokeId, throwsEvent.throwable);
            break;
        }
        case STEP_ORIGINAL_EVENT:
        default: {
            replaceEvent = event;
            break;
        }
    }

    try {
        stepRef.set(Step.STEP_ORIGINAL_EVENT);

        // 如果当前事件不在事件监听范围,则直接忽略什么都不用处理
        if (!ArrayUtils.contains(eventTypeArray, replaceEvent.type)) {
            return;
        }

        // 处理事件
        listener.onEvent(replaceEvent);

    } catch (ProcessControlException pce) {

        switch (pce.getState()) {
            case RETURN_IMMEDIATELY: {
                stepRef.set(Step.STEP_IMMEDIATELY_RETURN_EVENT);
                break;
            }
            case THROWS_IMMEDIATELY:
            default: {
                stepRef.set(Step.STEP_IMMEDIATELY_THROWS_EVENT);
            }
        }

        throw pce;

    } finally {
        if (replaceEvent instanceof ImmediatelyReturnEvent
                || replaceEvent instanceof ImmediatelyThrowsEvent) {
            eventPool.returnEvent(replaceEvent);
        }
    }

}
 
Example 18
Project: slides-converter   File: PowerPointToHTML.java   View Source Code Vote up 4 votes
private boolean isContentSlide(int slideNum) {
	return (slideNum >= mainTitleFromSlide && slideNum <= mainTitleToSlide)
			|| ArrayUtils.contains(nonSubtitleSlides, slideNum)
			|| ArrayUtils.contains(titleSlides, slideNum)
			|| ArrayUtils.contains(imageSlides, slideNum);
}
 
Example 19
Project: bluegreen-manager   File: TransitionTask.java   View Source Code Vote up 4 votes
/**
 * True if the transition parameters allow the transition to start from the specified mode.
 */
boolean isAllowedStartMode(DbFreezeMode mode)
{
  return ArrayUtils.contains(transitionParameters.getAllowedStartModes(), mode);
}
 
Example 20
Project: slides-converter   File: PowerPointToHTML.java   View Source Code Vote up 2 votes
private String calculateTitle(XSLFSlide slideX, HSLFSlide slide) {

		String title = slide.getTitle();

		if (title != null) {
			return title;
		}

		title = slideX.getTitle();

		if (title != null) {
			return title;
		}

		boolean titleSlide = ArrayUtils.contains(titleSlides,
				slideX.getSlideNumber());

		for (XSLFShape shape : slideX.getShapes()) {

			if (shape instanceof XSLFTextShape) {

				XSLFTextShape tsh = (XSLFTextShape) shape;

				Rectangle2D figure = getRelativeFigure(tsh);

				if (titleSlide || figure.getY() < 0.1) {

					StringBuilder titleSB = new StringBuilder();

					for (XSLFTextParagraph p : tsh) {
						for (XSLFTextRun r : p) {
							titleSB.append(r.getRawText());
						}
					}

					title = titleSB.toString();

					if (!title.trim().isEmpty()) {
						return title;
					}
				}
			}
		}

		return null;
	}