Example #1
0
 private void insertLetterInNonWord(TextBlock tb, char c, int cp) {
   WordBlock wb = new WordBlock();
   wb.setText("" + c);
   tb.insert(wb, cp);
   caretBlock = wb;
   caretPos = 1;
 }
Example #2
0
 private void addNewWordBlockAfter(TextBlock bpr, char c) {
   WordBlock wb = new WordBlock();
   wb.setText("" + c);
   Block bnx = bpr.next();
   bpr.setNext(wb);
   wb.setNext(bnx);
   caretBlock = wb;
   caretPos = 1;
 }
Example #3
0
 private WordBlock readWordBlock(int position) throws IOException {
   MappedByteBuffer buffer = fileChannel.map(MapMode.READ_ONLY, position, block_size).load();
   WordBlock block = new WordBlock(position);
   byte[] data = new byte[block_size];
   buffer.get(data);
   block.setData(data);
   block.decode();
   return block;
 }
Example #4
0
 private void writeWordBlock(WordBlock block) throws IOException {
   MappedByteBuffer buffer = fileChannel.map(MapMode.READ_WRITE, block.position, block_size);
   byte[] data = block.encode();
   if (data.length > block_size) {
     throw new RuntimeException();
   }
   buffer.put(data);
   // buffer.force();
 }
Example #5
0
 public void put(String key, String value) throws IOException {
   int hash = hash(key);
   int i = indexFor(hash, capacity);
   int position = i * block_size;
   WordBlock b = readWordBlock(position);
   for (; b.nextPosition > 0; b = readWordBlock(b.nextPosition)) {
     Object k;
     if (hash(b.word) == hash && ((k = b.word) == key || key.equals(k))) {
       b.translate = value;
       writeWordBlock(b);
       return;
     }
   }
   if (b.nextPosition == 0) {
     b = new WordBlock(b.position);
   } else {
     int nextPosition = 0;
     if (fileChannel.size() > capacity * block_size) {
       nextPosition = (int) fileChannel.size();
     } else {
       nextPosition = capacity * block_size;
     }
     System.out.println(key + "  " + b.word);
     b.nextPosition = nextPosition;
     writeWordBlock(b);
     b = new WordBlock(nextPosition);
   }
   b.word = key;
   b.translate = value;
   b.nextPosition = -1;
   writeWordBlock(b);
 }