mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
No effective change - remove unused
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.avaje.ebeaninternal.server.lib.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -9,104 +8,6 @@ import java.util.Map;
|
||||
*/
|
||||
public class StringHelper {
|
||||
|
||||
private static final char SINGLE_QUOTE = '\'';
|
||||
|
||||
private static final char DOUBLE_QUOTE = '"';
|
||||
|
||||
/**
|
||||
* parses a String of the form name1='value1' name2='value2'. Note that you
|
||||
* can use either single or double quotes for any particular name value pair
|
||||
* and the end quote must match the begin quote.
|
||||
*/
|
||||
public static HashMap<String, String> parseNameQuotedValue(String tag) throws RuntimeException {
|
||||
|
||||
if (tag == null || tag.length() < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// make sure that the quotes are matched...
|
||||
// int remainer = countOccurances(tag, ""+quote) % 2;
|
||||
// if (remainer == 1) {
|
||||
// dp("remainder = "+remainer);
|
||||
// throw new StringParsingException("Unmatched quote in "+tag);
|
||||
// }
|
||||
|
||||
// make sure that th last character is not an equals...
|
||||
// (check now so I don't need to check this every time..)
|
||||
if (tag.charAt(tag.length() - 1) == '=') {
|
||||
throw new RuntimeException("missing quoted value at the end of " + tag);
|
||||
}
|
||||
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
// recursively parse out the name value pairs...
|
||||
return parseNameQuotedValue(map, tag, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* recursively parse out name value pairs (where the value is quoted, with
|
||||
* either single or double quotes).
|
||||
*/
|
||||
private static HashMap<String, String> parseNameQuotedValue(HashMap<String, String> map,
|
||||
String tag, int pos) throws RuntimeException {
|
||||
|
||||
int equalsPos = tag.indexOf("=", pos);
|
||||
if (equalsPos > -1) {
|
||||
// check for begin quote...
|
||||
char firstQuote = tag.charAt(equalsPos + 1);
|
||||
if (firstQuote != SINGLE_QUOTE && firstQuote != DOUBLE_QUOTE) {
|
||||
throw new RuntimeException("missing begin quote at " + (equalsPos) + "["
|
||||
+ tag.charAt(equalsPos + 1) + "] in [" + tag + "]");
|
||||
}
|
||||
|
||||
// check for end quote...
|
||||
int endQuotePos = tag.indexOf(firstQuote, equalsPos + 2);
|
||||
if (endQuotePos == -1) {
|
||||
throw new RuntimeException("missing end quote [" + firstQuote + "] after " + pos
|
||||
+ " in [" + tag + "]");
|
||||
}
|
||||
|
||||
// we have a valid name and value...
|
||||
// dp("pos="+pos+" equalsPos="+equalsPos+"
|
||||
// endQuotePos="+endQuotePos);
|
||||
String name = tag.substring(pos, equalsPos);
|
||||
String value = tag.substring(equalsPos + 2, endQuotePos);
|
||||
// dp("name="+name+"; value="+value+";");
|
||||
|
||||
// trim off any whitespace from the front of name...
|
||||
name = trimFront(name, " ");
|
||||
if ((name.indexOf(SINGLE_QUOTE) > -1) || (name.indexOf(DOUBLE_QUOTE) > -1)) {
|
||||
throw new RuntimeException("attribute name contains a quote [" + name + "]");
|
||||
}
|
||||
map.put(name, value);
|
||||
|
||||
return parseNameQuotedValue(map, tag, endQuotePos + 1);
|
||||
|
||||
} else {
|
||||
// no more equals... stop parsing...
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of times a particular String occurs in another String.
|
||||
* e.g. count the number of single quotes.
|
||||
*/
|
||||
public static int countOccurances(String content, String occurs) {
|
||||
return countOccurances(content, occurs, 0, 0);
|
||||
}
|
||||
|
||||
private static int countOccurances(String content, String occurs, int pos, int countSoFar) {
|
||||
int equalsPos = content.indexOf(occurs, pos);
|
||||
if (equalsPos > -1) {
|
||||
countSoFar = countSoFar + 1;
|
||||
pos = equalsPos + occurs.length();
|
||||
// dp("countSoFar="+countSoFar+" pos="+pos);
|
||||
return countOccurances(content, occurs, pos, countSoFar);
|
||||
} else {
|
||||
return countSoFar;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses out a list of Name Value pairs that are delimited together. Will
|
||||
* always return a StringMap. If allNameValuePairs is null, or no name
|
||||
@@ -215,154 +116,6 @@ public class StringHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string that has delimited values (say comma delimited) in a
|
||||
* String[]. You must explicitly choose whether or not to include empty
|
||||
* values (say two commas that a right beside each other.
|
||||
*
|
||||
* <P>
|
||||
* e.g. "alpha,beta,,theta"<br>
|
||||
* With keepEmpties true, this results in a String[] of size 4 with the
|
||||
* third one having a String of 0 length. With keepEmpties false, this
|
||||
* results in a String[] of size 3.
|
||||
* </P>
|
||||
* <P>
|
||||
* </P>
|
||||
* <P>
|
||||
* e.g. ",alpha,beta,,theta,"<br>
|
||||
* With keepEmpties true, this results in a String[] of size 6 with the
|
||||
* 1st,4th and 6th one having a String of 0 length. With keepEmpties false,
|
||||
* this results in a String[] of size 3.
|
||||
* </P>
|
||||
*/
|
||||
public static String[] delimitedToArray(String str, String delimiter, boolean keepEmpties) {
|
||||
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
int startPos = 0;
|
||||
delimiter(str, delimiter, keepEmpties, startPos, list);
|
||||
String[] result = new String[list.size()];
|
||||
return list.toArray(result);
|
||||
}
|
||||
|
||||
private static void delimiter(String str, String delimiter, boolean keepEmpties, int startPos,
|
||||
ArrayList<String> list) {
|
||||
|
||||
int endPos = str.indexOf(delimiter, startPos);
|
||||
if (endPos == -1) {
|
||||
if (startPos <= str.length()) {
|
||||
String lastValue = str.substring(startPos, str.length());
|
||||
// dp("lastValue="+lastValue);
|
||||
if (keepEmpties || lastValue.length() != 0) {
|
||||
list.add(lastValue);
|
||||
}
|
||||
}
|
||||
// we have finished parsing the string...
|
||||
|
||||
} else {
|
||||
// get the delimited value... add it..
|
||||
String value = str.substring(startPos, endPos);
|
||||
// dp(startPos+","+endPos+" value="+value);
|
||||
if (keepEmpties || value.length() != 0) {
|
||||
list.add(value);
|
||||
}
|
||||
// recursively search as we are not at the end yet...
|
||||
delimiter(str, delimiter, keepEmpties, endPos + 1, list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the FIRST string in str that is bounded on the left by
|
||||
* leftBound, and bounded on the right by rightBound. This will return null
|
||||
* if the leftBound is not found within str.
|
||||
*
|
||||
* <P>
|
||||
* If leftBound can't be found this returns null.
|
||||
* </P>
|
||||
* <P>
|
||||
* This rightBound can't be found then this throws a
|
||||
* StringIndexOutOfBoundsException.
|
||||
* </P>
|
||||
*
|
||||
* @param str
|
||||
* the base string that we will search for the bounded string.
|
||||
* @param leftBound
|
||||
* the left bound of the string.
|
||||
* @param rightBound
|
||||
* the right bound of the string.
|
||||
*/
|
||||
public static String getBoundedString(String str, String leftBound, String rightBound)
|
||||
throws RuntimeException {
|
||||
|
||||
if (str == null) {
|
||||
throw new RuntimeException("string to parse is null?");
|
||||
}
|
||||
int startPos = str.indexOf(leftBound);
|
||||
if (startPos > -1) {
|
||||
startPos = startPos + leftBound.length();
|
||||
int endPos = str.indexOf(rightBound, startPos);
|
||||
// dp(str+" start:"+startPos+" end:"+endPos);
|
||||
if (endPos == -1) {
|
||||
throw new RuntimeException("Can't find rightBound: " + rightBound);
|
||||
}
|
||||
return str.substring(startPos, endPos);
|
||||
} else {
|
||||
// if no leftBound can be found.. return null... could be in a
|
||||
// search n parse type loop?
|
||||
// this keeps "no tag"==null different from "tag not formed
|
||||
// properly"==StringParsingException
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes the String bounded by leftBound & rightBound, and replaces it with
|
||||
* replaceString. Actually removes the left and right bound strings aswell.
|
||||
*/
|
||||
public static String setBoundedString(String str, String leftBound, String rightBound,
|
||||
String replaceString) {
|
||||
|
||||
int startPos = str.indexOf(leftBound);
|
||||
if (startPos > -1) {
|
||||
// startPos = startPos;
|
||||
int endPos = str.indexOf(rightBound, startPos + leftBound.length());
|
||||
if (endPos > -1) {
|
||||
String toReplace = str.substring(startPos, endPos + 1);
|
||||
return replaceString(str, toReplace, replaceString);
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
// public static String replaceString(String str, String oldSub, String
|
||||
// newSub) {
|
||||
//
|
||||
// if (str == null) {
|
||||
// return null;
|
||||
// }
|
||||
// StringBuilder newSB = new StringBuilder(str.length()+20);
|
||||
// int iPos = 0;
|
||||
// int iPrevPos = 0;
|
||||
//
|
||||
// while (true) {
|
||||
// iPos = str.indexOf(oldSub, iPrevPos);
|
||||
// if (iPos > -1) {
|
||||
// // found
|
||||
// newSB.append(str.substring(iPrevPos, iPos));
|
||||
// newSB.append(newSub);
|
||||
// iPrevPos = iPos + oldSub.length();
|
||||
// } else {
|
||||
// // not found
|
||||
// newSB.append(str.substring(iPrevPos));
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return newSB.toString();
|
||||
// }
|
||||
|
||||
/**
|
||||
* This method takes a String and will replace all occurrences of the match
|
||||
* String with that of the replace String.
|
||||
@@ -400,7 +153,7 @@ public class StringHelper {
|
||||
int additionalSize, int startPos, int endPos) {
|
||||
|
||||
if (source == null){
|
||||
return source;
|
||||
return null;
|
||||
}
|
||||
|
||||
char match0 = match.charAt(0);
|
||||
@@ -507,7 +260,7 @@ public class StringHelper {
|
||||
sb.append(source.substring(0, startPos));
|
||||
}
|
||||
|
||||
int matchCount = 0;
|
||||
int matchCount;
|
||||
|
||||
for (int i = startPos; i < len; i++) {
|
||||
sourceChar = source.charAt(i);
|
||||
@@ -544,49 +297,4 @@ public class StringHelper {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method takes a String as an argument and removes all occurrences of
|
||||
* the supplied Char. It returns the resulting String.
|
||||
*/
|
||||
public static String removeChar(String s, char chr) {
|
||||
|
||||
StringBuilder sb = new StringBuilder(s.length());
|
||||
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (c != chr){
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method takes a String as an argument and removes all occurrences of
|
||||
* the supplied Chars. It returns the resulting String.
|
||||
*/
|
||||
public static String removeChars(String s, char[] chr) {
|
||||
|
||||
StringBuilder sb = new StringBuilder(s.length());
|
||||
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (!charMatch(c, chr)){
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static boolean charMatch(int iChr, char[] chr) {
|
||||
for (int i = 0; i < chr.length; i++) {
|
||||
if (iChr == chr[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.lib.util;
|
||||
|
||||
/**
|
||||
* Builds a string from a stack trace.
|
||||
* <p>
|
||||
* Generally used to flatten a stack trace into a single string
|
||||
* removing \r\n and limiting the size of any given stack.
|
||||
* </p>
|
||||
*/
|
||||
public class ThrowablePrinter {
|
||||
|
||||
private static final String atString = " at ";
|
||||
|
||||
private String newLineChar = "\\r\\n";
|
||||
|
||||
private int maxStackTraceLines = 3;
|
||||
|
||||
/**
|
||||
* Set the maximum number of lines in any one part of
|
||||
* the stack trace. This is not the total maximum.
|
||||
*/
|
||||
public void setMaxStackTraceLines(int maxStackTraceLines) {
|
||||
this.maxStackTraceLines = maxStackTraceLines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the new line character used to replace \r\n with.
|
||||
* This is useful so that the stack is placed on a single line
|
||||
* in a log file.
|
||||
*/
|
||||
public void setNewLineChar(String newLineChar) {
|
||||
this.newLineChar = newLineChar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the error into a string representation.
|
||||
* <p>
|
||||
* Replaces the \r\n and limits the stack lines.
|
||||
* </p>
|
||||
*/
|
||||
public String print(Throwable e) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
printThrowable(sb, e, false);
|
||||
|
||||
String line = sb.toString();
|
||||
line = StringHelper.replaceString(line, "\r", "\\r");
|
||||
line = StringHelper.replaceString(line, "\n", "\\n");
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively output the Throwable stack trace to the log.
|
||||
*
|
||||
* @param sb the buffer to write the stack trace to
|
||||
* @param e the source throwable
|
||||
* @param isCause flag to indicate if this is the top level throwable or a
|
||||
* cause
|
||||
*/
|
||||
protected void printThrowable(StringBuffer sb, Throwable e, boolean isCause) {
|
||||
if (e != null) {
|
||||
if (isCause) {
|
||||
sb.append("Caused by: ");
|
||||
}
|
||||
sb.append(e.getClass().getName());
|
||||
sb.append(":");
|
||||
sb.append(e.getMessage()).append(newLineChar);
|
||||
|
||||
StackTraceElement[] ste = e.getStackTrace();
|
||||
int outputStackLines = ste.length;
|
||||
int notShownCount = 0;
|
||||
if (ste.length > maxStackTraceLines) {
|
||||
outputStackLines = maxStackTraceLines;
|
||||
notShownCount = ste.length - outputStackLines;
|
||||
}
|
||||
for (int i = 0; i < outputStackLines; i++) {
|
||||
sb.append(atString);
|
||||
sb.append(ste[i].toString()).append(newLineChar);
|
||||
}
|
||||
if (notShownCount > 0) {
|
||||
sb.append(" ... ");
|
||||
sb.append(notShownCount);
|
||||
sb.append(" more").append(newLineChar);
|
||||
}
|
||||
Throwable cause = e.getCause();
|
||||
if (cause != null) {
|
||||
printThrowable(sb, cause, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user