Example usage for java.util HashMap size

List of usage examples for java.util HashMap size

Introduction

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

Prototype

int size

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

Click Source Link

Document

The number of key-value mappings contained in this map.

Usage

From source file:com.hangum.tadpole.rdb.core.editors.table.TableViewerEditPart.java

/**
 * insert  ?//from  ww  w . j ava2  s  .  c  o m
 * @param tmpRs
 * @return
 */
private String makeInsert(HashMap<Integer, Object> tmpRs) {
    String insertStmt = "INSERT INTO " + initTableNameStr + "("; //$NON-NLS-1$ //$NON-NLS-2$

    // ?   .
    boolean isModifyColumn = false;
    for (int i = 1; i < tmpRs.size(); i++) {
        if (TbUtils.isModifyData(tmpRs.get(i).toString())) {
            insertStmt += mapColumns.get(i - 1) + ", "; //$NON-NLS-1$
            isModifyColumn = true;
        }
    }
    //  ? ? .   ? ? ? .
    if (!isModifyColumn)
        return ""; //$NON-NLS-1$

    insertStmt = StringUtils.chompLast(insertStmt, ", "); //$NON-NLS-1$
    insertStmt += ") VALUES ("; //$NON-NLS-1$

    // ? ? .
    for (int i = 1; i < tmpRs.size(); i++) {
        if (TbUtils.isModifyData(tmpRs.get(i).toString()))
            insertStmt += "'" + TbUtils.getOriginalData(tmpRs.get(i).toString()) + "', "; //$NON-NLS-1$ //$NON-NLS-2$
    }
    insertStmt = StringUtils.chompLast(insertStmt, ", "); //$NON-NLS-1$
    insertStmt += ");"; //$NON-NLS-1$

    return insertStmt;
}

From source file:com.google.gwt.emultest.java.util.HashMapTest.java

public void testClear() {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    checkEmptyHashMapAssumptions(hashMap);

    hashMap.put("Hello", "Bye");
    assertFalse(hashMap.isEmpty());/*from   w  w w .ja  va  2s . co m*/
    assertTrue(hashMap.size() == SIZE_ONE);

    hashMap.clear();
    assertTrue(hashMap.isEmpty());
    assertTrue(hashMap.size() == 0);
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.MafFileProcessor.java

@Override
protected File doWork(final File mafFile, final QcContext context) throws ProcessorException {
    // make sure the disease is set
    if (context.getArchive() != null) {
        DiseaseContextHolder.setDisease(context.getArchive().getTumorType());
    }/*from ww w . j a  va  2 s .  com*/

    FileReader fileReader = null;
    BufferedReader bufferedReader = null;

    try {
        // open file
        fileReader = new FileReader(mafFile);
        bufferedReader = new BufferedReader(fileReader);

        int lineNum = 0;

        // find first non-blank line not starting with #, this is the header
        String headerLine = bufferedReader.readLine();
        lineNum++;
        while (StringUtils.isEmpty(headerLine.trim())
                || StringUtils.startsWith(headerLine, COMMENT_LINE_TOKEN)) {
            headerLine = bufferedReader.readLine();
            lineNum++;
        }

        final List<String> headers = Arrays.asList(headerLine.split("\\t"));

        context.setFile(mafFile);
        final Map<String, Integer> fieldOrder = mapFieldOrder(headers);
        // need to find out the file id for this maf file
        final Long mafFileId = fileInfoQueries.getFileId(mafFile.getName(), context.getArchive().getId());
        if (mafFileId == null || mafFileId == -1) {
            context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW);
            throw new ProcessorException(new StringBuilder().append("File '").append(mafFile.getName())
                    .append("' was not found in the database").toString());
        }
        if (isAddMafInfo(mafFileId)) {
            HashMap<String, BCRID> biospecimens = new HashMap<String, BCRID>();
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                lineNum++;
                if (!StringUtils.isBlank(line.trim()) && !StringUtils.startsWith(line, COMMENT_LINE_TOKEN)) {
                    final String[] row = line.split("\\t");

                    try {
                        processRow(row, fieldOrder, mafFileId, biospecimens, context, mafFile, lineNum);
                        //  If exceeds batch size store it in the database
                        if (biospecimens.size() >= getBatchSize()) {
                            try {
                                insertBiospecimenToFileRelationships(biospecimens, context, mafFile);
                            } catch (UUIDException ue) {
                                throw new ProcessorException(ue.getMessage(), ue);
                            }
                            biospecimens.clear();
                        }
                    } catch (DataAccessException e) {
                        // catch DB errors per line
                        context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW);
                        context.addError(MessageFormat.format(MessagePropertyType.MAF_FILE_PROCESSING_ERROR,
                                mafFile.getName(),
                                new StringBuilder().append("Mutation information from file at line '")
                                        .append(lineNum).append("' was not successfully added. Root cause: ")
                                        .append(e.getMessage()).toString()));
                    }
                }
            }
            // process remaining biospecimens
            if (biospecimens.size() > 0) {
                try {
                    insertBiospecimenToFileRelationships(biospecimens, context, mafFile);
                } catch (UUIDException ue) {
                    context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW);
                    throw new ProcessorException(ue.getMessage(), ue);
                } catch (DataAccessException e) {
                    context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW);
                    throw new ProcessorException(e.getMessage(), e);
                }
                biospecimens.clear();
            }
        }
    } catch (IOException e) {
        context.getArchive().setDeployStatus(Archive.STATUS_IN_REVIEW);
        throw new ProcessorException(
                new StringBuilder().append("Error reading maf file ").append(mafFile.getName()).toString());
    } finally {
        if (bufferedReader != null) {
            try {
                bufferedReader.close();
            } catch (IOException e) {
                // ignore
            }
        }

        if (fileReader != null) {
            try {
                fileReader.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }

    return mafFile;
}

From source file:com.splicemachine.derby.impl.sql.execute.actions.DDLConstantOperation.java

/**
 * Add and drop dependencies of an object on UDTs.
 *
 * @param lcc Interpreter's state variable for this session.
 * @param dd Metadata/*from   ww  w.  j a  va  2 s  .c  om*/
 * @param dependent Object which depends on UDT
 * @param addUdtMap Map of UDTs for which dependencies should be added
 * @param dropUdtMap Map of UDT for which dependencies should be dropped
 */
private void adjustUDTDependencies(LanguageConnectionContext lcc, DataDictionary dd, Dependent dependent,
        HashMap addUdtMap, HashMap dropUdtMap) throws StandardException {
    // again, nothing to do if there are no columns of udt type
    if ((addUdtMap.size() == 0) && (dropUdtMap.size() == 0)) {
        return;
    }

    TransactionController tc = lcc.getTransactionExecute();
    DependencyManager dm = dd.getDependencyManager();
    ContextManager cm = lcc.getContextManager();

    // add new dependencies
    Iterator addIterator = addUdtMap.values().iterator();
    while (addIterator.hasNext()) {
        AliasDescriptor ad = (AliasDescriptor) addIterator.next();

        dm.addDependency(dependent, ad, cm);
    }

    // drop dependencies that are orphaned
    Iterator dropIterator = dropUdtMap.values().iterator();
    while (dropIterator.hasNext()) {
        AliasDescriptor ad = (AliasDescriptor) dropIterator.next();

        DependencyDescriptor dependency = new DependencyDescriptor(dependent, ad);

        dd.dropStoredDependency(dependency, tc);
    }
}

From source file:de.tud.kom.p2psim.impl.network.gnp.topology.GnpSpace.java

/**
 * Calculates good positions for all Hosts in Map
 * /*from   w  w w  . j ava  2 s . c  o  m*/
 * @param monitorResheduling
 *            number of rescheduling the downhill simplex
 */
private void insertCoordinates(int monitorResheduling) {
    GnpSpace.calculationStepStatus = 2;
    coordinateIndex.clear();
    HashMap<Integer, Host> peers = this.getMapRef().getHostIndex();
    int c = 0;
    for (Host host : peers.values()) {
        GnpSpace.calculationProgressStatus = c;
        if (host.getHostType() == Host.HOST) {
            GnpPosition coord = this.insertCoordinateDownhillSimplex(host, monitorResheduling);
            coordinateIndex.put(host.getIpAddress(), coord);
            c++;
            if (c % 1000 == 0)
                log.debug(c + " of " + peers.size() + " are positioned in gnp");
        }
        if (!calculationInProgress)
            return;
    }
    GnpSpace.calculationStepStatus = 0;
    GnpSpace.calculationInProgress = false;
}

From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java

public void testEntrySetEntrySetterNull() {
    HashMap hashMap = new HashMap();
    hashMap.put(null, 2);/*from   w  ww .j ava 2  s  .  c om*/
    Set entrySet = hashMap.entrySet();
    Entry entry = (Entry) entrySet.iterator().next();

    entry.setValue(3);
    assertEquals(3, hashMap.get(null));

    hashMap.put(null, 4);
    assertEquals(4, entry.getValue());

    assertEquals(1, hashMap.size());
}

From source file:com.hangum.tadpole.rdb.core.editors.table.TableViewerEditPart.java

/**
 * update  ?/*  w  w w .j  av  a 2  s  . c  o  m*/
 * 
 * @param tmpRs
 * @return
 */
private String makeUpdate(int rowSeq, HashMap<Integer, Object> tmpRs) {
    String updateStmt = "UPDATE " + initTableNameStr + //$NON-NLS-1$ //$NON-NLS-2$
            " SET "; //$NON-NLS-1$

    // ? ? ? .
    // 0  ? ??  ?
    for (int i = 1; i < tmpRs.size(); i++) {
        if (TbUtils.isModifyData(tmpRs.get(i).toString())) {
            updateStmt += mapColumns.get(i - 1) + " = '" + TbUtils.getOriginalData(tmpRs.get(i).toString()) //$NON-NLS-1$
                    + "', "; //$NON-NLS-1$
        }
    }
    updateStmt = StringUtils.chompLast(updateStmt, ", "); //$NON-NLS-1$

    updateStmt += " WHERE " + getWhereMake(rowSeq) + Define.SQL_DILIMITER; //$NON-NLS-1$ //$NON-NLS-2$
    return updateStmt;
}

From source file:org.messic.server.api.dlna.MusicService.java

@Transactional
public List<PlaylistItem> getPlaylists(String containerId, long startIndex, long maxCount, VisualContainer vc) {
    List<PlaylistItem> result = new ArrayList<PlaylistItem>();
    List<MDOPlaylist> playlists = this.daoPlaylist.getAllDLNA();

    for (long i = startIndex; i < startIndex + maxCount && i < playlists.size(); i++) {
        MDOPlaylist mdop = playlists.get((int) i);

        HashMap<MDOAuthor, String> authors = new HashMap<MDOAuthor, String>();
        List<MDOSong> songs = mdop.getSongs();
        for (int j = 0; j < songs.size(); j++) {
            MDOSong song = songs.get(j);
            authors.put(song.getAlbum().getAuthor(), "");
        }//from  w  w  w  .  j  a v  a  2  s.  c o  m

        PlaylistItem pli = new PlaylistItem();
        pli.setTitle(mdop.getName());
        pli.setDescription(mdop.getName());
        pli.setLongDescription(mdop.getName());
        pli.setDate("24/01/2013");
        MDOAuthor[] mdoauthors = new MDOAuthor[authors.size()];
        authors.keySet().toArray(mdoauthors);
        PersonWithRole[] persons = new PersonWithRole[mdoauthors.length];
        for (int k = 0; k < mdoauthors.length; k++) {
            MDOAuthor mdoa = mdoauthors[k];
            PersonWithRole pwr = new PersonWithRole(mdoa.getName());
            persons[k] = pwr;
        }
        pli.setArtists(persons);

        pli.setParentID(mdop.getOwner().getSid() + "");
        pli.setId(mdop.getOwner().getSid() + MessicContainer.SEPARATOR);

        for (int l = 0; l < mdop.getSongs().size(); l++) {
            MDOSong song = mdop.getSongs().get(l);

            MDOUser user = song.getOwner();
            String token = loginDLNA(user.getLogin(), user.getPassword());

            Res resource = new Res();
            EnumMap<DLNAAttribute.Type, DLNAAttribute> dlnaAttributes = new EnumMap<DLNAAttribute.Type, DLNAAttribute>(
                    DLNAAttribute.Type.class);

            URI originalUri = null;
            try {
                originalUri = new URI(
                        (isSecured() ? "https" : "http") + "://" + Util.getInternalIp() + ":" + getCurrentPort()
                                + "/messic/services/songs/" + song.getSid() + "/dlna?messic_token=" + token);
            } catch (URISyntaxException e) {
                log.error("failed!", e);
            } catch (Exception e) {
                log.error("failed!", e);
            }
            resource.setValue(originalUri.toString());
            DLNAProfiles originalProfile = DLNAProfiles.MP3;
            dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_PN, new DLNAProfileAttribute(originalProfile));
            dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_OP,
                    new DLNAOperationsAttribute(DLNAOperations.RANGE));
            dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_CI,
                    new DLNAConversionIndicatorAttribute(DLNAConversionIndicator.NONE));
            dlnaAttributes.put(DLNAAttribute.Type.DLNA_ORG_FLAGS,
                    new DLNAFlagsAttribute(DLNAFlags.STREAMING_TRANSFER_MODE,
                            DLNAFlags.BACKGROUND_TRANSFERT_MODE, DLNAFlags.DLNA_V15));

            resource.setProtocolInfo(new DLNAProtocolInfo(Protocol.HTTP_GET, ProtocolInfo.WILDCARD, "audio/mp3",
                    dlnaAttributes));

            pli.addResource(resource);

        }

        result.add(pli);
    }
    return result;
}

From source file:org.openmeetings.app.ldap.LdapLoginManagement.java

/**
 * Ldap Password Synch to OM DB set active ? defaults to true in case of
 * error so as to keep old behaviour/*w w  w.  j  a  v  a 2  s  .c  o  m*/
 */
public boolean getLdapPwdSynchStatus(Long ldapConfigId) { // TIBO
    // Retrieve Configuration Data
    HashMap<String, String> configData;

    LdapConfig ldapConfig = ldapConfigDao.getLdapConfigById(ldapConfigId);

    try {
        configData = getLdapConfigData(ldapConfig.getConfigFileName());
    } catch (Exception e) {
        log.error("Error on getLdapPwdSynchStatus : " + e.getMessage());
        return true;
    }

    if (configData == null || configData.size() < 1) {
        log.error("Error on getLdapPwdSynchStatus : Configurationdata couldnt be retrieved!");
        return true;
    }

    // Connection URL
    String ldap_synch_passwd_to_om = configData.get(CONFIGKEY_LDAP_SYNC_PASSWD_OM);
    if (ldap_synch_passwd_to_om.equals("no")) {
        log.debug("getLdapPwdSynchStatus: returns FALSE (val=" + ldap_synch_passwd_to_om + ")");
        return false;
    } else {
        log.debug("getLdapPwdSynchStatus: returns TRUE (val=" + ldap_synch_passwd_to_om + ")");
        return true;
    }
}