所有我的大學筆記JSON格式,當我得到一組的實際問題,從一個PDF它的格式是這樣的:轉換純文本與VIM特定的格式轉換成JSON
1. Download and compile the code. Run the example to get an understanding of how it works. (Note that both threads write to the standard output, and so there is some mixing up of the two conceptual streams, but this is an interface issue, not of concern in this course.) 2. Explore the classes SumTask and StringTask as well as the abstract class Task. 3. Modify StringTask.java so that it also writes out 「Executing a StringTask task」 when the execute() method is called. 4. Create a new subclass of Task called ProdTask that prints out the product of a small array of int. (You will have to add another option in TaskGenerationThread.java to allow the user to generate a ProdTask for the queue.) Note: you might notice strange behaviour with a naïve implementation of this and an array of int that is larger than 7 items with numbers varying between 0 (inclusive) and 20 (exclusive); see ProdTask.java in the answer for a discussion. 5. Play with the behaviour of the processing thread so that it polls more frequently and a larger number of times, but 「pop()」s off only the first task in the queue and executes it. 6. Remove the 「taskType」 member variable definition from the abstract Task class. Then add statements such as the following to the SumTask class definition: private static final String taskType = "SumTask"; Investigate what 「static」 and 「final」 mean. 7. More challenging: write an interface and modify the SumTask, StringTask and ProdTask classes so that they implement this interface. Here’s an example interface:
我會喜歡做的是將它複製到vim和執行的查找和替換將其轉換成這樣:
"1": {
"Task": "Download and compile the code. Run the example to get an understanding of how it works. (Note that both threads write to the standard output, and so there is some mixing up of the two conceptual streams, but this is an interface issue, not of concern in this course.)",
"Solution": ""
},
"2": {
"Task": "Explore the classes SumTask and StringTask as well as the abstract class Task.",
"Solution": ""
},
"3": {
"Task": "Modify StringTask.java so that it also writes out 「Executing a StringTask task」 when the execute() method is called.",
"Solution": ""
},
"4": {
"Task": "Create a new subclass of Task called ProdTask that prints out the product of a small array of int. (You will have to add another option in TaskGenerationThread.java to allow the user to generate a ProdTask for the queue.) Note: you might notice strange behaviour with a naïve implementation of this and an array of int that is larger than 7 items with numbers varying between 0 (inclusive) and 20 (exclusive); see ProdTask.java in the answer for a discussion.",
"Solution": ""
},
"5": {
"Task": "Play with the behaviour of the processing thread so that it polls more frequently and a larger number of times, but 「pop()」s off only the first task in the queue and executes it.",
"Solution": ""
},
"6": {
"Task": "Remove the 「taskType」 member variable definition from the abstract Task class. Then add statements such as the following to the SumTask class definition: private static final String taskType = 'SumTask'; Investigate what 「static」 and 「final」 mean.",
"Solution": ""
},
"7": {
"Task": "More challenging: write an interface and modify the SumTask, StringTask and ProdTask classes so that they implement this interface. Here’s an example interface:",
"Solution": ""
}
試圖在實際(而不是實際做實用)算出這個之後,這是我得到的最接近:
%s/\([1-9][1-9]*\)\. \(\_.\{-}\)--end--/"\1": {\r "Task": "\2",\r"Solution": "" \r},/g
的3個問題與此有
- 我要--end--添加到每個問題的結束。我希望通過展望以[1-9] [1-9] *開頭的行來知道問題何時結束。不幸的是,當我搜索它時,它也取代了這一部分。
- 這會保留問題中的所有新行(在JSON中無效)。我希望它刪除新的行。
- 中的最後一項不應該包含「」的輸入之後,因爲這也將是無效的JSON(注意:我不介意這個非常,因爲它很容易刪除最後一個「」手動)
請記住我在正則表達式中非常糟糕,我這樣做的原因之一就是要了解更多關於正則表達式的知識,所以請解釋任何您作爲解決方案發布的正則表達式。
這些線是由分隔'\ N'? –
@SahilGulati是的。 – KNejad