All Downloads are FREE. Search and download functionalities are using the official Maven repository.

water.parser.BufferedString Maven / Gradle / Ivy

There is a newer version: 3.8.2.9
Show newest version
package water.parser;

import com.google.common.base.Charsets;
import water.AutoBuffer;
import water.Iced;

import java.util.Arrays;
import java.util.Formatter;

public class BufferedString extends Iced implements Comparable {
   private byte [] _buf;
   private int _off;
   private int _len;

   BufferedString(byte[] buf, int off, int len) { _buf = buf;  _off = off;  _len = len; }
   BufferedString(byte[] buf) { this(buf,0,buf.length); }
   public BufferedString(String from) { this(from.getBytes(Charsets.UTF_8)); }
   // Cloning constructing used during collecting unique categoricals
   BufferedString(BufferedString from) { this(Arrays.copyOfRange(from._buf,from._off,from._off+from._len)); }
   // Used to make a temp recycling BufferedString in hot loops
   public BufferedString() { }

   public final AutoBuffer write_impl(AutoBuffer ab) {
     if( _buf == null ) return ab.putInt(-1);
     ab.putInt(_buf.length);
     return ab.putA1(_buf,_off,_len);
   }

  public final BufferedString read_impl(AutoBuffer ab){
    _buf = ab.getA1();
    if(_buf != null) _len = _buf.length;
    return this;
  }

   @Override public int compareTo( BufferedString o ) {
     int len = Math.min(_len,o._len);
     for( int i=0; i");
          inHex = false;
        }
        formatter.format("%c", _buf[_off + i]);
      }
    }
    if (inHex) sb.append(">"); // close hex values as trailing char
    return sb.toString();
  }

  public static String[] toString(BufferedString bStr[]) {
    if( bStr==null ) return null;
    String[] ss = new String[bStr.length];
    for( int i=0; i '9') return NA;
      i++;
    }
    if (decimalCnt > 0)
      if (decimalCnt == 1) return REAL;
      else return NA; //more than one decimal, NaN
    else return INT;
  }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy