Example usage for java.util LinkedHashMap LinkedHashMap

List of usage examples for java.util LinkedHashMap LinkedHashMap

Introduction

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

Prototype

public LinkedHashMap() 

Source Link

Document

Constructs an empty insertion-ordered LinkedHashMap instance with the default initial capacity (16) and load factor (0.75).

Usage

From source file:com.perceptive.epm.perkolcentral.dataaccessor.ImageNowLicenseDataAccessor.java

public LinkedHashMap<String, Imagenowlicenses> getAllImageNowLicenses() throws ExceptionWrapper {
    LinkedHashMap<String, Imagenowlicenses> imagenowlicensesLinkedHashMap = new LinkedHashMap<String, Imagenowlicenses>();
    try {//from  ww w. j  av a  2 s .  c o  m
        DetachedCriteria criteria = DetachedCriteria.forClass(Imagenowlicenses.class);
        criteria.createAlias("employeeByRequestedByEmployeeId", "emp");
        criteria.createAlias("groups", "group");
        criteria.addOrder(Order.asc("licenseRequestedOn"));
        criteria.setFetchMode("emp", FetchMode.JOIN);
        criteria.setFetchMode("group", FetchMode.JOIN);
        criteria.addOrder(Order.asc("licenseRequestedOn"));
        for (Object item : hibernateTemplate.findByCriteria(criteria)) {
            Imagenowlicenses imagenowlicenses = (Imagenowlicenses) item;
            imagenowlicensesLinkedHashMap.put(imagenowlicenses.getImageNowLicenseRequestId(), imagenowlicenses);
        }
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
    return imagenowlicensesLinkedHashMap;
}

From source file:org.kitodo.data.index.elasticsearch.type.ProjectType.java

@SuppressWarnings("unchecked")
@Override//from w  ww . j  a  va 2 s . c  o  m
public HttpEntity createDocument(Project project) {

    LinkedHashMap<String, String> orderedProjectMap = new LinkedHashMap<>();
    orderedProjectMap.put("name", project.getTitle());
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String startDate = project.getStartDate() != null ? dateFormat.format(project.getStartDate()) : null;
    orderedProjectMap.put("startDate", startDate);
    String endDate = project.getEndDate() != null ? dateFormat.format(project.getEndDate()) : null;
    orderedProjectMap.put("endDate", endDate);
    String numberOfPages = project.getNumberOfPages() != null ? project.getNumberOfPages().toString() : "null";
    orderedProjectMap.put("numberOfPages", numberOfPages);
    String numberOfVolumes = project.getNumberOfVolumes() != null ? project.getNumberOfVolumes().toString()
            : "null";
    orderedProjectMap.put("numberOfVolumes", numberOfVolumes);
    String archived = project.getProjectIsArchived() != null ? project.getProjectIsArchived().toString()
            : "null";
    orderedProjectMap.put("archived", archived);

    JSONObject projectObject = new JSONObject(orderedProjectMap);

    JSONArray processes = new JSONArray();
    List<Process> projectProcesses = project.getProcesses();
    for (Process process : projectProcesses) {
        JSONObject processObject = new JSONObject();
        processObject.put("id", process.getId().toString());
        processes.add(processObject);
    }
    projectObject.put("processes", processes);

    JSONArray users = new JSONArray();
    List<User> projectUsers = project.getUsers();
    for (User user : projectUsers) {
        JSONObject userObject = new JSONObject();
        userObject.put("id", user.getId().toString());
        users.add(userObject);
    }
    projectObject.put("users", users);

    JSONArray projectFileGroups = new JSONArray();
    List<ProjectFileGroup> projectProjectFileGroups = project.getProjectFileGroups();
    for (ProjectFileGroup projectFileGroup : projectProjectFileGroups) {
        JSONObject projectFileGroupObject = new JSONObject();
        projectFileGroupObject.put("name", projectFileGroup.getName());
        projectFileGroupObject.put("path", projectFileGroup.getPath());
        projectFileGroupObject.put("mimeType", projectFileGroup.getMimeType());
        projectFileGroupObject.put("suffix", projectFileGroup.getSuffix());
        projectFileGroupObject.put("folder", projectFileGroup.getFolder());
        projectFileGroups.add(projectFileGroupObject);
    }
    projectObject.put("projectFileGroups", projectFileGroups);

    return new NStringEntity(projectObject.toJSONString(), ContentType.APPLICATION_JSON);
}

From source file:org.kitodo.data.index.elasticsearch.type.TaskType.java

@SuppressWarnings("unchecked")
@Override//  www  .  j  av  a 2s .  com
public HttpEntity createDocument(Task task) {

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    LinkedHashMap<String, String> orderedTaskMap = new LinkedHashMap<>();
    orderedTaskMap.put("title", task.getTitle());
    String priority = task.getPriority() != null ? task.getPriority().toString() : "null";
    orderedTaskMap.put("priority", priority);
    String ordering = task.getOrdering() != null ? task.getOrdering().toString() : "null";
    orderedTaskMap.put("ordering", ordering);
    String processingStatus = task.getProcessingStatusEnum() != null ? task.getProcessingStatusEnum().toString()
            : "null";
    orderedTaskMap.put("processingStatus", processingStatus);
    String processingTime = task.getProcessingTime() != null ? dateFormat.format(task.getProcessingTime())
            : null;
    orderedTaskMap.put("processingTime", processingTime);
    String processingBegin = task.getProcessingBegin() != null ? dateFormat.format(task.getProcessingBegin())
            : null;
    orderedTaskMap.put("processingBegin", processingBegin);
    String processingEnd = task.getProcessingEnd() != null ? dateFormat.format(task.getProcessingEnd()) : null;
    orderedTaskMap.put("processingEnd", processingEnd);
    orderedTaskMap.put("homeDirectory", String.valueOf(task.getHomeDirectory()));
    orderedTaskMap.put("typeMetadata", String.valueOf(task.isTypeMetadata()));
    orderedTaskMap.put("typeAutomatic", String.valueOf(task.isTypeAutomatic()));
    orderedTaskMap.put("typeImportFileUpload", String.valueOf(task.isTypeImportFileUpload()));
    orderedTaskMap.put("typeExportRussian", String.valueOf(task.isTypeExportRussian()));
    orderedTaskMap.put("typeImagesRead", String.valueOf(task.isTypeImagesRead()));
    orderedTaskMap.put("typeImagesWrite", String.valueOf(task.isTypeImagesWrite()));
    orderedTaskMap.put("batchStep", String.valueOf(task.isBatchStep()));
    String processingUser = task.getProcessingUser() != null ? task.getProcessingUser().getId().toString()
            : "null";
    orderedTaskMap.put("processingUser", processingUser);
    String process = task.getProcess() != null ? task.getProcess().getId().toString() : "null";
    orderedTaskMap.put("process", process);

    JSONObject taskObject = new JSONObject(orderedTaskMap);

    JSONArray users = new JSONArray();
    List<User> taskUsers = task.getUsers();
    for (User user : taskUsers) {
        JSONObject propertyObject = new JSONObject();
        propertyObject.put("id", user.getId());
        users.add(propertyObject);
    }
    taskObject.put("users", users);

    JSONArray userGroups = new JSONArray();
    List<UserGroup> taskUserGroups = task.getUserGroups();
    for (UserGroup userGroup : taskUserGroups) {
        JSONObject userGroupObject = new JSONObject();
        userGroupObject.put("id", userGroup.getId().toString());
        userGroups.add(userGroupObject);
    }
    taskObject.put("userGroups", userGroups);

    return new NStringEntity(taskObject.toJSONString(), ContentType.APPLICATION_JSON);
}

From source file:TwitterClustering.java

public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
    Map<K, V> result = new LinkedHashMap<>();
    Stream<Map.Entry<K, V>> st = map.entrySet().stream();

    st.sorted(Comparator.comparing(e -> e.getValue())).forEach(e -> result.put(e.getKey(), e.getValue()));

    return result;
}

From source file:Main.java

/**
 * <p>/*from ww  w.  j ava 2  s .  c o  m*/
 * Returns a {@code Map} that keep the orders of its keys.
 * </p>
 *
 * @param <K> the type of the key
 * @param <V> the type of the value
 * @return the map
 */
public static <K, V> Map<K, V> orderedKeyMap() {
    return new LinkedHashMap<K, V>();
}

From source file:Main.java

/**
 * Splits the query parameters into key value pairs.
 * See: http://stackoverflow.com/a/13592567/534471.
 */// w ww  .  ja  v a 2s  .com
private static Map<String, List<String>> splitQuery(Uri uri) throws UnsupportedEncodingException {
    final Map<String, List<String>> query_pairs = new LinkedHashMap<>();
    String query = uri.getQuery();
    if (query == null)
        return query_pairs;

    final String[] pairs = query.split("&");
    for (String pair : pairs) {
        final int idx = pair.indexOf("=");
        final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), "UTF-8") : pair;
        if (!query_pairs.containsKey(key)) {
            query_pairs.put(key, new LinkedList<String>());
        }
        final String value = idx > 0 && pair.length() > idx + 1
                ? URLDecoder.decode(pair.substring(idx + 1), "UTF-8")
                : "";
        query_pairs.get(key).add(value);
    }
    return query_pairs;
}

From source file:com.iisigroup.cap.log.LogContext.java

/**
 * Get a map containing all the objects held by the current thread.
 *///from w  ww  . j av a  2 s .  co  m
private static Map getContext() {
    if (useMDC) {
        return org.apache.log4j.MDC.getContext();
    } else {
        Map m = logContext.get();
        if (m == null) {
            m = new LinkedHashMap();
            logContext.set(m);
        }
        return m;
    }
}

From source file:controllers.FASTCOProxy.java

public static F.Promise<Result> index(String query) {

    if (StringUtils.isEmpty(query)) {

        F.Promise.promise(new F.Function0<Object>() {
            @Override/*from w w  w.ja  va2 s  .  c  o  m*/
            public Object apply() throws Throwable {
                return ok(Json.toJson("Query parameter (q) not provided "));
            }

        });
    }

    String basicUrl = "http://www.fastcodesign.com/api/v1/search";

    // Additional query parameters
    String paged = "0";
    int limit = 10;

    F.Promise<WSResponse> wsResponsePromise = WS.url(basicUrl).setQueryParameter("q", query)
            .setQueryParameter("paged", paged).setQueryParameter("limit", Integer.toString(limit)).get();

    return wsResponsePromise.map(new F.Function<WSResponse, Result>() {
        @Override
        public Result apply(WSResponse wsResponse) throws Throwable {

            String body = wsResponse.getBody();
            List<Map<String, String>> results = new ArrayList<Map<String, String>>();

            try {

                JSONObject initialBody = new JSONObject(body);
                JSONArray resultArray = (JSONArray) initialBody.get("items");

                for (int i = 0; i < resultArray.length(); i++) {

                    Map<String, String> keyValue = new LinkedHashMap<String, String>();

                    JSONObject element = (JSONObject) resultArray.get(i);

                    // Get title
                    keyValue.put("title", element.get("title").toString());

                    // Get content
                    keyValue.put("content", element.get("deck").toString());

                    // Get date
                    element = (JSONObject) resultArray.get(i);
                    element = (JSONObject) element.get("date");
                    element = (JSONObject) element.get("updated");

                    keyValue.put("date", element.get("long").toString());

                    // Get url
                    element = (JSONObject) resultArray.get(i);

                    keyValue.put("url", "www." + element.get("url").toString().substring(2));

                    results.add(keyValue);
                }
            } catch (DOMException e) {
                e.printStackTrace();
            }

            return ok(Json.toJson(results));
        }
    });
}

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  ww . j a  v  a2  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;
}