Example usage for java.util Map.Entry get

List of usage examples for java.util Map.Entry get

Introduction

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

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:com.twosigma.beaker.core.module.config.DefaultBeakerConfig.java

@SuppressWarnings("unchecked")
private void augmentPluginOptions() {
    try {/*from w  w  w  .j  a  v a2  s. c o  m*/
        Map<String, JSONObject> plugins = (Map<String, JSONObject>) this.prefs.get("languages");
        for (Map.Entry<String, JSONObject> entry : plugins.entrySet()) {
            Object options = entry.getValue().get("options");
            String key = entry.getKey();
            if (options != null) {
                if (options instanceof String) {
                    addOption(key, (String) options);
                } else {
                    for (String o : (List<String>) options) {
                        addOption(key, o);
                    }
                }
            }
        }
    } catch (Exception e) {
        // ignore
    }
}

From source file:org.tariel.dependrpc.pos.JMystem.java

/**
 * Parses mystem output into temp word instances
 * @param in Mystem JSON Sentence/*from   w w w .j  a v  a2  s. c  om*/
 * @return List<JsonWord> words
 */
private List<JsonWord> processJsonOutput(String in) {
    JsonParser Unserializer_ = new JsonParser();
    JsonElement element = Unserializer_.parse(in);
    JsonArray arr = element.getAsJsonArray();

    List<JsonWord> words = new ArrayList<JsonWord>();

    for (JsonElement analysis : arr) {
        JsonWord tmpWord = new JsonWord();
        for (Map.Entry<String, JsonElement> entry : analysis.getAsJsonObject().entrySet()) {
            if (entry.getKey().equals("analysis")) {
                if (entry.getValue().getAsJsonArray().size() > 0) {
                    tmpWord.analysis = new JsonAnalysis();
                    Set<Map.Entry<String, JsonElement>> analysis_parts = entry.getValue().getAsJsonArray()
                            .get(0).getAsJsonObject().entrySet();
                    for (Map.Entry<String, JsonElement> part : analysis_parts) {
                        if (part.getKey().equals("lex")) {
                            tmpWord.analysis.lex = part.getValue().getAsString();
                        } else {
                            tmpWord.analysis.gr = part.getValue().getAsString();
                        }
                    }
                }
            } else {
                tmpWord.text = entry.getValue().getAsString();
            }
        }
        words.add(tmpWord);
    }

    return words;
}

From source file:org.yes.cart.service.vo.impl.VoFulfilmentServiceImpl.java

@Override
public void fillShopSummaryDetails(final VoShopSummary summary, final long shopId, final String lang)
        throws Exception {

    if (federationFacade.isShopAccessibleByCurrentManager(summary.getShopId())) {
        final Map<WarehouseDTO, Boolean> all = dtoWarehouseService.findAllByShopId(shopId);

        for (final Map.Entry<WarehouseDTO, Boolean> dto : all.entrySet()) {

            String name = dto.getKey().getName();
            if (MapUtils.isNotEmpty(dto.getKey().getDisplayNames())
                    && dto.getKey().getDisplayNames().get(lang) != null) {
                name = dto.getKey().getDisplayNames().get(lang);
            }/*from   w  w  w. j a  v a 2 s. c  o m*/
            summary.getFulfilmentCentres().add(MutablePair.of(name, dto.getValue()));

        }

    } else {
        throw new AccessDeniedException("Access is denied");
    }

}

From source file:com.alibaba.jstorm.ui.utils.UIUtils.java

private static void fillTPSValue2Edge(List<MetricInfo> componentMetrics, Map<String, TopologyEdge> edges) {
    String EDGE_DIM = "." + MetricDef.RECV_TPS;
    for (MetricInfo info : componentMetrics) {
        if (info == null)
            continue;
        for (Map.Entry<String, Map<Integer, MetricSnapshot>> metric : info.get_metrics().entrySet()) {
            String name = metric.getKey();
            String[] split_name = name.split("@");
            String metricName = UIMetricUtils.extractMetricName(split_name);

            // only handle with `.RecvTps` metrics
            if (metricName == null || !metricName.contains(EDGE_DIM)) {
                continue;
            }//from  www  .ja va 2s. c  o m
            String componentId = UIMetricUtils.extractComponentName(split_name);
            String src = metricName.split("\\.")[0];
            String key = src + ":" + componentId;

            //get 60 window metric
            MetricSnapshot snapshot = metric.getValue().get(AsmWindow.M1_WINDOW);
            TopologyEdge edge = edges.get(key);
            if (edge != null) {
                edge.setValue(snapshot.get_m1());
                edge.setTitle("TPS: " + UIMetricUtils.format.format(edges.get(key).getValue()));

                for (Map.Entry<Integer, MetricSnapshot> winData : metric.getValue().entrySet()) {
                    edge.putMapValue("TPS", winData.getKey(), UIMetricUtils.getMetricValue(winData.getValue()));
                }
            }
        }
    }
}

From source file:org.openremote.server.inventory.DiscoveryService.java

protected Adapter[] findAdapters(CamelContext context) throws Exception {
    List<Adapter> result = new ArrayList<>();
    for (Map.Entry<String, Properties> entry : CamelContextHelper.findComponents(context).entrySet()) {
        Object componentType = entry.getValue().get(COMPONENT_TYPE);
        if (componentType != null) {
            Component component = context.getComponent(entry.getKey());
            if (component == null) {
                throw new IllegalStateException(
                        "Configured component not available in context: " + entry.getKey());
            }/*from ww w  .jav a  2 s. co m*/
            if (component instanceof UriEndpointComponent) {
                UriEndpointComponent uriEndpointComponent = (UriEndpointComponent) component;
                result.add(createAdapter(entry.getKey(), componentType.toString(), uriEndpointComponent,
                        entry.getValue()));
            } else {
                LOG.warn("Component should implement " + UriEndpointComponent.class.getName() + ": "
                        + entry.getKey());
            }
        }
    }
    return result.toArray(new Adapter[result.size()]);
}

From source file:com.alibaba.jstorm.ui.utils.UIUtils.java

private static void fillTLCValue2Edge(List<MetricInfo> componentMetrics, Map<String, TopologyEdge> edges) {
    String EDGE_DIM = "." + MetricDef.TUPLE_LIEF_CYCLE;
    for (MetricInfo info : componentMetrics) {
        if (info == null)
            continue;
        for (Map.Entry<String, Map<Integer, MetricSnapshot>> metric : info.get_metrics().entrySet()) {
            String name = metric.getKey();
            String[] split_name = name.split("@");
            String metricName = UIMetricUtils.extractMetricName(split_name);

            // only handle with `.TupleLifeCycle` metrics
            if (metricName == null || !metricName.contains(EDGE_DIM)) {
                continue;
            }/* w  w w  . j a  va 2s  .  co m*/
            String componentId = UIMetricUtils.extractComponentName(split_name);
            String src = metricName.split("\\.")[0];
            String key = src + ":" + componentId;

            //get 60 window metric
            MetricSnapshot snapshot = metric.getValue().get(AsmWindow.M1_WINDOW);
            TopologyEdge edge = edges.get(key);
            if (edge != null) {
                double value = snapshot.get_mean() / 1000;
                edge.setCycleValue(value);
                edge.appendTitle("TupleLifeCycle: " + UIMetricUtils.format.format(value) + "ms");

                for (Map.Entry<Integer, MetricSnapshot> winData : metric.getValue().entrySet()) {
                    // put the tuple life cycle time , unit is ms
                    double v = winData.getValue().get_mean() / 1000;
                    edge.putMapValue(MetricDef.TUPLE_LIEF_CYCLE + "(ms)", winData.getKey(),
                            UIMetricUtils.format.format(v));
                }
            }
        }
    }
}

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnNewJavaFieldCutter.java

public DvnNewJavaFieldCutter(Map<Long, List<List<Integer>>> cargSet) {
    this.cargSet = cargSet;
    int collength = 0;
    for (Map.Entry<Long, List<List<Integer>>> cargSeti : cargSet.entrySet()) {
        for (int i = 0; i < cargSeti.getValue().size(); i++) {
            collength = cargSeti.getValue().get(i).get(1) - cargSeti.getValue().get(i).get(0) + 2;
            colwidth += collength;//from w  w  w . jav a  2 s . co  m
        }
        //out.println("key = "+ cargSeti.getKey() + ":colwidth"+colwidth);
    }
    //out.println("colwidth="+colwidth);
}

From source file:com.mirth.connect.server.attachments.MirthAttachmentHandler.java

public byte[] reAttachMessage(String raw, ImmutableConnectorMessage connectorMessage, String charsetEncoding,
        boolean binary) {
    try {//from   w  w w  . j  a v  a  2s  . c om
        Map<Integer, Map<Integer, Object>> replacementObjects = new TreeMap<Integer, Map<Integer, Object>>();
        // Determine the buffersize during the first pass for better memory performance
        int bufferSize = raw.length();
        int index = 0;
        int endIndex;
        // Initialize the objects here so only one retrieval of the attachment content is ever needed.
        byte[] dicomObject = null;
        Map<String, Attachment> attachmentMap = null;

        // Handle the special case if only a dicom message is requested. 
        // In this case we can skip any byte appending and thus do not need to base64 encode the dicom object
        // if the type is binary.
        if (raw.trim().equals(PREFIX + DICOM_KEY + SUFFIX)) {
            dicomObject = DICOMMessageUtil.getDICOMRawBytes(connectorMessage);

            if (!binary) {
                dicomObject = Base64Util.encodeBase64(dicomObject);
            }

            return dicomObject;
        }

        // Check the raw string in one pass for any attachments.
        // Stores the start and end indices to replace, along with the attachment content.
        while ((index = raw.indexOf(PREFIX, index)) != -1) {
            if (raw.startsWith(DICOM_KEY + SUFFIX, index + PREFIX.length())) {
                if (dicomObject == null) {
                    // Unfortunately, if the dicom data needs to appended to other base64 data, it must be done so in base64.
                    dicomObject = Base64Util.encodeBase64(DICOMMessageUtil.getDICOMRawBytes(connectorMessage));
                }

                endIndex = index + PREFIX.length() + DICOM_KEY.length() + SUFFIX.length();

                Map<Integer, Object> replacementMap = new HashMap<Integer, Object>();
                replacementMap.put(KEY_END_INDEX, endIndex);
                replacementMap.put(KEY_DATA, dicomObject);
                replacementObjects.put(index, replacementMap);

                bufferSize += dicomObject.length;
                index += endIndex - index;
            } else if (raw.startsWith(ATTACHMENT_KEY, index + PREFIX.length())) {
                if (attachmentMap == null) {
                    List<Attachment> list = getMessageAttachments(connectorMessage);

                    // Store the attachments in a map with the attachment's Id as the key
                    attachmentMap = new HashMap<String, Attachment>();
                    for (Attachment attachment : list) {
                        attachmentMap.put(attachment.getId(), attachment);
                    }
                }

                int attachmentIdStartIndex = index + PREFIX.length() + ATTACHMENT_KEY.length();
                int attachmentIdEndIndex = attachmentIdStartIndex + ATTACHMENT_ID_LENGTH;
                endIndex = attachmentIdEndIndex + SUFFIX.length();
                String attachmentId = raw.substring(attachmentIdStartIndex,
                        attachmentIdStartIndex + ATTACHMENT_ID_LENGTH);

                if (raw.substring(attachmentIdEndIndex, endIndex).equals(SUFFIX)) {
                    Map<Integer, Object> replacementMap = new HashMap<Integer, Object>();
                    replacementMap.put(KEY_END_INDEX, endIndex);

                    if (attachmentMap.containsKey(attachmentId)) {
                        Attachment attachment = attachmentMap.get(attachmentId);
                        replacementMap.put(KEY_DATA, attachment.getContent());

                        bufferSize += attachment.getContent().length;
                    } else {
                        replacementMap.put(KEY_DATA, new byte[0]);
                    }

                    replacementObjects.put(index, replacementMap);
                }
            } else {
                endIndex = index + PREFIX.length();
            }

            index += endIndex - index;
        }
        // Release the object pointers of the attachment content so they aren't held in memory for the entire method
        dicomObject = null;
        attachmentMap = null;

        // Initialize the stream's buffer size. The buffer size will always be slightly large than needed,
        // because the template keys are never removed from the buffer size.
        // It is not worth doing any extra calculations for the amount of memory saved. 
        ByteArrayOutputStream baos = new ByteArrayOutputStream(bufferSize);

        int segmentStartIndex = 0;
        for (Map.Entry<Integer, Map<Integer, Object>> entry : replacementObjects.entrySet()) {
            int startReplacementIndex = entry.getKey();
            int endReplacementIndex = (Integer) entry.getValue().get(KEY_END_INDEX);
            byte[] data = (byte[]) entry.getValue().get(KEY_DATA);

            // Allows the memory used by the attachments to be released at the end of the loop
            entry.getValue().clear();

            byte[] templateSegment;
            // If the data is binary, the content should be in base64, so using US-ASCII as the charset encoding should be sufficient.
            if (binary) {
                templateSegment = StringUtils
                        .getBytesUsAscii(raw.substring(segmentStartIndex, startReplacementIndex));
            } else {
                templateSegment = StringUtil.getBytesUncheckedChunked(
                        raw.substring(segmentStartIndex, startReplacementIndex), Constants.ATTACHMENT_CHARSET);
            }

            baos.write(templateSegment);
            baos.write(data);

            segmentStartIndex = endReplacementIndex;
        }

        byte[] templateSegment;
        if (binary) {
            templateSegment = StringUtils.getBytesUsAscii(raw.substring(segmentStartIndex));
        } else {
            templateSegment = StringUtil.getBytesUncheckedChunked(raw.substring(segmentStartIndex),
                    Constants.ATTACHMENT_CHARSET);
        }

        byte[] combined;
        // If there are no attachments, don't bother writing to the output stream.
        if (segmentStartIndex == 0) {
            combined = templateSegment;
        } else {
            // Write the segment after the last replacement.
            baos.write(templateSegment);

            combined = baos.toByteArray();
            // Release the memory used by the byte array stream. ByteArrayOutputStreams do not need to be closed. 
            baos = null;
        }

        templateSegment = null;

        // If binary, the content should be in base64 so it is necessary to decode the data.
        if (binary) {
            combined = Base64Util.decodeBase64(combined);
        } else if (charsetEncoding != null
                && !charsetEncoding.toUpperCase().equals(Constants.ATTACHMENT_CHARSET.toUpperCase())) {
            // Convert the byte array to a string using the internal encoding.
            String combinedString = StringUtils.newString(combined, Constants.ATTACHMENT_CHARSET);
            // First release the reference to the old byte data so it can be reallocated if necessary.
            combined = null;
            // Convert the string to a byte array using the requested encoding
            combined = StringUtil.getBytesUncheckedChunked(combinedString, charsetEncoding);
        }

        return combined;
    } catch (Exception e) {
        logger.error("Error reattaching attachments", e);
        return null;
    }
}

From source file:org.onosproject.store.mastership.impl.DistributedMastershipStore.java

@Override
public Set<DeviceId> getDevices(NodeId nodeId) {
    Set<DeviceId> devices = new HashSet<>();

    for (Map.Entry<DeviceId, RoleValue> el : roleMap.entrySet()) {
        if (nodeId.equals(el.getValue().get(MASTER))) {
            devices.add(el.getKey());/*w  w w .  j a v  a  2 s.  com*/
        }
    }

    return devices;
}

From source file:com.mirth.connect.server.attachments.MirthAttachmentHandlerProvider.java

public byte[] reAttachMessage(String raw, ImmutableConnectorMessage connectorMessage, String charsetEncoding,
        boolean binary) {
    try {/*from www  .ja  va  2 s.com*/
        Map<Integer, Map<Integer, Object>> replacementObjects = new TreeMap<Integer, Map<Integer, Object>>();
        // Determine the buffersize during the first pass for better memory performance
        int bufferSize = raw.length();
        int index = 0;
        int endIndex;
        // Initialize the objects here so only one retrieval of the attachment content is ever needed.
        byte[] dicomObject = null;
        Map<String, Attachment> attachmentMap = null;

        // Handle the special case if only a dicom message is requested. 
        // In this case we can skip any byte appending and thus do not need to base64 encode the dicom object
        // if the type is binary.
        if (raw.trim().equals(PREFIX + DICOM_KEY + SUFFIX)) {
            dicomObject = DICOMMessageUtil.getDICOMRawBytes(connectorMessage);

            if (!binary) {
                dicomObject = Base64Util.encodeBase64(dicomObject);
            }

            return dicomObject;
        }

        // Check the raw string in one pass for any attachments.
        // Stores the start and end indices to replace, along with the attachment content.
        while ((index = raw.indexOf(PREFIX, index)) != -1) {
            if (raw.startsWith(DICOM_KEY + SUFFIX, index + PREFIX.length())) {
                if (dicomObject == null) {
                    // Unfortunately, if the dicom data needs to appended to other base64 data, it must be done so in base64.
                    dicomObject = Base64Util.encodeBase64(DICOMMessageUtil.getDICOMRawBytes(connectorMessage));
                }

                endIndex = index + PREFIX.length() + DICOM_KEY.length() + SUFFIX.length();

                Map<Integer, Object> replacementMap = new HashMap<Integer, Object>();
                replacementMap.put(KEY_END_INDEX, endIndex);
                replacementMap.put(KEY_DATA, dicomObject);
                replacementObjects.put(index, replacementMap);

                bufferSize += dicomObject.length;
                index += endIndex - index;
            } else if (raw.startsWith(ATTACHMENT_KEY, index + PREFIX.length())) {
                if (attachmentMap == null) {
                    List<Attachment> list = getMessageAttachments(connectorMessage);

                    // Store the attachments in a map with the attachment's Id as the key
                    attachmentMap = new HashMap<String, Attachment>();
                    for (Attachment attachment : list) {
                        attachmentMap.put(attachment.getId(), attachment);
                    }
                }

                int attachmentIdStartIndex = index + PREFIX.length() + ATTACHMENT_KEY.length();
                int attachmentIdEndIndex = attachmentIdStartIndex + ATTACHMENT_ID_LENGTH;
                endIndex = attachmentIdEndIndex + SUFFIX.length();
                String attachmentId = raw.substring(attachmentIdStartIndex,
                        attachmentIdStartIndex + ATTACHMENT_ID_LENGTH);

                if (raw.substring(attachmentIdEndIndex, endIndex).equals(SUFFIX)) {
                    Map<Integer, Object> replacementMap = new HashMap<Integer, Object>();
                    replacementMap.put(KEY_END_INDEX, endIndex);

                    if (attachmentMap.containsKey(attachmentId)) {
                        Attachment attachment = attachmentMap.get(attachmentId);

                        attachment.setContent(replaceOutboundAttachment(attachment.getContent()));
                        replacementMap.put(KEY_DATA, attachment.getContent());
                        bufferSize += attachment.getContent().length;
                    } else {
                        replacementMap.put(KEY_DATA, new byte[0]);
                    }

                    replacementObjects.put(index, replacementMap);
                }
            } else {
                endIndex = index + PREFIX.length();
            }

            index += endIndex - index;
        }
        // Release the object pointers of the attachment content so they aren't held in memory for the entire method
        dicomObject = null;
        attachmentMap = null;

        // Initialize the stream's buffer size. The buffer size will always be slightly large than needed,
        // because the template keys are never removed from the buffer size.
        // It is not worth doing any extra calculations for the amount of memory saved. 
        ByteArrayOutputStream baos = new ByteArrayOutputStream(bufferSize);

        int segmentStartIndex = 0;
        for (Map.Entry<Integer, Map<Integer, Object>> entry : replacementObjects.entrySet()) {
            int startReplacementIndex = entry.getKey();
            int endReplacementIndex = (Integer) entry.getValue().get(KEY_END_INDEX);
            byte[] data = (byte[]) entry.getValue().get(KEY_DATA);

            // Allows the memory used by the attachments to be released at the end of the loop
            entry.getValue().clear();

            byte[] templateSegment;
            // If the data is binary, the content should be in base64, so using US-ASCII as the charset encoding should be sufficient.
            if (binary) {
                templateSegment = StringUtils
                        .getBytesUsAscii(raw.substring(segmentStartIndex, startReplacementIndex));
            } else {
                templateSegment = StringUtil.getBytesUncheckedChunked(
                        raw.substring(segmentStartIndex, startReplacementIndex), Constants.ATTACHMENT_CHARSET);
            }

            baos.write(templateSegment);
            baos.write(data);

            segmentStartIndex = endReplacementIndex;
        }

        byte[] templateSegment;
        if (binary) {
            templateSegment = StringUtils.getBytesUsAscii(raw.substring(segmentStartIndex));
        } else {
            templateSegment = StringUtil.getBytesUncheckedChunked(raw.substring(segmentStartIndex),
                    Constants.ATTACHMENT_CHARSET);
        }

        byte[] combined;
        // If there are no attachments, don't bother writing to the output stream.
        if (segmentStartIndex == 0) {
            combined = templateSegment;
        } else {
            // Write the segment after the last replacement.
            baos.write(templateSegment);

            combined = baos.toByteArray();
            // Release the memory used by the byte array stream. ByteArrayOutputStreams do not need to be closed. 
            baos = null;
        }

        templateSegment = null;

        // If binary, the content should be in base64 so it is necessary to decode the data.
        if (binary) {
            combined = Base64Util.decodeBase64(combined);
        } else if (charsetEncoding != null
                && !charsetEncoding.toUpperCase().equals(Constants.ATTACHMENT_CHARSET.toUpperCase())) {
            // Convert the byte array to a string using the internal encoding.
            String combinedString = StringUtils.newString(combined, Constants.ATTACHMENT_CHARSET);
            // First release the reference to the old byte data so it can be reallocated if necessary.
            combined = null;
            // Convert the string to a byte array using the requested encoding
            combined = StringUtil.getBytesUncheckedChunked(combinedString, charsetEncoding);
        }

        return combined;
    } catch (Exception e) {
        logger.error("Error reattaching attachments", e);
        return null;
    }
}