Example usage for java.util Map clear

List of usage examples for java.util Map clear

Introduction

In this page you can find the example usage for java.util Map clear.

Prototype

void clear();

Source Link

Document

Removes all of the mappings from this map (optional operation).

Usage

From source file:com.esd.ps.AdministratorController.java

/**
 * ??/*from  w w  w . ja  va2  s  . co  m*/
 * 
 * @param userName
 * @return
 */
@RequestMapping(value = "/checkPassWord", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> checkPassWord(String oldPassWord, HttpSession session) {
    Map<String, Object> map = new HashMap<String, Object>();
    if (passWord(oldPassWord, session) == 1) {
        map.clear();
        map.put(Constants.MESSAGE, MSG_PASSWORD_TRUE);
        map.put(Constants.REPLAY, 1);
        return map;
    }
    map.clear();
    map.put(Constants.MESSAGE, MSG_PASSWORD_NOT_ERROR);
    map.put(Constants.REPLAY, 0);
    return map;
}

From source file:com.jaspersoft.jasperserver.war.helper.GenericParametersHelper.java

private static ParameterizedType findParametrizedType(Class<?> classToParse, Class<?> genericClassToFind,
        Map<String, Class<?>> inputParameterValues) {
    ParameterizedType type = null;
    if (genericClassToFind.isInterface()) {
        final Type[] genericInterfaces = classToParse.getGenericInterfaces();
        if (genericInterfaces != null && genericInterfaces.length > 0) {
            for (Type genericInterface : genericInterfaces) {
                if (genericInterface == genericClassToFind) {
                    throw new IllegalArgumentException(classToParse.getName() + " is raw implementation of "
                            + genericClassToFind.getName());
                }/*from  w w w.ja  v a 2 s  .  co m*/
                if (genericInterface instanceof ParameterizedType) {
                    ParameterizedType currentParametrizedType = (ParameterizedType) genericInterface;
                    Map<String, Class<?>> currentParameterValues = new HashMap<String, Class<?>>(
                            inputParameterValues);
                    if (currentParametrizedType.getRawType() == genericClassToFind) {
                        type = (ParameterizedType) genericInterface;
                    } else {
                        currentParameterValues = getCurrentParameterValues(
                                ((Class<?>) currentParametrizedType.getRawType()).getTypeParameters(),
                                currentParametrizedType.getActualTypeArguments(),
                                new HashMap<String, Class<?>>(inputParameterValues));
                        type = findParametrizedType((Class<?>) currentParametrizedType.getRawType(),
                                genericClassToFind, currentParameterValues);
                    }
                    if (type != null) {
                        inputParameterValues.clear();
                        inputParameterValues.putAll(currentParameterValues);
                        break;
                    }
                }
            }
        }
    } else {
        final Type genericSuperclass = classToParse.getGenericSuperclass();
        if (genericSuperclass == genericClassToFind) {
            log.debug(classToParse.getName() + " is raw subclass of " + genericClassToFind.getName());
        } else if (genericSuperclass instanceof ParameterizedType
                && ((ParameterizedType) genericSuperclass).getRawType() == genericClassToFind) {
            type = (ParameterizedType) genericSuperclass;
        }
    }
    return type;
}

From source file:com.esd.ps.AdministratorController.java

/**
 * ??/*from  ww w.ja  va  2  s .  com*/
 * 
 * @param WorkerDisabilityCard
 * @return
 */
@RequestMapping(value = "/checkWorkerDisabilityCard", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> checkWorkerDisabilityCard(String WorkerDisabilityCard) {
    Map<String, Object> map = new HashMap<String, Object>();
    if (WorkerDisabilityCard.length() < 20) {
        map.clear();
        map.put(Constants.REPLAY, Constants.ZERO);
        map.put(Constants.MESSAGE, MSG_WORKERDISABILITYCARD_20);
        return map;
    }
    if (workerDisabilityCard(WorkerDisabilityCard) == 0) {
        map.clear();
        map.put(Constants.REPLAY, Constants.ONE);
    } else {
        map.clear();
        map.put(Constants.REPLAY, Constants.ZERO);
        map.put(Constants.MESSAGE, MSG_WORKERDISABILITYCARD_EXIST);
    }
    return map;
}

From source file:io.bitgrillr.gocddockerexecplugin.DockerExecPlugin.java

private GoPluginApiResponse handleExecuteRequest(JsonObject requestBody) {
    final String image = requestBody.getJsonObject(CONFIG).getJsonObject(IMAGE).getString(VALUE);
    final String command = requestBody.getJsonObject(CONFIG).getJsonObject("COMMAND").getString(VALUE);
    final JsonString argumentsJson = requestBody.getJsonObject(CONFIG).getJsonObject("ARGUMENTS")
            .getJsonString(VALUE);//from w  w w  . j a v a 2 s  .c o m
    final String[] arguments;
    if (argumentsJson != null) {
        arguments = argumentsJson.getString().split("\\r?\\n");
    } else {
        arguments = new String[0];
    }
    Map<String, String> envVars = requestBody.getJsonObject("context").getJsonObject("environmentVariables")
            .entrySet().stream()
            .map(e -> new AbstractMap.SimpleEntry<>(e.getKey(), ((JsonString) e.getValue()).getString()))
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    final String workingDir = requestBody.getJsonObject("context").getString("workingDirectory");
    final String pwd = Paths.get(System.getProperty("user.dir"), workingDir).toAbsolutePath().toString();

    final Map<String, Object> responseBody = new HashMap<>();
    try {
        final int exitCode = executeBuild(image, pwd, envVars, command, arguments);

        responseBody.put(MESSAGE,
                (new StringBuilder()).append("Command ")
                        .append(DockerUtils.getCommandString(command, arguments))
                        .append(" completed with status ").append(exitCode).toString());
        if (exitCode == 0) {
            responseBody.put(SUCCESS, Boolean.TRUE);
        } else {
            responseBody.put(SUCCESS, Boolean.FALSE);
        }
    } catch (DockerCleanupException dce) {
        responseBody.clear();
        responseBody.put(SUCCESS, Boolean.FALSE);
        if (dce.getNested() == null) {
            responseBody.put(MESSAGE, dce.getCause().getMessage());
        } else {
            responseBody.put(MESSAGE, dce.getNested().getMessage());
        }
    } catch (ImageNotFoundException infe) {
        responseBody.put(SUCCESS, Boolean.FALSE);
        responseBody.put(MESSAGE,
                (new StringBuilder()).append("Image '").append(image).append("' not found").toString());
    } catch (Exception e) {
        responseBody.clear();
        responseBody.put(SUCCESS, Boolean.FALSE);
        responseBody.put(MESSAGE, e.getMessage());
    }

    return DefaultGoPluginApiResponse.success(Json.createObjectBuilder(responseBody).build().toString());
}

From source file:com.redhat.rhtracking.core.services.DeliveryServiceHandler.java

@Override
public Map<String, Object> assignConsultant(Map<String, Object> event) {
    Map<String, Object> request = new HashMap<>();
    if (event.containsKey("opportunityId")) {
        request.put("id", (long) event.get("opportunityId"));
    } else if (event.containsKey("opportunityIdentifier")) {
        request.put("identifier", (String) event.get("opportunityIdentifier"));
    } else {//from  w w  w .ja v  a 2  s  .  c o m
        throw new IllegalArgumentException("request must containt opportunityId or opportunityIdentifier");
    }
    Map<String, Object> opportunity = opportunityPersistanceService.findBy(request);
    event.put("deliveryMatrixId", (long) opportunity.get("deliveryMatrixId"));

    // verifica horas correctas

    // obtine horas
    HourType aType = HourType.valueOf((String) event.get("hourType"));
    int aHours = (int) event.get("assignedHours");

    request.clear();
    request.put("id", (long) opportunity.get("id"));
    Map<String, Object> hours = opportunityPersistanceService.listOpportunityHours(request);

    logger.debug("hpurs" + hours);

    for (Map<String, Object> h : (List<Map<String, Object>>) hours.get("list")) {
        HourType t = HourType.valueOf((String) h.get("hourType"));
        if (aType.equals(t)) {
            int aviable = (int) h.get("quantity") - (int) h.get("hoursToAccrued");
            if (aviable < aHours) {
                Map<String, Object> err = new HashMap<>();
                err.put("status", EventStatus.EXCEPTION);
                return err;
            }
            h.put("hoursToAccrued", (int) h.get("hoursToAccrued") + aHours);
            opportunityPersistanceService.updateOpportunityHours(h);
        }
    }

    return assignmentPersistanceService.saveAssignment(event);
}

From source file:io.apiman.manager.test.es.ESMetricsAccessorTest.java

/**
 * Test method for {@link io.apiman.manager.api.es.ESMetricsAccessor#getUsagePerClient(java.lang.String, java.lang.String, java.lang.String, java.util.Date, java.util.Date)}.
 *//*from  w  ww.  j  a v a 2  s. c o m*/
@Test
public void testGetUsagePerClient() throws Exception {
    ESMetricsAccessor metrics = new ESMetricsAccessor();
    metrics.setEsClient(client);

    // data exists - all data for JBossOverlord/s-ramp-api:1.0
    UsagePerClientBean usagePerClient = metrics.getUsagePerClient("JBossOverlord", "s-ramp-api", "1.0",
            parseDate("2015-01-01"), new DateTime().withZone(DateTimeZone.UTC));
    Assert.assertNotNull(usagePerClient);
    Map<String, Long> expectedData = new HashMap<>();
    expectedData.put("dtgov", 29L);
    expectedData.put("rtgov", 14L);
    Assert.assertEquals(expectedData, usagePerClient.getData());

    // data exists - all data for Test/echo:1.0
    usagePerClient = metrics.getUsagePerClient("Test", "echo", "1.0", parseDate("2015-01-01"),
            new DateTime().withZone(DateTimeZone.UTC));
    Assert.assertNotNull(usagePerClient);
    expectedData.clear();
    expectedData.put("my-client", 136L);
    expectedData.put("client1", 78L);
    Assert.assertEquals(expectedData, usagePerClient.getData());

    // Test/echo:1.0 bounded by a different date range
    usagePerClient = metrics.getUsagePerClient("Test", "echo", "1.0", parseDate("2015-06-18"),
            new DateTime().withZone(DateTimeZone.UTC));
    Assert.assertNotNull(usagePerClient);
    expectedData.clear();
    Assert.assertEquals(expectedData, usagePerClient.getData());

    // data exists - all data for Test/echo:1.0
    usagePerClient = metrics.getUsagePerClient("Test", "echo", "1.0", parseDate("2015-06-01"),
            parseDate("2015-06-17"));
    Assert.assertNotNull(usagePerClient);
    expectedData.clear();
    expectedData.put("my-client", 136L);
    expectedData.put("client1", 78L);
    Assert.assertEquals(expectedData, usagePerClient.getData());

    // No data for API
    usagePerClient = metrics.getUsagePerClient("NA", "NA", "NA", parseDate("2015-01-01"),
            new DateTime().withZone(DateTimeZone.UTC));
    Assert.assertNotNull(usagePerClient);
    expectedData.clear();
    Assert.assertEquals(expectedData, usagePerClient.getData());
}

From source file:com.backelite.sonarqube.objectivec.issues.oclint.OCLintRulesDefinition.java

private void loadRules(NewRepository repository) throws IOException {

    Reader reader = new BufferedReader(
            new InputStreamReader(getClass().getResourceAsStream(RULES_FILE), CharEncoding.UTF_8));

    final List<String> listLines = IOUtils.readLines(reader);

    String previousLine = null;//from   w w w.j  a v  a2  s . co m
    Map<String, String> rule = new HashMap<String, String>();
    boolean inDescription = false;
    for (String line : listLines) {

        if (isLineIgnored(line)) {
            inDescription = false;

        } else if (line.matches("[\\-]{4,}.*")) {
            LOGGER.debug("Rule found : {}", previousLine);

            // Remove the rule name from the description of the previous
            // rule
            if (rule.get("description") != null) {
                String description = rule.get("description").toString();
                final int index = description.lastIndexOf(previousLine);
                if (index > 0) {
                    rule.put("description", description.substring(0, index));
                }

            }

            rule.clear();

            rule.put("name", StringUtils.capitalize(previousLine));
            rule.put("key", previousLine);

        } else if (line.matches("Summary:.*")) {
            inDescription = true;
            rule.put("description", line.substring(line.indexOf(':') + 1));
        } else if (line.matches("Category:.*")) {
            inDescription = true;

            // Create rule when last filed found
            RulesDefinition.NewRule newRule = repository.createRule(rule.get("key").toString());
            newRule.setName(rule.get("name").toString());
            newRule.setSeverity(rule.get("severity").toString());
            newRule.setHtmlDescription(rule.get("description").toString());

        } else if (line.matches("Severity:.*")) {
            inDescription = false;
            final String severity = line.substring("Severity: ".length());
            rule.put("severity", OCLintRuleSeverity.valueOfInt(Integer.valueOf(severity)).name());
        } else {
            if (inDescription) {
                line = ruleDescriptionLink(line);
                String description = (String) rule.get("description");
                rule.put("description", description + "<br>" + line);
            }
        }

        previousLine = line;
    }

}

From source file:eionet.cr.web.action.admin.staging.RDFExportWizardActionBean.java

/**
 * To be called when selected columns changed.
 *
 * @param selectedColumns//w  ww  .j  a v a 2 s. c  om
 *            the selected columns
 */
private void selectedColumnsChanged(Set<String> selectedColumns) {

    if (queryConf == null) {
        queryConf = new QueryConfiguration();
    }

    Map<String, ObjectProperty> curMappings = queryConf.getColumnMappings();
    if (selectedColumns == null || selectedColumns.isEmpty()) {
        curMappings.clear();
        return;
    }

    ObjectType objectType = getObjectType();
    LinkedCaseInsensitiveMap<ObjectProperty> newMappings = new LinkedCaseInsensitiveMap<ObjectProperty>();
    for (String column : selectedColumns) {
        if (curMappings.containsKey(column)) {
            ObjectProperty curProperty = curMappings.get(column);
            if (curProperty == null) {
                newMappings.put(column, null);
            } else if (!objectType.hasThisProperty(curProperty)) {
                newMappings.put(column, objectType.getDefaultProperty(column));
            } else {
                newMappings.put(column, curProperty);
            }
        } else {
            newMappings.put(column, objectType.getDefaultProperty(column));
        }
    }

    queryConf.setColumnMappings(newMappings);
}

From source file:gov.nih.nci.caarray.plugins.nimblegen.NdfHandler.java

private int loadProbes(ArrayDesignDetails details, Map<String, LogicalProbe> logicalProbes,
        ScrollableResults results) throws IOException {
    int count = 0;
    results.beforeFirst();//from  ww w.ja  va  2  s.  c  o  m
    String lastSeqId = null;
    while (results.next()) {
        final Object[] values = results.get();
        final Map<String, Object> vals = new HashMap<String, Object>();
        vals.put(PROBE_ID, values[0]);
        vals.put(SEQ_ID, values[1]);
        vals.put(CONTAINER2, values[2]);
        vals.put(X, values[3]);
        vals.put(Y, values[4]);

        if (lastSeqId != null && !vals.get(SEQ_ID).equals(lastSeqId)) {
            logicalProbes.clear();
            flushAndClearSession();
        }
        lastSeqId = (String) vals.get(SEQ_ID);

        final PhysicalProbe p = createPhysicalProbe(details, vals, logicalProbes);
        getArrayDao().save(p);
        ++count;
    }
    return count;
}

From source file:edu.cornell.med.icb.io.TestConditionsParser.java

public void testBean() throws IOException, ConditionsParsingException {
    final String input = "oneInt=123,twoDouble=456,threeString=def\t123\t5,6,7\n" + "#comment\n"
            + "oneInt=567,twoDouble=8.367,threeString=3bf,fourNada=abc";
    final Reader source = new StringReader(input);

    final ConditionsParser parser = new ConditionsParser();
    parser.addField(new ConditionField(ConditionField.FieldType.MAP, "one"));
    parser.addField(new ConditionField(ConditionField.FieldType.VALUE, "two"));
    parser.addField(new ConditionField(ConditionField.FieldType.VALUE, "three").setList(true));

    parser.beginParse(source);/* w  ww  .java 2s  .  c om*/
    SampleBean testBean;

    final Map<String, String> expValues = new HashMap<String, String>();
    final Map<String, String> foundValues = new HashMap<String, String>();

    assertTrue(parser.hasNext());
    testBean = new SampleBean();

    expValues.clear();
    expValues.put("oneInt", "123");
    expValues.put("twoDouble", "456");
    expValues.put("threeString", "def");
    foundValues.clear();
    Object retval = parser.parseFieldBean("one", testBean, foundValues);
    assertTrue(testBean == retval);
    checkMap(expValues, foundValues);
    assertEquals("123", parser.parseFieldValueString("two"));
    checkIntArray(new int[] { 5, 6, 7 }, parser.parseFieldValueIntArray("three"));
    assertEquals(123, testBean.getOneInt());
    assertEquals(456.0d, testBean.getTwoDouble());
    assertEquals("def", testBean.getThreeString());
    assertEquals(1, parser.getLineNumber());
    assertTrue(parser.hasNext());

    testBean = new SampleBean();
    expValues.clear();
    expValues.put("oneInt", "567");
    expValues.put("twoDouble", "8.367");
    expValues.put("threeString", "3bf");
    expValues.put("fourNada", "abc");
    foundValues.clear();
    retval = parser.parseFieldBean("one", testBean, foundValues);
    assertTrue(testBean == retval);
    checkMap(expValues, foundValues);
    assertEquals("", parser.parseFieldValueString("two"));
    checkIntArray(ArrayUtils.EMPTY_INT_ARRAY, parser.parseFieldValueIntArray("three"));
    assertEquals(567, testBean.getOneInt());
    assertEquals(8.367d, testBean.getTwoDouble());
    assertEquals("3bf", testBean.getThreeString());
    assertEquals(3, parser.getLineNumber());
    assertFalse(parser.hasNext());

    IOUtils.closeQuietly(source);
}