org.apache.commons.lang3.ArrayUtils#add ( )源码实例Demo

下面列出了org.apache.commons.lang3.ArrayUtils#add ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ameba   文件: TemplateHelper.java
/**
 * <p>getExtends.</p>
 *
 * @param config a {@link javax.ws.rs.core.Configuration} object.
 * @param module a {@link java.lang.String} object.
 * @param defaultExtensions an array of {@link java.lang.String} objects.
 * @return an array of {@link java.lang.String} objects.
 */
public static String[] getExtends(Configuration config, String module, String[] defaultExtensions) {
    String extension = getStringExtends(config, module);

    if (StringUtils.isBlank(extension)) {
        return defaultExtensions;
    } else {
        extension = extension.toLowerCase();
    }
    String[] extensions = extension.split(",");
    for (String ext : defaultExtensions) {
        if (!ArrayUtils.contains(extensions, ext.substring(1))
                && !ArrayUtils.contains(extensions, ext)) {
            extensions = ArrayUtils.add(extensions, ext);
        }
    }
    return extensions;
}
 
源代码2 项目: kylin-on-parquet-v2   文件: DataModelDesc.java
private boolean validatePkFkDim(TblColRef c) {
    String t = c.getTableAlias();
    ModelDimensionDesc dimDesc = null;
    for (ModelDimensionDesc dim : dimensions) {
        if (dim.getTable().equals(t)) {
            dimDesc = dim;
            break;
        }
    }

    if (dimDesc == null) {
        dimDesc = new ModelDimensionDesc();
        dimDesc.setTable(t);
        dimDesc.setColumns(new String[0]);
        dimensions.add(dimDesc);
    }

    if (ArrayUtils.contains(dimDesc.getColumns(), c.getName()) == false) {
        String[] newCols = ArrayUtils.add(dimDesc.getColumns(), c.getName());
        dimDesc.setColumns(newCols);
        return true;
    }

    return false;
}
 
源代码3 项目: p4ic4idea   文件: SearchDelegatorTest.java
/**
 * Runs before every test.
 */
@SuppressWarnings("unchecked")
@Before
public void beforeEach() throws ConnectionException, AccessException, RequestException {
    server = mock(Server.class);
    searchDelegator = new SearchDelegator(server);

    resultMap = mock(Map.class);
    List<Map<String, Object>> resultMaps = Lists.newArrayList(resultMap);

    opts = new SearchJobsOptions(CMD_OPTIONS);

    words = "my search words";
    cmdArgument = ArrayUtils.add(CMD_OPTIONS, words);

    when(server.execMapCmdList(eq(SEARCH.toString()), eq(cmdArgument), any()))
            .thenReturn(resultMaps);
}
 
源代码4 项目: gvnix   文件: QuerydslUtilsBeanImpl.java
/**
 * {@inheritDoc}
 */
@Override
public <T> Class<?> getFieldType1(String fieldName, PathBuilder<T> entity) {
    Class<?> entityType = entity.getType();
    String fieldNameToFindType = fieldName;

    // Makes the array of classes to find fieldName agains them
    Class<?>[] classArray = ArrayUtils.<Class<?>> toArray(entityType);
    if (fieldName.contains(SEPARATOR_FIELDS)) {
        String[] fieldNameSplitted = StringUtils.split(fieldName,
                SEPARATOR_FIELDS);
        for (int i = 0; i < fieldNameSplitted.length - 1; i++) {
            Class<?> fieldType = BeanUtils.findPropertyType(
                    fieldNameSplitted[i],
                    ArrayUtils.<Class<?>> toArray(entityType));
            classArray = ArrayUtils.add(classArray, fieldType);
            entityType = fieldType;
        }
        fieldNameToFindType = fieldNameSplitted[fieldNameSplitted.length - 1];
    }

    return BeanUtils.findPropertyType(fieldNameToFindType, classArray);
}
 
源代码5 项目: entando-components   文件: ContentFinderAction.java
public SearcherDaoPaginatedResult<String> getPaginatedContentsId(Integer limit) {
    SearcherDaoPaginatedResult<String> result = null;
    try {
        ContentFinderSearchInfo searchInfo = this.getContentSearchInfo();
        List<String> allowedGroups = this.getContentGroupCodes();
        String[] categories = null;
        Category category = this.getCategoryManager().getCategory(this.getCategoryCode());
        if (null != category && !category.isRoot()) {
            String catCode = this.getCategoryCode().trim();
            categories = new String[]{catCode};
            searchInfo.setCategoryCode(catCode);
        } else {
            searchInfo.setCategoryCode(null);
        }
        EntitySearchFilter[] filters = this.getFilters();
        if (null != limit) {
            filters = ArrayUtils.add(filters, this.getPagerFilter(limit));
        }
        result = this.getContentManager().getPaginatedWorkContentsId(categories, false, filters, allowedGroups);
    } catch (Throwable t) {
        logger.error("error in getPaginatedWorkContentsId", t);
        throw new RuntimeException("error in getPaginatedWorkContentsId", t);
    }
    return result;
}
 
源代码6 项目: citeproc-java   文件: ShellCommand.java
/**
 * Augments the given command line with context variables
 * @param args the current command line
 * @param cmd the last parsed command in the command line
 * @param acceptsInputFile true if the given command accepts an input file
 * @return the new command line
 */
private String[] augmentCommand(String[] args, Class<? extends Command> cmd,
        boolean acceptsInputFile) {
    OptionGroup<ID> options;
    try {
        if (acceptsInputFile) {
            options = OptionIntrospector.introspect(cmd, InputFileCommand.class);
        } else {
            options = OptionIntrospector.introspect(cmd);
        }
    } catch (IntrospectionException e) {
        // should never happen
        throw new RuntimeException(e);
    }

    ShellContext sc = ShellContext.current();
    for (Option<ID> o : options.getOptions()) {
        if (o.getLongName().equals("style")) {
            args = ArrayUtils.add(args, "--style");
            args = ArrayUtils.add(args, sc.getStyle());
        } else if (o.getLongName().equals("locale")) {
            args = ArrayUtils.add(args, "--locale");
            args = ArrayUtils.add(args, sc.getLocale());
        } else if (o.getLongName().equals("format")) {
            args = ArrayUtils.add(args, "--format");
            args = ArrayUtils.add(args, sc.getFormat());
        } else if (o.getLongName().equals("input") &&
                sc.getInputFile() != null && !sc.getInputFile().isEmpty()) {
            args = ArrayUtils.add(args, "--input");
            args = ArrayUtils.add(args, sc.getInputFile());
        }
    }

    return args;
}
 
源代码7 项目: entando-core   文件: TestGroupManager.java
@SuppressWarnings("rawtypes")
public void test_search_by_filter() throws ApsSystemException {
    FieldSearchFilter[] fieldSearchFilters = new FieldSearchFilter[0];

    FieldSearchFilter groupNameFilter = new FieldSearchFilter<>("groupname", "s", true, LikeOptionType.COMPLETE);
    fieldSearchFilters = ArrayUtils.add(fieldSearchFilters, groupNameFilter);

    SearcherDaoPaginatedResult<Group> result = this._groupManager.getGroups(fieldSearchFilters);
    assertThat(result.getCount(), is(3));
    assertThat(result.getList().size(), is(3));

    fieldSearchFilters = new FieldSearchFilter[0];
    FieldSearchFilter limitFilter = new FieldSearchFilter<>(2, 0);
    fieldSearchFilters = ArrayUtils.add(fieldSearchFilters, groupNameFilter);
    fieldSearchFilters = ArrayUtils.add(fieldSearchFilters, limitFilter);
    result = this._groupManager.getGroups(fieldSearchFilters);
    assertThat(result.getCount(), is(3));
    assertThat(result.getList().size(), is(2));

    fieldSearchFilters = new FieldSearchFilter[0];
    limitFilter = new FieldSearchFilter<>(2, 2);
    fieldSearchFilters = ArrayUtils.add(fieldSearchFilters, limitFilter);
    fieldSearchFilters = ArrayUtils.add(fieldSearchFilters, groupNameFilter);
    result = this._groupManager.getGroups(fieldSearchFilters);
    assertThat(result.getCount(), is(3));
    assertThat(result.getList().size(), is(1));

}
 
源代码8 项目: geowave   文件: GeoWaveRedisRow.java
public GeoWaveRedisPersistedRow[] getPersistedRows() {
  // this is intentionally not threadsafe because it isn't required
  if (mergedRows == null) {
    return new GeoWaveRedisPersistedRow[] {persistedRow};
  } else {
    return ArrayUtils.add(mergedRows.toArray(new GeoWaveRedisPersistedRow[0]), persistedRow);
  }
}
 
源代码9 项目: pcgen   文件: SortedListFacade.java
@Override
public void elementAdded(ListEvent<E> e)
{
	transform = ArrayUtils.add(transform, transform.length);
	sanityCheck();
	Arrays.sort(transform, indexComparator);
	int index = Arrays.binarySearch(transform, e.getIndex(), indexComparator);
	fireElementAdded(this, e.getElement(), index);
}
 
源代码10 项目: PneumaticCraft   文件: GuiAphorismTile.java
@Override
protected void keyTyped(char par1, int par2){
    if(par2 == 1) {
        NetworkHandler.sendToServer(new PacketAphorismTileUpdate(tile));
    } else if(par2 == 200) {
        cursorY--;
        if(cursorY < 0) cursorY = textLines.length - 1;
    } else if(par2 == 208 || par2 == 156) {
        cursorY++;
        if(cursorY >= textLines.length) cursorY = 0;
    } else if(par2 == 28) {
        cursorY++;
        textLines = ArrayUtils.add(textLines, cursorY, "");
    } else if(par2 == 14) {
        if(textLines[cursorY].length() > 0) {
            textLines[cursorY] = textLines[cursorY].substring(0, textLines[cursorY].length() - 1);
        } else if(textLines.length > 1) {
            textLines = ArrayUtils.remove(textLines, cursorY);
            cursorY--;
            if(cursorY < 0) cursorY = 0;
        }
    } else if(ChatAllowedCharacters.isAllowedCharacter(par1)) {
        textLines[cursorY] = textLines[cursorY] + par1;
    }
    tile.setTextLines(textLines);
    super.keyTyped(par1, par2);
}
 
源代码11 项目: p4ic4idea   文件: ProtectsDelegatorTest.java
/**
 * Runs before every test.
 */
@SuppressWarnings("unchecked")
@Before
public void beforeEach() {
    server = mock(Server.class);
    protectsDelegator = new ProtectsDelegator(server);
    Map<String, Object> resultMap = mock(Map.class);
    Map<String, Object> resultMap2 = mock(Map.class);
    resultMaps = newArrayList(resultMap, resultMap2);

    fileSpecs = FileSpecBuilder.makeFileSpecList(TEST_FILE_DEPOT_PATH);

    allUsers = true;
    hostName = "host name";
    userName = "user name";
    groupName = "group name";

    String[] cmdOptions = {
            "-a",
            "-g" + groupName,
            "-u" + userName,
            "-h" + hostName};

    cmdArguments = ArrayUtils.add(cmdOptions, TEST_FILE_DEPOT_PATH);

    opts = new GetProtectionEntriesOptions(cmdOptions);
}
 
源代码12 项目: ameba   文件: Application.java
@SuppressWarnings("unchecked")
private void configureResource() {
    String[] packages = StringUtils.deleteWhitespace(
            StringUtils.defaultIfBlank((String) getProperty("resource.packages"), "")).split(",");
    for (String key : getPropertyNames()) {
        if (key.startsWith("resource.packages.")) {
            Object pkgObj = getProperty(key);
            if (pkgObj instanceof String) {
                String pkgStr = (String) pkgObj;
                if (StringUtils.isNotBlank(pkgStr)) {
                    String[] pkgs = StringUtils.deleteWhitespace(pkgStr).split(",");
                    for (String pkg : pkgs) {
                        if (!ArrayUtils.contains(packages, pkg))
                            packages = ArrayUtils.add(packages, pkg);
                    }
                }
            }
        }
    }
    packages = ArrayUtils.removeElement(packages, "");
    if (packages.length > 0) {
        logger.info(Messages.get("info.configure.resource.package",
                StringUtils.join(packages, "," + LINE_SEPARATOR)));
    } else {
        logger.warn(Messages.get("info.configure.resource.package.none"));
    }
    packages(packages);
    subscribeResourceEvent();
}
 
源代码13 项目: blockchain-java   文件: Blockchain.java
/**
 * 查找所有的 unspent transaction outputs
 *
 * @return
 */
public Map<String, TXOutput[]> findAllUTXOs() {
    Map<String, int[]> allSpentTXOs = this.getAllSpentTXOs();
    Map<String, TXOutput[]> allUTXOs = Maps.newHashMap();
    // 再次遍历所有区块中的交易输出
    for (BlockchainIterator blockchainIterator = this.getBlockchainIterator(); blockchainIterator.hashNext(); ) {
        Block block = blockchainIterator.next();
        for (Transaction transaction : block.getTransactions()) {

            String txId = Hex.encodeHexString(transaction.getTxId());

            int[] spentOutIndexArray = allSpentTXOs.get(txId);
            TXOutput[] txOutputs = transaction.getOutputs();
            for (int outIndex = 0; outIndex < txOutputs.length; outIndex++) {
                if (spentOutIndexArray != null && ArrayUtils.contains(spentOutIndexArray, outIndex)) {
                    continue;
                }
                TXOutput[] UTXOArray = allUTXOs.get(txId);
                if (UTXOArray == null) {
                    UTXOArray = new TXOutput[]{txOutputs[outIndex]};
                } else {
                    UTXOArray = ArrayUtils.add(UTXOArray, txOutputs[outIndex]);
                }
                allUTXOs.put(txId, UTXOArray);
            }
        }
    }
    return allUTXOs;
}
 
源代码14 项目: entando-components   文件: ContentListTag.java
@Override
public void addCategory(String category) {
	if (null == category) return;
       this.categories = ArrayUtils.add(this.categories, category);
}
 
@Override
public void addCategory(String category) {
       this.categories = ArrayUtils.add(this.categories, category);
}
 
源代码16 项目: tutorials   文件: ArrayOperations.java
public static int[] appendIntWithUtils(int[] array, int newItem) {
    return ArrayUtils.add(array, newItem);
}
 
源代码17 项目: geowave   文件: IngestOptionsBuilderImpl.java
@Override
public Builder<T> addExtension(final String fileExtension) {
  fileExtensions = ArrayUtils.add(fileExtensions, fileExtension);
  return this;
}
 
源代码18 项目: entando-core   文件: RestListRequest.java
public void addFilter(Filter filter) {
    this.filters = ArrayUtils.add(this.filters, filter);
}
 
源代码19 项目: deeplearning4j   文件: MergeAddBp.java
public MergeAddBp(SameDiff sameDiff, @NonNull SDVariable[] inputs, @NonNull SDVariable gradO) {
    super("mergeadd_bp", sameDiff, ArrayUtils.add(inputs, gradO));
}
 
源代码20 项目: cryptotrader   文件: CompositeEstimator.java
@VisibleForTesting
Estimation estimate(Context context, Request request, BiFunction<Context, Request, Estimation> function) {

    List<Composite> composites = request.getEstimatorComposites();

    if (CollectionUtils.isEmpty(composites)) {
        return BAIL;
    }

    Request.RequestBuilder builder = Request.build(request);

    BigDecimal[] prices = new BigDecimal[1];

    BigDecimal[] confidences = new BigDecimal[1];

    for (Composite composite : composites) {

        String site = StringUtils.trimToEmpty(composite.getSite());

        if (site.length() <= 1) {
            return BAIL;
        }

        char operation = site.charAt(0);

        BinaryOperator<BigDecimal> operator = null;

        if ('+' == operation) {
            operator = BigDecimal::add;
        }

        if ('-' == operation) {
            operator = BigDecimal::subtract;
        }

        if ('*' == operation) {
            operator = BigDecimal::multiply;
        }

        if ('/' == operation) {
            operator = (o1, o2) -> o1.divide(o2, SCALE, HALF_UP);
        }

        if ('@' != operation && operator == null) {
            return BAIL;
        }

        String instrument = composite.getInstrument();

        Request elementRequest = builder.site(site.substring(1)).instrument(instrument).build();

        Estimation estimation = function.apply(context, elementRequest);

        if (estimation == null || estimation.getPrice() == null || estimation.getConfidence() == null) {
            return BAIL;
        }

        if (operator != null) {

            prices[0] = operator.apply(trim(prices[0], ONE), estimation.getPrice());

            confidences[0] = trim(confidences[0], ONE).multiply(estimation.getConfidence());

        } else {

            prices = ArrayUtils.add(prices, estimation.getPrice());

            confidences = ArrayUtils.add(confidences, estimation.getConfidence());

        }

    }

    long countPrice = Stream.of(prices).filter(Objects::nonNull).count();
    BigDecimal totalPrice = Stream.of(prices).filter(Objects::nonNull).reduce(BigDecimal::add).orElse(ZERO);
    BigDecimal averagePrice = totalPrice.divide(valueOf(countPrice), SCALE, HALF_UP);

    long countConfidence = Stream.of(confidences).filter(Objects::nonNull).count();
    BigDecimal totalConfidence = Stream.of(confidences).filter(Objects::nonNull).reduce(BigDecimal::add).orElse(ONE);
    BigDecimal averageConfidence = totalConfidence.divide(valueOf(countConfidence), SCALE, HALF_UP);

    return Estimation.builder().price(averagePrice).confidence(averageConfidence).build();

}