1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 09:49:19 +02:00

code simplification

This commit is contained in:
Nikolay Pultsin 2015-04-23 06:28:08 +01:00
parent 1f4641085d
commit 3256027dd8
8 changed files with 24 additions and 93 deletions

View file

@ -41,7 +41,6 @@ JavaClass AndroidUtil::Class_FileInfo("org/geometerplus/zlibrary/core/fonts/File
JavaClass AndroidUtil::Class_FileEncryptionInfo("org/geometerplus/zlibrary/core/drm/FileEncryptionInfo");
JavaClass AndroidUtil::Class_ZLFileImage("org/geometerplus/zlibrary/core/image/ZLFileImage");
JavaClass AndroidUtil::Class_ZLTextModel("org/geometerplus/zlibrary/text/model/ZLTextModel");
JavaClass AndroidUtil::Class_CachedCharStorageException("org/geometerplus/zlibrary/text/model/CachedCharStorageException");
JavaClass AndroidUtil::Class_Encoding("org/geometerplus/zlibrary/core/encodings/Encoding");
JavaClass AndroidUtil::Class_EncodingConverter("org/geometerplus/zlibrary/core/encodings/EncodingConverter");

View file

@ -80,7 +80,6 @@ public:
static JavaClass Class_FileEncryptionInfo;
static JavaClass Class_ZLFileImage;
static JavaClass Class_ZLTextModel;
static JavaClass Class_CachedCharStorageException;
static JavaClass Class_NativeFormatPlugin;
static JavaClass Class_PluginCollection;
static JavaClass Class_Encoding;

View file

@ -28,7 +28,7 @@ import org.geometerplus.zlibrary.text.model.*;
import org.geometerplus.fbreader.book.Book;
abstract class BookModelImpl extends BookModel {
protected CharStorage myInternalHyperlinks;
protected CachedCharStorage myInternalHyperlinks;
protected final HashMap<String,ZLImage> myImageMap = new HashMap<String,ZLImage>();
protected final HashMap<String,ZLTextModel> myFootnotes = new HashMap<String,ZLTextModel>();

View file

@ -31,7 +31,7 @@ public class NativeBookModel extends BookModelImpl {
}
public void initInternalHyperlinks(String directoryName, String fileExtension, int blocksNumber) {
myInternalHyperlinks = new CachedCharStorageRO(directoryName, fileExtension, blocksNumber);
myInternalHyperlinks = new CachedCharStorage(directoryName, fileExtension, blocksNumber);
}
private TOCTree myCurrentTree = TOCTree;
@ -55,7 +55,7 @@ public class NativeBookModel extends BookModelImpl {
int[] paragraphLenghts, int[] textSizes, byte[] paragraphKinds,
String directoryName, String fileExtension, int blocksNumber
) {
return new ZLTextNativeModel(
return new ZLTextPlainModel(
id, language, paragraphsNumber,
entryIndices, entryOffsets,
paragraphLenghts, textSizes, paragraphKinds,

View file

@ -24,20 +24,20 @@ import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
public final class CachedCharStorageRO implements CharStorage {
public final class CachedCharStorage {
protected final ArrayList<WeakReference<char[]>> myArray =
new ArrayList<WeakReference<char[]>>();
private final String myDirectoryName;
private final String myFileExtension;
public CachedCharStorageRO(String directoryName, String fileExtension, int blocksNumber) {
public CachedCharStorage(String directoryName, String fileExtension, int blocksNumber) {
myDirectoryName = directoryName + '/';
myFileExtension = '.' + fileExtension;
myArray.addAll(Collections.nCopies(blocksNumber, new WeakReference<char[]>(null)));
}
protected String fileName(int index) {
private String fileName(int index) {
return myDirectoryName + index + myFileExtension;
}

View file

@ -1,25 +0,0 @@
/*
* Copyright (C) 2007-2015 FBReader.ORG Limited <contact@fbreader.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
package org.geometerplus.zlibrary.text.model;
public interface CharStorage {
int size();
char[] block(int index);
}

View file

@ -1,46 +0,0 @@
/*
* Copyright (C) 2011-2015 FBReader.ORG Limited <contact@fbreader.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
package org.geometerplus.zlibrary.text.model;
import java.util.Map;
import org.geometerplus.zlibrary.core.fonts.FontManager;
import org.geometerplus.zlibrary.core.image.ZLImage;
public class ZLTextNativeModel extends ZLTextPlainModel {
public ZLTextNativeModel(
String id, String language, int paragraphsNumber,
int[] entryIndices, int[] entryOffsets,
int[] paragraphLengths, int[] textSizes,
byte[] paragraphKinds,
String directoryName, String fileExtension, int blocksNumber,
Map<String,ZLImage> imageMap,
FontManager fontManager
) {
super(
id, language,
entryIndices, entryOffsets, paragraphLengths, textSizes, paragraphKinds,
new CachedCharStorageRO(directoryName, fileExtension, blocksNumber),
imageMap,
fontManager
);
myParagraphsNumber = paragraphsNumber;
}
}

View file

@ -25,20 +25,20 @@ import org.geometerplus.zlibrary.core.fonts.FontManager;
import org.geometerplus.zlibrary.core.image.ZLImage;
import org.geometerplus.zlibrary.core.util.*;
public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
public final class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
private final String myId;
private final String myLanguage;
protected int[] myStartEntryIndices;
protected int[] myStartEntryOffsets;
protected int[] myParagraphLengths;
protected int[] myTextSizes;
protected byte[] myParagraphKinds;
private int[] myStartEntryIndices;
private int[] myStartEntryOffsets;
private int[] myParagraphLengths;
private int[] myTextSizes;
private byte[] myParagraphKinds;
protected int myParagraphsNumber;
private int myParagraphsNumber;
protected final CharStorage myStorage;
protected final Map<String,ZLImage> myImageMap;
private final CachedCharStorage myStorage;
private final Map<String,ZLImage> myImageMap;
private ArrayList<ZLTextMark> myMarks;
@ -298,26 +298,30 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
}
}
protected ZLTextPlainModel(
public ZLTextPlainModel(
String id,
String language,
int paragraphsNumber,
int[] entryIndices,
int[] entryOffsets,
int[] paragraphLenghts,
int[] paragraphLengths,
int[] textSizes,
byte[] paragraphKinds,
CharStorage storage,
String directoryName,
String fileExtension,
int blocksNumber,
Map<String,ZLImage> imageMap,
FontManager fontManager
) {
myId = id;
myLanguage = language;
myParagraphsNumber = paragraphsNumber;
myStartEntryIndices = entryIndices;
myStartEntryOffsets = entryOffsets;
myParagraphLengths = paragraphLenghts;
myParagraphLengths = paragraphLengths;
myTextSizes = textSizes;
myParagraphKinds = paragraphKinds;
myStorage = storage;
myStorage = new CachedCharStorage(directoryName, fileExtension, blocksNumber);
myImageMap = imageMap;
myFontManager = fontManager;
}