Example usage for java.util Map remove

List of usage examples for java.util Map remove

Introduction

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

Prototype

V remove(Object key);

Source Link

Document

Removes the mapping for a key from this map if it is present (optional operation).

Usage

From source file:com.omricat.yacc.backend.servlets.CurrenciesProcessor.java

@NotNull
CurrencyDataset download() throws IOException {
    final Map<String, String> rawDataMap = currencyService.getLatestCurrencies().get(0); // Should only be one element in the array
    final long timeStamp = Long.parseLong(rawDataMap.remove("DateTime"));
    final Set<Currency> currencySet = new HashSet<>();

    Map<CurrencyCode, String> names;
    try (Reader in = namesStore.getReader()) {
        names = mapper.readValue(in, mapType);
    } catch (FileNotFoundException e) {
        names = NamesHelper.getInstance(mapper, namesService).getAndStoreCurrencyNames(namesStore);
    }/*from ww  w  .  j av  a2 s.  c o  m*/

    DataConsistencyProcessor dataConsistencyProcessor = new DataConsistencyProcessor(names);

    for (Map.Entry<String, String> entry : rawDataMap.entrySet()) {
        // The currency service gives currency values which end
        //   with "\r" so we remove it from each
        String currencyValue = entry.getValue().replace("\r", "");
        String name = names.get(new CurrencyCode(entry.getKey()));
        if (name == null) {
            name = "";
        }
        final Optional<Currency> currency = dataConsistencyProcessor
                .fixData(new Currency(currencyValue, entry.getKey(), name));
        if (currency.isPresent()) {
            currencySet.add(currency.get());
        }
    }

    return new CurrencyDataset(currencySet, timeStamp);

}

From source file:com.glaf.core.web.springmvc.MxSystemParamController.java

@RequestMapping("/update")
public ModelAndView update(HttpServletRequest request, ModelMap modelMap) {

    Map<String, Object> params = RequestUtils.getParameterMap(request);
    params.remove("status");
    params.remove("wfStatus");
    String systemParamId = ParamUtils.getString(params, "systemParamId");
    SystemParam systemParam = null;/*  w w  w  .  j  a va2  s .  c om*/
    if (StringUtils.isNotEmpty(systemParamId)) {
        systemParam = systemParamService.getSystemParam(systemParamId);
    }

    if (systemParam != null) {

        Tools.populate(systemParam, params);
        systemParamService.save(systemParam);

    }

    return this.list(request, modelMap);
}

From source file:com.glaf.report.web.springmvc.MxReportFileController.java

@RequestMapping("/update")
public ModelAndView update(HttpServletRequest request, ModelMap modelMap) {
    Map<String, Object> params = RequestUtils.getParameterMap(request);
    params.remove("status");
    params.remove("wfStatus");
    String reportFileId = ParamUtils.getString(params, "reportFileId");
    ReportFile reportFile = null;//from w  ww . j  a  v a 2  s .  c om
    if (StringUtils.isNotEmpty(reportFileId)) {
        reportFile = reportFileService.getReportFile(reportFileId);
    }

    if (reportFile != null) {

        Tools.populate(reportFile, params);
        reportFileService.save(reportFile);

    }

    return this.list(request, modelMap);
}

From source file:com.hortonworks.streamline.streams.catalog.StreamInfo.java

@Override
public Map<String, Object> toMap() {
    Map<String, Object> map = super.toMap();
    map.remove(FIELDS);
    try {//from ww w . j av a2s  .  c om
        map.put(FIELDSDATA, getFieldsData());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return map;
}

From source file:org.sakaiproject.metaobj.shared.control.EditStructuredArtifactDefinitionController.java

public Object fillBackingObject(Object incomingModel, Map request, Map session, Map application)
        throws Exception {
    if (session.get(StructuredArtifactDefinitionManager.SAD_SESSION_TAG) != null) {
        return session.remove(StructuredArtifactDefinitionManager.SAD_SESSION_TAG);
    }/*from w  ww  .j a  va  2 s .c o m*/

    StructuredArtifactDefinitionBean home = (StructuredArtifactDefinitionBean) incomingModel;
    home = getStructuredArtifactDefinitionManager().loadHome(home.getId());
    return home;
}

From source file:org.graylog.plugins.beats.BeatsCodec.java

private Message parseGenericBeat(Map<String, Object> event) {
    final String message = String.valueOf(event.remove("message"));
    final Message gelfMessage = createMessage(message, event);
    gelfMessage.addField("facility", "genericbeat");
    final Map<String, Object> flattened = flatten(event, "beat", MAP_KEY_SEPARATOR);

    // Fix field names containing dots
    final Map<String, Object> withoutDots = MapUtils.replaceKeyCharacter(flattened, '.',
            MAP_KEY_SEPARATOR.charAt(0));
    gelfMessage.addFields(withoutDots);/*from  w ww  . j a v a2 s  .c o  m*/
    return gelfMessage;
}

From source file:com.datatorrent.stram.FSEventRecorder.java

public void writeEvent(StramEvent event) throws Exception {
    LOG.debug("Writing event {} to the storage", event.getType());
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bos.write((event.getTimestamp() + ":").getBytes());
    bos.write((event.getType() + ":").getBytes());
    @SuppressWarnings("unchecked")
    Map<String, String> data = BeanUtils.describe(event);
    data.remove("timestamp");
    data.remove("class");
    data.remove("type");
    Slice f = streamCodec.toByteArray(data);
    bos.write(f.buffer, f.offset, f.length);
    bos.write("\n".getBytes());
    storage.writeDataItem(bos.toByteArray(), true);
    if (numSubscribers > 0) {
        LOG.debug("Publishing event {} through websocket to gateway", event.getType());
        EventsAgent.EventInfo eventInfo = new EventsAgent.EventInfo();
        eventInfo.id = event.getId();//w w w  . java 2 s.  c om
        eventInfo.timestamp = event.getTimestamp();
        eventInfo.type = event.getType();
        eventInfo.data = data;
        eventInfo.data.remove("id");
        wsClient.publish(pubSubTopic, eventInfo);
    }
}

From source file:org.graylog.plugins.beats.BeatsCodec.java

/**
 * @see <a href="https://www.elastic.co/guide/en/beats/winlogbeat/1.2/exported-fields.html">Winlogbeat Exported Fields</a>
 *///w  w w  .  java2  s. c  o m
private Message parseWinlogbeat(Map<String, Object> event) {
    final String message = String.valueOf(event.remove("message"));
    final Message gelfMessage = createMessage(message, event);
    gelfMessage.addField("facility", "winlogbeat");
    final Map<String, Object> flattened = flatten(event, "winlogbeat", MAP_KEY_SEPARATOR);

    // Fix field names containing dots, like "user.name"
    final Map<String, Object> withoutDots = MapUtils.replaceKeyCharacter(flattened, '.',
            MAP_KEY_SEPARATOR.charAt(0));
    gelfMessage.addFields(withoutDots);
    return gelfMessage;
}

From source file:com.hp.octane.integrations.uft.UftTestDispatchUtils.java

/**
 * This method check whether discovered test are already exist on server, and instead of creation - those tests will be updated
 * Go over discovered and octane tests/*from   w  ww  .  j  ava  2  s.co m*/
 * 1.if test doesn't exist on octane - this is new test
 * 2.if test exist
 * 2.1 if test different from discovered - this is test for update
 * 2.2 if tests are equal - skip test
 * 3. all tests that are found in Octane but not discovered - those deleted tests and they will be turned to not executable
 *
 * @return true if there were changes comparing to discovered results
 */
private static void matchDiscoveryTestResultsWithOctaneForFullSync(EntitiesService entitiesService,
        UftTestDiscoveryResult discoveryResult) {
    Collection<String> additionalFields = SdkStringUtils.isNotEmpty(discoveryResult.getTestRunnerId())
            ? Arrays.asList(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD)
            : null;
    Map<String, Entity> octaneTestsMap = getTestsFromServer(entitiesService,
            Long.parseLong(discoveryResult.getWorkspaceId()),
            Long.parseLong(discoveryResult.getScmRepositoryId()), true, null, additionalFields);
    Map<String, Entity> octaneTestsMapWithoutScmRepository = getTestsFromServer(entitiesService,
            Long.parseLong(discoveryResult.getWorkspaceId()),
            Long.parseLong(discoveryResult.getScmRepositoryId()), false, null, additionalFields);

    for (AutomatedTest discoveredTest : discoveryResult.getAllTests()) {
        String key = createKey(discoveredTest.getPackage(), discoveredTest.getName());
        Entity octaneTest = octaneTestsMap.remove(key);
        Entity octaneTestWithoutScmRepository = octaneTestsMapWithoutScmRepository.remove(key);

        if (octaneTest != null) {
            //the only fields that might be different is description and executable
            boolean testsEqual = checkTestEquals(discoveredTest, octaneTest, discoveryResult.getTestRunnerId());
            if (!testsEqual) { //if equal - skip
                discoveredTest.setId(octaneTest.getId());
                discoveredTest.setOctaneStatus(OctaneStatus.MODIFIED);
                if (octaneTest.containsField(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD)
                        && octaneTest.getField(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD) == null) {
                    discoveredTest.setMissingTestRunner(true);
                }
            } else {
                discoveredTest.setOctaneStatus(OctaneStatus.NONE);
            }
        } else if (octaneTestWithoutScmRepository != null) {
            //special handling - test were injected from pipeline,or created from other fork. need to update scm repository
            discoveredTest.setId(octaneTestWithoutScmRepository.getId());
            discoveredTest.setOctaneStatus(OctaneStatus.MODIFIED);
            if (octaneTestWithoutScmRepository.containsField(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD)
                    && octaneTestWithoutScmRepository
                            .getField(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD) == null) {
                discoveredTest.setMissingTestRunner(true);
            }
            discoveredTest.setMissingScmRepository(true);
        }
        //else do nothing, status of test should remain NEW
    }

    //go over executable tests that exist in Octane but not discovered and disable them
    for (Entity octaneTest : octaneTestsMap.values()) {
        boolean octaneExecutable = octaneTest.getBooleanValue(EntityConstants.AutomatedTest.EXECUTABLE_FIELD);
        if (octaneExecutable) {
            AutomatedTest test = new AutomatedTest();
            discoveryResult.getAllTests().add(test);
            test.setId(octaneTest.getId());
            test.setExecutable(false);
            test.setName(octaneTest.getName());
            test.setPackage(octaneTest.getStringValue(EntityConstants.AutomatedTest.PACKAGE_FIELD));
            test.setOctaneStatus(OctaneStatus.DELETED);
        }
    }
}

From source file:io.lightlink.oracle.AbstractOracleType.java

protected STRUCT createStruct(Connection con, Object value, String type) throws SQLException {

    if (value == null)
        return null;

    Map mapValue;/*from ww w .  j a v a  2 s  .  c o  m*/
    if (value instanceof Map) {
        mapValue = (Map) value;
        mapValue = new CaseInsensitiveMap(mapValue);
    } else { // create a Map from bean
        Map map = new CaseInsensitiveMap(new BeanMap(value));
        map.remove("class");
        mapValue = map;
    }

    STRUCT struct;
    StructDescriptor structType = safeCreateStructureDescriptor(type, con);
    ResultSetMetaData stuctMeteData = structType.getMetaData();

    List<Object> orderedValues = new ArrayList<Object>();

    if (stuctMeteData.getColumnCount() == 1 && mapValue.size() == 1) {
        orderedValues.add(mapValue.values().iterator().next());
    } else {
        for (int col = 1; col <= stuctMeteData.getColumnCount(); col++) {
            Object v = mapValue.get(stuctMeteData.getColumnName(col));
            if (v == null) {
                v = mapValue.get(stuctMeteData.getColumnName(col).replaceAll("_", ""));
            }

            String typeName = stuctMeteData.getColumnTypeName(col);
            int columnType = stuctMeteData.getColumnType(col);
            if (columnType == OracleTypes.ARRAY) {
                v = createArray(con, v, typeName);
            } else if (columnType == OracleTypes.JAVA_STRUCT || columnType == OracleTypes.JAVA_OBJECT
                    || columnType == OracleTypes.STRUCT) {
                v = createStruct(con, v, typeName);
            }

            orderedValues.add(v);
        }
    }

    Object[] values = orderedValues.toArray();

    for (int j = 0; j < values.length; j++) {

        Object v = values[j];
        if (v instanceof Long && stuctMeteData.getColumnTypeName(j + 1).equalsIgnoreCase("TIMESTAMP")) {
            values[j] = new Timestamp((Long) v);
        } else if (v instanceof Long && stuctMeteData.getColumnTypeName(j + 1).equalsIgnoreCase("DATE")) {
            values[j] = new Date((Long) v);
        }

    }

    struct = new STRUCT(structType, con, values);

    return struct;
}