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:eu.sisob.uma.NPL.Researchers.GateDataExtractorSingle.java

/**
 *
 * @param csv_file//from  w  w w.  j  a v  a 2 s.co m
 * @param cvs_directory
 * @param withSplitter
 * @param verbose
 * @param verbose_dir
 * @return
 */
public static RepositoryPreprocessDataMiddleData createPreprocessRepositoryOfCVsFromTxt(File csv_file,
        File cvs_directory, boolean withSplitter, boolean verbose, File verbose_dir) {
    RepositoryPreprocessDataMiddleData preprocessedRep = new RepositoryPreprocessDataMiddleData();

    String path = csv_file.getParentFile().getAbsolutePath();

    HashMap<String, String> idToCvPath = new HashMap<String, String>();

    HashMap<String, String> id2Toid1 = new HashMap<String, String>();

    if (cvs_directory.exists()) {
        for (File f : cvs_directory.listFiles()) {
            if (f.isFile()) {
                String name = f.getName().substring(0, f.getName().lastIndexOf("."));
                try {
                    Integer.parseInt(name);
                    idToCvPath.put(name, f.getAbsolutePath());
                } catch (Exception ex) {
                    ProjectLogger.LOGGER.error("Not file: " + ex.getMessage());
                }
            }
        }

        FileReader fr;
        CSVReader reader;
        try {
            fr = new FileReader(csv_file);
            reader = new CSVReader(fr, '\t');
            String[] nextLine;
            while ((nextLine = reader.readNext()) != null) {
                String id_researcher_1 = nextLine[0];
                String id_researcher_2 = nextLine[1];

                id2Toid1.put(id_researcher_2, id_researcher_1);
            }
        } catch (FileNotFoundException ex) {
            ProjectLogger.LOGGER.error("Error", ex);
        } catch (IOException ex) {
            ProjectLogger.LOGGER.error("Error", ex);
        }

        for (String id2 : idToCvPath.keySet()) {
            if (id2Toid1.containsKey(id2)) {
                File cv_file = new File(idToCvPath.get(id2));

                boolean document_loaded = false;
                if (cv_file.exists()) {
                    if (withSplitter) {
                        DocumentSplitter spliter = new DocumentSplitter(
                                CVBlocks.getCVBlocksAndKeywords(new File("keywords")));
                        Document doc = null;
                        try {
                            ProjectLogger.LOGGER.info("Opening " + cv_file.getName());
                            doc = gate.Factory.newDocument((cv_file).toURI().toURL());
                            document_loaded = true;
                        } catch (MalformedURLException ex) {
                            ProjectLogger.LOGGER.error("Document not loaded ", ex);
                        } catch (ResourceInstantiationException ex) {
                            ProjectLogger.LOGGER.error("Document not loaded ", ex);
                        } catch (Exception ex) {
                            ProjectLogger.LOGGER.error("Document not loaded ", ex);
                        }

                        if (document_loaded) {
                            List<Entry<String, String>> blocks = spliter
                                    .SplitDocument(doc.getContent().toString());

                            //System.out.println("||||||||||||||||||||||||||||||||||||||||||||||1");
                            //System.out.println(cv_file.getName());
                            //System.out.println("||||||||||||||||||||||||||||||||||||||||||||||1");

                            for (Entry<String, String> block : blocks) {
                                //TESTING                                     
                                //if(block.getKey().equals(""))                                    
                                //    System.out.println("GENERAL");
                                //else
                                //    System.out.println(CVBlocks.CVBLOCK_DESCRIPTIONS[Integer.parseInt(block.getKey())]);

                                //System.out.println("----------------------------------------------");
                                //System.out.println(block.getValue());
                                //System.out.println("----------------------------------------------");

                                if (block.getKey().equals(CVBlocks.CVBLOCK_PROFESSIONAL_ACTIVITY.toString())
                                        || block.getKey().equals(CVBlocks.CVBLOCK_UNIVERSITY_STUDIES.toString())
                                        || block.getKey().equals(CVBlocks.CVBLOCK_PERSONAL.toString())
                                        || block.getKey().equals("")) {
                                    MiddleData aoPreProcessData = new MiddleData(id2Toid1.get(id2),
                                            DataExchangeLiterals.ID_TEXTMININGPARSER_GATERESEARCHER,
                                            DataExchangeLiterals.ID_TEXTMININGPARSER_GATERESEARCHER_DEFAULTANNREC,
                                            block.getValue(), null, verbose, verbose_dir);
                                    //cv_file.getAbsolutePath());                                                      
                                    preprocessedRep.addData(aoPreProcessData);
                                }
                            }
                        }
                    } else {
                        Document doc = null;
                        try {
                            ProjectLogger.LOGGER.info("Opening " + cv_file.getName());
                            doc = gate.Factory.newDocument((cv_file).toURI().toURL());
                            doc.setName(cv_file.getName());
                            document_loaded = true;
                        } catch (MalformedURLException ex) {
                            ProjectLogger.LOGGER.error("Document not loaded ", ex);
                        } catch (ResourceInstantiationException ex) {
                            ProjectLogger.LOGGER.error("Document not loaded ", ex);
                        } catch (Exception ex) {
                            ProjectLogger.LOGGER.error("Document not loaded ", ex);
                        }

                        if (document_loaded) {

                            //String content = doc.getContent().toString().replace("\r\n\r\n", "\r\n");

                            MiddleData aoPreProcessData = new MiddleData(id2Toid1.get(id2),
                                    DataExchangeLiterals.ID_TEXTMININGPARSER_GATERESEARCHER,
                                    DataExchangeLiterals.ID_TEXTMININGPARSER_GATERESEARCHER_DEFAULTANNREC,
                                    doc.getContent().toString(), null, verbose, verbose_dir);
                            preprocessedRep.addData(aoPreProcessData);
                        }
                    }
                }
            }
        }
    }

    return preprocessedRep;
}

From source file:net.dubboclub.reloud.cluster.ReloudShard.java

private void refreshSlaves(List<String> slaveAddresses) {
    HashMap<String, JedisPool> newSlaves = new HashMap<String, JedisPool>();
    //slave// w  w w .j  ava 2 s .c o  m
    for (int i = 1; i < slaveAddresses.size(); i++) {
        if (slaves.containsKey(slaveAddresses.get(i))) {
            newSlaves.put(slaveAddresses.get(i), slaves.get(slaveAddresses.get(i)));
        } else {
            newSlaves.put(slaveAddresses.get(i), createClient(slaveAddresses.get(i)));
        }
    }
    //???slave?slave?
    for (String address : slaves.keySet()) {
        if (!newSlaves.containsKey(address)) {
            slaves.get(address).destroy();
        }
    }
    //slave?slave??
    slaves = newSlaves;
}

From source file:org.mitre.svmp.activities.AppRTCRefreshAppsActivity.java

private void handleAppsResponse(Response response) {
    Log.v(TAG, "Received APPS response");
    SVMPProtocol.AppsResponse appsResponse = response.getApps();
    int connectionID = connectionInfo.getConnectionID();

    // get the existing (outdated) list of apps
    List<AppInfo> oldApps = dbHandler.getAppInfoList_All(connectionID);
    // create a HashMap for looping through
    HashMap<String, AppInfo> oldAppsMap = new HashMap<String, AppInfo>();
    for (AppInfo appInfo : oldApps)
        oldAppsMap.put(appInfo.getPackageName(), appInfo);

    // remove apps that don't exist on the VM anymore
    if (fullRefresh) {
        // if this was a full refresh, delete all existing apps (they will
        // be re-added)
        dbHandler.deleteAllAppInfos(connectionID);
    } else {//from w w w.j  av a2s.c  o  m
        // this was a partial refresh, only delete apps that the VM has
        // specified
        List<String> removedApps = appsResponse.getRemovedList();
        for (String packageName : removedApps) {
            if (oldAppsMap.containsKey(packageName))
                dbHandler.deleteAppInfo(oldAppsMap.get(packageName));
        }
    }

    // loop through the list of new AppInfos that were returned from the VM
    // and add them
    List<SVMPProtocol.AppInfo> newApps = appsResponse.getNewList();
    for (SVMPProtocol.AppInfo appInfo : newApps) {
        String packageName = appInfo.getPkgName(), appName = appInfo.getAppName();
        byte[] icon = appInfo.hasIcon() ? appInfo.getIcon().toByteArray() : null, iconHash = getIconHash(icon);
        AppInfo newAppInfo = new AppInfo(connectionID, packageName, appName, false, icon, iconHash);
        dbHandler.insertAppInfo(newAppInfo);
    }

    // loop through the list of updated AppInfos that were returned from the
    // VM and update them
    List<SVMPProtocol.AppInfo> updatedApps = appsResponse.getUpdatedList();
    for (SVMPProtocol.AppInfo appInfo : updatedApps) {
        String packageName = appInfo.getPkgName(), appName = appInfo.getAppName();
        boolean favorite = oldAppsMap.get(packageName).isFavorite();
        byte[] icon = appInfo.hasIcon() ? appInfo.getIcon().toByteArray() : null, iconHash = getIconHash(icon);
        AppInfo newAppInfo = new AppInfo(connectionID, packageName, appName, favorite, icon, iconHash);
        dbHandler.updateAppInfo(newAppInfo);
    }

    List<AppInfo> appsList = dbHandler.getAppInfoList_All(1);
    if (appsList != null) {

        for (int i = 0; i < appsList.size(); i++) {

            new IconsUrlFetchAsyncTask().execute(appsList.get(i).getPackageName(), i + "",
                    appsList.size() - 1 + "");

        }

    } else {
        Log.v(TAG, "Successfully processed APPS response");
        setResult(SvmpActivity.RESULT_OK);
        disconnectAndExit();
    }
}

From source file:tdunnick.phinmsx.model.Charts.java

/************************ PIE chart ***********************************/

public void getPieChart(DashBoardData dash) {
    ArrayList r = dash.getStats();
    ArrayList categories = new ArrayList();
    HashMap counts = new HashMap();

    if (r == null) {
        logger.severe("Unable to get dashboard statistics");
        return;/* w w  w .j ava 2 s.c  om*/
    }
    // count entries for each category
    for (int i = 0; i < r.size(); i++) {
        String[] item = (String[]) r.get(i);
        if (item == null) {
            logger.severe("Null category from dashboard statistics");
            return;
        }
        int v = 0;
        String k = item[0];
        if (k == null) {
            logger.severe("Null category entry " + i + " from dashboard statistics");
            return;
        }
        if (counts.containsKey(k))
            v = Integer.parseInt((String) counts.get(k));
        else
            categories.add(k);
        counts.put(k, Integer.toString(v + 1));
    }
    DefaultPieDataset dataset = new DefaultPieDataset();
    for (int i = 0; i < categories.size(); i++) {
        String k = categories.get(i).toString();
        dataset.setValue(k, Integer.parseInt(counts.get(k).toString()));
    }
    JFreeChart chart = createPieChart("Summary", dataset);
    dash.setPiechart(getJFreeObject(chart, "pie", 200, 175));
}

From source file:com.krawler.spring.documents.documentDAOImpl.java

public KwlReturnObject getDocuments(HashMap<String, Object> requestParams) throws ServiceException {
    List ll = null;/*from  www .  jav a 2  s. co  m*/
    int dl = 0;
    String recid = "";
    try {
        if (requestParams.containsKey("recid") && requestParams.get("recid") != null) {
            recid = requestParams.get("recid").toString();
        }
        String Hql = "select dm.docid FROM com.krawler.common.admin.Docmap dm where dm.recid=?  and dm.docid.deleteflag=0";
        ll = executeQuery(Hql, new Object[] { recid });
        dl = ll.size();
    } catch (Exception e) {
        throw ServiceException.FAILURE("documentDAOImpl.getDocuments : " + e.getMessage(), e);
    }
    return new KwlReturnObject(true, KWLErrorMsgs.S01, "", ll, dl);
}

From source file:tdunnick.jphineas.console.queue.Charts.java

/************************ PIE chart ***********************************/

public void getPieChart(DashBoardData dash) {
    ArrayList<String[]> r = dash.getStats();
    ArrayList<String> categories = new ArrayList<String>();
    HashMap<String, String> counts = new HashMap<String, String>();

    if (r == null) {
        Log.error("Unable to get dashboard statistics");
        return;//w w  w  . j a v a  2 s  .c o  m
    }
    // count entries for each category
    for (int i = 0; i < r.size(); i++) {
        String[] item = r.get(i);
        if (item == null) {
            Log.error("Null category from dashboard statistics");
            return;
        }
        int v = 0;
        String k = item[0];
        if (k == null) {
            Log.error("Null category entry " + i + " from dashboard statistics");
            return;
        }
        if (counts.containsKey(k))
            v = Integer.parseInt(counts.get(k));
        else
            categories.add(k);
        counts.put(k, Integer.toString(v + 1));
    }
    DefaultPieDataset dataset = new DefaultPieDataset();
    for (int i = 0; i < categories.size(); i++) {
        String k = categories.get(i).toString();
        dataset.setValue(k, Integer.parseInt(counts.get(k)));
    }
    JFreeChart chart = createPieChart("Summary", dataset);
    dash.setPiechart(getJFreeObject(chart, "pie", 200, 175));
}

From source file:it.cnr.icar.eric.server.lcm.versioning.VersionProcessor.java

@SuppressWarnings("static-access")
public boolean needToVersionRegistryObject(RegistryObjectType ro) throws RegistryException {
    boolean needToVersion = true;

    BindingUtility bu = BindingUtility.getInstance();
    boolean newObject = false;

    try {//  w  ww  . j a  v a 2 s  .  c  o m
        needToVersion = isVersionableClass(ro);

        if (needToVersion) {
            HashMap<?, ?> slotsMap;
            // Honour dontVersion flag if specified on request
            if (!context.getRegistryRequestStack().empty()) {
                slotsMap = bu.getSlotsFromRequest(context.getCurrentRegistryRequest());
                if (slotsMap.containsKey(bu.CANONICAL_SLOT_LCM_DONT_VERSION)) {
                    String val = (String) slotsMap.get(bu.CANONICAL_SLOT_LCM_DONT_VERSION);
                    if (val.trim().equalsIgnoreCase("true")) {
                        needToVersion = false;
                    }
                }
            }

            //Honour dontVersion flag if specified on ro
            slotsMap = bu.getSlotsFromRegistryObject(ro);
            if (slotsMap.containsKey(bu.CANONICAL_SLOT_LCM_DONT_VERSION)) {
                String val = (String) slotsMap.get(bu.CANONICAL_SLOT_LCM_DONT_VERSION);
                if (val.trim().equalsIgnoreCase("true")) {
                    needToVersion = false;
                }
            }
        }

        //TODO:
        //Need to investigate case where not versioning and it is a new object.
        //Need unit test for this case.
        if (needToVersion) {
            versions = getAllRegistryObjectVersions(ro);

            if (versions.size() == 0) { // If there are any existing versions (ie. ro's with same LID) then we need to version
                //This is a new ro and therefore need not be versioned
                needToVersion = false;
                newObject = true;
            }
        }

        //Must set versionName to match latest versionName if existing object
        //or set to version 1.1 if new object.
        if (!needToVersion) {
            RegistryObjectType lastVersion = getLatestVersionOfRegistryObject(ro);
            String versionName = null;
            if (lastVersion == null) {
                versionName = "1.1";
            } else {
                versionName = lastVersion.getVersionInfo().getVersionName();

                //Must bump up versionName for new objects
                if (newObject) {
                    versionName = nextVersion(versionName);
                }
            }

            VersionInfoType versionInfo = ro.getVersionInfo();
            if (versionInfo == null) {
                versionInfo = bu.rimFac.createVersionInfoType();
                ro.setVersionInfo(versionInfo);
            }
            versionInfo.setVersionName(versionName);
            if (!context.getRegistryRequestStack().empty()) {
                setVersionInfoComment(versionInfo);
            }
        }
    } catch (JAXBException e) {
        throw new RegistryException(e);
    }

    return needToVersion;
}

From source file:com.sec.ose.osi.report.standard.data.BillOfMaterialsRowGenerator.java

/**
 * key : component name + license name/*from ww w  .  j  a  va  2 s.com*/
 * value : identified file list
 * 
 * @param fileEntList
 * @return
 */
private HashMap<String, ArrayList<IdentifiedFilesRow>> toComponentFileEntHashMap(
        ArrayList<IdentifiedFilesRow> fileEntList) {

    HashMap<String, ArrayList<IdentifiedFilesRow>> hashMap = new HashMap<String, ArrayList<IdentifiedFilesRow>>();

    if (fileEntList == null || fileEntList.size() < 1)
        return hashMap;

    for (IdentifiedFilesRow ent : fileEntList) {
        String componentName = ent.getComponent();
        String licenseName = ent.getLicense();
        if (componentName != null)
            componentName = componentName.trim();
        if (licenseName != null)
            licenseName = licenseName.trim();
        String key = componentName + "#" + licenseName;

        if (hashMap.containsKey(key) == false) {
            ArrayList<IdentifiedFilesRow> fileEntSet = new ArrayList<IdentifiedFilesRow>();
            hashMap.put(key, fileEntSet);
        }
        hashMap.get(key).add(ent);

    }

    return hashMap;
}

From source file:biblivre3.cataloging.bibliographic.BiblioBO.java

public int[] generateLabelsByDate(Date startDate, Date endDate, String base) {
    ArrayList<HoldingDTO> list = new HoldingDAO().getHoldingByDate(expectedFormat.format(startDate),
            expectedFormat.format(endDate), Database.valueOf(base));
    HashMap<Integer, RecordDTO> recordHash = new HashMap<Integer, RecordDTO>();

    int total = list.size();
    int added = 0;

    HoldingBO hbo = new HoldingBO();
    BiblioDAO dao = new BiblioDAO();

    for (int i = 0; i < total; i++) {
        HoldingDTO holdintDto = list.get(i);

        boolean alreadyInList = new HoldingDAO().isLabelPending(holdintDto.getSerial());
        if (alreadyInList) {
            continue;
        }//from  www.  ja  va2  s  .  co m

        RecordDTO record;
        if (recordHash.containsKey(holdintDto.getRecordSerial())) {
            record = recordHash.get(holdintDto.getRecordSerial());
        } else {
            record = dao.getById(holdintDto.getRecordSerial());
            recordHash.put(holdintDto.getRecordSerial(), record);
        }

        if (record != null) {
            if (hbo.generateLabel(holdintDto.getSerial(), holdintDto.getRecordSerial(), record, holdintDto)) {
                added++;
            }
        }
    }

    int result[] = new int[2];
    result[0] = total;
    result[1] = added;

    return result;
}

From source file:jp.primecloud.auto.service.impl.FarmServiceImpl.java

/**
 * {@inheritDoc}//  ww w  .j av a 2  s .c om
 */
@Override
public List<FarmDto> getFarms(Long userNo, Long loginUserNo) {

    //?
    User user = userDao.read(loginUserNo);
    //?
    List<Farm> farms = new ArrayList<Farm>();
    //
    List<FarmDto> dtos = new ArrayList<FarmDto>();

    //?
    if (user.getPowerUser()) {
        farms = farmDao.readAll();
        for (Farm farm : farms) {
            FarmDto dto = new FarmDto();
            dto.setFarm(farm);
            dtos.add(dto);
        }
    }
    //????
    else {
        //??
        farms = farmDao.readByUserNo(userNo);

        //??
        List<UserAuth> userAuth = userAuthDao.readByUserNo(loginUserNo);
        HashMap<Long, Boolean> authMap = new HashMap<Long, Boolean>();
        for (UserAuth auth : userAuth) {
            if (auth.getFarmUse()) {
                authMap.put(auth.getFarmNo(), auth.getFarmUse());
            }
        }

        for (Farm farm : farms) {
            //????? ??
            if ((loginUserNo.equals(userNo)) || authMap.containsKey(farm.getFarmNo())) {
                FarmDto dto = new FarmDto();
                dto.setFarm(farm);
                dtos.add(dto);
            }
        }
    }

    // 
    Collections.sort(dtos, Comparators.COMPARATOR_FARM_DTO);

    return dtos;
}