Example usage for java.util HashMap keySet

List of usage examples for java.util HashMap keySet

Introduction

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

Prototype

public Set<K> keySet() 

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.LinkableBar.java

/**
 * Gets document parameters and return a string in the form &param1=value1&param2=value2 ...
 * // w  w w  . ja  v a 2  s .  c  o m
 * @param drillParameters the drill parameters
 * 
 * @return the document_ parameters
 */

public String getDocument_Parameters(HashMap<String, DrillParameter> _drillParametersMap) {
    logger.debug("IN");
    String document_parameter = "";
    if (_drillParametersMap != null) {
        for (Iterator iterator = _drillParametersMap.keySet().iterator(); iterator.hasNext();) {
            String name = (String) iterator.next();
            DrillParameter drillPar = (DrillParameter) _drillParametersMap.get(name);
            String value = drillPar.getValue();
            if (name != null && !name.equals("") && value != null && !value.equals("")) {
                document_parameter += "%26" + name + "%3D" + value;
                //document_parameter+="&"+name+"="+value;
            }
        }
    }
    logger.debug("OUT");
    return document_parameter;
}

From source file:babel.content.pages.Page.java

public Page(String url, Iterator<NutchChunk> values) {
    HashMap<String, List<NutchChunk>> verChunks = splitIntoVersions(values);

    m_pageProps = new MetaData("PageProperties");
    m_pageURL = (url == null) ? new String() : url; // TODO: Is URL already normalized?
    m_versions = new ArrayList<PageVersion>(verChunks.size());

    PageVersion curVer;/*w  w w  .  j  a v  a  2s  .co  m*/

    for (String segId : verChunks.keySet()) {
        curVer = new PageVersion(segId, verChunks.get(segId), this);

        if (curVer.isNutchComplete()) {
            addVersion(curVer);
        }
    }

    m_versions.trimToSize();
}

From source file:eu.planets_project.pp.plato.evaluation.evaluators.FITSEvaluator.java

private Value preservedValues(HashMap<String, String> sampleMetadata, HashMap<String, String> resultMetadata,
        Scale scale) {//  ww  w .  j  a v a2s .  c o  m
    int numMissing = 0;
    int numChanged = 0;
    BooleanValue v = (BooleanValue) scale.createValue();
    StringBuilder comment = new StringBuilder();
    for (String key : sampleMetadata.keySet()) {
        String sampleValue = sampleMetadata.get(key);
        String resultValue = resultMetadata.get(key);
        if (resultValue == null) {
            numMissing++;
            comment.append(" - " + key + "\n");
        } else if (!resultValue.equals(sampleValue)) {
            numChanged++;
            comment.append(" ~ " + key + ": sample=" + sampleValue + ", result=" + resultValue + "\n");
        }
    }
    if ((numChanged == 0) && (numMissing == 0)) {
        v.bool(true);
        v.setComment("result contains complete metadata of sample");
    } else {
        v.bool(false);
        comment.insert(0, "following differences found: (- .. missing, ~ .. altered):\n");
        v.setComment(comment.toString());
    }
    return v;
}

From source file:fi.mikuz.boarder.connection.ConnectionManager.java

public ConnectionManager(ConnectionListener connectionListener, final String url,
        final HashMap<String, String> sendList) {
    this.connectionListener = connectionListener;

    Thread t = new Thread() {
        public void run() {
            JSONObject json = new JSONObject();

            try {
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(url);

                if (sendList != null) {
                    for (String key : sendList.keySet()) {
                        json.put(key, sendList.get(key));
                    }//ww w.jav a 2s . c  om
                }
                json.put(InternetMenu.HTML_FILTER, false);

                StringEntity se = new StringEntity(json.toString());
                se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
                httppost.setEntity(se);

                if (GlobalSettings.getSensitiveLogging())
                    Log.v(TAG, "Sending to " + url + ": " + json.toString());

                HttpResponse response = httpclient.execute(httppost);
                InputStream in = response.getEntity().getContent(); //Get the data in the entity
                String result = convertStreamToString(in);

                try {
                    if (GlobalSettings.getSensitiveLogging())
                        Log.v(TAG, "Got from " + url + ": " + result);
                    else
                        Log.v(TAG, "Got answer from " + url);
                    connectionSuccessfulResponse = new ConnectionSuccessfulResponse(new JSONObject(result),
                            ConnectionUtils.getUrlConnectionId(url));
                    mHandler.post(connectionSuccessful);
                } catch (JSONException e) {
                    Log.e(TAG, "Couldn't convert to JSON object", e);
                    connectionErrorResponse = new ConnectionErrorResponse(Html.fromHtml(result).toString(),
                            url);
                    mHandler.post(connectionError);
                }

            } catch (Exception e) {
                String error = "Cannot establish connection";
                Log.e(TAG, error);
                connectionErrorResponse = new ConnectionErrorResponse(error,
                        ConnectionUtils.getUrlConnectionId(url));
                mHandler.post(connectionError);
            }
        }
    };
    t.start();
}

From source file:com.datafibers.kafka.connect.SchemaedFileSourceTask.java

private Struct ConvertMappingElement(Schema schema, HashMap element) {
    Struct struct = new Struct(schema);
    for (Object o : element.keySet()) {
        if (o instanceof String) {
            log.trace("Converting key {} from element", o.toString());
        } else {/*  ww  w .ja  v  a  2  s . c  o m*/
            log.warn("Element contains non-string key {}", o.toString());
            continue;
        }
        String key = (String) o;
        Object val = element.get(key);
        struct.put(key, (String) val);
        /*
        switch (schema.) {
        case Schema.BOOLEAN_SCHEMA: {
            if (val instanceof Boolean) {
                struct.put(key, (Boolean)val);
            } else {
                log.trace("Expected boolean for key {}; saw {}; storing null",
                    key, val.toString());
                struct.put(key, null);
            }
        }
        case Schema.FLOAT64_SCHEMA: {
            if (val instanceof Double) {
                struct.put(key, (Double)val);
            } else {
                log.trace("Expected number for key {}; saw {}; storing null",
                    key, val.toString());
                struct.put(key, null);
            }
        }
        case Schema.STRING_SCHEMA:
        default: {
            if (val instanceof String) {
                struct.put(key, (String)val);
            } else {
                log.trace("Expected string for key {}; saw {}; storing null",
                        key, val.toString());
                struct.put(key, null);
            }
        }
        }
        */
    }
    return struct;
}

From source file:de.fhg.fokus.odp.middleware.ckan.CKANGatewayUtil.java

/**
 * Sort the passed Map by the values//from w  w  w  .  j  av a 2  s  .c o  m
 * 
 * @param passedMap
 *            the HashMap to sort.
 * @return the sorted HashMap.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private static LinkedHashMap sortHashMapByValues(HashMap<String, Long> passedMap) {
    List<String> mapKeys = new ArrayList<String>(passedMap.keySet());
    List<Long> mapValues = new ArrayList<Long>(passedMap.values());

    Comparator comparator = Collections.reverseOrder();
    Collections.sort(mapValues, comparator);
    Collections.sort(mapKeys, comparator);

    LinkedHashMap<String, Long> sortedMap = new LinkedHashMap<String, Long>();

    Iterator valueIt = mapValues.iterator();
    while (valueIt.hasNext()) {
        Object val = valueIt.next();
        Iterator keyIt = mapKeys.iterator();

        while (keyIt.hasNext()) {
            Object key = keyIt.next();
            String comp1 = passedMap.get(key).toString();
            String comp2 = val.toString();

            if (comp1.equals(comp2)) {
                passedMap.remove(key);
                mapKeys.remove(key);
                sortedMap.put((String) key, (Long) val);
                break;
            }

        }

    }
    return sortedMap;

}

From source file:edu.ku.brc.specify.toycode.RegAdder.java

/**
 * @param trackId/* w  w  w .j a  va 2s.  c o m*/
 * @param mv
 * @param pStmt
 * @throws SQLException
 */
private void doTrackInserts(final int trackId, final HashMap<String, String> mv, final PreparedStatement pStmt)
        throws SQLException {
    for (String key : mv.keySet()) {
        String value = mv.get(key);
        pStmt.setString(1, key);
        if (!StringUtils.contains(value, ".") && StringUtils.isNumeric(value) && value.length() < 10) {
            pStmt.setInt(2, Integer.parseInt(value));
            pStmt.setNull(3, java.sql.Types.VARCHAR);

        } else if (value.length() < STR_SIZE + 1) {
            pStmt.setNull(2, java.sql.Types.INTEGER);
            pStmt.setString(3, value);

        } else {
            String v = value.substring(0, STR_SIZE);
            System.err.println(
                    "Error - On line " + lineNo + " Value[" + value + "] too big trunccating to[" + v + "]");

            pStmt.setNull(2, java.sql.Types.INTEGER);
            pStmt.setString(3, v);
        }
        pStmt.setInt(4, trackId);

        //System.out.println(pStmt2.toString());

        int rv = pStmt.executeUpdate();
        if (rv != 1) {
            for (String k : mv.keySet()) {
                System.out.println("[" + k + "][" + mv.get(k) + "]");
            }
            System.err.println("------------------------ Line No: " + lineNo);
            throw new RuntimeException("Error insert trackitem for Id: " + trackId);
        }
    }
}

From source file:org.openmeetings.app.data.basic.Sessionmanagement.java

/**
 * @param room_id/*www  .j a  v a  2  s  . co  m*/
 */
public void clearSessionByRoomId(Long room_id) {
    try {

        HashMap<String, RoomClient> MyUserList = clientListManager.getClientListByRoom(room_id);

        for (Iterator<String> iter = MyUserList.keySet().iterator(); iter.hasNext();) {
            String key = iter.next();

            RoomClient rcl = MyUserList.get(key);

            String aux = rcl.getSwfurl();

            int init_pos = aux.indexOf("sid=") + 4;
            int end_pos = init_pos + 32;
            if (end_pos > aux.length())
                end_pos = aux.length();
            String SID = aux.substring(init_pos, end_pos);

            Sessiondata sData = this.getSessionByHash(SID);

            sData = em.find(Sessiondata.class, sData.getId());
            em.remove(sData);
        }

    } catch (Exception err) {
        log.error("clearSessionByRoomId", err);
    }
}

From source file:de.nec.nle.siafu.graphics.Painter.java

/**
 * Load the images for all the sprites that will be used in the simulation.
 *///  w w  w  . ja  v a 2  s.c o m
private void preloadPeopleImages() {
    HashMap<String, InputStream> rawSprites = control.getSimulationData().getSprites();
    for (String fileName : rawSprites.keySet()) {
        String spriteName = fileName.split("-")[0];

        // Have we processed another direction of this sprite?
        if (personImg.containsKey(spriteName)) {
            continue;
        }
        Sprite s;
        try {
            String[] offset = fileName.split("-")[1].split("\\.");
            s = new Sprite(spriteName, new Integer(offset[0]), new Integer(offset[1]));

            for (int dir = 0; dir < MAX_DIR; dir++) {
                s.setImage(dir, new Image(display,
                        rawSprites.get(spriteName + "-" + s.getVOffset() + "." + s.getHOffset() + "-" + dir)));
            }
        } catch (Exception e) {
            throw new RuntimeException("Can't read the sprites for " + spriteName, e);
        }

        personImg.put(s.getName(), s);
    }
}

From source file:gr.cti.android.experimentation.controller.ui.RestRankingController.java

@ResponseBody
@RequestMapping(value = { "/results/{experimentId}" }, method = RequestMethod.GET)
public Set<DownloadableResultDTO> getResults(@PathVariable("experimentId") final int experimentId) {
    final Set<DownloadableResultDTO> externalResults = new TreeSet<>();
    final Set<Result> results = resultRepository.findByExperimentId(experimentId);
    LOGGER.info("Will try to convert " + results.size() + " results.");
    for (final Result result : results) {
        try {/*from   w ww . j  a v  a 2  s .com*/
            final DownloadableResultDTO dres = new DownloadableResultDTO();
            dres.setDate(result.getTimestamp());
            final HashMap<String, Object> dataMap = new ObjectMapper().readValue(result.getMessage(),
                    new HashMap<String, Object>().getClass());
            if (dataMap.containsKey(LONGITUDE) && dataMap.containsKey(LATITUDE)) {
                dres.setLongitude((Double) dataMap.get(LONGITUDE));
                dres.setLatitude((Double) dataMap.get(LATITUDE));
                dres.setResults(new HashMap<>());
                dataMap.keySet().stream().filter(key -> !key.equals(LATITUDE) && !key.contains(LONGITUDE))
                        .forEach(key -> {
                            dres.getResults().put(key, String.valueOf(dataMap.get(key)));
                        });
            }
            if (dres.getResults() != null) {
                externalResults.add(dres);
            }
        } catch (Exception e) {
            LOGGER.error(e, e);
        }
    }
    return externalResults;
}