Example usage for java.util Hashtable get

List of usage examples for java.util Hashtable get

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public synchronized 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:edu.stanford.epad.common.pixelmed.SegmentationObjectsFileWriter.java

private void add_attributes_to_shared_group(Hashtable<AttributeTag, SequenceAttribute> attrs,
        AttributeList shared) {//from w w  w  . j av a  2 s  .c  om
    /*
     * {TagFromName.SegmentIdentificationSequence, TagFromName.StackID, TagFromName.PlanePositionSequence,
     * TagFromName.PlaneOrientationSequence, TagFromName.SliceThickness, TagFromName.PixelSpacing}
     */
    Enumeration<AttributeTag> i = attrs.keys();
    while (i.hasMoreElements()) {
        AttributeTag tag = i.nextElement();
        if (tag.equals(TagFromName.StackID)) {
            Attribute a = SequenceAttribute.getNamedAttributeFromWithinSequenceWithSingleItem(attrs.get(tag),
                    tag);
            if (a == null)
                continue;
            SequenceAttribute seq = new SequenceAttribute(TagFromName.FrameContentSequence);
            AttributeList item = new AttributeList();
            item.put(a);
            seq.addItem(item);
            shared.put(seq);
        } else if (tag.equals(TagFromName.SliceThickness) || tag.equals(TagFromName.PixelSpacing)) {
            Attribute a = SequenceAttribute.getNamedAttributeFromWithinSequenceWithSingleItem(attrs.get(tag),
                    tag);
            if (a == null)
                continue;
            SequenceAttribute pixel_measures_seq = (SequenceAttribute) shared
                    .get(TagFromName.PixelMeasuresSequence);
            if (pixel_measures_seq != null) { // If PixelMeasuresSequence is already there, add one attribute to it instead
                                              // of rewriting it.
                AttributeList l = SequenceAttribute
                        .getAttributeListFromWithinSequenceWithSingleItem(pixel_measures_seq);
                l.put(a);
            } else {
                SequenceAttribute seq = new SequenceAttribute(TagFromName.PixelMeasuresSequence);
                AttributeList item = new AttributeList();
                item.put(a);
                seq.addItem(item);
                shared.put(seq);
            }
        } else
            shared.put(attrs.get(tag));
    }
}

From source file:edu.ku.brc.specify.config.init.DataBuilder.java

/**
 * @param filename//from  w  w  w. j av  a  2s. c om
 * @param prefix
 * @param groupMap
 */
public static void createDefaultPermissions(final Session sessionArg, final String filename,
        final String prefix, final Map<String, SpPrincipal> groupMap,
        final List<SecurityOptionIFace> additionalSecOpts) {
    Hashtable<String, Hashtable<String, PermissionOptionPersist>> mainHash = BaseTask
            .readDefaultPermsFromXML(filename);
    for (String permName : mainHash.keySet()) {
        String userType = "LimitedAccess";
        Hashtable<String, PermissionOptionPersist> hash = mainHash.get(permName);
        if (hash.get(userType) == null) {
            PermissionOptionPersist permOpts = hash.get("Manager");
            PermissionOptionPersist newPermOpts = new PermissionOptionPersist(permOpts.getTaskName(), userType,
                    permOpts.isCanView(), permOpts.isCanModify(), permOpts.isCanDel(), permOpts.isCanAdd());
            hash.put(userType, newPermOpts);
        }

        userType = "FullAccess";
        hash = mainHash.get(permName);
        if (hash.get(userType) == null) {
            PermissionOptionPersist permOpts = hash.get("Manager");
            PermissionOptionPersist newPermOpts = new PermissionOptionPersist(permOpts.getTaskName(), userType,
                    permOpts.isCanView(), permOpts.isCanModify(), permOpts.isCanDel(), permOpts.isCanAdd());
            hash.put(userType, newPermOpts);
        }
    }

    if (additionalSecOpts != null) {
        for (SecurityOptionIFace aso : additionalSecOpts) {
            Hashtable<String, PermissionOptionPersist> hash = mainHash.get(aso.getPermissionName());
            if (hash == null) {
                hash = new Hashtable<String, PermissionOptionPersist>();
                mainHash.put(aso.getPermissionName(), hash);
            }
            for (SpecifyUserTypes.UserType userType : SpecifyUserTypes.UserType.values()) {
                PermissionIFace asoPerm = aso.getDefaultPermissions(userType.toString());
                if (asoPerm != null) {
                    PermissionOptionPersist newPermOpts = new PermissionOptionPersist(aso.getPermissionName(),
                            userType.toString(), asoPerm.canView(), asoPerm.canModify(), asoPerm.canDelete(),
                            asoPerm.canAdd());
                    hash.put(userType.toString(), newPermOpts);
                }
            }
        }
    }
    writePerms(mainHash, filename);

    for (SpPrincipal p : groupMap.values()) {
        persist(p);
    }

    for (String permName : mainHash.keySet()) {
        Hashtable<String, PermissionOptionPersist> hash = mainHash.get(permName);
        for (String userType : hash.keySet()) {
            PermissionOptionPersist tp = hash.get(userType);
            SpPermission perm = tp.getSpPermission();
            sessionArg.saveOrUpdate(perm);

            Set<SpPrincipal> groupSet = new HashSet<SpPrincipal>();
            groupSet.add(groupMap.get(userType));
            perm.setPrincipals(groupSet);
            perm.setName(prefix + permName);
        }
    }
}

From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.MobileServiceFeaturesTests.java

public void testFeaturesToStringConversion() {
    Hashtable<EnumSet<MobileServiceFeatures>, String> cases;
    cases = new Hashtable<EnumSet<MobileServiceFeatures>, String>();
    for (MobileServiceFeatures feature : MobileServiceFeatures.class.getEnumConstants()) {
        cases.put(EnumSet.of(feature), feature.getValue());
    }//w ww. j a  v  a 2  s  .c om
    cases.put(EnumSet.of(MobileServiceFeatures.TypedTable, MobileServiceFeatures.AdditionalQueryParameters),
            "QS,TT");
    cases.put(EnumSet.of(MobileServiceFeatures.UntypedTable, MobileServiceFeatures.AdditionalQueryParameters),
            "QS,TU");
    cases.put(EnumSet.of(MobileServiceFeatures.TypedTable, MobileServiceFeatures.Offline), "OL,TT");
    cases.put(EnumSet.of(MobileServiceFeatures.UntypedTable, MobileServiceFeatures.Offline), "OL,TU");
    cases.put(EnumSet.of(MobileServiceFeatures.TypedApiCall, MobileServiceFeatures.AdditionalQueryParameters),
            "AT,QS");
    cases.put(EnumSet.of(MobileServiceFeatures.JsonApiCall, MobileServiceFeatures.AdditionalQueryParameters),
            "AJ,QS");
    cases.put(EnumSet.of(MobileServiceFeatures.OpportunisticConcurrency, MobileServiceFeatures.Offline,
            MobileServiceFeatures.UntypedTable), "OC,OL,TU");

    for (EnumSet<MobileServiceFeatures> features : cases.keySet()) {
        String expected = cases.get(features);
        String actual = MobileServiceFeatures.featuresToString(features);
        assertEquals(expected, actual);
    }
}

From source file:edu.ku.brc.specify.config.init.secwiz.UserPanel.java

/**
 * /*  w  w  w  . j  a va 2  s  .c o m*/
 */
private void sendKeys() {
    final Hashtable<String, String> emailPrefs = new Hashtable<String, String>();
    if (!EMailHelper.isEMailPrefsOK(emailPrefs)) {
        JOptionPane.showMessageDialog(UIRegistry.getTopWindow(), getResourceString("NO_EMAIL_PREF_INFO"),
                getResourceString("NO_EMAIL_PREF_INFO_TITLE"), JOptionPane.WARNING_MESSAGE);
        return;
    }

    int[] selectedIds = getSelectedIds();

    Vector<UserData> items = userModel.getUserData();
    for (int inx : selectedIds) {
        //UserData ud  = items.get(inx);
        /*emailPrefs.put("to", toAgent.getEmail() != null ? toAgent.getEmail() : "");
        emailPrefs.put("from", emailPrefs.get("email"));
        emailPrefs.put("subject", String.format(getResourceString("SEC_WIZ"), new Object[] {infoRequest.getIdentityTitle()}));
        emailPrefs.put("bodytext", "");
        */
        StringBuilder sb = new StringBuilder();

        // EMailHelper.setDebugging(true);
        String text = emailPrefs.get("bodytext").replace("\n", "<br>") + "<BR><BR>" + sb.toString();
        UIRegistry.displayLocalizedStatusBarText("SENDING_EMAIL");

        String password = Encryption.decrypt(emailPrefs.get("password"));
        if (StringUtils.isEmpty(password)) {
            password = EMailHelper.askForPassword((Frame) UIRegistry.getTopWindow());
        }

        if (StringUtils.isNotEmpty(password)) {
            final EMailHelper.ErrorType status = EMailHelper.sendMsg(emailPrefs.get("smtp"),
                    emailPrefs.get("username"), password, emailPrefs.get("email"), emailPrefs.get("to"),
                    emailPrefs.get("subject"), text, EMailHelper.HTML_TEXT, emailPrefs.get("port"),
                    emailPrefs.get("security"), null);
            if (status != EMailHelper.ErrorType.Cancel) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        UIRegistry.displayLocalizedStatusBarText(
                                status == EMailHelper.ErrorType.Error ? "EMAIL_SENT_ERROR" : "EMAIL_SENT_OK");
                    }
                });
            }
        }
    }
}

From source file:edu.ku.brc.specify.config.init.DataBuilder.java

/**
 * @param filename/*from w w w  . j a v a2 s  .  c  o m*/
 * @param prefix
 * @param groupMap
 */
public static void mergeDefaultPermissions(final String filename, final String prefix,
        final Map<String, List<Integer>> groupMap) {
    Hashtable<String, Hashtable<String, PermissionOptionPersist>> mainHash = BaseTask
            .readDefaultPermsFromXML(filename);
    for (String permName : mainHash.keySet()) {
        String userType = "LimitedAccess";
        Hashtable<String, PermissionOptionPersist> hash = mainHash.get(permName);
        if (hash.get(userType) == null) {
            PermissionOptionPersist permOpts = hash.get("Manager");
            PermissionOptionPersist newPermOpts = new PermissionOptionPersist(permOpts.getTaskName(), userType,
                    permOpts.isCanView(), permOpts.isCanModify(), permOpts.isCanDel(), permOpts.isCanAdd());
            hash.put(userType, newPermOpts);
        }

        userType = "FullAccess";
        hash = mainHash.get(permName);
        if (hash.get(userType) == null) {
            PermissionOptionPersist permOpts = hash.get("Manager");
            PermissionOptionPersist newPermOpts = new PermissionOptionPersist(permOpts.getTaskName(), userType,
                    permOpts.isCanView(), permOpts.isCanModify(), permOpts.isCanDel(), permOpts.isCanAdd());
            hash.put(userType, newPermOpts);
        }
    }

    /*if (additionalSecOpts != null)
    {
    for (SpecifyUserTypes.UserType userType : SpecifyUserTypes.UserType.values())
    {
        System.out.println(userType.toString()+" --------------------------------------");
        for (SecurityOptionIFace aso : additionalSecOpts)
        {
            PermissionIFace asoPerm = aso.getDefaultPermissions(userType.toString());
            if (asoPerm != null)
            {
                System.out.println("  "+prefix+aso.getPermissionName()+"  "+asoPerm.getOptions());
            }
        }
    }
    }*/

    HashMap<SpPermission, List<Integer>> prinPermHash = new HashMap<SpPermission, List<Integer>>();
    for (String permName : mainHash.keySet()) {
        String fullPermName = prefix + permName;

        Hashtable<String, PermissionOptionPersist> hash = mainHash.get(permName);
        for (String userType : hash.keySet()) {
            PermissionOptionPersist tp = hash.get(userType);
            SpPermission perm = tp.getSpPermission();

            for (Integer id : groupMap.get(userType)) {
                String str = "SELECT p.SpPermissionID FROM sppermission AS p Inner Join spprincipal_sppermission AS pp ON p.SpPermissionID = pp.SpPermissionID "
                        + "WHERE p.Name = '%s' AND pp.SpPrincipalID = %d";
                String sql = String.format(str, fullPermName, id);
                Integer permId = BasicSQLUtils.getCount(sql);
                if (permId == null) {
                    System.out.println(String.format("Going to create %s for Prin: %d", fullPermName, id));
                    List<Integer> list = prinPermHash.get(perm);
                    if (list == null) {
                        perm.setName(fullPermName);
                        list = new ArrayList<Integer>();
                        prinPermHash.put(perm, list);
                    }
                    list.add(id);
                }
            }
        }
    }

    if (prinPermHash.size() > 0) {
        Connection conn = null;
        PreparedStatement pstmt1 = null;
        PreparedStatement pstmt2 = null;
        try {
            conn = DatabaseService.getInstance().getConnection();
            pstmt1 = conn.prepareStatement(
                    "INSERT INTO sppermission (Actions, Name, PermissionClass) VALUES (?, ?, ?)", //$NON-NLS-1$
                    Statement.RETURN_GENERATED_KEYS);
            pstmt2 = conn.prepareStatement(
                    "INSERT INTO spprincipal_sppermission (SpPermissionID, SpPrincipalID) VALUES (?, ?)"); //$NON-NLS-1$
            for (SpPermission spPerm : prinPermHash.keySet()) {
                for (Integer prinId : prinPermHash.get(spPerm)) {
                    pstmt1.setString(1, spPerm.getActions());
                    pstmt1.setString(2, spPerm.getName());
                    pstmt1.setString(3, spPerm.getClass().getName());
                    pstmt1.setString(3, BasicSpPermission.class.getCanonicalName());
                    pstmt1.executeUpdate();

                    Integer newPermId = BasicSQLUtils.getInsertedId(pstmt1);
                    pstmt2.setInt(1, newPermId);
                    pstmt2.setInt(2, prinId);
                    pstmt2.executeUpdate();
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
            edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(PermissionService.class, e);
        } finally {
            try {
                if (pstmt1 != null)
                    pstmt1.close();
                if (pstmt2 != null)
                    pstmt2.close();
                if (conn != null)
                    conn.close();

            } catch (SQLException e) {
                e.printStackTrace();
                edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(PermissionService.class, e);
            }
        }
    }
}

From source file:org.agnitas.backend.Data.java

/**
 * Find entry in map for overwrite/virtual records
 * @param cid the customer id/*from  w w w.j av  a2s.  c o m*/
 * @param multi optional available multi hash table
 * @param simple optional simple hash table
 * @param colname the name of the column
 * @return the found string or null
 */
private String findInMap(Long cid, Hashtable<Long, Hashtable<String, String>> multi,
        Hashtable<String, String> simple, String colname) {
    Hashtable<String, String> map;

    if ((multi != null) && multi.containsKey(cid))
        map = multi.get(cid);
    else
        map = simple;
    if ((map != null) && map.containsKey(colname))
        return map.get(colname);
    return null;
}

From source file:com.flexive.tests.browser.AdmContentTest.java

/**
 * fill the content in//from   w  w  w .ja v  a2 s  .  c o m
 * @param contents key-value pairs representing the content
 */
private void fillInContent(Hashtable<String, Object> contents) {

    String htmlSrc = selenium.getHTMLSource("<div ", "</div>", "<input ");

    final String MARK = "<div class=\"display\" title=\"\" style=\"\">";
    String[] items1 = htmlSrc.split(MARK);
    final String MARK_ = "<div class=display title= style=>";
    String[] items2 = htmlSrc.split(MARK_);
    String[] items = new String[items1.length + items2.length];
    System.arraycopy(items1, 0, items, 0, items1.length);
    System.arraycopy(items2, 0, items, items1.length, items2.length);

    String tmpS;
    String name;
    Hashtable<String, Hashtable<String, String>> inputs = new Hashtable<String, Hashtable<String, String>>();
    Hashtable<String, String> params;
    int begin;
    int b, e;
    for (int i = 1; i < items.length; i++) {
        tmpS = items[i];
        begin = tmpS.indexOf("</div>");
        name = tmpS.substring(0, begin).trim();
        begin = tmpS.indexOf("<input ", begin);
        params = new Hashtable<String, String>();
        if (begin > 0) {
            begin += 7;
            b = tmpS.indexOf("id=\"", begin) + 4;
            if (b > 0) {
                e = tmpS.indexOf("\"", b);
            } else {
                b = tmpS.indexOf("id=", begin) + 3;
                e = tmpS.indexOf(" ", b);
            }
            params.put("id", tmpS.substring(b, e));

            b = tmpS.indexOf("type=\"", begin) + 6;
            if (b > 0) {
                e = tmpS.indexOf("\"", b);
            } else {
                b = tmpS.indexOf("type=", begin) + 5;
                e = tmpS.indexOf(" ", b);
            }
            params.put("type", tmpS.substring(b, e).toLowerCase());

            inputs.put(name, params);
        }
    }

    String type;
    String id;
    Object value;
    for (String curName : contents.keySet()) {
        params = inputs.get(curName);
        if (params != null) {
            type = params.get("type");
            id = params.get("id");
            value = contents.get(curName);
            if (type.equals("text")) {
                selenium.type(id, value.toString());
            } else if (type.equals("checkbox")) {
                setCheckboxState(id, (Boolean) value);
            }

        } else {
            //  TODO throw not found...               
        }
    }
}

From source file:edu.ku.brc.specify.utilapps.RegisterApp.java

/**
 * @param dateType/*www  .j  a  va  2 s. c om*/
 * @param srcList
 * @return
 */
private Vector<Pair<String, Integer>> getDateValuesFromList(final DateType dateType) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar cal = Calendar.getInstance();

    System.out.println(rp.getRegNumHash().values().size());

    Hashtable<String, Pair<String, Integer>> hash = new Hashtable<String, Pair<String, Integer>>();
    for (RegProcEntry entry : rp.getRoot(INCL_ANON).getKids()) {
        if (entry.get("reg_type").equals("Institution")) {
            String desc = null;
            Timestamp ts = entry.getTimestampCreated();
            cal.setTime(ts);

            switch (dateType) {
            case Time:
                desc = Integer.toString(cal.get(Calendar.HOUR_OF_DAY));
                break;

            case Monthly:
                desc = Integer.toString(cal.get(Calendar.MONTH));
                break;

            case Yearly:
                desc = Integer.toString(cal.get(Calendar.YEAR));
                break;

            case Date:
                desc = sdf.format(ts);
                break;

            case None:
                break;
            }

            Pair<String, Integer> pair = hash.get(desc);
            if (pair == null) {
                pair = new Pair<String, Integer>(desc, 1);
                hash.put(desc, pair);
            } else {
                pair.second++;
            }
        }
    }
    Vector<Pair<String, Integer>> values = new Vector<Pair<String, Integer>>(hash.values());

    int total = 0;
    for (Pair<String, Integer> p : values) {
        total += p.second;
    }
    System.err.println("Total: " + total);
    return values;
}

From source file:org.agnitas.backend.Data.java

/**
 * Parse options passed during runtime//from w ww.ja  v  a  2s .  c o m
 * @param opts the options to use
 * @param state if 1, the before initialization pass, 2 on execution pass
 */
@SuppressWarnings("unchecked")
public void options(Hashtable<String, Object> opts, int state) throws Exception {
    Object tmp;

    if (opts == null) {
        return;
    }
    if (state == 1) {
        tmp = opts.get("custom-tags");
        if (tmp != null) {
            if (customTags == null)
                customTags = new Vector<String>();
            for (Enumeration<String> e = ((Hashtable<String, Object>) tmp).keys(); e.hasMoreElements();) {
                String s = e.nextElement();

                if (s != null)
                    customTags.add(s);
            }
        }
        previewInput = (String) opts.get("preview-input");
        tmp = opts.get("preview-create-all");
        if (tmp != null)
            previewCreateAll = obj2bool(tmp, "preview-create-all");
    } else if (state == 2) {
        tmp = opts.get("customer-id");
        if (tmp != null)
            campaignCustomerID = obj2long(tmp, "customer-id");
        tmp = opts.get("transaction-id");
        if (tmp != null)
            campaignTransactionID = obj2long(tmp, "transaction-id");
        tmp = opts.get("user-status");
        if (tmp != null)
            campaignUserStatus = obj2int(tmp, "user-status");
        fixedEmail = (String) opts.get("fixed-email");
        tmp = opts.get("preview-for");
        if (tmp != null)
            previewCustomerID = obj2long(tmp, "preview-for");
        previewOutput = (Page) opts.get("preview-output");
        tmp = opts.get("preview-anon");
        if (tmp != null)
            previewAnon = obj2bool(tmp, "preview-anon");
        previewSelector = (String) opts.get("preview-selector");
        tmp = opts.get("preview-cachable");
        if (tmp != null)
            previewCachable = obj2bool(tmp, "preview-cachable");
        tmp = opts.get("preview-convert-entities");
        if (tmp != null)
            previewConvertEntities = obj2bool(tmp, "preview-convert-entities");
        tmp = opts.get("preview-legacy-uids");
        if (tmp != null)
            previewLegacyUIDs = obj2bool(tmp, "preview-legacy-uids");
        tmp = opts.get("send-date");
        if (tmp != null) {
            currentSendDate = obj2date(tmp, "send-date");
            sendSeconds = currentSendDate.getTime() / 1000;

            long now = System.currentTimeMillis() / 1000;
            if (sendSeconds < now)
                sendSeconds = now;
        }

        tmp = opts.get("step");
        if (tmp != null)
            setStepping(obj2int(tmp, "step"));
        tmp = opts.get("block-size");
        if (tmp != null)
            setBlockSize(obj2int(tmp, "block-size"));

        campaignSubselect = (TargetRepresentation) opts.get("select");

        customMap = (Hashtable<String, String>) opts.get("custom-tags");
        overwriteMap = (Hashtable<String, String>) opts.get("overwrite");
        virtualMap = (Hashtable<String, String>) opts.get("virtual");
        overwriteMapMulti = (Hashtable<Long, Hashtable<String, String>>) opts.get("overwrite-multi");
        virtualMapMulti = (Hashtable<Long, Hashtable<String, String>>) opts.get("virtual-multi");
    }
}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java

/**
 * @return//from  w  w w. jav  a2 s  . co  m
 */
protected Vector<FormCellField> getAvailableFieldCells() {
    Vector<FormCellField> list = new Vector<FormCellField>();
    Hashtable<String, FormCellLabel> labelForHash = new Hashtable<String, FormCellLabel>();
    // Add all the labels
    for (FormRowIFace row : formViewDef.getRows()) {
        for (FormCellIFace cell : row.getCells()) {
            if (cell instanceof FormCellLabel) {
                FormCellLabel fcl = (FormCellLabel) cell;
                if (StringUtils.isNotEmpty(fcl.getLabelFor())) {
                    labelForHash.put(fcl.getLabelFor(), (FormCellLabel) cell);
                }
            }
        }
    }

    // add the ones not in use
    for (FormRowIFace row : formViewDef.getRows()) {
        for (FormCellIFace cell : row.getCells()) {
            if (cell instanceof FormCellField) {
                FormCellField fcf = (FormCellField) cell;
                FormCellLabel label = labelForHash.get(fcf.getIdent());
                if (label == null) {
                    list.add(fcf);
                }
            }
        }
    }
    return list;
}