replacing for loops with get methods

This commit is contained in:
jenzur 2019-03-10 01:15:50 +01:00
parent 64dc2719a0
commit 7ab6c7ee0b
2 changed files with 54 additions and 60 deletions

View File

@ -174,7 +174,6 @@ public class MYSQLDatahandler {
public synchronized void checkIfUpdateMatrixes() {
refreshMatrixFromDB = false;
int updateBadgesInteger = 900;
int counter = 0;
if (stopwatch1.elapsed(TimeUnit.SECONDS) >= EXPIRE_TIME_IN_SECONDS1) {
refreshMatrixFromDB = true;
@ -197,14 +196,11 @@ public class MYSQLDatahandler {
}
if (!updatepresent) {
selectUpdate = ij2;
System.out.println("selectUpdate in primary: " + selectUpdate + "\n");
LinkedHashMap<String, Double> newLHM = new LinkedHashMap();
lHMSMX.put(str, newLHM);
break;
}
ij2++;
}
if (selectUpdate == -1) {
if (selectUpdate == -1 || selectUpdate + 1 == stringCachelocal.size()) {
int valueSize = stringCachelocal.size();
if (secondaryIterator >= valueSize) {
secondaryIterator = 0;
@ -212,44 +208,44 @@ public class MYSQLDatahandler {
selectUpdate = secondaryIterator;
secondaryIterator++;
}
if (selectUpdate == -1 || selectUpdate >= stringCachelocal.size()) {
selectUpdate = new Random().nextInt(stringCachelocal.size() - 1);
}
int beginindex = selectUpdate;
System.out.println("beginindex: " + beginindex + "\n");
ConcurrentMap<Integer, String> strIndexNavigator = new MapMaker().concurrencyLevel(2).makeMap();
String get = stringCachelocal.get(beginindex);
strIndexNavigator.put(0, get);
ConcurrentMap<Integer, String> randomIndexesToUpdate = new MapMaker().concurrencyLevel(2).makeMap();
int indexes = updateBadgesInteger;
if (indexes >= stringCachelocal.size()) {
indexes = stringCachelocal.size() - 1;
}
int beginindexes = new Random().nextInt((stringCachelocal.size()) - indexes);
int ij1 = 0;
while (beginindexes + ij1 < beginindexes + indexes) {
String get1 = stringCachelocal.get(beginindexes + ij1);
randomIndexesToUpdate.put(ij1, get1);
ij1++;
}
ConcurrentMap<Integer, SimilarityMatrix> matrixUpdateList = new MapMaker().concurrencyLevel(2).makeMap();
ConcurrentMap<Integer, Future<SimilarityMatrix>> futures = new MapMaker().concurrencyLevel(2).makeMap();
ConcurrentMap<Integer, ConcurrentMap<String, String>> strMap = new MapMaker().concurrencyLevel(2).makeMap();
strIndexNavigator.values().forEach((str) -> {
randomIndexesToUpdate.values().stream().filter((str1) -> (!str.equals(str1))).forEachOrdered((str1) -> {
stringCachelocal.values().stream().filter((str1) -> (!str.equals(str1))).forEachOrdered((str1) -> {
boolean present = false;
LinkedHashMap<String, Double> orDefault = LHMSMXLocal.getOrDefault(str, null);
if (orDefault != null) {
for (String strdefault : orDefault.keySet()) {
if (strdefault.equals(str1)) {
Double orDefault1 = orDefault.getOrDefault(str1, null);
if (orDefault1 != null) {
// System.out.println("present true \nstr: " + str + "\nstr1: " + str1 + "\n");
present = true;
}
}
if (!present) {
orDefault = LHMSMXLocal.getOrDefault(str1, null);
if (orDefault != null) {
Double orDefault1 = orDefault.getOrDefault(str, null);
if (orDefault1 != null) {
// System.out.println("present true \nstr: " + str + "\nstr1: " + str1 + "\n");
present = true;
break;
}
}
}
orDefault = LHMSMXLocal.getOrDefault(str1, null);
if (orDefault != null) {
for (String strdefault : orDefault.keySet()) {
if (strdefault.equals(str)) {
if (!present) {
for (ConcurrentMap<String, String> strconcuritr : strMap.values()) {
String orDefault1 = strconcuritr.getOrDefault(str, null);
if (orDefault1 != null && orDefault1.equals(str1)) {
present = true;
break;
}
orDefault1 = strconcuritr.getOrDefault(str1, null);
if (orDefault1 != null && orDefault1.equals(str)) {
present = true;
break;
}
@ -259,6 +255,9 @@ public class MYSQLDatahandler {
SimilarityMatrix SMX = new SimilarityMatrix(str, str1);
Callable<SimilarityMatrix> worker = new SentimentAnalyzerTest(str, str1, SMX);
futures.put(futures.size() + 1, executor.submit(worker));
ConcurrentMap<String, String> strmapLocal = new MapMaker().concurrencyLevel(2).makeMap();
strmapLocal.put(str, str1);
strMap.put(strMap.size() + 1, strmapLocal);
}
});
});
@ -293,25 +292,23 @@ public class MYSQLDatahandler {
public synchronized void checkIfUpdateStrings() throws CustomError {
if (stopwatch.elapsed(TimeUnit.SECONDS) >= EXPIRE_TIME_IN_SECONDS || !stopwatch.isRunning()) {
new Thread(() -> {
ConcurrentMap<Integer, String> str = MessageResponseHandler.getStr();
str = cutContent(str);
str = filterContent(str);
str = removeSlacks(str);
str = verifyCalculationFitness(str);
try {
DataMapper.InsertMYSQLStrings(str);
} catch (CustomError ex) {
Logger.getLogger(MYSQLDatahandler.class
.getName()).log(Level.SEVERE, null, ex);
}
MessageResponseHandler.setStr(new MapMaker().concurrencyLevel(2).makeMap());
int j = stringCache.size() + 1;
for (String str1 : str.values()) {
stringCache.put(j, str1);
j++;
}
}).start();
ConcurrentMap<Integer, String> str = MessageResponseHandler.getStr();
str = cutContent(str);
str = filterContent(str);
str = removeSlacks(str);
str = verifyCalculationFitness(str);
try {
DataMapper.InsertMYSQLStrings(str);
} catch (CustomError ex) {
Logger.getLogger(MYSQLDatahandler.class
.getName()).log(Level.SEVERE, null, ex);
}
MessageResponseHandler.setStr(new MapMaker().concurrencyLevel(2).makeMap());
int j = stringCache.size() + 1;
for (String str1 : str.values()) {
stringCache.put(j, str1);
j++;
}
if (!stopwatch.isRunning()) {
stopwatch.start();
} else {
@ -609,15 +606,7 @@ public class MYSQLDatahandler {
if (allStrings.isEmpty()) {
return strmap;
}
ConcurrentMap<Integer, String> intervalMap = new MapMaker().concurrencyLevel(2).makeMap();
int intervalAprove = 450;
int hardcap = allStrings.size() > intervalAprove ? intervalAprove : allStrings.size();
int intervalAproveRand = new Random().nextInt(hardcap < intervalAprove ? 1 : allStrings.size() - intervalAprove);
int ij = 0;
while (ij < hardcap && allStrings.size() > intervalAproveRand + ij) {
intervalMap.put(ij, allStrings.get(intervalAproveRand + ij));
ij++;
}
String str1 = "and to revise the questions and materials and such";
String str2 = "as William said earlier. Visiting your dentist once or twice a year is enough";
String str3 = "At least, you have more time to prepare then";
@ -629,11 +618,16 @@ public class MYSQLDatahandler {
futures.put(futures.size() + 1, executor.submit(worker));
worker = new SentimentAnalyzerTest(str, str3, new SimilarityMatrix(str, str3));
futures.put(futures.size() + 1, executor.submit(worker));
for (String strValues : intervalMap.values()) {
int ij2 = 0;
for (String strValues : allStrings.values()) {
if (ij2 > intervalAprove) {
break;
}
if (!strValues.equals(str1) && !strValues.equals(str2) && !strValues.equals(str3)) {
worker = new SentimentAnalyzerTest(str, strValues, new SimilarityMatrix(str, strValues));
futures.put(futures.size() + 1, executor.submit(worker));
}
ij2++;
}
int counter = 0;
boolean calculationIssues = false;

View File

@ -45,14 +45,14 @@ public class DiscordHandler {
}).start();
MYSQLDatahandler.shiftReduceParserInitiate();
MYSQLDatahandler.instance.instantiateExecutor();
/*
if (MYSQLDatahandler.instance.getstringCacheSize() != 0) {
while (MYSQLDatahandler.instance.getlHMSMXSize() * 3 < (MYSQLDatahandler.instance.getstringCacheSize()
* MYSQLDatahandler.instance.getstringCacheSize()) - MYSQLDatahandler.instance.getstringCacheSize()) {
while (MYSQLDatahandler.instance.getlHMSMXSize() * MYSQLDatahandler.instance.getlHMSMXSize() * 1.5
< (MYSQLDatahandler.instance.getstringCacheSize()
* MYSQLDatahandler.instance.getstringCacheSize())
- MYSQLDatahandler.instance.getstringCacheSize()) {
MYSQLDatahandler.instance.checkIfUpdateMatrixes();
}
}
*/
String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
api.addMessageCreateListener(event -> {