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

The following examples show how to use org.apache.commons.lang3.ArrayUtils#removeElement() . 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: DataModelDesc.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private boolean validate() {

        // ensure no dup between dimensions/metrics
        for (ModelDimensionDesc dim : dimensions) {
            String table = dim.getTable();
            for (String c : dim.getColumns()) {
                TblColRef dcol = findColumn(table, c);
                metrics = ArrayUtils.removeElement(metrics, dcol.getIdentity());
            }
        }

        Set<TblColRef> mcols = new HashSet<>();
        for (String m : metrics) {
            mcols.add(findColumn(m));
        }

        // validate PK/FK are in dimensions
        boolean pkfkDimAmended = false;
        for (Chain chain : joinsTree.getTableChains().values()) {
            pkfkDimAmended = validatePkFkDim(chain.join, mcols) || pkfkDimAmended;
        }
        return pkfkDimAmended;
    }
 
Example 2
Source File: DataModelDesc.java    From kylin with Apache License 2.0 6 votes vote down vote up
private boolean validate() {

        // ensure no dup between dimensions/metrics
        for (ModelDimensionDesc dim : dimensions) {
            String table = dim.getTable();
            for (String c : dim.getColumns()) {
                TblColRef dcol = findColumn(table, c);
                metrics = ArrayUtils.removeElement(metrics, dcol.getIdentity());
            }
        }

        Set<TblColRef> mcols = new HashSet<>();
        for (String m : metrics) {
            mcols.add(findColumn(m));
        }

        // validate PK/FK are in dimensions
        boolean pkfkDimAmended = false;
        for (Chain chain : joinsTree.getTableChains().values()) {
            pkfkDimAmended = validatePkFkDim(chain.join, mcols) || pkfkDimAmended;
        }
        return pkfkDimAmended;
    }
 
Example 3
Source File: CasMultiFactorWebflowConfigurer.java    From cas-mfa with Apache License 2.0 6 votes vote down vote up
@Override
@PostConstruct
public void afterPropertiesSet() throws Exception {
    try {

        String[] flowIds = flowDefinitionRegistry.getFlowDefinitionIds();
        flowIds = ArrayUtils.removeElement(flowIds, FLOW_ID_LOGIN);
        flowIds = ArrayUtils.removeElement(flowIds, FLOW_ID_LOGOUT);

        LOGGER.debug("Detected {} flow configurations: [{}]",
                flowIds.length,
                Arrays.toString(flowIds));

        LOGGER.debug("Configuring webflow for multifactor authentication...");
        setupWebflow(flowIds);
        LOGGER.debug("Configured webflow for multifactor authentication.");

        LOGGER.debug("Registering default credentials-to-principal resolver...");
        registerDefaultCredentialsToPrincipalResolver();
        LOGGER.debug("Registered default credentials-to-principal resolver.");
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
}
 
Example 4
Source File: DataRestRequestBuilder.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
/**
 * Build parameters.
 *
 * @param domainType the domain type
 * @param openAPI the open api
 * @param handlerMethod the handler method
 * @param requestMethod the request method
 * @param methodAttributes the method attributes
 * @param operation the operation
 * @param resourceMetadata the resource metadata
 */
public void buildParameters(Class<?> domainType, OpenAPI openAPI, HandlerMethod handlerMethod, RequestMethod requestMethod, MethodAttributes methodAttributes, Operation operation, ResourceMetadata resourceMetadata) {
	String[] pNames = this.localSpringDocParameterNameDiscoverer.getParameterNames(handlerMethod.getMethod());
	MethodParameter[] parameters = handlerMethod.getMethodParameters();
	if (!resourceMetadata.isPagingResource()) {
		Optional<MethodParameter> methodParameterPage = Arrays.stream(parameters).filter(methodParameter -> DefaultedPageable.class.equals(methodParameter.getParameterType())).findFirst();
		if (methodParameterPage.isPresent())
			parameters = ArrayUtils.removeElement(parameters, methodParameterPage.get());
	}
	String[] reflectionParametersNames = Arrays.stream(handlerMethod.getMethod().getParameters()).map(java.lang.reflect.Parameter::getName).toArray(String[]::new);
	if (pNames == null || Arrays.stream(pNames).anyMatch(Objects::isNull))
		pNames = reflectionParametersNames;
	buildCommonParameters(domainType, openAPI, requestMethod, methodAttributes, operation, pNames, parameters);
}
 
Example 5
Source File: SingleBlockGenerator.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void generate(Random gridRandom, IBlockGeneratorAccess relativeBlockAccess) {
    MutableBlockPos relativePos = new MutableBlockPos();
    int blocksCount = minBlocksCount == maxBlocksCount ? maxBlocksCount : minBlocksCount + gridRandom.nextInt(maxBlocksCount - minBlocksCount);
    EnumFacing prevDirection = null;
    for (int i = 0; i < blocksCount; i++) {
        EnumFacing[] allowedFacings = ArrayUtils.removeElement(EnumFacing.VALUES, prevDirection);
        prevDirection = allowedFacings[gridRandom.nextInt(allowedFacings.length)];
        relativePos.offset(prevDirection);
        relativeBlockAccess.generateBlock(relativePos.getX(), relativePos.getY(), relativePos.getZ());
    }
}
 
Example 6
Source File: Node.java    From jease with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Detaches parent from node.
 */
protected void detachParent() {
    if (parent != null && ArrayUtils.contains(parent.children, this)) {
        parent.children = ArrayUtils.removeElement(parent.children, this);
        parent.markChanged();
    }
    parent = null;
    markChanged();
}
 
Example 7
Source File: SortedListFacade.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void elementRemoved(ListEvent<E> e)
{
	int index = ArrayUtils.indexOf(transform, e.getIndex());
	transform = ArrayUtils.removeElement(transform, transform.length - 1);
	sanityCheck();
	Arrays.sort(transform, indexComparator);
	fireElementRemoved(this, e.getElement(), index);
}
 
Example 8
Source File: SortedListFacade.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void elementRemoved(ListEvent<E> e)
{
	int index = ArrayUtils.indexOf(transform, e.getIndex());
	transform = ArrayUtils.removeElement(transform, transform.length - 1);
	sanityCheck();
	Arrays.sort(transform, indexComparator);
	fireElementRemoved(this, e.getElement(), index);
}
 
Example 9
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 10
Source File: ArrayUtilsUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenArray_whenRemovingAnElement_thenCorrect() {
    int[] oldArray = { 1, 2, 3, 3, 4 };
    int[] newArray = ArrayUtils.removeElement(oldArray, 3);
    int[] expectedArray = { 1, 2, 3, 4 };
    assertArrayEquals(expectedArray, newArray);
}
 
Example 11
Source File: Main.java    From tools with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {

		if (args.length < 1) {
			usage();
			return;
		}

		String spdxTool = args[0];
		args = ArrayUtils.removeElement(args, args[0]);

		if (spdxTool.equalsIgnoreCase("SpdxViewer")) {
			SpdxViewer.main(args);
		} else if (spdxTool.equalsIgnoreCase("TagToSpreadsheet")) {
			TagToSpreadsheet.main(args);
		} else if (spdxTool.equalsIgnoreCase("TagToRDF")) {
			TagToRDF.main(args);
		} else if (spdxTool.equalsIgnoreCase("RdfToTag")) {
			RdfToTag.main(args);
		} else if (spdxTool.equalsIgnoreCase("RdfToHtml")) {
			RdfToHtml.main(args);
		} else if (spdxTool.equalsIgnoreCase("RdfToSpreadsheet")) {
			RdfToSpreadsheet.main(args);
		} else if (spdxTool.equalsIgnoreCase("SpreadsheetToRDF")) {
			SpreadsheetToRDF.main(args);
		} else if (spdxTool.equalsIgnoreCase("SpreadsheetToTag")){
			SpreadsheetToTag.main(args);
		} else if (spdxTool.equalsIgnoreCase("CompareMultipleSpdxDocs")) {
			CompareMultpleSpdxDocs.main(args);
		} else if (spdxTool.equalsIgnoreCase("CompareSpdxDocs")) {
			System.out.println("This tool has not been updated to the 2.1 spec.  Please use the CompareMultipleSpdxDocs command.");
		} else if (spdxTool.equalsIgnoreCase("Verify")) {
			Verify.main(args);
		} else if (spdxTool.equalsIgnoreCase("GenerateVerificationCode")) {
			GenerateVerificationCode.main(args);
		} else if (spdxTool.equalsIgnoreCase("MergeSpdxDocs")) {
			System.out.println("The merge tools are currently being upgraded to SPDX 2.0");
		//	MergeSpdxDocs.main(args);
		} else if (spdxTool.equalsIgnoreCase("MatchingStandardLicenses")) {
			MatchingStandardLicenses.main(args);
		} else if (spdxTool.equalsIgnoreCase("Version")) {
			System.out.println("SPDX Tool Version: "+SpdxDocumentContainer.CURRENT_IMPLEMENTATION_VERSION + 
					"; Specification Version: "+SpdxDocumentContainer.CURRENT_SPDX_VERSION + 
					"; License List Version: "+ListedLicenses.getListedLicenses().getLicenseListVersion());
		} else {
			usage();
		}

	}
 
Example 12
Source File: RemoveElementFromAnArray.java    From tutorials with MIT License 4 votes vote down vote up
public int[] removeFirstOccurrenceOfGivenElement(int[] array, int element) {
    return ArrayUtils.removeElement(array, element);
}
 
Example 13
Source File: RemoveElementFromArray.java    From levelup-java-examples with Apache License 2.0 4 votes vote down vote up
@Test
public void remove_element_from_array_apache_commons () {
	
	String[] daysOfWeek = {"Sunday", "Monday", "Tuesday", "Wednesday", 
			"Thursday", "Friday", "Saturday"};
	
	String[] favoriteDaysOfTheWeek = ArrayUtils.removeElement(daysOfWeek, "Monday");
	
	logger.info(Arrays.toString(daysOfWeek));
	
	assertTrue(favoriteDaysOfTheWeek.length == 6);
	assertThat(favoriteDaysOfTheWeek, arrayContaining(
			"Sunday", "Tuesday", "Wednesday", 
			"Thursday", "Friday", "Saturday"));

}