Example usage for java.util List contains

List of usage examples for java.util List contains

Introduction

In this page you can find the example usage for java.util List contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this list contains the specified element.

Usage

From source file:com.linecorp.armeria.server.ServerTest.java

private static void testSimple(String reqLine, String expectedStatusLine, String... expectedHeaders)
        throws Exception {

    try (Socket socket = new Socket()) {
        socket.setSoTimeout((int) (idleTimeoutMillis * 4));
        socket.connect(server().activePort().get().localAddress());
        PrintWriter outWriter = new PrintWriter(socket.getOutputStream(), false);

        outWriter.print(reqLine);//from ww w . j  av  a 2s  .  com
        outWriter.print("\r\n");
        outWriter.print("Connection: close\r\n");
        outWriter.print("Content-Length: 0\r\n");
        outWriter.print("\r\n");
        outWriter.flush();

        BufferedReader in = new BufferedReader(
                new InputStreamReader(socket.getInputStream(), StandardCharsets.US_ASCII));

        assertThat(in.readLine(), is(expectedStatusLine));
        // Read till the end of the connection.
        List<String> headers = new ArrayList<>();
        for (;;) {
            String line = in.readLine();
            if (line == null) {
                break;
            }

            // This is not really correct, but just wanna make it as simple as possible.
            headers.add(line);
        }

        for (String expectedHeader : expectedHeaders) {
            if (!headers.contains(expectedHeader)) {
                fail("does not contain '" + expectedHeader + "': " + headers);
            }
        }
    }
}

From source file:com.baidu.rigel.biplatform.tesseract.util.QueryRequestUtil.java

public static void generateGroupBy(SearchIndexResultRecord record, List<String> groups, Meta meta)
        throws NoSuchFieldException {
    if (CollectionUtils.isNotEmpty(groups)) {
        String groupBy = "";
        Serializable field = null;
        for (String name : meta.getFieldNameArray()) {
            if (groups.contains(name)) {
                field = record.getField(meta.getFieldIndex(name));
                if (field != null) {
                    groupBy += field.toString() + ",";
                }// www .  j av a  2  s.  co  m
            }
        }
        record.setGroupBy(groupBy);
    }
}

From source file:net.rim.ejde.internal.ui.launchers.LaunchUtils.java

public static DeviceInfo getDeviceToLaunch(ILaunchConfiguration configuration) throws CoreException {
    String bundleName = configuration.getAttribute(IFledgeLaunchConstants.ATTR_GENERAL_BUNDLE,
            StringUtils.EMPTY);//from ww  w  .j  a  v a2 s  .com
    String simDir = configuration.getAttribute(IFledgeLaunchConstants.ATTR_GENERAL_SIM_DIR, StringUtils.EMPTY);
    String deviceName = configuration.getAttribute(IFledgeLaunchConstants.ATTR_GENERAL_DEVICE,
            StringUtils.EMPTY);
    String configFileName = configuration.getAttribute(IFledgeLaunchConstants.ATTR_GENERAL_CONFIG_FILE,
            StringUtils.EMPTY);
    IVMInstall vm = LaunchUtils.getVMFromConfiguration(configuration);
    List<DeviceInfo> devices = LaunchUtils.getDevicesInfo(vm);
    if (devices.isEmpty()) {
        throw new CoreException(
                StatusFactory.createErrorStatus(NLS.bind(Messages.Launch_Error_DeviceNotFound, vm.getId())));
    }
    if (!devices.contains(new DeviceInfo(bundleName, deviceName, simDir, configFileName))) {
        // JRE is changed, choose the default device instead
        DeviceInfo di = LaunchUtils.getDefaultDeviceInfo(vm);
        if (di != null) {
            bundleName = di.getBundleName();
            simDir = di.getDirectory();
            deviceName = di.getDeviceName();
            configFileName = di.getConfigName();
            // save the changes
            ILaunchConfigurationWorkingCopy workingCopy = configuration.getWorkingCopy();
            workingCopy.setAttribute(IFledgeLaunchConstants.ATTR_GENERAL_BUNDLE, bundleName);
            workingCopy.setAttribute(IFledgeLaunchConstants.ATTR_GENERAL_SIM_DIR, simDir);
            workingCopy.setAttribute(IFledgeLaunchConstants.ATTR_GENERAL_DEVICE, deviceName);
            workingCopy.setAttribute(IFledgeLaunchConstants.ATTR_GENERAL_CONFIG_FILE, configFileName);
            workingCopy.doSave();
        } else {
            throw new CoreException(StatusFactory
                    .createErrorStatus(NLS.bind(Messages.Launch_Error_DefaultDeviceNotFound, vm.getId())));
        }
    }
    return new DeviceInfo(bundleName, deviceName, simDir, configFileName);
}

From source file:com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil.java

/**
 * Return a set of processors in a template, optionally allowing the framework to traverse into a templates input ports to get the connecting process groups
 *
 * @param template      a template to parse
 * @param excludeInputs {@code true} will traverse down into the input ports and gather processors in the conencting groups, {@code false} will traverse input ports and their respective process
 *                      groups//from  w ww.j  ava 2s.  c  o m
 * @return return a set of processors
 */
public static Set<ProcessorDTO> getProcessors(TemplateDTO template, boolean excludeInputs) {
    Set<ProcessorDTO> processors = new HashSet<>();
    for (ProcessorDTO processorDTO : template.getSnippet().getProcessors()) {
        processors.add(processorDTO);
    }
    if (template.getSnippet().getProcessGroups() != null) {
        for (ProcessGroupDTO groupDTO : template.getSnippet().getProcessGroups()) {
            processors.addAll(getProcessors(groupDTO));
        }
    }

    if (excludeInputs) {
        final List<ProcessorDTO> inputs = NifiTemplateUtil.getInputProcessorsForTemplate(template);
        Iterables.removeIf(processors, new Predicate<ProcessorDTO>() {
            @Override
            public boolean apply(ProcessorDTO processorDTO) {
                return (inputs.contains(processorDTO));
            }
        });
    }
    return processors;
}

From source file:com.aliyun.openservices.odps.console.utils.CommandParserUtils.java

public static void removeHook(List<String> optionList, ExecutionContext sessionContext) {

    // hook?command??optioncontext
    if (optionList.contains("--enablehook")) {

        if (optionList.indexOf("--enablehook") + 1 < optionList.size()) {

            int index = optionList.indexOf("--enablehook");
            // command
            String hook = optionList.get(index + 1);

            // --enablehook ??
            optionList.remove(optionList.indexOf("--enablehook"));
            optionList.remove(optionList.indexOf(hook));

            if (!Boolean.valueOf(hook)) {
                sessionContext.setOdpsHooks(null);
            }/*from   ww w .  ja v a 2 s  .  co m*/
        }
    }

}

From source file:com.silverpeas.util.i18n.I18NHelper.java

public static String getHTMLLinks(List<String> languages, String currentLanguage) {
    if (!isI18N || languages == null) {
        return "";
    }//from   w  w w.j a va 2 s  .  c  om

    StringBuilder links = new StringBuilder(512);
    String link = "";

    String begin = "";
    String end = "";

    boolean first = true;
    for (String code : allCodes) {
        String className = "";

        if (languages.contains(code)) {
            link = "javaScript:showTranslation('" + code + "');";
            if (!first) {
                links.append("&nbsp;");
            }

            if (code.equals(currentLanguage) || languages.size() == 1) {
                className = "ArrayNavigationOn";
            }

            links.append("<a href=\"").append(link).append("\" class=\"").append(className)
                    .append("\" id=\"translation_").append(code).append("\">")
                    .append(code.toUpperCase(defaultLocale)).append("</a>");
            first = false;
        }
    }
    return links.toString();
}

From source file:de.mpg.escidoc.pubman.viewItem.bean.FileBean.java

public static String getOpenPDFSearchParameter(List<SearchHitBean> shbList) {
    String param = "\"";
    List<String> searchWords = new ArrayList<String>();
    for (SearchHitBean shb : shbList) {
        if (!searchWords.contains(shb.getSearchHitString())) {
            searchWords.add(shb.getSearchHitString());
        }/*  w ww  .j ava2s. c o  m*/
    }

    for (String word : searchWords) {
        param += word + " ";
    }
    param = param.trim() + "\"";
    return param;
}

From source file:main.java.spatialrelex.Evaluator.java

/**
 * /*from   w ww  . ja va2s . co  m*/
 * @param test
 * @param result
 * @return 
 */
public static List<String> getExtractedElements(String[] test, String[] result) {
    List<String> trueElements = new ArrayList<>();
    for (int i = 0; i < test.length; i++) {
        double r = Double.parseDouble(result[i].trim());
        String[] testTokens = test[i].trim().split("\\s");
        String element = testTokens[testTokens.length - 1].replace("-null", "");

        if (r >= 0.0 && !trueElements.contains(element))
            trueElements.add(element);
    }
    return trueElements;
}

From source file:com.dell.asm.asmcore.asmmanager.util.deployment.HostnameUtil.java

/**
 * Linux and Windows hostnames use different rules for validation.
 * @param hostName  Hostname to validate.
 * @param component    The component will be used to determine what hostname validation rule to apply.
 * @return//  w w w .ja v  a 2 s . c  om
 */
public static boolean isValidHostName(String hostName, ServiceTemplateComponent component) {
    boolean isWindows = false;
    boolean isEsxi = false;
    ServiceTemplateSetting imageType = component
            .getTemplateSetting(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_OS_TYPE_ID);
    if (imageType != null) {
        List<String> winTargets = new ArrayList<>();
        List<String> esxiTargets = new ArrayList<>();
        winTargets.add(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_WINDOWS2012_VALUE);
        winTargets.add(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_WINDOWS2008_VALUE);
        winTargets.add(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_HYPERV_VALUE);
        esxiTargets.add(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_ESXI_VALUE);
        isWindows = winTargets.contains(imageType.getValue());
        isEsxi = esxiTargets.contains(imageType.getValue());
    } else {
        // hyper-v cloned vm?
        if (component.getTemplateResource(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_HV_VM_RESOURCE) != null) {
            isWindows = true;
        }
    }

    if (isWindows && component.getType() != ServiceTemplateComponentType.VIRTUALMACHINE)
        return ASMCommonsUtils.isValidWindowsHostName(hostName);
    if (isEsxi)
        return ASMCommonsUtils.isValidEsxiHostName(hostName);
    if (component.getType() == ServiceTemplateComponentType.VIRTUALMACHINE)
        return ASMCommonsUtils.isValidVmHostName(hostName);
    else
        return ASMCommonsUtils.isValidHostName(hostName);
}

From source file:at.alladin.rmbt.qos.QoSUtil.java

/**
 * /*from   w ww.  jav  a2  s. c  om*/
 * @param settings
 * @param conn
 * @param answer
 * @param lang
 * @param errorList
 * @throws SQLException 
 * @throws JSONException 
 * @throws HstoreParseException 
 * @throws IllegalAccessException 
 * @throws IllegalArgumentException 
 */
public static void evaluate(final ResourceBundle settings, final Connection conn, final TestUuid uuid,
        final JSONObject answer, String lang, final ErrorList errorList) throws SQLException,
        HstoreParseException, JSONException, IllegalArgumentException, IllegalAccessException {
    // Load Language Files for Client

    final List<String> langs = Arrays.asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*"));

    if (langs.contains(lang)) {
        errorList.setLanguage(lang);
    } else {
        lang = settings.getString("RMBT_DEFAULT_LANGUAGE");
    }

    if (conn != null) {

        final Client client = new Client(conn);
        final Test test = new Test(conn);

        boolean necessaryDataAvailable = false;

        if (uuid != null && uuid.getType() != null && uuid.getUuid() != null) {
            switch (uuid.getType()) {
            case OPEN_TEST_UUID:
                if (test.getTestByOpenTestUuid(UUID.fromString(uuid.getUuid())) > 0
                        && client.getClientByUid(test.getField("client_id").intValue())) {
                    necessaryDataAvailable = true;
                }
                break;
            case TEST_UUID:
                if (test.getTestByUuid(UUID.fromString(uuid.getUuid())) > 0
                        && client.getClientByUid(test.getField("client_id").intValue())) {
                    necessaryDataAvailable = true;
                }
                break;
            }
        }

        final long timeStampFullEval = System.currentTimeMillis();

        if (necessaryDataAvailable) {

            final Locale locale = new Locale(lang);
            final ResultOptions resultOptions = new ResultOptions(locale);
            final JSONArray resultList = new JSONArray();

            QoSTestResultDao resultDao = new QoSTestResultDao(conn);
            List<QoSTestResult> testResultList = resultDao.getByTestUid(test.getUid());
            if (testResultList == null || testResultList.isEmpty()) {
                throw new UnsupportedOperationException("test " + test + " has no result list");
            }
            //map that contains all test types and their result descriptions determined by the test result <-> test objectives comparison
            Map<TestType, TreeSet<ResultDesc>> resultKeys = new HashMap<>();

            //test description set:
            Set<String> testDescSet = new TreeSet<>();
            //test summary set:
            Set<String> testSummarySet = new TreeSet<>();

            //Staring timestamp for evaluation time measurement
            final long timeStampEval = System.currentTimeMillis();

            //iterate through all result entries
            for (final QoSTestResult testResult : testResultList) {

                //reset test counters
                testResult.setFailureCounter(0);
                testResult.setSuccessCounter(0);

                //get the correct class of the result;
                TestType testType = null;
                try {
                    testType = TestType.valueOf(testResult.getTestType().toUpperCase(Locale.US));
                } catch (IllegalArgumentException e) {
                    final String errorMessage = "WARNING: QoS TestType '"
                            + testResult.getTestType().toUpperCase(Locale.US)
                            + "' not supported by ControlServer. Test with UID: " + testResult.getUid()
                            + " skipped.";
                    System.out.println(errorMessage);
                    errorList.addErrorString(errorMessage);
                    testType = null;
                }

                if (testType == null) {
                    continue;
                }

                Class<? extends AbstractResult<?>> clazz = testType.getClazz();
                //parse hstore data
                final JSONObject resultJson = new JSONObject(testResult.getResults());
                AbstractResult<?> result = QoSUtil.HSTORE_PARSER.fromJSON(resultJson, clazz);
                result.setResultJson(resultJson);

                if (result != null) {
                    //add each test description key to the testDescSet (to fetch it later from the db)
                    if (testResult.getTestDescription() != null) {
                        testDescSet.add(testResult.getTestDescription());
                    }
                    if (testResult.getTestSummary() != null) {
                        testSummarySet.add(testResult.getTestSummary());
                    }
                    testResult.setResult(result);

                }

                //compare test results
                compareTestResults(testResult, result, resultKeys, testType, resultOptions);

                //resultList.put(testResult.toJson());

                //save all test results after the success and failure counters have been set
                //resultDao.updateCounter(testResult);
            }

            //ending timestamp for evaluation time measurement
            final long timeStampEvalEnd = System.currentTimeMillis();

            //-------------------------------------------------------------
            //fetch all result strings from the db
            QoSTestDescDao descDao = new QoSTestDescDao(conn, locale);

            //FIRST: get all test descriptions
            Set<String> testDescToFetchSet = testDescSet;
            testDescToFetchSet.addAll(testSummarySet);

            Map<String, String> testDescMap = descDao.getAllByKeyToMap(testDescToFetchSet);

            for (QoSTestResult testResult : testResultList) {

                //and set the test results + put each one to the result list json array
                String preParsedDesc = testDescMap.get(testResult.getTestDescription());
                if (preParsedDesc != null) {
                    String description = String.valueOf(
                            TestScriptInterpreter.interprete(testDescMap.get(testResult.getTestDescription()),
                                    QoSUtil.HSTORE_PARSER, testResult.getResult(), true, resultOptions));
                    testResult.setTestDescription(description);
                }

                //do the same for the test summary:
                String preParsedSummary = testDescMap.get(testResult.getTestSummary());
                if (preParsedSummary != null) {
                    String description = String.valueOf(
                            TestScriptInterpreter.interprete(testDescMap.get(testResult.getTestSummary()),
                                    QoSUtil.HSTORE_PARSER, testResult.getResult(), true, resultOptions));
                    testResult.setTestSummary(description);
                }

                resultList.put(testResult.toJson(uuid.getType()));
            }

            //finally put results to json
            answer.put("testresultdetail", resultList);

            JSONArray resultDescArray = new JSONArray();

            //SECOND: fetch all test result descriptions 
            for (TestType testType : resultKeys.keySet()) {
                TreeSet<ResultDesc> descSet = resultKeys.get(testType);
                //fetch results to same object
                descDao.loadToTestDesc(descSet);

                //another tree set for duplicate entries:
                //TODO: there must be a better solution 
                //(the issue is: compareTo() method returns differnt values depending on the .value attribute (if it's set or not))
                TreeSet<ResultDesc> descSetNew = new TreeSet<>();
                //add fetched results to json

                for (ResultDesc desc : descSet) {
                    if (!descSetNew.contains(desc)) {
                        descSetNew.add(desc);
                    } else {
                        for (ResultDesc d : descSetNew) {
                            if (d.compareTo(desc) == 0) {
                                d.getTestResultUidList().addAll(desc.getTestResultUidList());
                            }
                        }
                    }
                }

                for (ResultDesc desc : descSetNew) {
                    if (desc.getValue() != null) {
                        resultDescArray.put(desc.toJson());
                    }
                }

            }
            //System.out.println(resultDescArray);
            //put result descriptions to json
            answer.put("testresultdetail_desc", resultDescArray);

            QoSTestTypeDescDao testTypeDao = new QoSTestTypeDescDao(conn, locale);
            JSONArray testTypeDescArray = new JSONArray();
            for (QoSTestTypeDesc desc : testTypeDao.getAll()) {
                final JSONObject testTypeDesc = desc.toJson();
                if (testTypeDesc != null) {
                    testTypeDescArray.put(testTypeDesc);
                }
            }

            //put result descriptions to json
            answer.put("testresultdetail_testdesc", testTypeDescArray);
            JSONObject evalTimes = new JSONObject();
            evalTimes.put("eval", (timeStampEvalEnd - timeStampEval));
            evalTimes.put("full", (System.currentTimeMillis() - timeStampFullEval));
            answer.put("eval_times", evalTimes);

            //System.out.println(answer);
        } else
            errorList.addError("ERROR_REQUEST_TEST_RESULT_DETAIL_NO_UUID");

    } else
        errorList.addError("ERROR_DB_CONNECTION");
}