Example usage for java.util LinkedHashMap keySet

List of usage examples for java.util LinkedHashMap keySet

Introduction

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

Prototype

public Set<K> keySet() 

Source Link

Document

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

Usage

From source file:com.glaf.shiro.SecurityConfig.java

public static void reload() {
    InputStream inputStream = null;
    try {/*  w  w w .j av  a2 s  .  com*/
        loading.set(true);
        String config_path = SystemProperties.getConfigRootPath() + "/conf/security/";
        String defaultFileName = config_path + "system-security.properties";
        File defaultFile = new File(defaultFileName);
        if (defaultFile.isFile()) {
            inputStream = new FileInputStream(defaultFile);
            LinkedHashMap<String, String> p = PropertiesUtils.load(inputStream);
            if (p != null) {
                Iterator<String> it = p.keySet().iterator();
                while (it.hasNext()) {
                    String key = it.next();
                    String value = p.get(key);
                    /**
                     * ?????????
                     */
                    if (!filterChainDefinitionMap.containsKey(key)) {
                        filterChainDefinitionMap.put(key, value);
                    }
                }
            }
            IOUtils.closeQuietly(inputStream);
            inputStream = null;
        }
        File directory = new File(config_path);
        if (directory.isDirectory()) {
            String[] filelist = directory.list();
            for (int i = 0; i < filelist.length; i++) {
                String filename = config_path + filelist[i];
                if (StringUtils.equals(filename, "system-security.properties")) {
                    continue;
                }
                File file = new File(filename);
                if (file.isFile() && file.getName().endsWith(".properties")) {
                    inputStream = new FileInputStream(file);
                    LinkedHashMap<String, String> p = PropertiesUtils.load(inputStream);
                    if (p != null) {
                        Iterator<String> it = p.keySet().iterator();
                        while (it.hasNext()) {
                            String key = it.next();
                            String value = p.get(key);
                            /**
                             * ?????????
                             */
                            if (!filterChainDefinitionMap.containsKey(key)) {
                                filterChainDefinitionMap.put(key, value);
                            }
                        }
                    }
                    IOUtils.closeQuietly(inputStream);
                    inputStream = null;
                }
            }
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        loading.set(false);
        IOUtils.closeQuietly(inputStream);
    }
}

From source file:gr.demokritos.iit.cru.creativity.reasoning.semantic.WebMiner.java

public static String WebMiner(String seed, int difficulty, String language, boolean compactForm)
        throws ClassNotFoundException, SQLException, IOException, InstantiationException,
        IllegalAccessException {/*from  w  w w  . ja v a 2  s  .  c o m*/
    Gson gson = new Gson();
    Connect c = new Connect(language);
    RandomWordGenerator r = new RandomWordGenerator(c);
    String randomPhrase = r.selectRandomWord(seed, difficulty).replace(",", " ");
    InfoSummarization inf = new InfoSummarization(c);
    LinkedHashMap<String, Double> TagCloud = new LinkedHashMap<String, Double>();

    Set<String> pages = new HashSet<String>();
    ArrayList<String> urls = new ArrayList<String>();
    ArrayList<String> urls_temp = new ArrayList<String>();
    if (language.equalsIgnoreCase("en")) {
        if (randomPhrase.length() == 0) {
            randomPhrase = seed;
        }
        String bingAppId = c.getBingAppId();
        BingCrawler bc = new BingCrawler(bingAppId, language);
        urls_temp = bc.crawl(randomPhrase);
        int url_loop = 0;
        while ((url_loop < 5) && (url_loop < urls_temp.size())) {
            urls.add(urls_temp.get(url_loop));
            url_loop++;
        }
    } else if (language.equalsIgnoreCase("el")) {
        String bingAppId = c.getBingAppId();
        BingCrawler bc = new BingCrawler(bingAppId, language);
        urls_temp = bc.crawl(randomPhrase);
        int url_loop = 0;
        while ((url_loop < 5) && (url_loop < urls_temp.size())) {
            urls.add(urls_temp.get(url_loop));
            url_loop++;
        }
    } else if (language.equalsIgnoreCase("de")) {//keep only the first word of the random phrase for search
        if (randomPhrase.length() == 0) {
            randomPhrase = seed;
        }
        urls_temp = HTMLUtilities.linkExtractor(
                "http://www.fragfinn.de/kinderliste/suche?start=0&query=" + randomPhrase.split(" ")[0], "UTF-8",
                0);

        for (String url : urls_temp) {
            urls.add(StringEscapeUtils.unescapeHtml4(url));
            if (urls.size() == 5) {
                break;
            }
        }
    }
    String delims = "[{} .,;?!():\"]+";

    String[] words = randomPhrase.split(",");
    String[] user_keywords = seed.split(delims);
    if (urls.size() > 0) {
        ExecutorService threadPool = Executors.newFixedThreadPool(urls.size());
        for (String url : urls) {
            threadPool.submit(new HTMLPages(url, pages, language)); //stopWordSet, tokensHashMap,language));
            // threadPool.submit(HTMLTokenizer());
        }
        threadPool.shutdown();
        while (!threadPool.isTerminated()) {

        }

        LinkedHashMap<ArrayList<String>, Double> temp = inf.TopTermsBing(pages, compactForm);
        HashMap<String, Double> temp2 = new HashMap<String, Double>();
        for (ArrayList<String> stems : temp.keySet()) {
            for (int j = 0; j < stems.size(); j++) {
                String s = stems.get(j).split("\\{")[0];
                s = s.replace(",", " ");
                s = s.trim();

                boolean wordnet = true;
                //if term is not one of the initial random phrase
                for (int i = 0; i < words.length; i++) {
                    if (s.equalsIgnoreCase(words[i])) {
                        wordnet = false;
                    }
                }
                //and if it 's not in the initial words of user
                for (int i = 0; i < user_keywords.length; i++) {
                    if (s.equalsIgnoreCase(user_keywords[i])) {
                        wordnet = false;
                    }
                }
                //in german or greek, ignore english words from search english words
                if (language.equalsIgnoreCase("de") || language.equalsIgnoreCase("el")) {
                    if (c.getWn().getCommonPos(s) != null) {
                        continue;
                    }
                }
                //return it with its stem's weight
                if (wordnet) {
                    //for every stem, put each of its corresponding terms to tagCloud with the stem's tf
                    temp2.put(stems.get(j), temp.get(stems));
                }
            }
        }
        TagCloud = inf.sortHashMapByValues(temp2);
        threadPool.shutdownNow();
    }
    String json = gson.toJson(TagCloud);
    c.CloseConnection();
    return json;
}

From source file:com.app.model.m3.M3ConfigModel.java

public static List<String> formatUIConfig(LinkedHashMap<String, M3ConfigurationInfo> conf) {
    ArrayList<String> l = new ArrayList<>();
    if (conf != null) {
        for (String c : conf.keySet()) {
            l.add(conf.get(c).getName() + " (" + conf.get(c).getDescription() + ")");
        }//  w w  w  .ja  va2 s  .co m
    }
    return l;
}

From source file:com.mycomm.dao.mydao.base.MyDaoSupport.java

/**
 * order by?//from ww w . ja v a  2s . c  o  m
 *
 * @param orderby
 * @return
 */
protected static String buildOrderby(LinkedHashMap<String, String> orderby) {
    StringBuffer orderbyql = new StringBuffer("");
    if (orderby != null && orderby.size() > 0) {
        orderbyql.append(" order by ");
        for (String key : orderby.keySet()) {
            orderbyql.append("o.").append(key).append(" ").append(orderby.get(key)).append(",");
        }
        orderbyql.deleteCharAt(orderbyql.length() - 1);
    }
    return orderbyql.toString();
}

From source file:PerformanceGraph.java

/**
 * Plots the performance graph of the best fitness value so far versus the
 * number of function calls (NFC)./*from w  w w .  ja  va2  s. c  o m*/
 * 
 * @param bestFitness A linked hashmap mapping the NFC to the best fitness value
 * found so far.
 * @param fitnessFunction The name of the fitness function, used for the title and the
 * name of the file that is saved, e.g. "De Jong".
 */
public static void plot(LinkedHashMap<Integer, Double> bestFitness, String fitnessFunction) {
    /* Create an XYSeries plot */
    XYSeries series = new XYSeries("Best Fitness Value Vs. Number of Function Calls");

    /* Add the NFC and best fitness value data to the series */
    for (Integer NFC : bestFitness.keySet()) {
        /* Jfreechart crashes if double values are too large! */
        if (bestFitness.get(NFC) <= 10E12) {
            series.add(NFC.doubleValue(), bestFitness.get(NFC).doubleValue());
        }
    }

    /* Add the x,y series data to the dataset */
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);

    /* Plot the data as an X,Y line chart */
    JFreeChart chart = ChartFactory.createXYLineChart("Best Fitness Value Vs. Number of Function Calls",
            "Number of Function Calls (NFC)", "Best Fitness Value", dataset, PlotOrientation.VERTICAL, false,
            true, false);

    /* Configure the chart settings such as anti-aliasing, background colour */
    chart.setAntiAlias(true);

    XYPlot plot = chart.getXYPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);
    plot.setDomainGridlinePaint(Color.black);

    /* Set the domain range from 0 to NFC */
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setRange(0.0, ControlVariables.MAX_FUNCTION_CALLS.doubleValue());

    /* Logarithmic range axis */
    plot.setRangeAxis(new LogAxis());

    /* Set the thickness and colour of the lines */
    XYItemRenderer renderer = plot.getRenderer();
    BasicStroke thickLine = new BasicStroke(3.0f);
    renderer.setSeriesStroke(0, thickLine);
    renderer.setPaint(Color.BLACK);

    /* Display the plot in a JFrame */
    ChartFrame frame = new ChartFrame(fitnessFunction + " Best Fitness Value", chart);
    frame.setVisible(true);
    frame.setSize(1000, 600);

    /* Save the plot as an image named after fitness function
    try
    {
       ChartUtilities.saveChartAsJPEG(new File("plots/" + fitnessFunction + ".jpg"), chart, 1600, 900);
    }
    catch (IOException e)
    {
       e.printStackTrace();
    }*/
}

From source file:com.projity.field.Select.java

public static String toConfigurationXMLOptions(LinkedHashMap map, String keyPrefix) {
    // MapIterator i = map.i();
    Iterator i = map.keySet().iterator();
    StringBuffer buf = new StringBuffer();
    HashSet duplicateSet = new HashSet(); // don't allow duplicate keys
    while (i.hasNext()) {
        String key = (String) i.next();
        // notion of key and value is switched
        String value = (String) map.get(key);
        int dupCount = 2;
        String newKey = key;//from   w  w w .j av  a  2s. c o m
        while (duplicateSet.contains(newKey)) {
            newKey = key + "-" + dupCount++;
        }
        key = newKey;
        duplicateSet.add(key);
        if (key == null || key.length() == 0)
            continue;
        if (value == null || value.length() == 0)
            continue;
        key = keyPrefix + key;
        // String key = "<html>" + keyPrefix + ": " + "<b>" + i.getValue()
        // +"</b></html>";
        buf.append(SelectOption.toConfigurationXML(key, value));
    }
    return buf.toString();
}

From source file:org.coocood.vcontentprovider.VContentProvider.java

private static void addOperations(ArrayList<ContentProviderOperation> operations, Uri uri, Uri baseUri,
        JSONObject json, LinkedHashMap<String, String> subJSONObjectMap) throws JSONException {
    if (subJSONObjectMap != null) {
        for (String key : subJSONObjectMap.keySet()) {
            JSONObject subJson = json.getJSONObject(key);
            String subTable = subJSONObjectMap.get(key);
            operations.add(getOperation(baseUri, subJson, subTable));
        }/*w w w. j  ava2s  .c o  m*/
    }
    String table = getTableName(uri);
    operations.add(getOperation(baseUri, json, table));
}

From source file:com.geewhiz.pacify.utils.ArchiveUtils.java

public static void replaceFilesInArchives(List<PFile> replacePFiles) {
    // for performance, get all pfiles of the same archive
    Map<PArchive, List<PFile>> pFilesToReplace = getPFilesToReplace(replacePFiles);

    // replace the pfiles
    for (PArchive pArchive : pFilesToReplace.keySet()) {
        List<PFile> pFiles = pFilesToReplace.get(pArchive);
        replacePFilesInArchive(pArchive, pFiles);
        for (PFile toDelete : pFiles) {
            // delete the temporary extracted file
            toDelete.getFile().delete();
        }/*from  www . j a v a 2 s  .  c  o m*/
    }

    // if we have an archive in archive, replace it. Order is relevant, so we use a LinkedHashMap pfile -> parchive3 -> parchive2 -> parchive1
    LinkedHashMap<PArchive, List<PArchive>> parentArchives = getParentArchives(replacePFiles);

    // replace the archives within the parent archive
    for (PArchive parentArchive : parentArchives.keySet()) {
        List<PArchive> pArchives = parentArchives.get(parentArchive);
        replacePArchivesInArchive(parentArchive, pArchives);
        for (PArchive pArchive : pArchives) {
            // delete the temporary extracted file
            pArchive.getFile().delete();
        }
    }
}

From source file:com.act.lcms.db.analysis.StandardIonAnalysis.java

/**
 * This function gets all the best time windows from spectra in water and meoh media, so that they can analyzed
 * by the yeast media samples for snr analysis.
 * @param waterAndMeohSpectra A list of ions to best XZ value.
 * @return A map of ion to list of restricted time windows.
 *//*from   w  w w  . j a  va 2 s . c o m*/
public static Map<String, List<Double>> getRestrictedTimeWindowsForIonsFromWaterAndMeOHMedia(
        List<LinkedHashMap<String, XZ>> waterAndMeohSpectra) {

    Map<String, List<Double>> ionToRestrictedTimeWindows = new HashMap<>();

    for (LinkedHashMap<String, XZ> entry : waterAndMeohSpectra) {
        for (String ion : entry.keySet()) {
            List<Double> restrictedTimes = ionToRestrictedTimeWindows.get(ion);
            if (restrictedTimes == null) {
                restrictedTimes = new ArrayList<>();
                ionToRestrictedTimeWindows.put(ion, restrictedTimes);
            }
            Double timeValue = entry.get(ion).getTime();
            restrictedTimes.add(timeValue);
        }
    }

    return ionToRestrictedTimeWindows;
}

From source file:com.qwarz.graph.process.GraphProcess.java

public static void createUpdateNodes(GraphBase base, LinkedHashMap<String, GraphNode> nodes, Boolean upsert)
        throws IOException, URISyntaxException, ServerException {
    if (nodes == null || nodes.isEmpty())
        return;// w w w  .j  a  va 2 s .  c o m
    GraphProcessInterface graphImpl = getImplementation(base.data);
    if (upsert != null && upsert) {
        // If the nodes already exists, we merge them
        Map<String, GraphNode> dbNodes = graphImpl.getNodes(base, nodes.keySet());
        if (dbNodes != null) {
            for (Map.Entry<String, GraphNode> entry : nodes.entrySet()) {
                GraphNode dbNode = dbNodes.get(entry.getKey().intern());
                if (dbNode != null)
                    entry.getValue().add(dbNode);
            }
        }
    }
    graphImpl.createUpdateNodes(base, nodes);
}