Skip to content

Commit

Permalink
Moved some code out of StringUtil into ClientDelete (since that is th…
Browse files Browse the repository at this point in the history
…e only place it is used). I don't know why I did this...
  • Loading branch information
apavlo committed May 25, 2013
1 parent e5d4d74 commit 1d4a7ba
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 47 deletions.
26 changes: 24 additions & 2 deletions src/benchmarks/org/voltdb/benchmark/dedupe/ClientDelete.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,31 @@
import org.voltdb.client.ProcCallException;
import org.voltdb.utils.Pair;

import edu.brown.utils.StringUtil;
import edu.brown.hstore.HStoreConstants;

public class ClientDelete {


/**
* Return the HOST+PORT pair extracted from a string with
* "<hostname>:<portnum>"
*
* @param hostnport
* @return
*/
public static Pair<String, Integer> getHostPort(String hostnport, int port) {
String host = hostnport;
if (host.contains(":")) {
String split[] = hostnport.split("\\:", 2);
host = split[0];
port = Integer.valueOf(split[1]);
}
return (Pair.of(host, port));
}
public static Pair<String, Integer> getHostPort(String hostnport) {
return (getHostPort(hostnport, HStoreConstants.DEFAULT_PORT));
}

public static void main(String args[]) {
long numDeletes = Long.valueOf(args[0]);
String serverList = args[1];
Expand All @@ -62,7 +84,7 @@ public static void main(String args[]) {
for (String thisServer : voltServers) {
try {
System.out.printf("Connecting to server: %s\n",thisServer);
Pair<String, Integer> p = StringUtil.getHostPort(thisServer);
Pair<String, Integer> p = getHostPort(thisServer);
voltclient.createConnection(null, p.getFirst(), p.getSecond(), "program", "none");
} catch (IOException e) {
e.printStackTrace();
Expand Down
70 changes: 25 additions & 45 deletions src/frontend/edu/brown/utils/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@
import java.util.regex.Pattern;

import org.voltdb.types.TimestampType;
import org.voltdb.utils.Pair;

import com.google.protobuf.ByteString;

import edu.brown.hstore.HStoreConstants;

/**
* @author pavlo
*/
Expand All @@ -69,7 +66,7 @@ public abstract class StringUtil {
public static final String SET_PLAIN_TEXT = "\033[0;0m";
public static final String SET_BOLD_TEXT = "\033[0;1m";

private static final double BASE = 1024, KB = BASE, MB = KB * BASE, GB = MB * BASE;
private static final float BASE = 1024, KB = BASE, MB = KB * BASE, GB = MB * BASE;
private static final DecimalFormat df = new DecimalFormat("#.##");

private static final String HEADER_MARKER = "-";
Expand Down Expand Up @@ -558,16 +555,14 @@ public static String title(String string) {

/**
* Converts a string to title case (ala Python)
*
* @param string
* @param keep_upper
* If true, then any non-first character that is uppercase stays
* uppercase
* @param keep_upper If true, then any non-first character that is uppercase stays uppercase
* @return
*/
public static String title(String string, boolean keep_upper) {
StringBuilder sb = new StringBuilder();
String add = "";
boolean first = true;
for (String part : TITLE_SPLIT.split(string)) {
sb.append(add).append(part.substring(0, 1).toUpperCase());
int len = part.length();
Expand All @@ -582,7 +577,10 @@ public static String title(String string, boolean keep_upper) {
sb.append(part.substring(1).toLowerCase());
}
}
add = " ";
if (first) {
add = " ";
first = false;
}
} // FOR
return (sb.toString());
}
Expand All @@ -602,30 +600,38 @@ public static String addSpacers(String str) {
}

/**
* Python join()
* Python join() for arrays
*
* @param <T>
* @param delimiter
* @param items
* @return
*/
@SafeVarargs
public static <T> String join(String delimiter, T... items) {
return (join(delimiter, Arrays.asList(items)));
return (join(null, delimiter, Arrays.asList(items)));
}

/**
* Python join() for iterators
*
* @param delimiter
* @param items
* @return
*/
public static <T> String join(String delimiter, final Iterator<T> items) {
return (join("", delimiter, CollectionUtil.iterable(items)));
return (join(null, delimiter, CollectionUtil.iterable(items)));
}

/**
* Python join()
* Python join() for iterables
*
* @param delimiter
* @param items
* @return
*/
public static String join(String delimiter, Iterable<?> items) {
return (join("", delimiter, items));
return (join(null, delimiter, items));
}

/**
Expand All @@ -639,14 +645,12 @@ public static String join(String delimiter, Iterable<?> items) {
public static String join(String prefix, String delimiter, Iterable<?> items) {
if (items == null)
return ("");
if (prefix == null)
prefix = "";


boolean hasPrefix = (prefix != null);
StringBuilder sb = new StringBuilder();
int i = 0;
for (Object x : items) {
if (prefix.isEmpty() == false)
sb.append(prefix);
if (hasPrefix) sb.append(String.format(prefix, i));
sb.append(x != null ? x.toString() : x).append(delimiter);
i++;
}
Expand All @@ -657,27 +661,6 @@ public static String join(String prefix, String delimiter, Iterable<?> items) {
return sb.toString();
}

/**
* Return the HOST+PORT pair extracted from a string with
* "<hostname>:<portnum>"
*
* @param hostnport
* @return
*/
public static Pair<String, Integer> getHostPort(String hostnport) {
return (getHostPort(hostnport, HStoreConstants.DEFAULT_PORT));
}

public static Pair<String, Integer> getHostPort(String hostnport, int port) {
String host = hostnport;
if (host.contains(":")) {
String split[] = hostnport.split("\\:", 2);
host = split[0];
port = Integer.valueOf(split[1]);
}
return (Pair.of(host, port));
}

private static final char[] CHARACTERS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

private static char nibbleToHexChar(int nibble) {
Expand All @@ -686,11 +669,8 @@ private static char nibbleToHexChar(int nibble) {
}

/**
* Dump a ByteString to a text representation Copied from:
* http://people.csail
* .mit.edu/evanj/hg/index.cgi/javatxn/file/tip/src/edu/mit
* /ExampleServer.java
*
* Dump a ByteString to a text representation
* Copied from: http://people.csail.mit.edu/evanj/hg/index.cgi/javatxn/file/tip/src/edu/mit/ExampleServer.java
* @param bytes
* @return
*/
Expand Down

0 comments on commit 1d4a7ba

Please sign in to comment.