Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- fix for http://www.yacy-forum.de/viewtopic.php?p=32758#32758
- Diff takes any objects now, not only strings

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3455 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
karlchenofhell committed Mar 8, 2007
1 parent 045d758 commit 264a82e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 29 deletions.
10 changes: 3 additions & 7 deletions htroot/Settings_p.java
Expand Up @@ -68,10 +68,7 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve

String page = (post == null) ? "general" : post.get("page", "general");

if (page.equals("general")) {
prop.put("settingsTables", "Settings_General.inc");
}
else if (page.equals("ProxyAccess")) {
if (page.equals("ProxyAccess")) {
prop.put("settingsTables", "Settings_ProxyAccess.inc");
}
else if (page.equals("http")) {
Expand Down Expand Up @@ -100,9 +97,8 @@ else if (page.equals("parser")) {
}
else if (page.equals("crawler")) {
prop.put("settingsTables", "Settings_Crawler.inc");
}
else {
prop.put("settingsTables", "Settings_General.inc");
} else {
prop.put("settingsTables", "");
}

prop.put("port", env.getConfig("port", "8080"));
Expand Down
5 changes: 3 additions & 2 deletions htroot/index.java
Expand Up @@ -93,10 +93,11 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
if (cds.equals("image")) contentdom = plasmaSearchQuery.CONTENTDOM_IMAGE;
if (cds.equals("app")) contentdom = plasmaSearchQuery.CONTENTDOM_APP;

long mylinks = 0;
try {
prop.put("links", groupDigits(Long.parseLong(yacyCore.seedDB.mySeed.get(yacySeed.LCOUNT, "0"))));
prop.put("links", groupDigits(mylinks = Long.parseLong(yacyCore.seedDB.mySeed.get(yacySeed.LCOUNT, "0"))));
} catch (NumberFormatException e) { prop.put("links", "0"); }
prop.put("total-links", groupDigits(yacyCore.seedDB.countActiveURL()));
prop.put("total-links", groupDigits(mylinks + yacyCore.seedDB.countActiveURL()));

// we create empty entries for template strings
String promoteSearchPageGreeting = env.getConfig("promoteSearchPageGreeting", "");
Expand Down
57 changes: 37 additions & 20 deletions source/de/anomic/data/Diff.java
Expand Up @@ -55,19 +55,16 @@
public class Diff {

private final ArrayList /* of Part */ parts = new ArrayList();
private final String o;
private final String n;
private final Object[] o;
private final Object[] n;

/**
* @param o the original <code>String</code>
* @param n the new <code>String</code>
* @throws NullPointerException if one of the arguments is <code>null</code>
*/
public Diff(String o, String n) {
if (o == null || n == null) throw new NullPointerException("neither o nor n must be null");
this.o = o;
this.n = n;
parse(1);
this(o, n, 1);
}

/**
Expand All @@ -80,6 +77,17 @@ public Diff(String o, String n) {
* <code>null</code>
*/
public Diff(String o, String n, int minConsecutive) {
if (o == null || n == null) throw new NullPointerException("neither o nor n must be null");
this.o = new Comparable[o.length()];
for (int i=0; i<o.length(); i++)
this.o[i] = new Character(o.charAt(i));
this.n = new Comparable[n.length()];
for (int i=0; i<n.length(); i++)
this.n[i] = new Character(n.charAt(i));
parse((minConsecutive > 0) ? minConsecutive : 1);
}

public Diff(Object[] o, Object[] n, int minConsecutive) {
if (o == null || n == null) throw new NullPointerException("neither o nor n must be null");
this.o = o;
this.n = n;
Expand Down Expand Up @@ -108,22 +116,21 @@ private void parse(int minLength) {
* E| | |#| | | | | | | | |#| | |#| | |#|
* N| | | | | | | | | | | | |#| | |#| | |
* C| | | | | | | | | | | | | | | | |#| |
* E| | |#| | | | | | | | | |#| | |#| |#|
* E| | |#| | | | | | | | |#| | |#| | |#|
*/
boolean[][] matrix = new boolean[this.n.length()][this.o.length()];
for (int y=0; y<this.n.length(); y++)
for (int x=0; x<this.o.length(); x++)
matrix[y][x] = this.o.charAt(x) == this.n.charAt(y);
boolean[][] matrix = new boolean[this.n.length][this.o.length];
for (int y=0; y<this.n.length; y++)
for (int x=0; x<this.o.length; x++)
matrix[y][x] = this.o[x].equals(this.n[y]);

int s = 0, t = 0;
int[] tmp = findDiagonal(s, t, matrix, minLength);
while (tmp != null) {
int[] tmp;
while ((tmp = findDiagonal(s, t, matrix, minLength)) != null) {
addReplacementParts(s, t, tmp[0], tmp[1]);
this.parts.add(new Part(Part.UNCHANGED, tmp[0], s = tmp[0] + tmp[2]));
t = tmp[1] + tmp[2];
tmp = findDiagonal(s, t, matrix, minLength);
}
addReplacementParts(s, t, this.o.length(), this.n.length());
addReplacementParts(s, t, this.o.length, this.n.length);
}

private void addReplacementParts(int startx, int starty, int endx, int endy) {
Expand Down Expand Up @@ -154,8 +161,10 @@ private static int[] findDiagonal(int x, int y, boolean[][] matrix, int minLengt
for (yy=y; yy<matrix.length; yy++)
for (xx=x; xx<matrix[yy].length; xx++)
if (matrix[yy][xx]) { // reverse order! [y][x]
// save position
rx = xx;
ry = yy;
// follow diagonal as long as far as possible
for (i=1; (yy + i)<matrix.length && (xx + i)<matrix[yy].length; i++)
if (!matrix[yy + i][xx + i])
break;
Expand All @@ -166,14 +175,14 @@ private static int[] findDiagonal(int x, int y, boolean[][] matrix, int minLengt
}

/**
* @return the original <code>String</code> passed to this class on instantiation
* @return the original <code>Object[]</code> passed to this class on instantiation
*/
public String getOriginal() { return this.o; }
public Object[] getOriginal() { return this.o; }

/**
* @return the new <code>String</code> passed to this class on instantiation
* @return the new <code>Object[]</code> passed to this class on instantiation
*/
public String getNew() { return this.n; }
public Object[] getNew() { return this.n; }

/**
* A diff is composed of different parts. Each of these parts stands for an
Expand Down Expand Up @@ -225,7 +234,15 @@ private Part(int action, int posOld, int posNew) {
* @return the plain string this diff-part cares about
*/
public String getString() {
return ((this.action == ADDED) ? Diff.this.n : Diff.this.o).substring(this.posOld, this.posNew);
final StringBuffer sb = new StringBuffer(this.posNew - this.posOld);
if (this.action == ADDED) {
for (int i=this.posOld; i<this.posNew; i++)
sb.append(Diff.this.n[i]);
} else {
for (int i=this.posOld; i<this.posNew; i++)
sb.append(Diff.this.o[i]);
}
return new String(sb);
}

/**
Expand Down

0 comments on commit 264a82e

Please sign in to comment.