This commit is contained in:
YuCheng Hu 2023-09-25 13:34:09 -04:00 committed by honeymoose
parent ea40e59e37
commit fe382b8309
6 changed files with 185 additions and 73 deletions

View File

@ -8,36 +8,34 @@
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="assertion-libraries" />
<module name="core-java-annotations" />
<module name="core-java-numbers" />
<module name="core-java-strings" />
<module name="core-java-11" />
<module name="core-java-collections-conversions" />
<module name="core-java-collections" />
<module name="core-java-datetime-conversion" />
<module name="junit-5-basics" />
<module name="activejdbc" />
<module name="codebank" />
<module name="core-java-collections-list" />
<module name="spring-data-jpa-repo-2" />
<module name="core-java-streams" />
<module name="core-java-io-2" />
<module name="core-java-io" />
<module name="core-java-8-2" />
<module name="discourse" />
<module name="image-processing" />
<module name="spring-data-redis" />
<module name="core-java" />
<module name="core-java-collections-list-2" />
<module name="core-java-collections-conversions-2" />
<module name="core-java-collections-list-3" />
<module name="core-java-8" />
<module name="core-java-collections-3" />
<module name="core-java-collections-2" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="core-java-11" target="11" />
<module name="core-java-8-2" target="11" />
<module name="core-java-annotations" target="11" />
<module name="core-java-collections" target="11" />
<module name="core-java-collections-2" target="11" />
<module name="core-java-collections-3" target="11" />
<module name="core-java-collections-conversions" target="11" />
<module name="core-java-collections-conversions-2" target="11" />
<module name="core-java-collections-list" target="11" />
<module name="core-java-collections-list-3" target="11" />
<module name="core-java-numbers" target="11" />
<module name="core-java-strings" target="11" />
</bytecodeTargetLevel>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">

View File

@ -45,6 +45,8 @@
<file url="file://$PROJECT_DIR$/image-processing/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/parent-boot-2/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/parent-boot-2/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/parent-boot-3/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/parent-boot-3/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/activejdbc/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/activejdbc/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-jpa-repo-2/src/main/java" charset="UTF-8" />

View File

@ -52,3 +52,16 @@ Java 代码使用的是 JDK 11。
| CN 博客 | [http://www.cwikius.cn/](http://www.cwikius.cn/) | CWIKIUS.CN 一个有独立思考和温度的清新站 |
##
| 基本类型 | 大小 | 包装器类型 |
|---------|-------|-----------|
| boolean | / | Boolean |
| char | 16bit | Character |
| byte | 8bit | Byte |
| short | 16bit | Short |
| int | 32bit | Integer |
| long | 64bit | Long |
| float | 32bit | Float |
| double | 64bit | Double |
| void | / | Void |

View File

@ -45,6 +45,7 @@
<!-- <module>jackson-simple</module>-->
<!-- <module>parent-java</module>-->
<module>parent-boot-2</module>
<module>parent-boot-3</module>
<module>persistence-modules</module>
<module>testing-modules</module>
<module>toolkits</module>

View File

@ -1,7 +1,9 @@
package com.ossez.toolkits.codebank;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import com.google.gdata.data.docs.Size;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
@ -30,68 +32,119 @@ public class Main {
public static void main(String[] args) {
// get the idx feed properties file
Main.parseProperties();
SizeCount sizeCount = new SizeCount();
// load console options
Main.parseCommandLine(args);
sizeCount.setCustomer(70);
sizeCount.setTeller(3);
sizeCount.setQueueSize(3);
logger.debug("Starting feeds...");
System.out.println("starting feeds...");
// execute the feeds
Main.executeFeeds();
SizeCount exeSizeCount = algorithmBanker(sizeCount);
logger.debug("time Require ->>> {}", exeSizeCount.getTimeRequire());
if (exeSizeCount.getCustomer() > 0) {
exeSizeCount = exeSizeCount = callOtherBank(exeSizeCount);
logger.debug("time Require - {}", exeSizeCount.getTimeRequire());
}
// Current Size:
logger.debug("Spending Time: [{}]", exeSizeCount.getTimeRequire());
/**
* Executes the feeds specified in the feeds.properties file.
* After this time, all process will done and we can re-check again.
* if we set sizeCount.setCustomer(70);
* After this value check function.
* we still have 64 customer need to get processed.
* In this case, we need may call callOtherBank more than once. to reach the value banker manager wanted.
*/
private static void executeFeeds() {
}
/**
* Parses the properties file to get a list of all feeds.
* How many Teller need for C.
* We need to set up time frame first.
*
* For current, will sizeCount.getCustomer - sizeCount.getQueueSize.
* Because, we don't want getCustomer waite.
*/
private static void parseProperties() {
try {
// load the properties file
logger.debug("Parsing properties");
Main.properties.load(Main.class.getClassLoader().getResourceAsStream("rets.properties"));
// load the feeds
} catch (Exception ex) {
ex.printStackTrace();
logger.error("Could not parse feed properties", ex);
}
}
/**
* Handles creation of console options.
* About send tellter to home.
*
* There are three conditions:
* 1. Size of Customer == 0;
* 2. Size of Queue == 0;
* 3. No active Thread is running, or active thread < size of teller.
*/
private static void parseCommandLine(String[] args) {
// parse command line options
CommandLineParser parser = new GnuParser();
/**
* About how many teller.
* Time is matter, different tiller can process different business.
* We need to have average time for each business process may coast. in this case I was set time all == 1000ms (not in real world).
* And the Size of Queue too.
*
* Check the algorithmBanker function bellow.
*
* Run this function, if sizeCount.getCustomer > 0. All init teller should in.
* and we need to get extra teller for size sizeCount.getCustomer()
*
* if sizeCount.getCustomer < sizeCount.getQueueSize + sizeCount.getTeller(), we can send some teller to home.
*
* Check this every exeSizeCount.getTimeRequire(), make sure exeSizeCount.getTimeRequire() == 0 then do tellter call.
*/
try {
Main.cl = parser.parse(Main.options, args);
}
// get the dry run option
Main.dryRun = Main.cl.hasOption("d");
logger.trace("Value of dryRun: " + dryRun);
// get the limit option
// Main.limit = Utility.parseInt(Main.cl.getOptionValue("l", "0"));
logger.trace("Value of limit: " + Main.limit);
public static SizeCount algorithmBanker(SizeCount sizeCount) {
// get the force option
Main.force = Main.cl.hasOption("u");
logger.trace("Value of force: " + Main.force);
} catch (Exception ex) {
logger.error("An error ocurred parsing command line arguments", ex);
if (sizeCount.getCustomer() <= sizeCount.getTeller()) {
Integer exeCount = sizeCount.getCustomer();
for (int i = 0; i < exeCount; i++) {
TellerThread R1 = new TellerThread("TellerThread-1", 1000);
R1.start();
sizeCount.setTimeRequire(sizeCount.getTimeRequire() + 1000);
}
sizeCount.setCustomer(0);
} else {
logger.debug("working / sleep teller - {}/{}", sizeCount.getTeller(), 0);
Integer exeCount = sizeCount.getCustomer();
for (int i = 0; i < sizeCount.getTeller(); i++) {
TellerThread R1 = new TellerThread("TellerThread-1", 1000);
R1.start();
sizeCount.setCustomer(sizeCount.getCustomer() - 1);
sizeCount.setTimeRequire(sizeCount.getTimeRequire() + 1000);
}
// Q
if ((exeCount - sizeCount.getTeller()) > sizeCount.getQueueSize()) {
for (int i = 0; i < sizeCount.getQueueSize(); i++) {
TellerThread R1 = new TellerThread("TellerThread-1", 1000);
R1.start();
sizeCount.setCustomer(sizeCount.getCustomer() - 1);
sizeCount.setTimeRequire(sizeCount.getTimeRequire() + 1000);
}
} else {
for (int i = 0; i < exeCount - sizeCount.getTeller(); i++) {
TellerThread R1 = new TellerThread("TellerThread-1", 1000);
R1.start();
sizeCount.setCustomer(sizeCount.getCustomer() - 1);
sizeCount.setTimeRequire(sizeCount.getTimeRequire() + 1000);
}
}
}
return sizeCount;
}
private static SizeCount callOtherBank(SizeCount sizeCount) {
TellerThread R1 = new TellerThread("TellerThread-1", 1000);
R1.start();
sizeCount.setCustomer(sizeCount.getCustomer() - 1);
sizeCount.setTimeRequire(sizeCount.getTimeRequire() + 1000);
return sizeCount;
}
}

View File

@ -1,14 +1,17 @@
package com.ossez.toolkits.codebank.tests;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
* String Test Case
@ -35,17 +38,59 @@ public class EmptyQuickTest {
@Test
public void testMain() {
Integer[] nums = {2, 7, 11, 15};
String strTransform = "AI is driving the world crazy";
Integer target = 9;
List<String> test = List.of(StringUtils.split(strTransform, " "));
String s1 = "Question, what kind of bear is best?";
String s2 = "That's a ridiculous question!";
String s3 = "False.";
String s4 = "Black bear is the best bear.";
for (int i = 0; i < test.size(); i++) {
if (hasVowels(test.get(i))) {
log.debug("Vowel STR - {}", test.get(i));
List<String> inputStr = new ArrayList<>();
inputStr.add(RegExUtils.replaceAll(s1, "[^a-zA-Z\\s]", "").toLowerCase());
inputStr.add(RegExUtils.replaceAll(s2, "[^a-zA-Z\\s]", "").toLowerCase());
inputStr.add(RegExUtils.replaceAll(s3, "[^a-zA-Z\\s]", "").toLowerCase());
inputStr.add(RegExUtils.replaceAll(s4, "[^a-zA-Z\\s]", "").toLowerCase());
HashMap<String, List<String>> wordsMap = new HashMap<>();
for (int i = 0; i < inputStr.size(); i++) {
String words = inputStr.get(i);
List<String> wordsList = List.of(StringUtils.split(inputStr.get(i)));
for (int j = 0; j < wordsList.size(); j++) {
String word = wordsList.get(j);
List<String> inStr = new ArrayList<>();
if (wordsMap.get(word) != null) {
inStr = wordsMap.get(word);
}
inStr.add("" + (i + 1));
wordsMap.put(word, inStr);
}
}
TreeMap<Integer, List<String>> countMap = new TreeMap<>(Collections.reverseOrder());
for (Map.Entry<String, List<String>> stringListEntry : wordsMap.entrySet()) {
Integer wordCount = stringListEntry.getValue().size();
List<String> wordsList = new ArrayList<>();
if (countMap.get(wordCount) != null) {
wordsList = countMap.get(wordCount);
}
wordsList.add(stringListEntry.getKey());
countMap.put(wordCount, wordsList);
}
for (Map.Entry<Integer, List<String>> integerListEntry : countMap.entrySet()) {
List<String> outputList = integerListEntry.getValue();
for (int i = 0; i < outputList.size(); i++) {
List<String> sList = wordsMap.get(outputList.get(i));
log.debug("{}[{}:{}]", outputList.get(i), integerListEntry.getKey(), sList.stream().distinct().collect(Collectors.toList()));
}
}
}
private Boolean hasVowels(String str) {