Example usage for java.util HashMap entrySet

List of usage examples for java.util HashMap entrySet

Introduction

In this page you can find the example usage for java.util HashMap entrySet.

Prototype

Set entrySet

To view the source code for java.util HashMap entrySet.

Click Source Link

Document

Holds cached entrySet().

Usage

From source file:keel.Algorithms.UnsupervisedLearning.AssociationRules.Visualization.keelassotiationrulesbarchart.ResultsProccessor.java

public void writeToFile(String outName)
        throws FileNotFoundException, UnsupportedEncodingException, IOException {
    calcMeans();//w ww .ja  va  2s. c o m
    calcAvgRulesBySeed();

    // Create JFreeChart Dataset
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    HashMap<String, Double> measuresFirst = algorithmMeasures.entrySet().iterator().next().getValue();
    for (Map.Entry<String, Double> measure : measuresFirst.entrySet()) {
        String measureName = measure.getKey();
        //Double measureValue = measure.getValue();
        dataset.clear();

        for (Map.Entry<String, HashMap<String, Double>> entry : algorithmMeasures.entrySet()) {
            String alg = entry.getKey();
            Double measureValue = entry.getValue().get(measureName);

            // Parse algorithm name to show it correctly
            String aName = alg.substring(0, alg.length() - 1);
            int startAlgName = aName.lastIndexOf("/");
            aName = aName.substring(startAlgName + 1);

            dataset.addValue(measureValue, aName, measureName);

            ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
            JFreeChart barChart = ChartFactory.createBarChart("Assotiation Rules Measures", measureName,
                    measureName, dataset, PlotOrientation.VERTICAL, true, true, false);
            StandardChartTheme.createLegacyTheme().apply(barChart);

            CategoryItemRenderer renderer = barChart.getCategoryPlot().getRenderer();

            // Black and White
            int numItems = algorithmMeasures.size();
            for (int i = 0; i < numItems; i++) {
                Color color = Color.DARK_GRAY;
                if (i % 2 == 1) {
                    color = Color.LIGHT_GRAY;
                }
                renderer.setSeriesPaint(i, color);
                renderer.setSeriesOutlinePaint(i, Color.BLACK);
            }

            int width = 640 * 2; /* Width of the image */
            int height = 480 * 2; /* Height of the image */

            // JPEG
            File BarChart = new File(outName + "_" + measureName + "_barchart.jpg");
            ChartUtilities.saveChartAsJPEG(BarChart, barChart, width, height);

            // SVG
            SVGGraphics2D g2 = new SVGGraphics2D(width, height);
            Rectangle r = new Rectangle(0, 0, width, height);
            barChart.draw(g2, r);
            File BarChartSVG = new File(outName + "_" + measureName + "_barchart.svg");
            SVGUtils.writeToSVG(BarChartSVG, g2.getSVGElement());
        }
    }
    /*
    for (Map.Entry<String, HashMap<String, Double>> entry : algorithmMeasures.entrySet())
    {
    String alg = entry.getKey();
    HashMap<String, Double> measures = entry.getValue();
            
    for (Map.Entry<String, Double> entry1 : measures.entrySet())
    {
        String measureName = entry1.getKey();
        Double measureValue = entry1.getValue();
                
        dataset.addValue(measureValue, alg, measureName);
    }
    }
        */

}

From source file:eu.domibus.common.dao.MessageLogDao.java

public List<MessageLogEntry> findPaged(int from, int max, String column, boolean asc,
        HashMap<String, Object> filters) {

    CriteriaBuilder cb = this.em.getCriteriaBuilder();
    CriteriaQuery<MessageLogEntry> cq = cb.createQuery(MessageLogEntry.class);
    Root<MessageLogEntry> mle = cq.from(MessageLogEntry.class);
    cq.select(mle);//from w  w w .  j  a  va2 s.c  o  m
    List<Predicate> predicates = new ArrayList<Predicate>();
    for (Map.Entry<String, Object> filter : filters.entrySet()) {
        if (filter.getValue() != null) {
            if (filter.getValue() instanceof String) {
                if (!filter.getValue().toString().isEmpty()) {
                    switch (filter.getKey().toString()) {
                    case "receivedFrom":
                        predicates.add(cb.greaterThanOrEqualTo(mle.<Date>get("received"),
                                Timestamp.valueOf(filter.getValue().toString())));
                        break;
                    case "receivedTo":
                        predicates.add(cb.lessThanOrEqualTo(mle.<Date>get("received"),
                                Timestamp.valueOf(filter.getValue().toString())));
                        break;
                    default:
                        predicates.add(cb.like(mle.<String>get(filter.getKey()), (String) filter.getValue()));
                        break;
                    }
                }
            } else {
                predicates.add(cb.equal(mle.<String>get(filter.getKey()), filter.getValue()));
            }
        }
    }
    cq.where(cb.and(predicates.toArray(new Predicate[predicates.size()])));
    if (column != null) {
        if (asc) {
            cq.orderBy(cb.asc(mle.get(column)));
        } else {
            cq.orderBy(cb.desc(mle.get(column)));
        }

    }
    final TypedQuery<MessageLogEntry> query = this.em.createQuery(cq);
    query.setFirstResult(from);
    query.setMaxResults(max);
    return query.getResultList();
}

From source file:io.personium.test.jersey.PersoniumRestAdapter.java

/**
 * DELETE./*from   w  w w.j a  v a 2  s.  c  o m*/
 * @param url URL
 * @param headers ??
 * @return DcResponse
 * @throws PersoniumException DAO
 */
public final PersoniumResponse del(final String url, final HashMap<String, String> headers)
        throws PersoniumException {
    HttpDelete req = new HttpDelete(url);
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        req.setHeader(entry.getKey(), entry.getValue());
    }
    req.addHeader("X-Personium-Version", PersoniumCoreTestConfig.getCoreVersion());

    debugHttpRequest(req, "");
    return this.request(req);
}

From source file:cc.aileron.accessor.PojoAccessorMixerImpl.java

@Override
public PojoAccessor<?> mixin(final List<PojoAccessor<?>> accessors, final List<Object> parents) {
    final InstanceManager i = accessors.get(0).instanceManager();

    final HashMap<String, PojoAccessor<?>> map = new HashMap<String, PojoAccessor<?>>();
    final EnumMap<PojoAccessorMethod, List<String>> keys = new EnumMap<PojoAccessorMethod, List<String>>(
            PojoAccessorMethod.class);
    keys.put(PojoAccessorMethod.GET, new SkipList<String>());
    keys.put(PojoAccessorMethod.SET, new SkipList<String>());

    final HashMap<String, PojoAccessor<?>> setmap = new HashMap<String, PojoAccessor<?>>();
    for (final PojoAccessor<?> accessor : accessors) {
        for (final PojoAccessorMethod method : PojoAccessorMethod.values()) {
            final List<String> methodKeys = accessor.keys(method);
            keys.get(method).addAll(methodKeys);
        }//from   w  w w  . j a va  2  s.c o m
        for (final String key : accessor.keys(PojoAccessorMethod.GET)) {
            map.put(key, accessor);
        }
        for (final String key : accessor.keys(PojoAccessorMethod.SET)) {
            setmap.put(key, accessor);
        }
    }
    final PojoAccessorManagerLocal manager = this.manager;
    return new PojoAccessor<Object>() {
        @Override
        public boolean exist(final String key) {
            for (final PojoAccessor<?> accessor : accessors) {
                if (accessor.exist(key)) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public InstanceManager instanceManager() {
            return i;
        }

        @Override
        public List<String> keys(final PojoAccessorMethod method) {
            return keys.get(method);
        }

        @Override
        public PojoAccessor<?> mixin(final Object... objects) {
            final SkipList<PojoAccessor<?>> list = new SkipList<PojoAccessor<?>>();
            list.add(this);
            for (final Object object : objects) {
                list.add(manager.from(object, parents));
            }
            return PojoAccessorMixerImpl.this.mixin(list, parents);
        }

        @Override
        public Iterable<PojoAccessorValue> set(final PojoAccessorMethod method) {
            final HashMap<String, PojoAccessor<?>> m = method == PojoAccessorMethod.GET ? map : setmap;
            return new Iterable<PojoAccessorValue>() {

                @Override
                public Iterator<PojoAccessorValue> iterator() {
                    final Iterator<Entry<String, PojoAccessor<?>>> ite = m.entrySet().iterator();
                    return new Iterator<PojoAccessorValue>() {
                        @Override
                        public boolean hasNext() {
                            return ite.hasNext();
                        }

                        @Override
                        public PojoAccessorValue next() {
                            final Entry<String, PojoAccessor<?>> e = ite.next();
                            try {
                                return e.getValue().to(e.getKey());
                            } catch (final PojoAccessorValueNotFoundException e1) {
                                throw new Error(e1);
                            } catch (final PojoPropertiesNotFoundException e1) {
                                throw new Error(e1);
                            }
                        }

                        @Override
                        public void remove() {
                            throw new UnsupportedOperationException();
                        }
                    };
                }
            };
        }

        @Override
        public PojoAccessorValue to(final String key)
                throws PojoAccessorValueNotFoundException, PojoPropertiesNotFoundException {
            {
                final PojoAccessor<?> a = map.get(key);
                if (a != null) {
                    return a.to(key);
                }
            }
            for (final PojoAccessor<?> a : accessors) {
                if (a.exist(key)) {
                    return a.to(key);
                }
            }
            for (final PojoAccessor<?> a : accessors) {
                try {
                    final PojoAccessorValue result = a.to(key);
                    if (result != null) {
                        return result;
                    }
                } catch (final PojoAccessorValueNotFoundException e) {
                } catch (final PojoPropertiesNotFoundException e) {
                }
            }
            throw new PojoAccessorValueNotFoundException(accessors, key);
        }

        @Override
        public String toString() {
            return ReflectionToStringBuilder.toString(this);
        }

        @Override
        public Object toTarget() {
            throw new UnsupportedOperationException();
        }
    };
}

From source file:io.personium.test.jersey.PersoniumRestAdapter.java

/**
 * ????GET.//from  ww  w  . j av a 2 s.com
 * @param url URL
 * @param headers ??
 * @return DcResponse
 * @throws PersoniumException DAO
 */
public final PersoniumResponse get(final String url, final HashMap<String, String> headers)
        throws PersoniumException {
    HttpUriRequest req = new HttpGet(url);
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        req.setHeader(entry.getKey(), entry.getValue());
    }
    req.addHeader("X-Personium-Version", PersoniumCoreTestConfig.getCoreVersion());

    debugHttpRequest(req, "");
    PersoniumResponse res = this.request(req);
    return res;
}

From source file:info.plugmania.mazemania.Util.java

/**
 * Takes two compressed inventories and returns a string representation of the difference
 * @param before HashMap<String,Integer> of inventory before changes
 * @param after HashMap<String,Integer> of inventory after changes
 * @return String in the form item:data,amount&item:data,amount@item:data,amount&item:data,amount where the first part is additions and second is subtractions
 *//*  ww w  . ja va 2 s . c om*/
public String createDifferenceString(HashMap<String, Integer> before, HashMap<String, Integer> after) {
    List<String> add = new ArrayList<String>();
    List<String> sub = new ArrayList<String>();

    if ((before == null) || (after == null))
        return "";
    for (Entry<String, Integer> item : before.entrySet()) {
        //If the item does not appear after changes
        if (!after.containsKey(item.getKey())) {
            String loot = item.getKey().replace("_", " ");
            sub.add(ChatColor.GREEN + "1 " + loot + " " + ChatColor.BLUE);
        }
        //If the item is smaller after changes
        //else if (item.getValue() > after.get(item.getKey())) sub.add(item.getKey() + "," + (item.getValue() - after.get(item.getKey())));
        //If the item is larger after changes
        //else if (item.getValue() < after.get(item.getKey())) add.add(item.getKey() + "," + (after.get(item.getKey()) - item.getValue()));
    }
    //for (Entry<String, Integer> item : after.entrySet()) {
    //If the item does not appear before changes
    //if (!before.containsKey(item.getKey())) add.add(item.getKey() + "," + item.getValue());
    //}
    //return join(add.toArray(), "&",0) + "" + join(sub.toArray(), "&",0);

    return join(sub.toArray(), " & ", 0);
}

From source file:loadTest.loadTestLib.LUtil.java

private Entry<String, Integer> getLowestDockerHost() {
    HashMap<String, Integer> dockerNodes = getDockerNodes();
    Entry<String, Integer> lowest = null;

    if (this.startedClusterContainer.size() < dockerNodes.size()) {
        for (Entry<String, Integer> entry : dockerNodes.entrySet()) {
            if (!this.startedClusterContainer.containsKey(entry.getKey())) {
                return new AbstractMap.SimpleEntry<>(entry.getKey(), 0);
            }/* w w w.ja  v a2s .  c o m*/
        }
    }

    for (Entry<String, Integer> entry : startedClusterContainer.entrySet()) {
        if (entry.getValue() < dockerNodes.get(entry.getKey())) {
            if (lowest == null) {
                lowest = entry;
            } else {
                if (lowest.getValue() > entry.getValue()) {
                    lowest = entry;
                }
            }
        }
    }

    return lowest;
}

From source file:com.esri.geoportal.geoportal.commons.geometry.GeometryService.java

/**
 * Translates UTM points from a string into lat lon values
 * //from   w w  w  .j a v a2  s  . com
 * @param coordinateStrings the points to translate, in the format {@code <grid><hemisphere> <easting> <northing>} E.G. {@code 18N 60000 80000}
 * @param toWkid the coordinate system to translate into
 * 
 * @return the translated points
 */
public MultiPoint fromGeoCoordinateString(List<String> coordinateStrings, int toWkid)
        throws IOException, URISyntaxException {
    HttpPost request = new HttpPost(createFromGeoCoordinateStringUrl().toURI());

    HashMap<String, String> params = new HashMap<>();
    params.put("f", "json");
    params.put("sr", Integer.toString(toWkid));
    params.put("strings", String.format("[\"%s\"]", String.join("\",\"", coordinateStrings)));
    params.put("conversionType", "UTM");
    params.put("coversionMode", "utmDefault");

    HttpEntity entity = new UrlEncodedFormEntity(params.entrySet().stream()
            .map(e -> new BasicNameValuePair(e.getKey(), e.getValue())).collect(Collectors.toList()), "UTF-8");
    request.setEntity(entity);

    try (CloseableHttpResponse httpResponse = httpClient.execute(request);
            InputStream contentStream = httpResponse.getEntity().getContent();) {
        if (httpResponse.getStatusLine().getStatusCode() >= 400) {
            throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(),
                    httpResponse.getStatusLine().getReasonPhrase());
        }

        FromGeoCoordinateStringResponse response = mapper.readValue(contentStream,
                FromGeoCoordinateStringResponse.class);
        return response.toMultipointGeometry();
    }
}

From source file:com.supernovapps.audio.jstreamsourcer.ShoutcastV1.java

public HttpUriRequest getUpdateMetadataRequest(String song, String artist, String album) {
    if (!started) {
        return null;
    }/*from  w w  w  .  j a v  a  2 s .  co m*/

    String metadata = metadataTemplate.replace("_song_", song).replace("_artist_", artist).replace("_album_",
            album);

    final MetaDataHttpRequestParams params = new MetaDataHttpRequestParams();
    params.put("mode", "updinfo");
    params.put("charset", "UTF-8");
    params.put("song", metadata);
    params.put("pass", password);

    final HashMap<String, String> headers = new HashMap<String, String>();
    headers.put("User-Agent", USER_AGENT);

    HttpUriRequest httpRequest = new HttpGet(MetaDataHttpRequestParams
            .getUrlWithQueryString("http://" + host + ":" + Integer.toString(port) + "/admin.cgi", params));
    if (headers != null) {
        for (Map.Entry<String, String> entry : headers.entrySet()) {
            httpRequest.addHeader(entry.getKey(), entry.getValue());
        }
    }

    return httpRequest;
}

From source file:com.example.cuisoap.agrimac.homePage.homeFragment.java

public void replaceDataItem(HashMap<String, String> item) {
    HashMap<String, String> map;
    for (int i = 0; i < data.size(); i++) {
        map = data.get(i);/*from ww  w  . j  av a  2s  .c om*/
        System.out.println("id=" + map.get("id"));
        if (map.get("id").equals(item.get("id"))) {
            data.set(i, item);
            map = data.get(i);
            Iterator iter = map.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry) iter.next();
                System.out.println(entry.getKey() + "=" + entry.getValue());
            }
            break;
        }
    }

}