久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何獲取壓縮文件(通過索引)并重新創(chuàng)建原始文件

How do I take a compressed file (through indexes) and re-create the original file? (Java)(如何獲取壓縮文件(通過索引)并重新創(chuàng)建原始文件?(爪哇))
本文介紹了如何獲取壓縮文件(通過索引)并重新創(chuàng)建原始文件?(爪哇)的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

問題背景

我一直在開發(fā)一些代碼,首先關(guān)注的是讀取字符串和創(chuàng)建文件.其次,將字符串拆分為數(shù)組.然后獲取數(shù)組中每個(gè)單詞的索引,最后刪除重復(fù)項(xiàng)并將其打印到不同的文件中.我目前已經(jīng)為此制作了代碼,這是一個(gè)鏈接 https://pastebin.com/gqWH0x0 (有一個(gè)菜單系統(tǒng))但它相當(dāng)長,所以我沒有在這個(gè)問題中實(shí)現(xiàn)它.

I have been developing some code that focuses on firstly, reading a string and creating a file. Secondly, spliting a string into an array. Then getting the indexes for each word in the array and finally, removing the duplicates and printing it to a different file. I currently have made the code for this here is a link https://pastebin.com/gqWH0x0 (there is a menu system as well) but it is rather long so I have refrained from implementing it in this question.

壓縮方法是通過 hashmaps 完成的,獲取數(shù)組的索引并將它們映射到相關(guān)的單詞.這是一個(gè)例子:

The compression method is done via hashmaps, getting indexes of the array and mapping them to the relevant word. Here is an example:

原文:《海見海見海見》

Original: "sea sea see sea see see"

輸出:見[2, 4, 5],sea[0, 1, 3],

Output: see[2, 4, 5],sea[0, 1, 3],

問題

下一階段是將輸出恢復(fù)到原始狀態(tài).我目前對 java 比較陌生,所以我不知道所需的技術(shù).代碼應(yīng)該能夠獲取輸出文件(如上所示)并將其放回原始文件.

The next stage is getting the output back into the original state. I am currently relatively new to java so I am not aware of the techniques required. The code should be able to take the output file (shown above) and put it back into the original.

我目前的想法是您只需重寫此哈希圖(如下).我這樣想對嗎?我想我應(yīng)該先檢查堆棧溢出!

My current thinking is that you would just rewrite this hashmap (below). Would I be correct in thinking this? I thought I should check with stack overflow first!

Map<String, Set<Integer>> seaMap = new HashMap<>(); //new hashmap
                    for (int seaInt = 0; seaInt < sealist.length; seaInt++) {
                        if (seaMap.keySet().contains(sealist[seaInt])) {
                            Set<Integer> index = seaMap.get(sealist[seaInt]);
                            index.add(seaInt);
                        } else {
                            Set<Integer> index = new HashSet<>();
                            index.add(seaInt);
                            seaMap.put(sealist[seaInt], index);
                        }                
                    }
                    System.out.print("Compressed: ");
                    seaMap.forEach((seawords, seavalues) -> System.out.print(seawords + seavalues + ","));
                    System.out.println("
");

如果有人有任何好的想法/答案,請告訴我,我真的很渴望解決方案!

If anyone has any good ideas / answers then please let me know, I am really desperate for a solution!

鏈接到當(dāng)前代碼:https://pastebin.com/gqWH0x0K

推薦答案

首先,您必須使用您的示例將帶有索引的單詞與壓縮行分開:

first you will have to separate the words with index(es) from your compressed line, using your example:

"see[2, 4, 5],sea[0, 1, 3],"

獲取以下字符串:

"see[2, 4, 5]" and "sea[0, 1, 3]"

對于每個(gè)您必須閱讀的索引,例如首先:

for each you must read the indexes, e.g. for first:

2, 4 and 5

現(xiàn)在只需在給定索引處的 ArrayList(或數(shù)組)中寫入單詞.

now just write the word in an ArrayList (or array) at the given index.

對于前兩個(gè)步驟,您可以使用正則表達(dá)式來查找每個(gè)單詞和索引列表.然后使用 String.split 和 Integer.parseInt 獲取所有索引.

For the first two steps you can use a regular expression to find each word and the index list. Then use String.split and Integer.parseInt to get all indexes.

Pattern pattern = Pattern.compile("(.*?)\[(.*?)\],");
String line = "see[2, 4, 5],sea[0, 1, 3],";
Matcher matcher = pattern.matcher(line);
while (matcher.find()) {
    String word = matcher.group(1);
    String[] indexes = matcher.group(2).split(", ");
    for (String str : indexes) {
        int index = Integer.parseInt(str);

現(xiàn)在只需檢查結(jié)果列表是否足夠大并將單詞設(shè)置在找到的索引處.

Now just check that the result List is big enough and set the word at the found indexes.

這篇關(guān)于如何獲取壓縮文件(通過索引)并重新創(chuàng)建原始文件?(爪哇)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Couchbase Bucket authentication error(Couchbase 存儲桶身份驗(yàn)證錯(cuò)誤)
How to setup SDK in IntelliJ IDEA?(如何在 IntelliJ IDEA 中設(shè)置 SDK?)
error importing com.google.android.gms.*;(導(dǎo)入 com.google.android.gms.* 時(shí)出錯(cuò);)
Cannot list image publishers from Azure java SDK(無法從 Azure java SDK 列出圖像發(fā)布者)
How do I know that the Soundpool is ready using SDK target below 2.2?(我如何知道 Soundpool 已準(zhǔn)備好使用低于 2.2 的 SDK 目標(biāo)?)
What is #39;savedInstanceState#39;?(什么是“已保存實(shí)例狀態(tài)?)
主站蜘蛛池模板: 久久久久久久久久久久久久国产 | 亚洲高清在线 | 国产视频二区在线观看 | 天天操伊人 | 亚洲国产精品精华素 | 午夜小视频免费观看 | 欧美视频一区二区三区 | 欧美日韩在线精品 | 国产成年人视频 | 精品国产乱码久久久久久中文 | av网址在线播放 | 最近日韩中文字幕 | 久久蜜桃av一区二区天堂 | 操人网| 自拍视频网| 91 在线| 中文日韩字幕 | 美女福利视频网站 | 国产一级片在线观看视频 | 日韩成人在线电影 | 亚洲欧洲精品在线 | 国精产品一区二区三区 | 激情一区二区三区 | 先锋av资源在线 | 成人免费视频在线观看 | 中文字幕在线免费 | 精品福利在线 | 欧美日韩亚洲国产 | 99精品国产一区二区青青牛奶 | 成人国产精品免费观看 | 99re视频这里只有精品 | 国产精品成人一区 | 久久国产精品亚洲 | 伊人啪啪网 | 天天av天天好逼 | 亚洲精品一区二区 | 91精品国产综合久久久动漫日韩 | 亚洲成人久久久 | 久久lu| 亚洲午夜视频 | 中文字幕日韩一区 |