Home | History | Annotate | Download | only in makedict
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.inputmethod.latin.makedict;
     18 
     19 import com.android.inputmethod.annotations.UsedForTesting;
     20 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
     21 
     22 import java.io.File;
     23 import java.io.IOException;
     24 import java.util.ArrayList;
     25 
     26 /**
     27  * An implementation of DictUpdater for version 4 binary dictionary.
     28  */
     29 @UsedForTesting
     30 public class Ver4DictUpdater extends Ver4DictDecoder implements DictUpdater {
     31 
     32     @UsedForTesting
     33     public Ver4DictUpdater(final File dictDirectory, final int factoryType) {
     34         // DictUpdater must have an updatable DictBuffer.
     35         super(dictDirectory, ((factoryType & MASK_DICTBUFFER) == USE_BYTEARRAY)
     36                 ? USE_BYTEARRAY : USE_WRITABLE_BYTEBUFFER);
     37     }
     38 
     39     @Override
     40     public void deleteWord(final String word) throws IOException, UnsupportedFormatException {
     41         if (mDictBuffer == null) openDictBuffer();
     42         readHeader();
     43         final int wordPos = getTerminalPosition(word);
     44         if (wordPos != FormatSpec.NOT_VALID_WORD) {
     45             mDictBuffer.position(wordPos);
     46             final int flags = PtNodeReader.readPtNodeOptionFlags(mDictBuffer);
     47             mDictBuffer.position(wordPos);
     48             mDictBuffer.put((byte) DynamicBinaryDictIOUtils.markAsDeleted(flags));
     49         }
     50     }
     51 
     52     @Override
     53     public void insertWord(final String word, final int frequency,
     54         final ArrayList<WeightedString> bigramStrings, final ArrayList<WeightedString> shortcuts,
     55         final boolean isNotAWord, final boolean isBlackListEntry)
     56                 throws IOException, UnsupportedFormatException {
     57         // TODO: Implement this method.
     58     }
     59 }
     60