Skip to content
This repository has been archived by the owner on Jul 16, 2022. It is now read-only.

Commit

Permalink
PDIC: refactoring byte search and code styles
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
  • Loading branch information
miurahr committed Sep 28, 2021
1 parent f6fb84b commit 6000e3d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 28 deletions.
3 changes: 3 additions & 0 deletions src/main/java/io/github/eb4j/ebview/dictionary/PDic.java
Expand Up @@ -8,6 +8,9 @@
import java.util.HashSet;
import java.util.Set;

/**
* @author Hiroshi Miura
*/
public class PDic implements IDictionaryFactory {
/**
* Determine whether or not the supplied file is supported by this factory.
Expand Down
Expand Up @@ -13,6 +13,10 @@
import java.util.ArrayList;
import java.util.List;

/**
* @author wak (Apache-2.0)
* @author Hiroshi Miura
*/
public class PdicDictionary implements IDictionary {

static final Logger LOG = LoggerFactory.getLogger(PdicDictionary.class.getName());
Expand Down Expand Up @@ -65,7 +69,7 @@ public String getDictionaryName() {
* @return List of entries. May be empty, but cannot be null.
*/
@Override
public List<DictionaryEntry> readArticles(String word) {
public List<DictionaryEntry> readArticles(final String word) {
List<DictionaryEntry> lists = new ArrayList<>();
if (dicInfo.searchWord(word.toLowerCase())) {
PdicResult result = dicInfo.getResult();
Expand Down Expand Up @@ -98,14 +102,14 @@ public List<DictionaryEntry> readArticles(String word) {
* @return List of entries. May be empty, but cannot be null.
*/
@Override
public List<DictionaryEntry> readArticlesPredictive(String word) {
public List<DictionaryEntry> readArticlesPredictive(final String word) {
return readArticles(word);
}

/**
* Dispose IDictionary. Default is no action.
*/
@Override
public void close() throws IOException {
public void close() {
}
}
@@ -1,8 +1,9 @@
/**
* Copyright (C) 2014 wak (Apache-2.0)
*/
package io.github.eb4j.ebview.dictionary.pdic;

/**
* @author wak (Apache-2.0)
* @author Hiroshi Miura
*/
@SuppressWarnings("visibilitymodifier")
final class PdicElement {
public byte mAttr = 0;
Expand Down
@@ -1,11 +1,12 @@
/**
* Copyright (C) 2014 wak (Apache-2.0)
*/
package io.github.eb4j.ebview.dictionary.pdic;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/**
* @author wak (Apache-2.0)
* @author Hiroshi Miura
*/
@SuppressWarnings("visibilitymodifier")
final class PdicHeader {
private static final int L_HEADERNAME = 100; // ヘッダー部文字列長
Expand Down
29 changes: 16 additions & 13 deletions src/main/java/io/github/eb4j/ebview/dictionary/pdic/PdicInfo.java
@@ -1,9 +1,7 @@
/**
* Copyright (C) 2014 wak (Apache-2.0)
*/
package io.github.eb4j.ebview.dictionary.pdic;

import com.ibm.icu.charset.CharsetICU;
import org.apache.commons.lang3.ArrayUtils;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -17,6 +15,10 @@
import java.nio.charset.Charset;
import java.util.WeakHashMap;

/**
* @author wak (Apache-2.0)
* @author Hiroshi Miura
*/
@SuppressWarnings("membername")
class PdicInfo {
protected File m_file;
Expand Down Expand Up @@ -203,17 +205,18 @@ public int getBlockNo(int num) {
}

/**
* 次の0までの長さを返す
* 次の0までの長さを返す.
*
* @param array
* @param pos
* @return
* @param array target byte array
* @param pos start position
* @return length of index.
*/
static protected int getLengthToNextZero(byte[] array, int pos) {
int len = 0;
while (array[pos + len] != 0)
len++;
return len;
static protected int getLengthToNextZero(final byte[] array, final int pos) {
return ArrayUtils.indexOf(array, (byte) 0, pos) - pos;
// int len = 0;
// while (array[pos + len] != 0)
// len++;
// return len;
}

boolean IsMatch() {
Expand Down Expand Up @@ -251,7 +254,7 @@ public boolean searchWord(String _word) {
boolean match = false;

boolean searchret = false;
for (; ; ) {
while (true) {
// 最終ブロックは超えない
if (ret < m_nindex) {
// 該当ブロック読み出し
Expand Down
@@ -1,6 +1,3 @@
/**
* Copyright (C) 2014 wak (Apache-2.0)
*/
package io.github.eb4j.ebview.dictionary.pdic;

import com.ibm.icu.charset.CharsetICU;
Expand All @@ -10,6 +7,10 @@
import java.lang.ref.WeakReference;
import java.util.WeakHashMap;

/**
* @author wak (Apache-2.0)
* @author Hiroshi Miura
*/
class PdicInfoCache {
private final boolean mFix;
private final int mBlockSize;
Expand Down
@@ -1,10 +1,11 @@
/**
* Copyright (C) 2014 wak (Apache-2.0)
*/
package io.github.eb4j.ebview.dictionary.pdic;

import java.util.ArrayList;

/**
* @author wak (Apache-2.0)
* @author Hiroshi Miura
*/
final class PdicResult extends ArrayList<PdicElement> {

private static final long serialVersionUID = -7784622190169021306L;
Expand Down

0 comments on commit 6000e3d

Please sign in to comment.