Example usage for java.util HashMap containsKey

List of usage examples for java.util HashMap containsKey

Introduction

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

Prototype

public boolean containsKey(Object key) 

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:sg.edu.ntu.hrms.service.EmployeeListService.java

private String convertToJson(List<UserDTO> userList, HashMap map) {
    JsonArrayBuilder array = Json.createArrayBuilder();
    for (int i = 0; i < userList.size(); i++) {
        UserDTO user = userList.get(i);//from w ww  . j a va 2 s .  c om
        Date datejoin = user.getDateJoin();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String joinDateStr = formatter.format(datejoin);

        String approver = "";

        if (map.containsKey(user.getApprover())) {
            UserDTO mgr = (UserDTO) map.get(user.getApprover());
            approver = mgr.getName();
        }
        String deptDescr = "";
        if (user.getDept() != null) {
            deptDescr = user.getDept().getDept().getDescription();
        }
        System.out.println("approver: " + approver);
        array.add(Json.createObjectBuilder().add("id", user.getLogin()).add("name", user.getName())
                .add("email", user.getEmail()).add("dept", deptDescr)
                //.add("dept", user.getDept().getDept().getDescription())
                .add("title", user.getTitle().getDescription())
                //.add("category","coming")
                .add("manager", approver).add("datejoin", joinDateStr));

    }
    return array.build().toString();
}

From source file:ch.cyberduck.core.azure.AzureWriteFeature.java

@Override
public StatusOutputStream<Void> write(final Path file, final TransferStatus status,
        final ConnectionCallback callback) throws BackgroundException {
    try {/*ww  w.j  av a  2s .  c  om*/
        final CloudAppendBlob blob = session.getClient()
                .getContainerReference(containerService.getContainer(file).getName())
                .getAppendBlobReference(containerService.getKey(file));
        if (StringUtils.isNotBlank(status.getMime())) {
            blob.getProperties().setContentType(status.getMime());
        }
        final HashMap<String, String> headers = new HashMap<>();
        // Add previous metadata when overwriting file
        headers.putAll(status.getMetadata());
        blob.setMetadata(headers);
        // Remove additional headers not allowed in metadata and move to properties
        if (headers.containsKey(HttpHeaders.CACHE_CONTROL)) {
            blob.getProperties().setCacheControl(headers.get(HttpHeaders.CACHE_CONTROL));
            headers.remove(HttpHeaders.CACHE_CONTROL);
        }
        if (headers.containsKey(HttpHeaders.CONTENT_TYPE)) {
            blob.getProperties().setCacheControl(headers.get(HttpHeaders.CONTENT_TYPE));
            headers.remove(HttpHeaders.CONTENT_TYPE);
        }
        final Checksum checksum = status.getChecksum();
        if (Checksum.NONE != checksum) {
            switch (checksum.algorithm) {
            case md5:
                try {
                    blob.getProperties().setContentMD5(
                            Base64.toBase64String(Hex.decodeHex(status.getChecksum().hash.toCharArray())));
                    headers.remove(HttpHeaders.CONTENT_MD5);
                } catch (DecoderException e) {
                    // Ignore
                }
                break;
            }
        }
        final BlobRequestOptions options = new BlobRequestOptions();
        options.setConcurrentRequestCount(1);
        options.setStoreBlobContentMD5(preferences.getBoolean("azure.upload.md5"));
        final BlobOutputStream out;
        if (status.isAppend()) {
            options.setStoreBlobContentMD5(false);
            out = blob.openWriteExisting(AccessCondition.generateEmptyCondition(), options, context);
        } else {
            out = blob.openWriteNew(AccessCondition.generateEmptyCondition(), options, context);
        }
        return new VoidStatusOutputStream(out) {
            @Override
            protected void handleIOException(final IOException e) throws IOException {
                if (StringUtils.equals(SR.STREAM_CLOSED, e.getMessage())) {
                    log.warn(String.format("Ignore failure %s", e));
                    return;
                }
                final Throwable cause = ExceptionUtils.getRootCause(e);
                if (cause instanceof StorageException) {
                    throw new IOException(e.getMessage(),
                            new AzureExceptionMappingService().map((StorageException) cause));
                }
                throw e;
            }
        };
    } catch (StorageException e) {
        throw new AzureExceptionMappingService().map("Upload {0} failed", e, file);
    } catch (URISyntaxException e) {
        throw new NotfoundException(e.getMessage(), e);
    }
}

From source file:com.ibm.bi.dml.hops.OptimizerUtils.java

/**
 * /*from ww  w. ja  v  a  2s . c o  m*/
 * @param root
 * @param valMemo
 * @return
 * @throws HopsException
 */
protected static double rEvalSimpleUnaryDoubleExpression(Hop root, HashMap<Long, Double> valMemo)
        throws HopsException {
    //memoization (prevent redundant computation of common subexpr)
    if (valMemo.containsKey(root.getHopID()))
        return valMemo.get(root.getHopID());

    double ret = Double.MAX_VALUE;

    UnaryOp uroot = (UnaryOp) root;
    Hop input = uroot.getInput().get(0);

    if (uroot.getOp() == Hop.OpOp1.NROW)
        ret = (input.getDim1() > 0) ? input.getDim1() : Double.MAX_VALUE;
    else if (uroot.getOp() == Hop.OpOp1.NCOL)
        ret = (input.getDim2() > 0) ? input.getDim2() : Double.MAX_VALUE;
    else {
        double lval = rEvalSimpleDoubleExpression(uroot.getInput().get(0), valMemo);
        if (lval != Double.MAX_VALUE) {
            switch (uroot.getOp()) {
            case SQRT:
                ret = Math.sqrt(lval);
                break;
            case ROUND:
                ret = Math.round(lval);
                break;
            case CAST_AS_BOOLEAN:
                ret = (lval != 0) ? 1 : 0;
                break;
            case CAST_AS_INT:
                ret = UtilFunctions.toLong(lval);
                break;
            case CAST_AS_DOUBLE:
                ret = lval;
                break;
            default:
                ret = Double.MAX_VALUE;
            }
        }
    }

    valMemo.put(root.getHopID(), ret);
    return ret;
}

From source file:com.ibm.bi.dml.hops.OptimizerUtils.java

/**
 * /* w w w.ja  va  2s. c  om*/
 * @param root
 * @param valMemo
 * @return
 * @throws HopsException
 */
protected static double rEvalSimpleBinaryDoubleExpression(Hop root, HashMap<Long, Double> valMemo)
        throws HopsException {
    //memoization (prevent redundant computation of common subexpr)
    if (valMemo.containsKey(root.getHopID()))
        return valMemo.get(root.getHopID());

    double ret = Double.MAX_VALUE;

    BinaryOp broot = (BinaryOp) root;

    double lret = rEvalSimpleDoubleExpression(broot.getInput().get(0), valMemo);
    double rret = rEvalSimpleDoubleExpression(broot.getInput().get(1), valMemo);
    //note: positive and negative values might be valid subexpressions
    if (lret != Double.MAX_VALUE && rret != Double.MAX_VALUE) //if known
    {
        switch (broot.getOp()) {
        case PLUS:
            ret = lret + rret;
            break;
        case MINUS:
            ret = lret - rret;
            break;
        case MULT:
            ret = lret * rret;
            break;
        case DIV:
            ret = lret / rret;
            break;
        case MIN:
            ret = Math.min(lret, rret);
            break;
        case MAX:
            ret = Math.max(lret, rret);
            break;
        case POW:
            ret = Math.pow(lret, rret);
            break;
        default:
            ret = Double.MAX_VALUE;
        }
    }

    valMemo.put(root.getHopID(), ret);
    return ret;
}

From source file:com.linkedin.pinot.util.DataTableCustomSerDeTest.java

/**
 * Test for ser/de of HashMap&lt;String, Double&gt;
 */// www  . ja  v  a 2 s.c  o m
@Test
public void testStringDoubleHashMap() {
    for (int i = 0; i < NUM_ITERATIONS; i++) {
        Map<String, Double> expected = new HashMap<>();

        int size = random.nextInt(100);
        for (int j = 0; j < size; j++) {
            expected.put(RandomStringUtils.random(random.nextInt(20), true, true), random.nextDouble());
        }

        byte[] bytes = serde.serialize(expected);
        HashMap<String, Double> actual = serde.deserialize(bytes, DataTableSerDe.DataType.HashMap);

        Assert.assertEquals(actual.size(), expected.size(), "Random seed: " + randomSeed);
        for (Map.Entry<String, Double> entry : expected.entrySet()) {
            String key = entry.getKey();
            Assert.assertTrue(actual.containsKey(key), "Random seed: " + randomSeed);
            Assert.assertEquals(actual.get(key), entry.getValue(), "Random seed: " + randomSeed);
        }
    }
}

From source file:com.exalttech.trex.util.TrafficProfile.java

/**
 * Convert stream name to integer/*  w ww. ja v a 2 s  .  co m*/
 *
 * @param trafficProfileArray
 * @return
 */
public Map<String, Integer> convertStreamNameToInteger(Profile[] trafficProfileArray) {
    HashMap<String, Integer> streamNameMap = new HashMap<>();
    int streamID = 0;
    for (Profile profile : trafficProfileArray) {
        if (!streamNameMap.containsKey(profile.getName())) {
            streamNameMap.put(profile.getName(), streamID++);
        }
    }
    return streamNameMap;
}

From source file:com.mindquarry.desktop.preferences.profile.Profile.java

public static List<Profile> loadProfiles(PreferenceStore store) {
    HashMap<Integer, Profile> storedProfiles = new HashMap<Integer, Profile>();

    // load stored profiles
    String[] prefs = store.preferenceNames();
    for (String pref : prefs) {
        if (pref.startsWith(PROFILE_KEY_BASE)) {
            String val = store.getString(pref);
            if (val.trim().equals(EMPTY)) {
                // ignore empty values as PreferenceStore cannot properly
                // delete entries, so we just set deleted entries to the
                // empty string
                continue;
            }//from  w  w w . j av  a  2s.  co m
            // analyze preference
            int number = Integer
                    .valueOf(pref.substring(PROFILE_KEY_BASE.length(), PROFILE_KEY_BASE.length() + 1));
            String prefName = pref.substring(PROFILE_KEY_BASE.length() + 2, pref.length());

            // initialize profile
            Profile profile;
            if (storedProfiles.containsKey(number)) {
                profile = storedProfiles.get(number);
            } else {
                // TODO: maybe set type here to a non-value?
                profile = new Profile(EMPTY, EMPTY, EMPTY, EMPTY, EMPTY);
                storedProfiles.put(number, profile);
            }
            setProfileAttribute(store, profile, pref, prefName);
        }
    }
    // set profile list
    List<Profile> profiles = new ArrayList<Profile>();
    Iterator<Integer> keyIter = storedProfiles.keySet().iterator();
    while (keyIter.hasNext()) {
        Profile profile = storedProfiles.get(keyIter.next());
        profiles.add(profile);
    }
    return profiles;
}

From source file:com.ibm.bi.dml.hops.OptimizerUtils.java

/**
 * /*from w  w w .j ava 2 s .co m*/
 * @param root
 * @param valMemo
 * @param vars
 * @return
 * @throws HopsException
 */
public static double rEvalSimpleDoubleExpression(Hop root, HashMap<Long, Double> valMemo, LocalVariableMap vars)
        throws HopsException {
    //memoization (prevent redundant computation of common subexpr)
    if (valMemo.containsKey(root.getHopID()))
        return valMemo.get(root.getHopID());

    double ret = Double.MAX_VALUE;

    if (OptimizerUtils.ALLOW_SIZE_EXPRESSION_EVALUATION) {
        if (root instanceof LiteralOp)
            ret = HopRewriteUtils.getDoubleValue((LiteralOp) root);
        else if (root instanceof UnaryOp)
            ret = rEvalSimpleUnaryDoubleExpression(root, valMemo, vars);
        else if (root instanceof BinaryOp)
            ret = rEvalSimpleBinaryDoubleExpression(root, valMemo, vars);
        else if (root instanceof DataOp) {
            String name = root.getName();
            Data dat = vars.get(name);
            if (dat != null && dat instanceof ScalarObject)
                ret = ((ScalarObject) dat).getDoubleValue();
        }
    }

    valMemo.put(root.getHopID(), ret);
    return ret;
}

From source file:com.liteoc.domain.rule.RuleSetRuleBean.java

@Transient
public HashMap<String, ArrayList<RuleActionBean>> getAllActionsWithEvaluatesToAsKey() {
    HashMap<String, ArrayList<RuleActionBean>> h = new HashMap<String, ArrayList<RuleActionBean>>();
    for (RuleActionBean action : actions) {
        String key = action.getExpressionEvaluatesTo().toString();
        if (h.containsKey(key)) {
            h.get(key).add(action);//from   w  w  w .  j  a  v  a2s. c  o  m
        } else {
            ArrayList<RuleActionBean> a = new ArrayList<RuleActionBean>();
            a.add(action);
            h.put(key, a);
        }
    }
    return h;
}

From source file:edu.gmu.cs.sim.util.media.chart.PieChartGenerator.java

HashMap convertIntoAmountsAndLabels(Object[] objs) {
    // Total the amounts
    HashMap map = new HashMap();
    for (int i = 0; i < objs.length; i++) {
        String label = "null";
        if (objs[i] != null) {
            label = objs[i].toString();//from   w w w .  j a  v a 2  s.c om
        }
        if (map.containsKey(label)) {
            map.put(label, new Double(((Double) (map.get(label))).doubleValue() + 1));
        } else {
            map.put(label, new Double(1));
        }
    }
    return map;
}