update to row/column handling

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2154 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 19 years ago
parent 9d83ed4006
commit d580f582dc

@ -25,17 +25,16 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package de.anomic.kelondro;
public class kelondroColumn {
public static int celltype_undefined = 0;
public static int celltype_boolean = 1;
public static int celltype_bytes = 2;
public static int celltype_string = 3;
public static int celltype_cardinal = 4;
public static int celltype_real = 5;
public static final int celltype_undefined = 0;
public static final int celltype_boolean = 1;
public static final int celltype_bytes = 2;
public static final int celltype_string = 3;
public static final int celltype_cardinal = 4;
public static final int celltype_real = 5;
private int celltype, dbwidth;
private String nickname, description;
@ -62,4 +61,5 @@ public class kelondroColumn {
public String description() {
return this.description;
}
}

@ -27,17 +27,31 @@
package de.anomic.kelondro;
import java.util.HashMap;
public class kelondroRow {
public static final int encoder_b64e = 0;
public static final int encoder_string = 1;
public static final int encoder_bytes = 2;
public static final int encoder_char = 3;
private kelondroColumn[] row;
private HashMap encodedFormConfiguration;
private int encodedFormLength;
public kelondroRow(kelondroColumn[] row) {
this.row = row;
this.encodedFormConfiguration = null;
this.encodedFormLength = -1;
}
public kelondroRow(int[] row) {
this.row = new kelondroColumn[row.length];
for (int i = 0; i < row.length; i++) this.row[i] = new kelondroColumn(kelondroColumn.celltype_undefined, row[i], "", "");
for (int i = 0; i < row.length; i++) this.row[i] = new kelondroColumn(kelondroColumn.celltype_undefined, row[i], "col_" + i, "");
this.encodedFormConfiguration = null;
this.encodedFormLength = -1;
}
public int columns() {
@ -54,4 +68,70 @@ public class kelondroRow {
return w;
}
private static int encoderCode(String encoderName) {
if (encoderName.equals("b54e")) return encoder_b64e;
if (encoderName.equals("string")) return encoder_string;
if (encoderName.equals("char")) return encoder_char;
return -1;
}
public void configureEncodedForm(String[][] configuration) {
encodedFormConfiguration = new HashMap();
String nick;
int encoder, length;
this.encodedFormLength = 0;
for (int i = 0; i < configuration.length; i++) {
nick = configuration[i][0];
encoder = encoderCode(configuration[i][1]);
length = Integer.parseInt(configuration[i][2]);
encodedFormConfiguration.put(nick, new int[]{encoder, length});
this.encodedFormLength += length;
}
}
public class Entry {
private byte[][] cols;
public Entry(byte[][] cols) {
this.cols = cols;
}
public byte[] toEncodedBytesForm() {
byte[] b = new byte[encodedFormLength];
int[] format;
int encoder, length;
int p = 0;
for (int i = 0; i < row.length; i++) {
format = (int[]) encodedFormConfiguration.get(row[i].nickname());
encoder = format[0];
length = format[1];
switch (row[i].celltype()) {
case kelondroColumn.celltype_undefined:
throw new kelondroException("ROW", "toEncodedForm of celltype undefined not possible");
case kelondroColumn.celltype_boolean:
throw new kelondroException("ROW", "toEncodedForm of celltype boolean not yet implemented");
case kelondroColumn.celltype_bytes:
System.arraycopy(cols[i], 0, b, p, length);
p += length;
continue;
case kelondroColumn.celltype_string:
System.arraycopy(cols[i], 0, b, p, length);
p += length;
continue;
case kelondroColumn.celltype_cardinal:
if (encoder == encoder_b64e) {
long c = kelondroRecords.bytes2long(cols[i]);
System.arraycopy(kelondroBase64Order.enhancedCoder.encodeLongSmart(c, length).getBytes(), 0, b, p, length);
p += length;
continue;
}
throw new kelondroException("ROW", "toEncodedForm of celltype cardinal has no encoder (" + encoder + ")");
case kelondroColumn.celltype_real:
throw new kelondroException("ROW", "toEncodedForm of celltype real not yet implemented");
}
}
return b;
}
}
}

Loading…
Cancel
Save