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

The following are Jave code examples for showing how to use contains() of the org.apache.commons.lang.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: pds   File: SysUserController.java   View Source Code Vote up 7 votes
/**
 * 删除用户
 */
@SysLog("删除用户")
@RequestMapping("/delete")
@RequiresPermissions("sys:user:delete")
public R delete(@RequestBody Long[] userIds){
	if(ArrayUtils.contains(userIds, 1L)){
		return R.error("系统管理员不能删除");
	}
	
	if(ArrayUtils.contains(userIds, getUserId())){
		return R.error("当前用户不能删除");
	}
	
	sysUserService.deleteBatch(userIds);
	
	return R.ok();
}
 
Example 2
Project: my-spring-boot-project   File: SysUserController.java   View Source Code Vote up 7 votes
/**
 * 删除用户
 */
@SysLog("删除用户")
@RequestMapping("/delete")
@RequiresPermissions("sys:user:delete")
public Result delete(@RequestBody Long[] userIds) {
    if (ArrayUtils.contains(userIds, 1L)) {
        return Result.error("系统管理员不能删除");
    }

    if (ArrayUtils.contains(userIds, getUserId())) {
        return Result.error("当前用户不能删除");
    }

    try {
        sysUserService.deleteBatch(userIds);
    } catch (Exception e) {
        logger.error("删除用户异常", e);
        return Result.error("删除用户异常");
    }

    return Result.ok();
}
 
Example 3
Project: pangaea   File: EnvironmentModifierFilter.java   View Source Code Vote up 6 votes
@Override
public ContainerRequest filter(ContainerRequest request) {
    // only if the query parameters contain the configured name
    // and one of the values from "fromValues"
    if (request.getQueryParameters() != null
            && !request.getQueryParameters().isEmpty()
            && request.getQueryParameters().containsKey(queryParamToModify)
            && ArrayUtils.contains(fromValues,
              request.getQueryParameters().getFirst(queryParamToModify))) {

        URI modifiedUri = getModifiedUri(request.getRequestUri());

        request.setUris(request.getBaseUri(), modifiedUri);
    }
    return request;
}
 
Example 4
Project: renren-fast   File: SysUserController.java   View Source Code Vote up 6 votes
/**
 * 删除用户
 */
@SysLog("删除用户")
@RequestMapping("/delete")
@RequiresPermissions("sys:user:delete")
public R delete(@RequestBody Long[] userIds){
	if(ArrayUtils.contains(userIds, 1L)){
		return R.error("系统管理员不能删除");
	}
	
	if(ArrayUtils.contains(userIds, getUserId())){
		return R.error("当前用户不能删除");
	}
	
	sysUserService.deleteBatch(userIds);
	
	return R.ok();
}
 
Example 5
Project: YiDu-Novel   File: RegiAuthorAction.java   View Source Code Vote up 6 votes
/**
 * <p>
 * 保存画面的内容
 * </p>
 * 
 * @return
 * @throws Exception
 */
public String register() {
    logger.debug("register start.");
    if (ArrayUtils.contains(YiDuConstants.ALLOW_SAMPLE_TYPES, getSampleContentType())) {
        try {
            // saveArticlespic();
        } catch (Exception e) {
            addActionError(getText("errors.file.save"));
            return FREEMARKER;
        }
    } else {
        addActionError(getText("errors.file.type"));
        return FREEMARKER;
    }

    addActionMessage(getText("messages.save.success"));
    logger.debug("register normally end.");
    return FREEMARKER;
}
 
Example 6
Project: Equella   File: ExtendedPropertiesLayout.java   View Source Code Vote up 6 votes
private String escapeKey(String key)
{
	StringBuilder newkey = new StringBuilder();

	for( int i = 0; i < key.length(); i++ )
	{
		char c = key.charAt(i);

		if( ArrayUtils.contains(SEPARATORS, c) || ArrayUtils.contains(WHITE_SPACE, c) )
		{
			// escape the separator
			newkey.append('\\');
			newkey.append(c);
		}
		else
		{
			newkey.append(c);
		}
	}

	return newkey.toString();
}
 
Example 7
Project: Equella   File: ExtendedPropertiesLayout.java   View Source Code Vote up 6 votes
private String escapeKey(String key)
{
	StringBuffer newkey = new StringBuffer();

	for( int i = 0; i < key.length(); i++ )
	{
		char c = key.charAt(i);

		if( ArrayUtils.contains(SEPARATORS, c) || ArrayUtils.contains(WHITE_SPACE, c) )
		{
			// escape the separator
			newkey.append('\\');
			newkey.append(c);
		}
		else
		{
			newkey.append(c);
		}
	}

	return newkey.toString();
}
 
Example 8
Project: lams   File: EqualsBuilder.java   View Source Code Vote up 6 votes
/**
 * <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) {
    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");
            }
        }
    }
}
 
Example 9
Project: renren-msg   File: SysUserController.java   View Source Code Vote up 6 votes
/**
 * 删除用户
 */
@SysLog("删除用户")
@RequestMapping("/delete")
@RequiresPermissions("sys:user:delete")
public R delete(@RequestBody Long[] userIds){
	if(ArrayUtils.contains(userIds, 1L)){
		return R.error("系统管理员不能删除");
	}
	
	if(ArrayUtils.contains(userIds, getUserId())){
		return R.error("当前用户不能删除");
	}
	
	sysUserService.deleteBatch(userIds);
	
	return R.ok();
}
 
Example 10
Project: smaph   File: SmaphUtils.java   View Source Code Vote up 5 votes
/**
 * @param base
 * @param ftrId
 * @return a new feature vector composed by base with the addition of ftrId.
 */
public static int[] addFtrVect(int[] base, int ftrId) {
	if (base == null)
		return new int[] { ftrId };
	else {
		if (ArrayUtils.contains(base, ftrId))
			throw new IllegalArgumentException("Trying to add a feature to a vector that already contains it.");
		int[] newVect = new int[base.length + 1];
		System.arraycopy(base, 0, newVect, 0, base.length);
		newVect[newVect.length - 1] = ftrId;
		Arrays.sort(newVect);
		return newVect;
	}
}
 
Example 11
Project: smaph   File: ExampleGatherer.java   View Source Code Vote up 5 votes
private String writeLineLibSvm(double[] ftrVect, BufferedWriter wr, double gold, int id, int[] selectedFeatures)
		throws IOException {
	String line = String.format("%.5f ", gold);
	for (int ftr = 0; ftr < ftrVect.length; ftr++)
		if (selectedFeatures == null || ArrayUtils.contains(selectedFeatures, ftr + 1))
			line += String.format("%d:%.9f ", ftr + 1, ftrVect[ftr]);
	line += " #id=" + id;
	return line;
}
 
Example 12
Project: os   File: LNUtils.java   View Source Code Vote up 5 votes
/**
 * 检查one数组是否包含two数组所有元素
 * 
 * @param one
 * @param two
 * @return
 */
public static boolean containsAll(Object[] one, Object[] two) {
	for (Object b : two) {
		if (!ArrayUtils.contains(one, b)) {
			return false;
		}
	}
	return true;
}
 
Example 13
Project: lams   File: HashCodeBuilder.java   View Source Code Vote up 5 votes
/**
 * <p>
 * Appends the fields and values defined by the given object of the given <code>Class</code>.
 * </p>
 * 
 * @param object
 *            the object to append details of
 * @param clazz
 *            the class to append details of
 * @param builder
 *            the builder to append to
 * @param useTransients
 *            whether to use transient fields
 * @param excludeFields
 *            Collection of String field names to exclude from use in calculation of hash code
 */
private static void reflectionAppend(Object object, Class clazz, HashCodeBuilder builder, boolean useTransients,
        String[] excludeFields) {
    if (isRegistered(object)) {
        return;
    }
    try {
        register(object);
        Field[] fields = clazz.getDeclaredFields();
        AccessibleObject.setAccessible(fields, true);
        for (int i = 0; i < fields.length; i++) {
            Field field = fields[i];
            if (!ArrayUtils.contains(excludeFields, field.getName())
                && (field.getName().indexOf('$') == -1)
                && (useTransients || !Modifier.isTransient(field.getModifiers()))
                && (!Modifier.isStatic(field.getModifiers()))) {
                try {
                    Object fieldValue = field.get(object);
                    builder.append(fieldValue);
                } 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(object);
    }
}
 
Example 14
Project: lams   File: CompareToBuilder.java   View Source Code Vote up 5 votes
/**
 * <p>Appends to <code>builder</code> the comparison of <code>lhs</code>
 * to <code>rhs</code> using the fields defined in <code>clazz</code>.</p>
 * 
 * @param lhs  left-hand object
 * @param rhs  right-hand object
 * @param clazz  <code>Class</code> that defines fields to be compared
 * @param builder  <code>CompareToBuilder</code> to append to
 * @param useTransients  whether to compare transient fields
 * @param excludeFields  fields to exclude
 */
private static void reflectionAppend(
    Object lhs,
    Object rhs,
    Class clazz,
    CompareToBuilder builder,
    boolean useTransients,
    String[] excludeFields) {
    
    Field[] fields = clazz.getDeclaredFields();
    AccessibleObject.setAccessible(fields, true);
    for (int i = 0; i < fields.length && builder.comparison == 0; 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");
            }
        }
    }
}
 
Example 15
Project: openddr-java   File: VocabularyHolder.java   View Source Code Vote up 5 votes
public VocabularyProperty existProperty(String propertyName, String aspect, String vocabularyIRI) throws NameException {
    String realAspect = aspect;
    VocabularyProperty vocabularyProperty = (VocabularyProperty) vocabularyPropertyCache.getCachedElement(propertyName + aspect + vocabularyIRI);

    if (vocabularyProperty == null) {
        if (vocabularies.get(vocabularyIRI) != null) {
            Map<String, VocabularyProperty> propertyMap = vocabularies.get(vocabularyIRI).getProperties();
            vocabularyProperty = propertyMap.get(propertyName);

            if (vocabularyProperty != null) {
                if (realAspect != null && realAspect.trim().length() > 0) {
                    if (ArrayUtils.contains(vocabularyProperty.getAspects(), realAspect)) {
                        vocabularyPropertyCache.setCachedElement(propertyName + aspect + vocabularyIRI, vocabularyProperty);
                        return vocabularyProperty;

                    } else {
                        throw new NameException(NameException.ASPECT_NOT_RECOGNIZED, "unknow \"" + realAspect + "\" aspect");
                    }

                } else {
                    return vocabularyProperty;
                }

            } else {
                throw new NameException(NameException.PROPERTY_NOT_RECOGNIZED, "unknow \"" + propertyName + "\" property");
            }

        } else {
            throw new NameException(NameException.VOCABULARY_NOT_RECOGNIZED, "unknow \"" + vocabularyIRI + "\" vacabulary");
        }

    } else {
        return vocabularyProperty;
    }
}
 
Example 16
Project: monarch   File: SocketCreatorFactory.java   View Source Code Vote up 5 votes
private SocketCreator getSSLSocketCreator(final SecurableCommunicationChannel sslComponent,
    final SSLConfig sslConfig) {
  if (sslConfig.isEnabled()) {
    if (ArrayUtils.contains(getDistributionConfig().getSecurableCommunicationChannels(),
        SecurableCommunicationChannel.ALL)) {
      return createSSLSocketCreator(SecurableCommunicationChannel.ALL, sslConfig);
      // } else if
      // (ArrayUtils.contains(getDistributionConfig().getSecurableCommunicationChannels(),
      // sslComponent)) {
    } else {
      return createSSLSocketCreator(sslComponent, sslConfig);
    }
  }
  return createSSLSocketCreator(sslComponent, sslConfig);
}
 
Example 17
Project: winter   File: TableParser.java   View Source Code Vote up 5 votes
/**
 * Writes the content from a String[][] into the provided table.
 * 
 * @param tContent
 *            has the content, which has to be populated
 * @param t
 *            has the table, which is populated
 * @param skipRows
 *            holds the indexes for header, empty and sum rows. These rows are skipped,
 *            because they do not belong to the content. Likewise these rows
 *            do not increase the row id, thus table row id and parsed table
 *            row id maid slightly differ depending on the header.
 */

public void populateTable(String[][] tContent, Table t, int[] skipRows) {
	int tableRowIndex = 0;
	for (int rowIdx = 0; rowIdx < tContent.length; rowIdx++) {
		if (!ArrayUtils.contains(skipRows, rowIdx)) {
			String[] rowData = tContent[rowIdx];
			Object[] values = new Object[tContent[rowIdx].length];
			for (int i = 0; i < rowData.length && i < values.length; i++) {
				if (rowData[i] != null && !rowData[i].trim().isEmpty()) {
					values[i] = stringNormalizer.normaliseValue(rowData[i], false);

					if (((String) values[i]).equalsIgnoreCase(StringNormalizer.nullValue)) {
						values[i] = null;
					} else {
						values[i] = values[i];
					}
				}
			}
			
			// make sure the row number is the row's position in the table.
			TableRow r = new TableRow(tableRowIndex, t);    				
			tableRowIndex++;
			r.set(values);
			t.addRow(r);
		}
	}
}
 
Example 18
Project: YiDu-Novel   File: ArticleEditAction.java   View Source Code Vote up 4 votes
/**
 * <p>
 * 保存画面的内容
 * </p>
 * 
 * @return 结果,画面
 */
public String save() {
    logger.debug("save start.");

    TArticle article = new TArticle();
    if (articleno != 0) {
        article = articleService.getByNo(articleno);
    } else {
        article.setDeleteflag(false);
        String pinyin = Utils.getPinYin(articlename);
        TArticle articletemp = articleService.findByPinyinRegularRxpressions(pinyin);
        if (Utils.isDefined(articletemp)) {
            // 存在的话
            if (StringUtils.equals(articletemp.getPinyin(), pinyin)) {
                // 如果存在相同拼音的就在后面加数字
                pinyin = pinyin + 2;
            } else {
                // TODO 此处多线程的话会有问题,后台同时操作的时候应该不多!暂时不对应
                int suffixNumber = Integer.valueOf(StringUtils.substring(articletemp.getPinyin(), pinyin.length(),
                        articletemp.getPinyin().length()));
                pinyin = pinyin + (suffixNumber + 1);
            }
        }
        article.setPinyin(pinyin);
    }

    BeanUtils.copyProperties(this, article);

    article.setModifytime(new Date());
    article.setModifyuserno(LoginManager.getLoginUser().getUserno());

    articleService.save(article);

    // 保存图片文件
    if (Utils.isDefined(articlespic)) {
        if (ArrayUtils.contains(YiDuConstants.ALLOW_PIC_TYPES, getArticlespicContentType())) {
            try {
                Utils.saveArticlespic(article.getArticleno(), articlespic, articlespicFileName);
            } catch (Exception e) {
                addActionError(getText("errors.file.save"));
            }
        } else {
            addActionError(getText("errors.file.type"));
        }

        if (StringUtils.equals(getArticlespicContentType(), YiDuConstants.ImgageMateType.JPG)) {
            article.setImgflag(YiDuConstants.ImageType.JPG);
        } else if (StringUtils.equals(getArticlespicContentType(), YiDuConstants.ImgageMateType.GIF)) {
            article.setImgflag(YiDuConstants.ImageType.GIF);
        } else if (StringUtils.equals(getArticlespicContentType(), YiDuConstants.ImgageMateType.PNG)) {
            article.setImgflag(YiDuConstants.ImageType.PNG);
        }
    }

    if(hasActionErrors()){
        // 初始化类别下拉列表选项
        initCollections(new String[] { "collectionProperties.article.category",
                "collectionProperties.article.fullflag", "collectionProperties.article.authorflag",
                "collectionProperties.article.permission", "collectionProperties.article.firstflag" });
    	return INPUT;
    }

    articleService.save(article);

    logger.debug("save normally end.");
    return REDIRECT;
}
 
Example 19
Project: Yidu   File: ArticleEditAction.java   View Source Code Vote up 4 votes
/**
 * <p>
 * 保存画面的内容
 * </p>
 * 
 * @return 结果,画面
 */
public String save() {
    logger.debug("save start.");

    TArticle article = new TArticle();
    if (articleno != 0) {
        article = articleService.getByNo(articleno);
    } else {
        article.setDeleteflag(false);
        String pinyin = Utils.getPinYin(articlename);
        TArticle articletemp = articleService.findByPinyinRegularRxpressions(pinyin);
        if (Utils.isDefined(articletemp)) {
            // 存在的话
            if (StringUtils.equals(articletemp.getPinyin(), pinyin)) {
                // 如果存在相同拼音的就在后面加数字
                pinyin = pinyin + 2;
            } else {
                // TODO 此处多线程的话会有问题,后台同时操作的时候应该不多!暂时不对应
                int suffixNumber = Integer.valueOf(StringUtils.substring(articletemp.getPinyin(), pinyin.length(),
                        articletemp.getPinyin().length()));
                pinyin = pinyin + (suffixNumber + 1);
            }
        }
        article.setPinyin(pinyin);
    }

    BeanUtils.copyProperties(this, article);

    article.setModifytime(new Date());
    article.setModifyuserno(LoginManager.getLoginUser().getUserno());

    articleService.save(article);

    // 保存图片文件
    if (Utils.isDefined(articlespic)) {
        if (ArrayUtils.contains(YiDuConstants.ALLOW_PIC_TYPES, getArticlespicContentType())) {
            try {
                Utils.saveArticlespic(article.getArticleno(), articlespic, articlespicFileName);
            } catch (Exception e) {
                addActionError(getText("errors.file.save"));
            }
        } else {
            addActionError(getText("errors.file.type"));
        }

        if (StringUtils.equals(getArticlespicContentType(), YiDuConstants.ImgageMateType.JPG)) {
            article.setImgflag(YiDuConstants.ImageType.JPG);
        } else if (StringUtils.equals(getArticlespicContentType(), YiDuConstants.ImgageMateType.GIF)) {
            article.setImgflag(YiDuConstants.ImageType.GIF);
        } else if (StringUtils.equals(getArticlespicContentType(), YiDuConstants.ImgageMateType.PNG)) {
            article.setImgflag(YiDuConstants.ImageType.PNG);
        }
    }

    if(hasActionErrors()){
        // 初始化类别下拉列表选项
        initCollections(new String[] { "collectionProperties.article.category",
                "collectionProperties.article.fullflag", "collectionProperties.article.authorflag",
                "collectionProperties.article.permission", "collectionProperties.article.firstflag" });
    	return INPUT;
    }

    articleService.save(article);

    logger.debug("save normally end.");
    return REDIRECT;
}
 
Example 20
Project: dubbo-mock   File: MockOperDefineController.java   View Source Code Vote up 4 votes
@ResponseBody
@RequestMapping(value = "/selectMockRuleResults")
public String selectMockRuleResults(HttpServletRequest arg0, Boolean selectFlag) throws Exception {
    JSONObject object = new JSONObject();
    object.put("result", "success");
    String method = null;
    String result = null;
    try {
        Map<String, String> context = Maps.newLinkedHashMap();
        String serviceId = arg0.getParameter("serviceId");
        String mockTestIds = arg0.getParameter("mockTestIds");
        String[] mocks = mockTestIds.split(",");
        Integer[] integers = new Integer[mocks.length];
        for (int i = 0; i < mocks.length; i++) {
            integers[i] = Integer.valueOf(mocks[i]);
        }
        String mockRules = arg0.getParameter("mockRules");
        mockRules = URLDecoder.decode(mockRules, Charset.defaultCharset().toString());
        String[] params = mockRules.split("&");
        List<String> mockKeys = Lists.newArrayList();
        List<String> mockValus = Lists.newArrayList();
        List<String> mockTypes = Lists.newArrayList();
        for (int i = 0; i < params.length; i++) {
            String[] param = params[i].split("=");
            if (param[0].equals("mockTestKey")) {
                if (i > 0 && ArrayUtils.contains(intelChars, param[1])) {
                    throw new RuntimeException("KEY命名不能包含以下关键字:" + ArrayUtils.toString(intelChars));
                }
                mockKeys.add(param[1]);
            }
            if (param[0].equals("mockTestValue")) {
                mockValus.add(param[1]);
            }
            if (param[0].equals("mockTestType")) {
                mockTypes.add(param[1]);
            }
        }
        for (int i = 0; i < mockKeys.size(); i++) {
            context.put(mockKeys.get(i), mockValus.get(i));
        }
        method = context.remove("methodName");
        result = mockTestServiceImpl.testMockService(Integer.valueOf(serviceId), method, context, integers);
    } catch (Exception e) {
        object.put("result", "error");
        result = e.getMessage();
        e.printStackTrace();
    }
    object.put("context", result);
    return object.toJSONString();
}