Merge pull request #34 from lacerta-doc/improve/remove_page_index

Indexの廃止
This commit is contained in:
ろむねこ 2024-01-09 17:26:14 +09:00 committed by GitHub
commit 0140c0376b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 2 additions and 63 deletions

View File

@ -70,35 +70,4 @@ public class XmlMetaModel {
this.pages = pages;
}
// Public Methods
public void addPage(XmlMetaPageModel page) {
this.pages.add(page);
}
public void addPageAfterIndex(int index, XmlMetaPageModel page) {
this.pages.add(index, page);
//Update index
this.updateIndex();
}
public void removePage(XmlMetaPageModel page) {
this.pages.remove(page);
}
public void removePageAtIndex(int index) {
this.pages.remove(index);
//Update index
this.updateIndex();
}
// Internal Methods
private void updateIndex() { // TODO-rca: 効率悪そう
for (int i = 0; i < this.pages.size(); i++) {
this.pages.get(i).setIndex(i);
}
}
}

View File

@ -2,7 +2,6 @@ package one.nem.lacerta.model.document.internal;
public class XmlMetaPageModel {
int index;
String filename;
// Constructor
@ -10,27 +9,18 @@ public class XmlMetaPageModel {
public XmlMetaPageModel() {
}
public XmlMetaPageModel(int index, String filename) {
this.index = index;
public XmlMetaPageModel(String filename) {
this.filename = filename;
}
// Getter
public int getIndex() {
return index;
}
public String getFilename() {
return filename;
}
// Setter
public void setIndex(int index) {
this.index = index;
}
public void setFilename(String filename) {
this.filename = filename;
}

View File

@ -102,11 +102,10 @@ public class DocumentProcessorImpl implements DocumentProcessor{
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
xmlMetaPageModel.setFilename(filename);
xmlMetaPageModel.setIndex(xmlMetaModel.getPages().size() + 1);
xmlMetaModel.getPages().add(xmlMetaPageModel);
logger.info("addNewPageToLast", "finished");
logger.info("addNewPageToLast", "filename: " + filename + ", index: " + xmlMetaPageModel.getIndex());
logger.info("addNewPageToLast", "filename: " + filename);
}
@Override
@ -118,19 +117,6 @@ public class DocumentProcessorImpl implements DocumentProcessor{
} // TODO-rca: 効率悪いので改善する
}
// Internal
// Indexを振り直す
private ArrayList<XmlMetaPageModel> reIndexPages(ArrayList<XmlMetaPageModel> pages) {
logger.debug("reIndexPages", "called"); // TODO-rca: 効率化
ArrayList<XmlMetaPageModel> newPages = new ArrayList<>();
for (int i = 0; i < pages.size(); i++) {
XmlMetaPageModel xmlMetaPageModel = pages.get(i);
xmlMetaPageModel.setIndex(i + 1);
newPages.add(xmlMetaPageModel);
}
return newPages;
}
@Override
public void addNewPageAfterIndex(Bitmap bitmap, int index) throws Exception {
logger.debug("addNewPageAfterIndex", "called");
@ -140,9 +126,7 @@ public class DocumentProcessorImpl implements DocumentProcessor{
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
xmlMetaPageModel.setFilename(filename);
xmlMetaPageModel.setIndex(index + 1);
xmlMetaModel.getPages().add(index, xmlMetaPageModel);
xmlMetaModel.setPages(reIndexPages(xmlMetaModel.getPages()));
}
@Override
@ -154,9 +138,7 @@ public class DocumentProcessorImpl implements DocumentProcessor{
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
xmlMetaPageModel.setFilename(filename);
xmlMetaPageModel.setIndex(index);
xmlMetaModel.getPages().add(index - 1, xmlMetaPageModel);
xmlMetaModel.setPages(reIndexPages(xmlMetaModel.getPages()));
}
@Override

View File

@ -41,7 +41,6 @@ public class XmlMetaParserImpl implements XmlMetaParser{
for(int i = 0; i < rootElement.getElementsByTagName("pages").getLength(); i++) {
Element pageElement = (Element) rootElement.getElementsByTagName("page").item(i);
XmlMetaPageModel page = new XmlMetaPageModel();
page.setIndex(Integer.parseInt(pageElement.getElementsByTagName("index").item(0).getTextContent()));
page.setFilename(pageElement.getElementsByTagName("filename").item(0).getTextContent());
pages.add(page);
}
@ -73,7 +72,6 @@ public class XmlMetaParserImpl implements XmlMetaParser{
Element pagesElement = document.createElement("pages");
for(XmlMetaPageModel page : meta.getPages()) {
Element pageElement = document.createElement("page");
appendElement(document, pageElement, "index", String.valueOf(page.getIndex()));
appendElement(document, pageElement, "filename", page.getFilename());
pagesElement.appendChild(pageElement);
}