mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-29 04:04:43 +02:00
StringMan instead of StringUtils
This commit is contained in:
@ -1,89 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
|
||||
/**
|
||||
* Logging of errors and debug messages.
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class Logger {
|
||||
private static ArrayList<String> entries;
|
||||
private static File log;
|
||||
|
||||
public static void setup(final File file) {
|
||||
log = file;
|
||||
entries = new ArrayList<>();
|
||||
try {
|
||||
final BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
entries.add(line);
|
||||
}
|
||||
reader.close();
|
||||
} catch (final IOException e) {
|
||||
PS.log(C.PREFIX.s() + "File setup error Logger#setup");
|
||||
}
|
||||
}
|
||||
|
||||
public static void write() throws IOException {
|
||||
final FileWriter writer = new FileWriter(log);
|
||||
for (final String string : entries) {
|
||||
writer.write(string + System.lineSeparator());
|
||||
}
|
||||
writer.close();
|
||||
}
|
||||
|
||||
public static void add(final LogLevel level, final String string) {
|
||||
append("[" + level.toString() + "] " + string);
|
||||
}
|
||||
|
||||
private static void append(final String string) {
|
||||
entries.add("[" + new Date().toString() + "]" + string);
|
||||
}
|
||||
|
||||
public enum LogLevel {
|
||||
GENERAL("General"),
|
||||
WARNING("Warning"),
|
||||
DANGER("Danger");
|
||||
private final String name;
|
||||
|
||||
LogLevel(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
}
|
@ -24,6 +24,30 @@ public class MathMan {
|
||||
return i * 2;
|
||||
}
|
||||
|
||||
public static boolean isInteger(String str) {
|
||||
if (str == null) {
|
||||
return false;
|
||||
}
|
||||
int length = str.length();
|
||||
if (length == 0) {
|
||||
return false;
|
||||
}
|
||||
int i = 0;
|
||||
if (str.charAt(0) == '-') {
|
||||
if (length == 1) {
|
||||
return false;
|
||||
}
|
||||
i = 1;
|
||||
}
|
||||
for (; i < length; i++) {
|
||||
char c = str.charAt(i);
|
||||
if (c <= '/' || c >= ':') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static double getSD(double[] array, double av) {
|
||||
double sd = 0;
|
||||
for (int i=0; i<array.length;i++)
|
||||
|
@ -53,7 +53,7 @@ public class SetBlockQueue {
|
||||
runnables = new HashSet<>();
|
||||
}
|
||||
if (!running) {
|
||||
TaskManager.index.increment();
|
||||
TaskManager.index.incrementAndGet();
|
||||
final int current = TaskManager.index.intValue();
|
||||
int task = TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
|
@ -23,8 +23,6 @@ package com.intellectualcrafters.plot.util;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
* String comparison library
|
||||
*
|
||||
@ -76,7 +74,7 @@ public class StringComparison<T> {
|
||||
* @return match
|
||||
*/
|
||||
public static int compare(final String s1, final String s2) {
|
||||
int distance = StringUtils.getLevenshteinDistance(s1, s2);
|
||||
int distance = StringMan.getLevenshteinDistance(s1, s2);
|
||||
if (s2.contains(s1)) {
|
||||
distance -= (Math.min(s1.length(), s2.length()));
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@ -41,8 +42,107 @@ public class StringMan {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static boolean isAlphanumeric(String str) {
|
||||
for (int i=0; i<str.length(); i++) {
|
||||
char c = str.charAt(i);
|
||||
if (c < 0x30 || (c >= 0x3a && c <= 0x40) || (c > 0x5a && c <= 0x60) || c > 0x7a) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isAlpha(String str) {
|
||||
for (int i=0; i<str.length(); i++) {
|
||||
char c = str.charAt(i);
|
||||
if ((c <= 0x40) || (c > 0x5a && c <= 0x60) || c > 0x7a) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String join(Collection<?> collection, String delimiter) {
|
||||
return join(collection.toArray(), delimiter);
|
||||
}
|
||||
|
||||
public static String join(Collection<?> collection, char delimiter) {
|
||||
return join(collection.toArray(), delimiter + "");
|
||||
}
|
||||
|
||||
public static boolean isAsciiPrintable(char c) {
|
||||
return (c >= ' ') && (c < '');
|
||||
}
|
||||
|
||||
public static boolean isAsciiPrintable(String s) {
|
||||
for (char c: s.toCharArray()) {
|
||||
if (!isAsciiPrintable(c)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int getLevenshteinDistance(String s, String t) {
|
||||
int n = s.length();
|
||||
int m = t.length();
|
||||
if (n == 0) {
|
||||
return m;
|
||||
} else if (m == 0) {
|
||||
return n;
|
||||
}
|
||||
if (n > m) {
|
||||
String tmp = s;
|
||||
s = t;
|
||||
t = tmp;
|
||||
n = m;
|
||||
m = t.length();
|
||||
}
|
||||
int p[] = new int[n+1];
|
||||
int d[] = new int[n+1];
|
||||
int _d[];
|
||||
int i;
|
||||
int j;
|
||||
char t_j;
|
||||
int cost;
|
||||
for (i = 0; i<=n; i++) {
|
||||
p[i] = i;
|
||||
}
|
||||
for (j = 1; j<=m; j++) {
|
||||
t_j = t.charAt(j-1);
|
||||
d[0] = j;
|
||||
|
||||
for (i=1; i<=n; i++) {
|
||||
cost = s.charAt(i-1)==t_j ? 0 : 1;
|
||||
d[i] = Math.min(Math.min(d[i-1]+1, p[i]+1), p[i-1]+cost);
|
||||
}
|
||||
_d = p;
|
||||
p = d;
|
||||
d = _d;
|
||||
}
|
||||
return p[n];
|
||||
}
|
||||
|
||||
public static String join(Object[] array, String delimiter) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0, j = array.length; i < j; i++) {
|
||||
if (i > 0) {
|
||||
result.append(delimiter);
|
||||
}
|
||||
result.append(array[i]);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static boolean isEqual(String a, String b ) {
|
||||
return (a == b || (a.length() == b.length() && a.hashCode() == b.hashCode() && a.equals(b)));
|
||||
}
|
||||
|
||||
|
||||
public static String repeat(String s, int n) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for(int i = 0; i < n; i++) {
|
||||
sb.append(s);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -2,15 +2,14 @@ package com.intellectualcrafters.plot.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.lang.mutable.MutableInt;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
|
||||
public abstract class TaskManager {
|
||||
public static HashSet<String> TELEPORT_QUEUE = new HashSet<>();
|
||||
|
||||
public static MutableInt index = new MutableInt(0);
|
||||
public static AtomicInteger index = new AtomicInteger(0);
|
||||
public static HashMap<Integer, Integer> tasks = new HashMap<>();
|
||||
|
||||
public static int runTaskRepeat(final Runnable r, final int interval) {
|
||||
|
Reference in New Issue
Block a user