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

The following examples show how to use org.apache.commons.lang3.ArrayUtils#contains() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StrUtil.java    From jboot with Apache License 2.0 6 votes vote down vote up
public static Model escapeModel(Model model, String... ignoreAttrs) {
    String[] attrNames = model._getAttrNames();
    for (String attr : attrNames) {

        if (ArrayUtils.contains(ignoreAttrs, attr)) {
            continue;
        }

        Object value = model.get(attr);

        if (value != null && value instanceof String) {
            model.set(attr, escapeHtml(value.toString()));
        }
    }

    return model;
}
 
Example 2
Source File: OAS2Parser.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Update OAS definition with GW endpoints and API information
 *
 * @param swagger        Swagger
 * @param basePath       API context
 * @param transports     transports types
 * @param hostsWithSchemes GW hosts with protocol mapping
 */
private void updateEndpoints(Swagger swagger, String basePath, String transports,
                             Map<String, String> hostsWithSchemes) {

    String host = StringUtils.EMPTY;
    String[] apiTransports = transports.split(",");
    List<Scheme> schemes = new ArrayList<>();
    if (ArrayUtils.contains(apiTransports, APIConstants.HTTPS_PROTOCOL)
            && hostsWithSchemes.get(APIConstants.HTTPS_PROTOCOL) != null) {
        schemes.add(Scheme.HTTPS);
        host = hostsWithSchemes.get(APIConstants.HTTPS_PROTOCOL).trim()
                .replace(APIConstants.HTTPS_PROTOCOL_URL_PREFIX, "");
    }
    if (ArrayUtils.contains(apiTransports, APIConstants.HTTP_PROTOCOL)
            && hostsWithSchemes.get(APIConstants.HTTP_PROTOCOL) != null) {
        schemes.add(Scheme.HTTP);
        if (StringUtils.isEmpty(host)) {
            host = hostsWithSchemes.get(APIConstants.HTTP_PROTOCOL).trim()
                    .replace(APIConstants.HTTP_PROTOCOL_URL_PREFIX, "");
        }
    }
    swagger.setSchemes(schemes);
    swagger.setBasePath(basePath);
    swagger.setHost(host);
}
 
Example 3
Source File: HTMLParser.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
private DomNode findElementOnStack(final String... searchedElementNames) {
    DomNode searchedNode = null;
    for (final DomNode node : stack_) {
        if (ArrayUtils.contains(searchedElementNames, node.getNodeName())) {
            searchedNode = node;
            break;
        }
    }

    if (searchedNode == null) {
        searchedNode = stack_.peek(); // this is surely wrong but at least it won't throw a NPE
    }

    return searchedNode;
}
 
Example 4
Source File: FileExtensionUtils.java    From kbase-doc with Apache License 2.0 5 votes vote down vote up
/**
 * 是否是 ppt 文件
 * @author eko.zhan at 2018年9月1日 上午10:16:11
 * @param filename
 * @return
 */
public static Boolean isPpt(String filename) {
	String[] arr = new String[]{"ppt", "pptx"};
	String extension = FilenameUtils.getExtension(filename).toLowerCase();
	if (ArrayUtils.contains(arr, extension)){
		return true;
	}
	return false;
}
 
Example 5
Source File: DefaultRulesExecutorBuilder.java    From yare with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DefaultRulesExecutorBuilder withFunctionMappings(Map<String, FeaturedObject<CallMetadata>> functionMappings) {
    for (Map.Entry<String, FeaturedObject<CallMetadata>> entry : functionMappings.entrySet()) {
        String name = entry.getKey();
        FeaturedObject<CallMetadata> object = entry.getValue();
        boolean shouldCache = !ArrayUtils.contains(object.getFeatures(), DefaultEngineFeature.DISABLE_CACHE_FUNCTION_RESULT);
        this.functionMappings.put(name, object.getObject());
        withFunctionCacheable(name, shouldCache);
    }
    return this;
}
 
Example 6
Source File: UpsellingController.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
private String getView(UpsellingForm form) {
    if (ArrayUtils.contains(CUSTOM_VIEWS, form.getPage())) {
        return form.getPage();
    }

    return GENERAL_VIEW;
}
 
Example 7
Source File: SystemEntityTestUtils.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected static Object getTestValue(Class returnType, ParameterizedType parameterizedType) {
  if (ArrayUtils.contains(BOOLEAN_CLASS, returnType)) {
    return new Random().nextBoolean();
  }
  if (Entity.class.isAssignableFrom(returnType)) {
    return getTestEntity(returnType);
  }
  if (returnType.equals(Iterable.class)) {
    Object type = getTypedTestEntity(parameterizedType);
    return newArrayList(type);
  }
  if (returnType.equals(LocalDate.class)) {
    return getRandomDate();
  }
  if (returnType.equals(Instant.class)) {
    return Instant.ofEpochSecond(new Random().nextInt());
  }
  if (ArrayUtils.contains(DOUBLE_CLASS, returnType)) {
    return new Random().nextDouble();
  }
  if (returnType.equals(String.class)) {
    return getRandomString();
  }
  if (ArrayUtils.contains(INT_CLASS, returnType)) {
    return new Random().nextInt();
  }
  if (ArrayUtils.contains(LONG_CLASS, returnType)) {
    return new Random().nextLong();
  }
  throw new RuntimeException("Unknown returntype: " + returnType.getSimpleName());
}
 
Example 8
Source File: HTMLElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the value of the {@code vAlign} property.
 * @param valid the valid values; if {@code null}, any value is valid
 * @param defaultValue the default value to use, if necessary
 * @return the value of the {@code vAlign} property
 */
protected String getVAlign(final String[] valid, final String defaultValue) {
    final String valign = getDomNodeOrDie().getAttributeDirect("valign");
    if (valid == null || ArrayUtils.contains(valid, valign)) {
        return valign;
    }
    return defaultValue;
}
 
Example 9
Source File: QueryHelper.java    From mybatis-dynamic-query with Apache License 2.0 5 votes vote down vote up
public String toSelectColumnsExpression(final Class entityClass,
                                        final String[] selectedProperties,
                                        final String[] ignoredProperties,
                                        final boolean mapUnderscoreToCamelCase) {
    ColumnInfo[] columnInfos = entityCache.getColumnInfos(entityClass);
    List<String> columns = new ArrayList<>();
    boolean isSelectedPropertiesNotEmpty = ArrayUtils.isNotEmpty(selectedProperties);
    boolean isIgnoredPropertiesNotEmpty = ArrayUtils.isNotEmpty(ignoredProperties);
    for (ColumnInfo columnInfo : columnInfos) {
        String fieldName = columnInfo.getField().getName();
        boolean needSelectColumn;
        if (isSelectedPropertiesNotEmpty) {
            needSelectColumn = ArrayUtils.contains(selectedProperties, fieldName);
        } else if (isIgnoredPropertiesNotEmpty) {
            needSelectColumn = !ArrayUtils.contains(ignoredProperties, fieldName);
        } else {
            needSelectColumn = true;
        }

        if (needSelectColumn) {
            // 这里我们需要判断一下,是否设置了 @column ,如果有的话,我们不做驼峰
            String useFieldName = mapUnderscoreToCamelCase ? EntityHelper.camelCaseToUnderscore(fieldName) : fieldName;
            String column = String.format("%s AS %s", columnInfo.getQueryColumn(), useFieldName);
            columns.add(column);
        }
    }
    return String.join(", ", columns);
}
 
Example 10
Source File: EqualsBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Appends the fields and values defined by the given object of the
 * given Class.</p>
 *
 * @param lhs  the left hand object
 * @param rhs  the right hand object
 * @param clazz  the class to append details of
 * @param builder  the builder to append to
 * @param useTransients  whether to test transient fields
 * @param excludeFields  array of field names to exclude from testing
 */
private static void reflectionAppend(
    Object lhs,
    Object rhs,
    Class<?> clazz,
    EqualsBuilder builder,
    boolean useTransients,
    String[] excludeFields) {

    if (isRegistered(lhs, rhs)) {
        return;
    }

    try {
        register(lhs, rhs);
        Field[] fields = clazz.getDeclaredFields();
        AccessibleObject.setAccessible(fields, true);
        for (int i = 0; i < fields.length && builder.isEquals; i++) {
            Field f = fields[i];
            if (!ArrayUtils.contains(excludeFields, f.getName())
                && (f.getName().indexOf('$') == -1)
                && (useTransients || !Modifier.isTransient(f.getModifiers()))
                && (!Modifier.isStatic(f.getModifiers()))) {
                try {
                    builder.append(f.get(lhs), f.get(rhs));
                } catch (IllegalAccessException e) {
                    //this can't happen. Would get a Security exception instead
                    //throw a runtime exception in case the impossible happens.
                    throw new InternalError("Unexpected IllegalAccessException");
                }
            }
        }
    } finally {
        unregister(lhs, rhs);
    }
}
 
Example 11
Source File: AO_TargetExt.java    From svg2vector with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the target for a given set value.
 * @return the target if valid value in the option, null if no value was set or the required target not in the list of supported targets
 */
public SvgTargets getTarget(){
	SvgTargets target = null;
	try{
		target = SvgTargets.valueOf(this.getValue());
	}
	catch(Exception ignore) {}

	return (ArrayUtils.contains(supportedTargets, target))?target:null;
}
 
Example 12
Source File: FastjsonHttpMessageConverter.java    From java-platform with Apache License 2.0 5 votes vote down vote up
@Override
public boolean apply(Object object, String name, Object value) {
	if (object instanceof BizEntity) {
		if (ArrayUtils.contains(
				new String[] { "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate" }, name)) {
			return false;
		}
	}
	return true;
}
 
Example 13
Source File: SidedRespective.java    From Sandbox with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setStack(int slot, ItemStack stack) {
    if (ArrayUtils.contains(inventory.getInvAvailableSlots(WrappingUtil.convert(direction)), slot))
        super.setStack(slot, stack);
}
 
Example 14
Source File: InventoryPanel.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(Batch batch, float a) {
  int x, y;
  if (Riiablo.charData.getItems().getAlternate() > 0) {
    x = xOffsAlt == Integer.MIN_VALUE ? xOffs : xOffsAlt;
    y = yOffsAlt == Integer.MIN_VALUE ? yOffs : yOffsAlt;
  } else {
    x = xOffs;
    y = yOffs;
  }

  if (item == null) {
    batch.draw(background, getX() + x, getY() + y);
  }

  boolean blocked = false;
  Item cursorItem = Riiablo.cursor.getItem();
  if (cursorItem != null) {
    blocked = !ArrayUtils.contains(cursorItem.typeEntry.BodyLoc, bodyPart);
  }

  // TODO: red if does not meet item requirements
  boolean isOver = clickListener.isOver();
  PaletteIndexedBatch b = (PaletteIndexedBatch) batch;
  if (isOver && !blocked && (cursorItem != null || item != null)) {
    b.setBlendMode(BlendMode.SOLID, backgroundColorG);
    b.draw(fill, getX(), getY(), getWidth(), getHeight());
    b.resetBlendMode();
  }

  // FIXME: Alt images on weapons are slightly off by maybe a pixel or so (rounding?) -- backgrounds fine
  if (item != null && item.checkLoaded()) {
    BBox box = item.invFile.getBox();
    item.setPosition(
        getX() + getWidth()  / 2 - box.width  / 2f + x,
        getY() + getHeight() / 2 - box.height / 2f + y);
    item.draw(b, 1);
  }

  if (isOver && blocked) {
    b.setBlendMode(BlendMode.SOLID, backgroundColorR);
    b.draw(fill, getX(), getY(), getWidth(), getHeight());
    b.resetBlendMode();
  }

  if (isOver && item != null && cursorItem == null) {
    Riiablo.game.setDetails(item.details(), item, InventoryPanel.this, this);
  }
}
 
Example 15
Source File: MethodInterceptorAdaptor.java    From onetwo with Apache License 2.0 4 votes vote down vote up
protected boolean isInterceptMethod(T target, Method method){
	return ArrayUtils.contains(interceptMethodNames, method.getName());
}
 
Example 16
Source File: ActionDownloadImageWidthHeight.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, Integer width, Integer height)
		throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		ActionResult<Wo> result = new ActionResult<>();
		Attachment2 attachment = emc.find(id, Attachment2.class, ExceptionWhen.not_found);
		/* 判断文件的当前用户是否是管理员或者文件创建者 或者当前用户在分享或者共同编辑中 */
		if (effectivePerson.isNotManager() && effectivePerson.isNotPerson(attachment.getPerson())) {
			throw new Exception("person{name:" + effectivePerson.getDistinguishedName() + "} access attachment{id:"
					+ id + "} denied.");
		}
		if (!ArrayUtils.contains(IMAGE_EXTENSIONS, attachment.getExtension())) {
			throw new Exception("attachment not image file.");
		}
		if (width < 0 || width > 5000) {
			throw new Exception("invalid width:" + width + ".");
		}
		if (height < 0 || height > 5000) {
			throw new Exception("invalid height:" + height + ".");
		}
		OriginFile originFile = emc.find(attachment.getOriginFile(),OriginFile.class);
		if (null == originFile) {
			throw new ExceptionAttachmentNotExist(id,attachment.getOriginFile());
		}
		Wo wo = null;
		String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), id+width+height);
		Element element = cache.get(cacheKey);
		if ((null != element) && (null != element.getObjectValue())) {
			wo = (Wo) element.getObjectValue();
			result.setData(wo);
		} else {
			StorageMapping mapping = ThisApplication.context().storageMappings().get(OriginFile.class,
					originFile.getStorage());
			try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
				originFile.readContent(mapping, output);
				try (ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray())) {
					BufferedImage src = ImageIO.read(input);
					int scalrWidth = (width == 0) ? src.getWidth() : width;
					int scalrHeight = (height == 0) ? src.getHeight() : height;
					Scalr.Mode mode = Scalr.Mode.FIT_TO_WIDTH;
					if(src.getWidth()>src.getHeight()){
						mode = Scalr.Mode.FIT_TO_HEIGHT;
					}
					BufferedImage scalrImage = Scalr.resize(src,Scalr.Method.SPEED, mode, NumberUtils.min(scalrWidth, src.getWidth()),
							NumberUtils.min(scalrHeight, src.getHeight()));
					try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
						ImageIO.write(scalrImage, "png", baos);
						byte[] bs = baos.toByteArray();

						wo = new Wo(bs, this.contentType(false, attachment.getName()),
								this.contentDisposition(false, attachment.getName()));

						cache.put(new Element(cacheKey, wo));
						result.setData(wo);
					}
				}
			}
		}

		return result;
	}
}
 
Example 17
Source File: WordBlacklist.java    From youran with Apache License 2.0 4 votes vote down vote up
public static boolean isClassNameBlacklist(String value) {
    return ArrayUtils.contains(classNameBlacklist, value);
}
 
Example 18
Source File: ParamServer.java    From systemds with Apache License 2.0 4 votes vote down vote up
private boolean allFinished() {
	return !ArrayUtils.contains(_finishedStates, false);
}
 
Example 19
Source File: TemplateBase.java    From systemds with Apache License 2.0 4 votes vote down vote up
public boolean isIn(TemplateType... types) {
	return ArrayUtils.contains(types, this);
}
 
Example 20
Source File: HirelingPanel.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(Batch batch, float a) {
  int x, y;
  x = xOffs;
  y = yOffs;

  if (item == null) {
    batch.draw(background, getX() + x, getY() + y);
  }

  boolean blocked = false;
  Item cursorItem = Riiablo.cursor.getItem();
  if (cursorItem != null) {
    blocked = !ArrayUtils.contains(cursorItem.typeEntry.BodyLoc, bodyPart);
  }

  // TODO: red if does not meet item requirements
  boolean isOver = clickListener.isOver();
  PaletteIndexedBatch b = (PaletteIndexedBatch) batch;
  if (isOver && !blocked && (cursorItem != null || item != null)) {
    b.setBlendMode(BlendMode.SOLID, backgroundColorG);
    b.draw(fill, getX(), getY(), getWidth(), getHeight());
    b.resetBlendMode();
  }

  // FIXME: Alt images on weapons are slightly off by maybe a pixel or so (rounding?) -- backgrounds fine
  if (item != null && item.checkLoaded()) {
    BBox box = item.invFile.getBox();
    item.setPosition(
        getX() + getWidth()  / 2 - box.width  / 2f + x,
        getY() + getHeight() / 2 - box.height / 2f + y);
    item.draw(b, 1);
  }

  if (isOver && blocked) {
    b.setBlendMode(BlendMode.SOLID, backgroundColorR);
    b.draw(fill, getX(), getY(), getWidth(), getHeight());
    b.resetBlendMode();
  }

  if (isOver && item != null && cursorItem == null) {
    Riiablo.game.setDetails(item.details(), item, HirelingPanel.this, this);
  }
}