mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
code simplification
This commit is contained in:
parent
b6a701520e
commit
70a58af8e7
3 changed files with 32 additions and 36 deletions
|
@ -22,6 +22,7 @@ package org.geometerplus.fbreader.network;
|
|||
import java.util.*;
|
||||
|
||||
import org.geometerplus.zlibrary.core.options.ZLStringListOption;
|
||||
import org.geometerplus.zlibrary.core.language.ZLLanguageUtil;
|
||||
|
||||
import org.geometerplus.fbreader.network.urlInfo.*;
|
||||
|
||||
|
@ -169,4 +170,33 @@ public abstract class AbstractNetworkLink implements INetworkLink, Basket {
|
|||
+ "; infos=" + myInfos
|
||||
+ "}";
|
||||
}
|
||||
|
||||
private String getTitleForComparison() {
|
||||
String title = getTitle();
|
||||
for (int index = 0; index < title.length(); ++index) {
|
||||
final char ch = title.charAt(index);
|
||||
if (ch < 128 && Character.isLetter(ch)) {
|
||||
return title.substring(index);
|
||||
}
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
private static int getLanguageOrder(String language) {
|
||||
if (language == ZLLanguageUtil.MULTI_LANGUAGE_CODE) {
|
||||
return 1;
|
||||
}
|
||||
if (language.equals(Locale.getDefault().getLanguage())) {
|
||||
return 0;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int compareTo(INetworkLink link) {
|
||||
final int diff = getLanguageOrder(getLanguage()) - getLanguageOrder(link.getLanguage());
|
||||
if (diff != 0) {
|
||||
return diff;
|
||||
}
|
||||
return getTitleForComparison().compareToIgnoreCase(((AbstractNetworkLink)link).getTitleForComparison());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.geometerplus.fbreader.network.authentication.NetworkAuthenticationMan
|
|||
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
|
||||
import org.geometerplus.fbreader.network.urlInfo.UrlInfoWithDate;
|
||||
|
||||
public interface INetworkLink {
|
||||
public interface INetworkLink extends Comparable<INetworkLink> {
|
||||
public static final int INVALID_ID = -1;
|
||||
|
||||
int getId();
|
||||
|
|
|
@ -49,40 +49,6 @@ public class NetworkLibrary {
|
|||
return ZLResource.resource("networkLibrary");
|
||||
}
|
||||
|
||||
private static class LinksComparator implements Comparator<INetworkLink> {
|
||||
private static String filterLinkTitle(String title) {
|
||||
for (int index = 0; index < title.length(); ++index) {
|
||||
final char ch = title.charAt(index);
|
||||
if (ch < 128 && Character.isLetter(ch)) {
|
||||
return title.substring(index);
|
||||
}
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
private static int languageOrder(String language) {
|
||||
if (language == ZLLanguageUtil.MULTI_LANGUAGE_CODE) {
|
||||
return 1;
|
||||
}
|
||||
if (language.equals(Locale.getDefault().getLanguage())) {
|
||||
return 0;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int compare(INetworkLink link1, INetworkLink link2) {
|
||||
final int languageOrder1 = languageOrder(link1.getLanguage());
|
||||
final int languageOrder2 = languageOrder(link2.getLanguage());
|
||||
if (languageOrder1 != languageOrder2) {
|
||||
return languageOrder1 - languageOrder2;
|
||||
}
|
||||
final String title1 = filterLinkTitle(link1.getTitle());
|
||||
final String title2 = filterLinkTitle(link2.getTitle());
|
||||
return title1.compareToIgnoreCase(title2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface OnNewLinkListener {
|
||||
void onNewLink(INetworkLink link);
|
||||
}
|
||||
|
@ -303,7 +269,7 @@ public class NetworkLibrary {
|
|||
int nodeCount = 0;
|
||||
|
||||
final ArrayList<INetworkLink> links = new ArrayList<INetworkLink>(activeLinks());
|
||||
Collections.sort(links, new LinksComparator());
|
||||
Collections.sort(links);
|
||||
for (int i = 0; i < links.size(); ++i) {
|
||||
INetworkLink link = links.get(i);
|
||||
boolean processed = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue