use pre-compiled patterns in ymark

pull/1/head
Michael Peter Christen 11 years ago
parent 34633044b4
commit 74466d731a

@ -2,7 +2,6 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.regex.Pattern;
import net.yacy.cora.document.id.DigestURL;
import net.yacy.cora.protocol.ClientIdentification;
@ -94,7 +93,7 @@ public class get_metadata {
}
public static int putTags(final String tagString, final String var) {
final String list[] = Pattern.compile(YMarkUtil.TAGS_SEPARATOR).split(tagString, 0);
final String list[] = YMarkUtil.TAGS_SEPARATOR_PATTERN.split(tagString, 0);
int count = 0;
for (final String element : list) {
final String tag = element;

@ -4,7 +4,6 @@ import java.util.Date;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.TreeMap;
import java.util.regex.Pattern;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.cora.document.encoding.UTF8;
@ -98,11 +97,11 @@ public class get_treeview {
} catch (final IOException e) {
ConcurrentLog.logException(e);
}
int n = Pattern.compile(YMarkUtil.FOLDERS_SEPARATOR).split(root, 0).length;
int n = YMarkUtil.FOLDERS_SEPARATOR_PATTERN.split(root, 0).length;
if (n == 0) n = 1;
while (it.hasNext()) {
final String folder = it.next();
foldername = folder.split(YMarkUtil.FOLDERS_SEPARATOR);
foldername = YMarkUtil.FOLDERS_SEPARATOR_PATTERN.split(folder);
if (foldername.length == n+1) {
prop.put("folders_"+count+"_foldername", foldername[n]);
prop.put("folders_"+count+"_expanded", "false");

@ -52,7 +52,7 @@ public class get_xbel {
root = "";
}
final int root_depth = root.split(YMarkUtil.FOLDERS_SEPARATOR).length - 1;
final int root_depth = YMarkUtil.FOLDERS_SEPARATOR_PATTERN.split(root).length - 1;
// Log.logInfo(YMarkTables.BOOKMARKS_LOG, "root: "+root+" root_depth: "+root_depth);
Iterator<String> fit = null;
Iterator<Tables.Row> bit = null;
@ -67,7 +67,7 @@ public class get_xbel {
while (fit.hasNext()) {
final String folder = fit.next();
foldername = folder.split(YMarkUtil.FOLDERS_SEPARATOR);
foldername = YMarkUtil.FOLDERS_SEPARATOR_PATTERN.split(folder);
final int len = foldername.length -1;
if(n > root_depth) {
for (; len <= n; n--) {

@ -60,7 +60,7 @@ public class YMarkDMOZImporter extends YMarkImporter {
}
public void setDepth(int d) {
this.depth = d + this.targetFolder.split(YMarkUtil.FOLDERS_SEPARATOR).length-1;
this.depth = d + YMarkUtil.FOLDERS_SEPARATOR_PATTERN.split(this.targetFolder).length-1;
}
public class DMOZParser extends DefaultHandler {

@ -259,7 +259,7 @@ public class YMarkTables {
while(bit.hasNext()) {
bmk_row = bit.next();
if(bmk_row.containsKey(YMarkEntry.BOOKMARK.FOLDERS.key())) {
final String[] folderArray = (new String(bmk_row.get(YMarkEntry.BOOKMARK.FOLDERS.key()),"UTF8")).split(YMarkUtil.TAGS_SEPARATOR);
final String[] folderArray = YMarkUtil.TAGS_SEPARATOR_PATTERN.split(new String(bmk_row.get(YMarkEntry.BOOKMARK.FOLDERS.key()),"UTF8"));
for (final String folder : folderArray) {
if(folder.length() > root.length() && folder.substring(0, root.length()+1).equals(r)) {
if(!folders.contains(folder)) {

@ -29,6 +29,7 @@ package net.yacy.data.ymark;
import java.net.MalformedURLException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.regex.Pattern;
import net.yacy.cora.document.encoding.UTF8;
import net.yacy.cora.document.id.DigestURL;
@ -40,6 +41,9 @@ public class YMarkUtil {
public final static String SPACE = " ";
public final static String EMPTY_STRING = new String();
public final static Pattern TAGS_SEPARATOR_PATTERN = Pattern.compile(TAGS_SEPARATOR);
public final static Pattern FOLDERS_SEPARATOR_PATTERN = Pattern.compile(FOLDERS_SEPARATOR);
/**
* conveniance function to generate url hashes for YMark bookmarks
* @param url a string representation of a valid url

Loading…
Cancel
Save