@ -28,19 +28,11 @@
package de.anomic.kelondro ;
package de.anomic.kelondro ;
import java.io.UnsupportedEncodingException ;
import java.io.UnsupportedEncodingException ;
import java.util.HashMap ;
public class kelondroRow {
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 kelondroColumn [ ] row ;
protected int [ ] colstart ;
protected int [ ] colstart ;
private HashMap encodedFormConfiguration ;
private int encodedFormLength ;
private int encodedFormLength ;
private int objectsize ;
private int objectsize ;
@ -48,25 +40,26 @@ public class kelondroRow {
this . row = row ;
this . row = row ;
this . colstart = new int [ row . length ] ;
this . colstart = new int [ row . length ] ;
this . objectsize = 0 ;
this . objectsize = 0 ;
this . encodedFormLength = 0 ;
for ( int i = 0 ; i < row . length ; i + + ) {
for ( int i = 0 ; i < row . length ; i + + ) {
this . colstart [ i ] = this . objectsize ;
this . colstart [ i ] = this . objectsize ;
this . objectsize + = row [ i ] . cellwidth ( ) ;
this . objectsize + = this . row [ i ] . cellwidth ( ) ;
this . encodedFormLength + = this . row [ i ] . encodedwidth ( ) ;
}
}
this . encodedFormConfiguration = null ;
this . encodedFormLength = - 1 ;
}
}
public kelondroRow ( int [ ] row ) {
public kelondroRow ( int [ ] row i ) {
this . row = new kelondroColumn [ row . length ] ;
this . row = new kelondroColumn [ row i . length ] ;
this . colstart = new int [ row . length ] ;
this . colstart = new int [ row i . length ] ;
this . objectsize = 0 ;
this . objectsize = 0 ;
for ( int i = 0 ; i < row . length ; i + + ) {
this . encodedFormLength = 0 ;
this . row [ i ] = new kelondroColumn ( kelondroColumn . celltype_undefined , row [ i ] , "col_" + i , "" ) ;
for ( int i = 0 ; i < rowi . length ; i + + ) {
this . row [ i ] = new kelondroColumn ( "col_" + i , kelondroColumn . celltype_undefined , rowi [ i ] , kelondroColumn . encoder_none , rowi [ i ] , "" ) ;
this . colstart [ i ] = this . objectsize ;
this . colstart [ i ] = this . objectsize ;
this . objectsize + = row [ i ] ;
this . objectsize + = this . row [ i ] . cellwidth ( ) ;
this . encodedFormLength + = this . row [ i ] . encodedwidth ( ) ;
}
}
this . encodedFormConfiguration = null ;
this . encodedFormLength = - 1 ;
}
}
public int columns ( ) {
public int columns ( ) {
@ -87,27 +80,6 @@ public class kelondroRow {
return w ;
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 Entry newEntry ( ) {
public Entry newEntry ( ) {
return new Entry ( ) ;
return new Entry ( ) ;
}
}
@ -194,26 +166,6 @@ public class kelondroRow {
kelondroBase64Order . enhancedCoder . encodeLong ( cell , rowinstance , colstart [ column ] , row [ column ] . cellwidth ( ) ) ;
kelondroBase64Order . enhancedCoder . encodeLong ( cell , rowinstance , colstart [ column ] , row [ column ] . cellwidth ( ) ) ;
}
}
/ *
public byte [ ] [ ] getCols ( ) {
byte [ ] [ ] values = new byte [ row . length ] [ ] ;
int length , offset ;
for ( int i = 0 ; i < row . length ; i + + ) {
length = row [ i ] . cellwidth ( ) ;
offset = colstart [ i ] ;
while ( ( length > 0 ) & & ( rowinstance [ offset + length - 1 ] = = 0 ) ) length - - ;
if ( length = = 0 ) {
values [ i ] = null ;
} else {
values [ i ] = new byte [ length ] ;
System . arraycopy ( rowinstance , offset , values [ i ] , 0 , length ) ;
}
}
return values ;
}
* /
public String getColString ( int column , String encoding ) {
public String getColString ( int column , String encoding ) {
int length = row [ column ] . cellwidth ( ) ;
int length = row [ column ] . cellwidth ( ) ;
int offset = colstart [ column ] ;
int offset = colstart [ column ] ;
@ -251,31 +203,29 @@ public class kelondroRow {
public byte [ ] toEncodedBytesForm ( ) {
public byte [ ] toEncodedBytesForm ( ) {
byte [ ] b = new byte [ encodedFormLength ] ;
byte [ ] b = new byte [ encodedFormLength ] ;
int [ ] format ;
int encoder , encodedwidth ;
int encoder , length ;
int p = 0 ;
int p = 0 ;
for ( int i = 0 ; i < row . length ; i + + ) {
for ( int i = 0 ; i < row . length ; i + + ) {
format = ( int [ ] ) encodedFormConfiguration . get ( row [ i ] . nickname ( ) ) ;
encoder = row [ i ] . encoder ( ) ;
encoder = format [ 0 ] ;
encodedwidth = row [ i ] . encodedwidth ( ) ;
length = format [ 1 ] ;
switch ( row [ i ] . celltype ( ) ) {
switch ( row [ i ] . celltype ( ) ) {
case kelondroColumn . celltype_undefined :
case kelondroColumn . celltype_undefined :
throw new kelondroException ( "ROW" , "toEncodedForm of celltype undefined not possible" ) ;
throw new kelondroException ( "ROW" , "toEncodedForm of celltype undefined not possible" ) ;
case kelondroColumn . celltype_boolean :
case kelondroColumn . celltype_boolean :
throw new kelondroException ( "ROW" , "toEncodedForm of celltype boolean not yet implemented" ) ;
throw new kelondroException ( "ROW" , "toEncodedForm of celltype boolean not yet implemented" ) ;
case kelondroColumn . celltype_binary :
case kelondroColumn . celltype_binary :
System . arraycopy ( rowinstance , colstart [ i ] , b , p , leng th) ;
System . arraycopy ( rowinstance , colstart [ i ] , b , p , encodedwid th) ;
p + = leng th;
p + = encodedwid th;
continue ;
continue ;
case kelondroColumn . celltype_string :
case kelondroColumn . celltype_string :
System . arraycopy ( rowinstance , colstart [ i ] , b , p , leng th) ;
System . arraycopy ( rowinstance , colstart [ i ] , b , p , encodedwid th) ;
p + = leng th;
p + = encodedwid th;
continue ;
continue ;
case kelondroColumn . celltype_cardinal :
case kelondroColumn . celltype_cardinal :
if ( encoder = = encoder_b64e) {
if ( encoder = = kelondroColumn. encoder_b64e) {
long c = bytes2long ( rowinstance , colstart [ i ] ) ;
long c = bytes2long ( rowinstance , colstart [ i ] ) ;
System . arraycopy ( kelondroBase64Order . enhancedCoder . encodeLongSmart ( c , leng th) . getBytes ( ) , 0 , b , p , leng th) ;
System . arraycopy ( kelondroBase64Order . enhancedCoder . encodeLongSmart ( c , encodedwid th) . getBytes ( ) , 0 , b , p , encodedwid th) ;
p + = leng th;
p + = encodedwid th;
continue ;
continue ;
}
}
throw new kelondroException ( "ROW" , "toEncodedForm of celltype cardinal has no encoder (" + encoder + ")" ) ;
throw new kelondroException ( "ROW" , "toEncodedForm of celltype cardinal has no encoder (" + encoder + ")" ) ;