Example usage for java.util Arrays stream

List of usage examples for java.util Arrays stream

Introduction

In this page you can find the example usage for java.util Arrays stream.

Prototype

public static DoubleStream stream(double[] array) 

Source Link

Document

Returns a sequential DoubleStream with the specified array as its source.

Usage

From source file:com.wso2telco.core.userprofile.permission.impl.WSO2PermissionBuilder.java

/**
 * This will build the permision tree using given users name
 *///  w  w w . j  ava  2 s .com
public Map<String, Object> build(final String userName) throws BusinessException {
    Map<String, Object> permisionTree = Collections.emptyMap();
    RetunEntitiy retunItem = new RetunEntitiy();
    try {
        UserRoleProsser userRoleRetriever = new UserRoleProsser();
        UIPermissionNode uiPermissionTree = null;

        List<String> currentUserRoleList = userRoleRetriever.getRolesByUserName(userName);
        /**
         * None of the roles are assign for the user
         */
        if (currentUserRoleList.isEmpty()) {
            throw new BusinessException("No roles assigned for user :" + userName);
        }

        for (Iterator<String> iterator = currentUserRoleList.iterator(); iterator.hasNext();) {

            String roleName = iterator.next();

            UIPermissionNode rolePermissions = userAdminStub.getRolePermissions(roleName);
            /**
             * if the permission node is empty
             */
            if (rolePermissions == null || rolePermissions.getNodeList() == null) {
                continue;
            }

            /**
             * filter out ui permission only
             */
            Optional<UIPermissionNode> optNode = Arrays.stream(rolePermissions.getNodeList())
                    .filter(rowItem -> rowItem.getDisplayName()
                            .equalsIgnoreCase(UserRolePermissionType.UI_PERMISSION.getTObject()))
                    .findFirst();

            /**
             * check for existence of node
             */
            if (optNode.isPresent()) {
                uiPermissionTree = optNode.get();

                if (uiPermissionTree.getNodeList() != null && uiPermissionTree.getNodeList().length > 0) {
                    retunItem = popUserRolePermissions(uiPermissionTree.getNodeList());
                    if (retunItem.atLeastOneSelected) {
                        break;
                    }
                } else {
                    /**
                     * if the current role does not contain Ui permission then continue
                     */
                    continue;
                }
            }

        }

        if (retunItem.returnMap.isEmpty()) {
            throw new BusinessException(UserRolePermissionType.UI_PERMISSION.getTObject()
                    + " not assigned for the user :" + userName + " , assigned roles :[ "
                    + StringUtils.join(currentUserRoleList, ",") + "]");
        }

    } catch (RemoteException | UserAdminUserAdminException e) {
        log.error("UIPermission.build", e);
        throw new BusinessException(GenaralError.INTERNAL_SERVER_ERROR);
    }
    if (retunItem.returnMap.isEmpty()) {
        log.warn(" No ui permission tree found for " + userName);
        return Collections.emptyMap();
    } else {
        return retunItem.returnMap;
    }

}

From source file:com.intellij.plugins.haxe.model.HaxeFileModel.java

public List<HaxeImportStatement> getImportStatements() {
    return Arrays.stream(file.getChildren()).filter(element -> element instanceof HaxeImportStatement)
            .map(element -> ((HaxeImportStatement) element)).collect(Collectors.toList());
}

From source file:cop.raml.mocks.MockUtils.java

private static <T extends AnnotatedConstructMock> T setAnnotations(AnnotatedConstructMock mock,
        AnnotatedElement element) {
    if (mock != null && element != null)
        Arrays.stream(element.getAnnotations()).forEach(mock::addAnnotation);
    return (T) mock;
}

From source file:com.cloudera.oryx.app.serving.als.model.LocalitySensitiveHashTest.java

private static void doTestHashDistribution(int features, double sampleRate, int numCores) {
    LocalitySensitiveHash lsh = new LocalitySensitiveHash(sampleRate, features, numCores);
    int numHashes = lsh.getNumHashes();
    RandomGenerator random = RandomManager.getRandom();
    int[] counts = new int[1 << numHashes];
    int trials = 100_000;
    for (int i = 0; i < trials; i++) {
        counts[lsh.getIndexFor(VectorMath.randomVectorF(features, random))]++;
    }//from   www .j  a v a  2 s  .c om
    log.info("{}", Arrays.toString(counts));

    IntSummaryStatistics stats = Arrays.stream(counts).summaryStatistics();
    log.info("Total {} / Max {} / Min {}", stats.getSum(), stats.getMax(), stats.getMin());
    assertEquals(trials, stats.getSum());
    assertLessOrEqual(stats.getMax(), 2 * stats.getMin());
}

From source file:co.runrightfast.core.security.auth.x500.DistinguishedName.java

/**
 *
 * @return String DN in RFC 2253 format//from www .ja  v  a  2 s. c  o  m
 */
@Override
public String toString() {
    final StringBuilder sb = new StringBuilder(128);
    if (StringUtils.isNotBlank(userid)) {
        sb.append("UID=").append(userid).append(',');
    }
    if (StringUtils.isNotBlank(commonName)) {
        sb.append("CN=").append(commonName).append(',');
    }
    if (StringUtils.isNotBlank(organizationalUnitName)) {
        sb.append("OU=").append(organizationalUnitName).append(',');
    }
    if (StringUtils.isNotBlank(organizationName)) {
        sb.append("O=").append(organizationName).append(',');
    }
    if (StringUtils.isNotBlank(country)) {
        sb.append("C=").append(country).append(',');
    }
    if (StringUtils.isNotBlank(stateOrProvinceName)) {
        sb.append("ST=").append(stateOrProvinceName).append(',');
    }
    if (StringUtils.isNotBlank(streetAddress)) {
        sb.append("STREET=").append(streetAddress).append(',');
    }
    if (StringUtils.isNotBlank(country)) {
        sb.append("C=").append(country).append(',');
    }
    if (StringUtils.isNotBlank(domain)) {
        Arrays.stream(StringUtils.split(domain, '.'))
                .forEach(domainComponent -> sb.append("DC=").append(domainComponent).append(','));
    }
    if (sb.length() > 0) {
        sb.deleteCharAt(sb.length() - 1);
    }

    return sb.toString();
}

From source file:cop.raml.utils.Utils.java

/**
 * Convert enum constants in given {@code arr} to no duplication constant collection.
 *
 * @param arr array of enum items/*w  ww .  j  ava  2 s.c o  m*/
 * @return {@code null} or not empty enum item set
 */
@NotNull
public static Set<String> asSet(String... arr) {
    if (ArrayUtils.isEmpty(arr))
        return Collections.emptySet();

    return Arrays.stream(arr).filter(StringUtils::isNotBlank).map(String::trim)
            .collect(toCollection(LinkedHashSet::new));
}

From source file:com.netflix.spinnaker.clouddriver.google.controllers.GoogleNamedImageLookupController.java

@VisibleForTesting
public static Map<String, String> buildTagsMap(Image image) {
    Map<String, String> tags = new HashMap<>();

    String description = image.getDescription();
    // For a description of the form:
    // key1: value1, key2: value2, key3: value3
    // we'll build a map associating each key with
    // its associated value
    if (description != null) {
        tags = Arrays.stream(description.split(",")).filter(token -> token.contains(": "))
                .map(token -> token.split(": ", 2))
                .collect(Collectors.toMap(token -> token[0].trim(), token -> token[1].trim(), (a, b) -> b));
    }/*  w ww  .ja v a  2  s.c o  m*/

    Map<String, String> labels = image.getLabels();
    if (labels != null) {
        tags.putAll(labels);
    }

    return tags;
}

From source file:jp.co.opentone.bsol.linkbinder.service.notice.impl.SendMailServiceImpl.java

private String[] convertEmpNoToMailAddress(String empNoCsvList) {
    return Arrays.stream(StringUtils.split(empNoCsvList, ',')).map(this::findMailAddressByEmpNo)
            .filter(StringUtils::isNotEmpty).toArray(String[]::new);
}

From source file:hydrograph.ui.propertywindow.widgets.customwidgets.RadioButtonsWidget.java

@Override
public void attachToPropertySubGroup(AbstractELTContainerWidget container) {
    ELTDefaultSubgroupComposite defaultSubgroupComposite = new ELTDefaultSubgroupComposite(
            container.getContainerControl());
    buttonText = radioButtonConfig.getWidgetDisplayNames();
    buttons = new Button[buttonText.length];
    defaultSubgroupComposite.createContainerWidget();
    defaultSubgroupComposite.numberOfBasicWidgets(buttonText.length + 1);

    AbstractELTWidget defaultLabel = new ELTDefaultLable(radioButtonConfig.getPropertyName());
    defaultSubgroupComposite.attachWidget(defaultLabel);

    setPropertyHelpWidget((Control) defaultLabel.getSWTWidgetControl());

    SelectionListener selectionListener = new SelectionAdapter() {
        @Override/*from  w w w.j a  va2s.c o  m*/
        public void widgetSelected(SelectionEvent event) {
            Button button = ((Button) event.widget);

            matchValue.setMatchValue(button.getText());
            matchValue.setRadioButtonSelected(true);
            propertyDialogButtonBar.enableApplyButton(true);
        }
    };

    for (int i = 0; i < buttonText.length; i++) {
        ELTRadioButton eltRadioButton = new ELTRadioButton(buttonText[i]);
        defaultSubgroupComposite.attachWidget(eltRadioButton);
        buttons[i] = ((Button) eltRadioButton.getSWTWidgetControl());
        ((Button) eltRadioButton.getSWTWidgetControl()).addSelectionListener(selectionListener);
    }
    buttons[0].setSelection(true);

    if (!radioButtonConfig.getRadioButtonListners().isEmpty()) {
        Stream<Button> stream = Arrays.stream(buttons);
        stream.forEach(button -> {
            Listners radioListners = radioButtonConfig.getRadioButtonListners().get(0);
            IELTListener listener = radioListners.getListener();
            Listener listnr = listener.getListener(propertyDialogButtonBar, null, button);
            button.addListener(SWT.Selection, listnr);
        });
    }
    populateWidget();
}

From source file:eu.stamp_project.automaticbuilder.MavenAutomaticBuilder.java

@Override
public void runPit(String pathToRootOfProject, CtType<?>... testClasses) {
    try {//  w  w w .  ja  va  2s . c o m
        org.apache.commons.io.FileUtils.deleteDirectory(new File(pathToRootOfProject + "/target/pit-reports"));
    } catch (Exception ignored) {

    }
    try {
        String[] phases = new String[] {
                CMD_PIT_MUTATION_COVERAGE + ":" + PitMutantScoreSelector.pitVersion + ":"
                        + GOAL_PIT_MUTATION_COVERAGE, //
                OPT_WITH_HISTORY, //
                OPT_TARGET_CLASSES + configuration.getProperty("filter"), //
                OPT_VALUE_REPORT_DIR, //
                OPT_VALUE_FORMAT, //
                OPT_VALUE_TIMEOUT, //
                OPT_VALUE_MEMORY, //
                OPT_TARGET_TESTS + Arrays.stream(testClasses).map(DSpotUtils::ctTypeToFullQualifiedName)
                        .collect(Collectors.joining(",")), //
                OPT_ADDITIONAL_CP_ELEMENTS + "target/dspot/dependencies/"
                        + (configuration.getProperty(PROPERTY_ADDITIONAL_CP_ELEMENTS) != null
                                ? "," + configuration.getProperty(PROPERTY_ADDITIONAL_CP_ELEMENTS)
                                : ""), //
                PitMutantScoreSelector.descartesMode ? OPT_MUTATION_ENGINE_DESCARTES
                        : OPT_MUTATION_ENGINE_DEFAULT,
                PitMutantScoreSelector.descartesMode ? "" : OPT_MUTATORS + VALUE_MUTATORS_ALL, //
                configuration.getProperty(PROPERTY_EXCLUDED_CLASSES) != null
                        ? OPT_EXCLUDED_CLASSES + configuration.getProperty(PROPERTY_EXCLUDED_CLASSES)
                        : ""//
        };
        if (this.runGoals(pathToRootOfProject, phases) != 0) {
            throw new RuntimeException(
                    "Maven build failed! Enable verbose mode for more information (--verbose)");
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}