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

The following examples show how to use org.apache.commons.lang3.ArrayUtils#add() . 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: ContentFinderAction.java    From entando-components with GNU Lesser General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: TemplateHelper.java    From ameba with MIT License 6 votes vote down vote up
/**
 * <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;
}
 
Example 3
Source File: DataModelDesc.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: QuerydslUtilsBeanImpl.java    From gvnix with GNU General Public License v3.0 6 votes vote down vote up
/**
 * {@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);
}
 
Example 5
Source File: SearchDelegatorTest.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source File: GuiAphorismTile.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example 7
Source File: Blockchain.java    From blockchain-java with Apache License 2.0 5 votes vote down vote up
/**
 * 查找所有的 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;
}
 
Example 8
Source File: Application.java    From ameba with MIT License 5 votes vote down vote up
@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();
}
 
Example 9
Source File: ProtectsDelegatorTest.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 10
Source File: SortedListFacade.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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);
}
 
Example 11
Source File: GeoWaveRedisRow.java    From geowave with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 12
Source File: TestGroupManager.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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));

}
 
Example 13
Source File: ShellCommand.java    From citeproc-java with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source File: ContentListTag.java    From entando-components with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void addCategory(String category) {
	if (null == category) return;
       this.categories = ArrayUtils.add(this.categories, category);
}
 
Example 15
Source File: IngestOptionsBuilderImpl.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public Builder<T> addExtension(final String fileExtension) {
  fileExtensions = ArrayUtils.add(fileExtensions, fileExtension);
  return this;
}
 
Example 16
Source File: ArrayOperations.java    From tutorials with MIT License 4 votes vote down vote up
public static int[] appendIntWithUtils(int[] array, int newItem) {
    return ArrayUtils.add(array, newItem);
}
 
Example 17
Source File: RestListRequest.java    From entando-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void addFilter(Filter filter) {
    this.filters = ArrayUtils.add(this.filters, filter);
}
 
Example 18
Source File: MergeAddBp.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public MergeAddBp(SameDiff sameDiff, @NonNull SDVariable[] inputs, @NonNull SDVariable gradO) {
    super("mergeadd_bp", sameDiff, ArrayUtils.add(inputs, gradO));
}
 
Example 19
Source File: MockContentListTagBean.java    From entando-components with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void addCategory(String category) {
       this.categories = ArrayUtils.add(this.categories, category);
}
 
Example 20
Source File: CompositeEstimator.java    From cryptotrader with GNU Affero General Public License v3.0 2 votes vote down vote up
@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();

}