replaced _all_ size() == 0 with isEmpty() and all size() > 0 with !isEmpty(). The isEmpty() method is much faster in some cases, especially when used to access badly balanced hashtables where an size() operation becomes a large iteration.

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6510 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 15 years ago
parent f4946eaf27
commit 4a5100789f

@ -113,8 +113,8 @@ public class BlacklistCleaner_p {
prop.put(RESULTS + "blList", blacklistToUse);
prop.put(RESULTS + "entries", illegalEntries.size());
prop.putHTML(RESULTS + "blEngine", Switchboard.urlBlacklist.getEngineInfo());
prop.put(RESULTS + "disabled", (illegalEntries.size() == 0) ? "1" : "0");
if (illegalEntries.size() > 0) {
prop.put(RESULTS + "disabled", (illegalEntries.isEmpty()) ? "1" : "0");
if (!illegalEntries.isEmpty()) {
prop.put(RESULTS + DISABLED + "entries", illegalEntries.size());
int i = 0;
String key;
@ -148,7 +148,7 @@ public class BlacklistCleaner_p {
}
if (supported) {
if (lists.size() > 0) {
if (!lists.isEmpty()) {
prop.put("disabled", "0");
prop.put(DISABLED + "blacklists", lists.size());
int count = 0;

@ -61,7 +61,7 @@ public class BlacklistImpExp_p {
prop.putHTML("blacklistEngine", Switchboard.urlBlacklist.getEngineInfo());
// if we have not chosen a blacklist until yet we use the first file
if (blacklistToUse == null && dirlist != null && dirlist.size() > 0) {
if (blacklistToUse == null && dirlist != null && !dirlist.isEmpty()) {
blacklistToUse = dirlist.get(0);
}

@ -354,7 +354,7 @@ public class Blacklist_p {
}
// if we have not chosen a blacklist until yet we use the first file
if (blacklistToUse == null && dirlist != null && dirlist.size() > 0) {
if (blacklistToUse == null && dirlist != null && !dirlist.isEmpty()) {
blacklistToUse = dirlist.get(0);
}

@ -177,7 +177,7 @@ public class ConfigUpdate_p {
}
}
// latest downloaded release
yacyVersion dflt = (downloadedReleases.size() == 0) ? null : downloadedReleases.last();
yacyVersion dflt = (downloadedReleases.isEmpty()) ? null : downloadedReleases.last();
int relcount = 0;
for(yacyRelease release : downloadedReleases) {
prop.put("candeploy_downloadedreleases_" + relcount + "_name", ((release.isMainRelease()) ? "main" : "dev") + " " + release.getReleaseNr() + "/" + release.getSvn());
@ -204,7 +204,7 @@ public class ConfigUpdate_p {
}
// dev
dflt = (releasess.dev.size() == 0) ? null : releasess.dev.last();
dflt = (releasess.dev.isEmpty()) ? null : releasess.dev.last();
final TreeSet<yacyRelease> remoteDevReleases = releasess.dev;
remoteDevReleases.removeAll(downloadedReleases);
for(yacyRelease release : remoteDevReleases) {

@ -390,7 +390,7 @@ public class IndexControlRWIs_p {
URIMetadataRow entry;
String us;
long rn = -1;
while ((ranked.size() > 0) && ((entry = ranked.takeURL(false, 60000)) != null)) {
while (!ranked.isEmpty() && (entry = ranked.takeURL(false, 60000)) != null) {
if ((entry == null) || (entry.metadata() == null)) continue;
url = entry.metadata().url();
if (url == null) continue;

@ -126,7 +126,7 @@ public class News {
final Map<String, String> attributeMap = record.attributes();
prop.putHTML("table_list_" + i + "_att", attributeMap.toString());
int j = 0;
if (attributeMap.size() > 0) {
if (!attributeMap.isEmpty()) {
for (Entry<String, String> attribute: attributeMap.entrySet()) {
prop.put("table_list_" + i + "_attributes_" + j + "_name", attribute.getKey());
prop.putHTML("table_list_" + i + "_attributes_" + j + "_value", attribute.getValue());

@ -134,7 +134,7 @@ public class Threaddump_p {
HashMap<String, Integer> dumps = dumpStatistic(rootPath, traces, plain, stateIn);
// write dumps
while (dumps.size() > 0) {
while (!dumps.isEmpty()) {
Entry<String, Integer> e = removeMax(dumps);
bufferappend(buffer, plain, "Occurrences: " + e.getValue());
bufferappend(buffer, plain, e.getKey());

@ -54,7 +54,7 @@ public class feed {
// read the channel
feed = RSSFeed.channels(channels[channelIndex]);
if ((feed == null) || (feed.size() == 0)) continue channelIteration;
if (feed == null || feed.isEmpty()) continue channelIteration;
RSSMessage message = feed.getChannel();
if (message != null) {
@ -62,7 +62,7 @@ public class feed {
prop.putXML("channel_description", message.getDescription());
prop.put("channel_pubDate", message.getPubDate());
}
while ((messageMaxCount > 0) && (feed.size() > 0)) {
while (messageMaxCount > 0 && !feed.isEmpty()) {
message = feed.pollMessage();
if (message == null) continue;

@ -212,7 +212,7 @@ public final class transferRWI {
unknownURLs.append(",").append(it.next());
}
if (unknownURLs.length() > 0) { unknownURLs.delete(0, 1); }
if ((wordhashes.size() == 0) || (received == 0)) {
if (wordhashes.isEmpty() || received == 0) {
sb.getLog().logInfo("Received 0 RWIs from " + otherPeerName + ", processed in " + (System.currentTimeMillis() - startProcess) + " milliseconds, requesting " + unknownURL.size() + " URLs, blocked " + blocked + " RWIs");
} else {
String firstHash = wordhashes.get(0);

@ -377,7 +377,7 @@ public class yacysearch {
// filter out stopwords
final TreeSet<String> filtered = SetTools.joinConstructive(query[0], Switchboard.stopwords);
if (filtered.size() > 0) {
if (!filtered.isEmpty()) {
SetTools.excludeDestructive(query[0], Switchboard.stopwords);
}
@ -543,7 +543,7 @@ public class yacysearch {
// find geographic info
Set<Location> coordinates = LibraryProvider.geoDB.find(originalquerystring);
if (coordinates == null || coordinates.size() == 0 || offset > 0) {
if (coordinates == null || coordinates.isEmpty() || offset > 0) {
prop.put("geoinfo", "0");
} else {
int i = 0;
@ -628,14 +628,14 @@ public class yacysearch {
prop.put("eventID", theQuery.id(false)); // for bottomline
// process result of search
if (filtered.size() > 0) {
if (!filtered.isEmpty()) {
prop.put("excluded", "1");
prop.putHTML("excluded_stopwords", filtered.toString());
} else {
prop.put("excluded", "0");
}
if (prop == null || prop.size() == 0) {
if (prop == null || prop.isEmpty()) {
if (post == null || post.get("query", post.get("search", "")).length() < 3) {
prop.put("num-results", "2"); // no results - at least 3 chars
} else {

@ -61,7 +61,7 @@ public class yacysearchtrailer {
// host navigators
ArrayList<NavigatorEntry> hostNavigator = theSearch.getHostNavigator(10);
if (hostNavigator == null || hostNavigator.size() == 0) {
if (hostNavigator == null || hostNavigator.isEmpty()) {
prop.put("nav-domains", 0);
} else {
prop.put("nav-domains", 1);
@ -83,7 +83,7 @@ public class yacysearchtrailer {
// author navigators
ArrayList<NavigatorEntry> authorNavigator = theSearch.getAuthorNavigator(10);
if (authorNavigator == null || authorNavigator.size() == 0) {
if (authorNavigator == null || authorNavigator.isEmpty()) {
prop.put("nav-authors", 0);
} else {
prop.put("nav-authors", 1);
@ -107,7 +107,7 @@ public class yacysearchtrailer {
// topics navigator
ArrayList<NavigatorEntry> topicNavigator = theSearch.getTopicNavigator(10);
if (topicNavigator == null || topicNavigator.size() == 0) {
if (topicNavigator == null || topicNavigator.isEmpty()) {
topicNavigator = new ArrayList<NavigatorEntry>();
prop.put("nav-topics", "0");
} else {

@ -194,7 +194,7 @@ public class Balancer {
while (i.hasNext()) {
if (urlHashes.contains(i.next())) i.remove();
}
if (stack.size() == 0) q.remove();
if (stack.isEmpty()) q.remove();
}
return removedCounter;
@ -214,12 +214,16 @@ public class Balancer {
return urlFileIndex.size();
}
public boolean isEmpty() {
return urlFileIndex.isEmpty();
}
private boolean domainStacksNotEmpty() {
if (domainStacks == null) return false;
synchronized (domainStacks) {
final Iterator<LinkedList<String>> i = domainStacks.values().iterator();
while (i.hasNext()) {
if (i.next().size() > 0) return true;
if (!i.next().isEmpty()) return true;
}
}
return false;
@ -275,7 +279,7 @@ public class Balancer {
}
private String nextFromDelayed() {
if (this.delayed.size() == 0) return null;
if (this.delayed.isEmpty()) return null;
Long first = this.delayed.firstKey();
if (first.longValue() < System.currentTimeMillis()) {
return this.delayed.remove(first);
@ -284,7 +288,7 @@ public class Balancer {
}
private String anyFromDelayed() {
if (this.delayed.size() == 0) return null;
if (this.delayed.isEmpty()) return null;
Long first = this.delayed.firstKey();
return this.delayed.remove(first);
}
@ -325,11 +329,11 @@ public class Balancer {
Request crawlEntry = null;
synchronized (this) {
String failhash = null;
while (this.urlFileIndex.size() > 0) {
while (!this.urlFileIndex.isEmpty()) {
// first simply take one of the entries in the top list, that should be one without any delay
String nexthash = nextFromDelayed();
//System.out.println("*** nextFromDelayed=" + nexthash);
if (nexthash == null && this.top.size() > 0) {
if (nexthash == null && !this.top.isEmpty()) {
nexthash = top.remove();
//System.out.println("*** top.remove()=" + nexthash);
}
@ -418,7 +422,7 @@ public class Balancer {
}
private void filltop(boolean delay, long maximumwaiting, boolean acceptonebest) {
if (this.top.size() > 0) return;
if (!this.top.isEmpty()) return;
//System.out.println("*** DEBUG started filltop delay=" + ((delay) ? "true":"false") + ", maximumwaiting=" + maximumwaiting + ", acceptonebest=" + ((acceptonebest) ? "true":"false"));
@ -438,7 +442,7 @@ public class Balancer {
entry = i.next();
// clean up empty entries
if (entry.getValue().size() == 0) {
if (entry.getValue().isEmpty()) {
i.remove();
continue;
}
@ -457,18 +461,18 @@ public class Balancer {
}
n = entry.getValue().removeFirst();
this.top.add(n);
if (entry.getValue().size() == 0) i.remove();
if (entry.getValue().isEmpty()) i.remove();
}
// if we could not find any entry, then take the best we have seen so far
if (acceptonebest && this.top.size() > 0 && besthash != null) {
if (acceptonebest && !this.top.isEmpty() && besthash != null) {
removeHashFromDomainStacks(besthash);
this.top.add(besthash);
}
}
private void fillDomainStacks(int maxdomstacksize) throws IOException {
if (this.domainStacks.size() > 0 && System.currentTimeMillis() - lastDomainStackFill < 120000L) return;
if (!this.domainStacks.isEmpty() && System.currentTimeMillis() - lastDomainStackFill < 120000L) return;
this.domainStacks.clear();
//synchronized (this.delayed) { delayed.clear(); }
this.lastDomainStackFill = System.currentTimeMillis();

@ -501,7 +501,6 @@ public class CrawlProfile {
} else {
// increase counter
dp.inc();
doms.put(domain, dp);
}
domsCache.put(this.mem.get(HANDLE), doms);
}

@ -380,7 +380,7 @@ public class CrawlQueues {
// check if we have an entry in the provider list, otherwise fill the list
yacySeed seed;
if (remoteCrawlProviderHashes.size() == 0) {
if (remoteCrawlProviderHashes.isEmpty()) {
if (sb.peers != null && sb.peers.sizeConnected() > 0) {
final Iterator<yacySeed> e = PeerSelection.getProvidesRemoteCrawlURLs(sb.peers);
while (e.hasNext()) {
@ -391,12 +391,12 @@ public class CrawlQueues {
}
}
}
if (remoteCrawlProviderHashes.size() == 0) return false;
if (remoteCrawlProviderHashes.isEmpty()) return false;
// take one entry from the provider list and load the entries from the remote peer
seed = null;
String hash = null;
while ((seed == null) && (remoteCrawlProviderHashes.size() > 0)) {
while ((seed == null) && (!remoteCrawlProviderHashes.isEmpty())) {
hash = remoteCrawlProviderHashes.remove(remoteCrawlProviderHashes.size() - 1);
if (hash == null) continue;
seed = sb.peers.get(hash);
@ -411,7 +411,7 @@ public class CrawlQueues {
// we know a peer which should provide remote crawl entries. load them now.
final RSSFeed feed = yacyClient.queryRemoteCrawlURLs(sb.peers, seed, 30, 60000);
if (feed == null || feed.size() == 0) {
if (feed == null || feed.isEmpty()) {
// something is wrong with this provider. To prevent that we get not stuck with this peer
// we remove it from the peer list
sb.peers.peerActions.peerDeparture(seed, "no results from provided remote crawls");

@ -82,6 +82,11 @@ public final class CrawlStacker {
public int size() {
return this.fastQueue.queueSize() + this.slowQueue.queueSize();
}
public boolean isEmpty() {
if (!this.fastQueue.queueIsEmpty()) return false;
if (!this.slowQueue.queueIsEmpty()) return false;
return true;
}
public void clear() {
this.fastQueue.clear();

@ -170,7 +170,7 @@ public class ExternalIndexImporter extends AbstractImporter implements Importer
if (isAborted()) break;
// importing entity container to home db
if (newContainer.size() > 0) { homeWordIndex.termIndex().add(newContainer); }
if (!newContainer.isEmpty()) { homeWordIndex.termIndex().add(newContainer); }
// delete complete index entity file
this.importWordIndex.termIndex().delete(this.wordHash);

@ -121,6 +121,14 @@ public class NoticedURL {
return ((coreStack == null) ? 0 : coreStack.size()) + ((limitStack == null) ? 0 : limitStack.size()) + ((remoteStack == null) ? 0 : remoteStack.size());
}
public boolean isEmpty() {
if (coreStack == null) return true;
if (!coreStack.isEmpty()) return false;
if (!limitStack.isEmpty()) return false;
if (!remoteStack.isEmpty()) return false;
return true;
}
public int stackSize(final int stackType) {
switch (stackType) {
case STACK_TYPE_CORE: return (coreStack == null) ? 0 : coreStack.size();

@ -187,7 +187,7 @@ public class RobotsEntry {
}
public boolean isDisallowed(String path) {
if ((this.mem == null) || (this.denyPathList.size() == 0)) return false;
if ((this.mem == null) || (this.denyPathList.isEmpty())) return false;
// if the path is null or empty we set it to /
if ((path == null) || (path.length() == 0)) path = "/";

@ -73,7 +73,7 @@ public class DidYouMean {
*/
public String getSuggestion(final String word, long timeout) {
Set<String> s = getSuggestions(word, timeout);
if (s == null || s.size() == 0) return null;
if (s == null || s.isEmpty()) return null;
return s.iterator().next();
}
@ -85,7 +85,7 @@ public class DidYouMean {
*/
public String getSuggestion(final String word, long timeout, int preSortSelection) {
Set<String> s = getSuggestions(word, timeout, preSortSelection);
if (s == null || s.size() == 0) return null;
if (s == null || s.isEmpty()) return null;
return s.iterator().next();
}
@ -133,7 +133,7 @@ public class DidYouMean {
SortedSet<String> result = new TreeSet<String>();
StringBuilder sb;
for (int i = 0; i < words.length; i++) {
if (s[i].size() == 0) continue;
if (s[i].isEmpty()) continue;
sb = new StringBuilder(20);
for (int j = 0; j < words.length; j++) {
if (j > 0) sb.append(' ');

@ -12,7 +12,7 @@ public class MimeTable {
private static final Properties mimeTable = new Properties();
public static void init(File mimeFile) {
if (mimeTable.size() == 0) {
if (mimeTable.isEmpty()) {
// load the mime table
BufferedInputStream mimeTableInputStream = null;
try {
@ -30,6 +30,10 @@ public class MimeTable {
return mimeTable.size();
}
public static boolean isEmpty() {
return mimeTable.isEmpty();
}
public static String ext2mime(String ext) {
return mimeTable.getProperty(ext, "application/" + ext);
}

@ -71,7 +71,7 @@ public class listManager {
public static void removeFromListSet(final String setName, final String listName) {
final Set<String> listSet = getListSet(setName);
if (listSet.size() > 0) {
if (!listSet.isEmpty()) {
listSet.remove(listName);
switchboard.setConfig(setName, collection2string(listSet));
}
@ -127,7 +127,7 @@ public class listManager {
public static String collection2string(final Collection<String> col){
final StringBuilder str = new StringBuilder();
if (col != null && (col.size() > 0)) {
if (col != null && !col.isEmpty()) {
final Iterator<String> it = col.iterator();
str.append(it.next());
while(it.hasNext()) {

@ -142,7 +142,7 @@ public final class HTTPDFileHandler {
if (switchboard == null) {
switchboard = theSwitchboard;
if (MimeTable.size() == 0) {
if (MimeTable.isEmpty()) {
// load the mime table
final String mimeTablePath = theSwitchboard.getConfig("mimeTable","");
Log.logConfig("HTTPDFiles", "Loading mime mapping file " + mimeTablePath);
@ -174,7 +174,7 @@ public final class HTTPDFileHandler {
if (!(htTemplatePath.exists())) htTemplatePath.mkdir();
}
//This is now handles by #%env/templates/foo%#
//if (templates.size() == 0) templates.putAll(httpTemplate.loadTemplates(htTemplatePath));
//if (templates.isEmpty()) templates.putAll(httpTemplate.loadTemplates(htTemplatePath));
// create htLocaleDefault, htLocalePath
if (htDefaultPath == null) htDefaultPath = theSwitchboard.getConfigPath("htDefaultPath", "htroot");

@ -485,7 +485,7 @@ public final class HTTPDProxyHandler {
final ResponseHeader responseHeader = res.getResponseHeader();
// determine if it's an internal error of the httpc
if (responseHeader.size() == 0) {
if (responseHeader.isEmpty()) {
throw new Exception(res.getStatusLine());
}
@ -570,7 +570,7 @@ public final class HTTPDProxyHandler {
FileUtils.copy(res.getDataAsStream(), toClientAndMemory);
// cached bytes
byte[] cacheArray;
if(byteStream.size() > 0) {
if (byteStream.size() > 0) {
cacheArray = byteStream.toByteArray();
} else {
cacheArray = null;
@ -821,7 +821,7 @@ public final class HTTPDProxyHandler {
// determine if it's an internal error of the httpc
final ResponseHeader responseHeader = res.getResponseHeader();
if (responseHeader.size() == 0) {
if (responseHeader.isEmpty()) {
throw new Exception(res.getStatusLine());
}
@ -937,7 +937,7 @@ public final class HTTPDProxyHandler {
final ResponseHeader responseHeader = res.getResponseHeader();
// determine if it's an internal error of the httpc
if (responseHeader.size() == 0) {
if (responseHeader.isEmpty()) {
throw new Exception(res.getStatusLine());
}

@ -1167,9 +1167,9 @@ public final class HTTPDemon implements serverHandler, Cloneable {
switch (errorcase) {
case ERRORCASE_FILE:
tp.put("errorMessageType_file", (detailedErrorMsgFile == null) ? "" : detailedErrorMsgFile.toString());
if ((detailedErrorMsgValues != null) && (detailedErrorMsgValues.size() > 0)) {
if ((detailedErrorMsgValues != null) && !detailedErrorMsgValues.isEmpty()) {
// rewriting the value-names and add the proper name prefix:
for(Entry<String, String> entry: detailedErrorMsgValues.entrySet()) {
for (Entry<String, String> entry: detailedErrorMsgValues.entrySet()) {
tp.put("errorMessageType_" + entry.getKey(), entry.getValue());
}
}

@ -109,7 +109,7 @@ public class MediaSnippet implements Comparable<MediaSnippet>, Comparator<MediaS
}
public static ArrayList<MediaSnippet> retrieveMediaSnippets(final DigestURI url, final TreeSet<byte[]> queryhashes, final ContentDomain mediatype, final boolean fetchOnline, final int timeout, final boolean reindexing) {
if (queryhashes.size() == 0) {
if (queryhashes.isEmpty()) {
Log.logFine("snippet fetch", "no query hashes given for url " + url);
return new ArrayList<MediaSnippet>();
}
@ -194,12 +194,12 @@ public class MediaSnippet implements Comparable<MediaSnippet>, Comparator<MediaS
url = entry.getKey();
desc = entry.getValue();
s = removeAppearanceHashes(url.toNormalform(false, false), queryhashes);
if (s.size() == 0) {
if (isEmpty()) {
result += "<br /><a href=\"" + url + "\">" + ((desc.length() == 0) ? url : desc) + "</a>";
continue;
}
s = removeAppearanceHashes(desc, s);
if (s.size() == 0) {
if (isEmpty()) {
result += "<br /><a href=\"" + url + "\">" + ((desc.length() == 0) ? url : desc) + "</a>";
continue;
}

@ -131,7 +131,7 @@ public final class RankingProcess extends Thread {
this.localSearchInclusion = search.inclusion();
final ReferenceContainer<WordReference> index = search.joined();
MemoryTracker.update("SEARCH", new ProfilingGraph.searchEvent(query.id(true), SearchEvent.JOIN, index.size(), System.currentTimeMillis() - timer), false);
if (index.size() == 0) {
if (index.isEmpty()) {
return;
}
@ -147,7 +147,7 @@ public final class RankingProcess extends Thread {
// attention: if minEntries is too high, this method will not terminate within the maxTime
assert (index != null);
if (index.size() == 0) return;
if (index.isEmpty()) return;
if (local) {
this.local_resourceSize += fullResource;
} else {
@ -306,7 +306,7 @@ public final class RankingProcess extends Thread {
// returns from the current RWI list the best entry and removes this entry from the list
SortStack<WordReferenceVars> m;
SortStack<WordReferenceVars>.stackElement rwi;
while (stack.size() > 0) {
while (!stack.isEmpty()) {
rwi = stack.pop();
if (rwi == null) continue; // in case that a synchronization problem occurred just go lazy over it
if (!skipDoubleDom) return rwi;
@ -336,7 +336,7 @@ public final class RankingProcess extends Thread {
break; // not the best solution...
}
if (m == null) continue;
if (m.size() == 0) continue;
if (m.isEmpty()) continue;
if (bestEntry == null) {
bestEntry = m.top();
continue;
@ -461,6 +461,14 @@ public final class RankingProcess extends Thread {
return c;
}
public boolean isEmpty() {
if (!stack.isEmpty()) return false;
for (SortStack<WordReferenceVars> s: this.doubleDomCache.values()) {
if (!s.isEmpty()) return false;
}
return true;
}
public int[] flagCount() {
return flagcount;
}
@ -705,3 +713,12 @@ public final class RankingProcess extends Thread {
}
}
/*
Thread= Thread-937 id=4224 BLOCKED
Thread= Thread-919 id=4206 BLOCKED
Thread= Thread-936 id=4223 BLOCKED
at net.yacy.kelondro.util.SortStack.pop(SortStack.java:118)
at de.anomic.search.RankingProcess.takeRWI(RankingProcess.java:310)
at de.anomic.search.RankingProcess.takeURL(RankingProcess.java:371)
at de.anomic.search.ResultFetcher$Worker.run(ResultFetcher.java:161)
*/

@ -107,7 +107,7 @@ public class ReferenceOrder {
entry = di.next();
doms.addScore(entry.getKey(), (entry.getValue()).intValue());
}
if (doms.size() > 0) maxdomcount = doms.getMaxScore();
if (!doms.isEmpty()) maxdomcount = doms.getMaxScore();
} catch (InterruptedException e) {
Log.logException(e);
} catch (Exception e) {

@ -161,7 +161,7 @@ public class ResultEntry implements Comparable<ResultEntry>, Comparator<ResultEn
return (this.textSnippet != null) && (this.textSnippet.getErrorCode() < 11);
}
public boolean hasMediaSnippets() {
return (this.mediaSnippets != null) && (this.mediaSnippets.size() > 0);
return (this.mediaSnippets != null) && (!this.mediaSnippets.isEmpty());
}
public String resource() {
// generate transport resource

@ -88,7 +88,7 @@ public class ResultFetcher {
// only with the query minus the stopwords which had not been used for the search
final TreeSet<byte[]> filtered = SetTools.joinConstructive(query.queryHashes, Switchboard.stopwordHashes);
this.snippetFetchWordHashes = (TreeSet<byte[]>) query.queryHashes.clone();
if ((filtered != null) && (filtered.size() > 0)) {
if (filtered != null && !filtered.isEmpty()) {
SetTools.excludeDestructive(this.snippetFetchWordHashes, Switchboard.stopwordHashes);
}
@ -241,7 +241,7 @@ public class ResultFetcher {
final long snippetComputationTime = System.currentTimeMillis() - startTime;
Log.logInfo("SEARCH_EVENT", "media snippet load time for " + metadata.url() + ": " + snippetComputationTime);
if ((mediaSnippets != null) && (mediaSnippets.size() > 0)) {
if (mediaSnippets != null && !mediaSnippets.isEmpty()) {
// found media snippets, return entry
return new ResultEntry(page, query.getSegment(), peers, null, mediaSnippets, dbRetrievalTime, snippetComputationTime);
} else if (snippetMode == 1) {

@ -114,7 +114,7 @@ public final class SearchEvent {
// start global searches
final long timer = System.currentTimeMillis();
Log.logFine("SEARCH_EVENT", "STARTING " + fetchpeers + " THREADS TO CATCH EACH " + query.displayResults() + " URLs");
this.primarySearchThreads = (query.queryHashes.size() == 0) ? null : yacySearch.primaryRemoteSearches(
this.primarySearchThreads = (query.queryHashes.isEmpty()) ? null : yacySearch.primaryRemoteSearches(
QueryParams.hashSet2hashString(query.queryHashes),
QueryParams.hashSet2hashString(query.excludeHashes),
"",

@ -73,7 +73,7 @@ public class SearchEventCache {
String id = query.id(false);
SearchEvent event = SearchEventCache.lastEvents.get(id);
if (Switchboard.getSwitchboard() != null && Switchboard.getSwitchboard().crawlQueues.noticeURL.size() > 0 && event != null && System.currentTimeMillis() - event.getEventTime() > 60000) {
if (Switchboard.getSwitchboard() != null && !Switchboard.getSwitchboard().crawlQueues.noticeURL.isEmpty() && event != null && System.currentTimeMillis() - event.getEventTime() > 60000) {
// if a local crawl is ongoing, don't use the result from the cache to use possibly more results that come from the current crawl
// to prevent that this happens during a person switches between the different result pages, a re-search happens no more than
// once a minute

@ -468,7 +468,7 @@ public class Segment {
}
}
}
if (urlHashs.size() > 0) try {
if (!urlHashs.isEmpty()) try {
final int removed = termIndex.remove(container.getTermHash(), urlHashs);
Log.logFine("INDEXCLEANER", container.getTermHashAsString() + ": " + removed + " of " + container.size() + " URL-entries deleted");
lastWordHash = container.getTermHash();

@ -433,7 +433,7 @@ public final class Switchboard extends serverSwitch {
listManager.reloadBlacklists();
// load badwords (to filter the topwords)
if (badwords == null || badwords.size() == 0) {
if (badwords == null || badwords.isEmpty()) {
final File badwordsFile = new File(rootPath, SwitchboardConstants.LIST_BADWORDS_DEFAULT);
badwords = SetTools.loadList(badwordsFile, NaturalOrder.naturalComparator);
badwordHashes = Word.words2hashes(badwords);
@ -443,7 +443,7 @@ public final class Switchboard extends serverSwitch {
}
// load stopwords
if (stopwords == null || stopwords.size() == 0) {
if (stopwords == null || stopwords.isEmpty()) {
final File stopwordsFile = new File(rootPath, SwitchboardConstants.LIST_STOPWORDS_DEFAULT);
stopwords = SetTools.loadList(stopwordsFile, NaturalOrder.naturalComparator);
stopwordHashes = Word.words2hashes(stopwords);
@ -1092,7 +1092,7 @@ public final class Switchboard extends serverSwitch {
crawlQueues.coreCrawlJobSize() > 0 ||
crawlQueues.limitCrawlJobSize() > 0 ||
crawlQueues.remoteTriggeredCrawlJobSize() > 0 ||
(crawlStacker != null && crawlStacker.size() > 0) ||
(crawlStacker != null && !crawlStacker.isEmpty()) ||
crawlQueues.noticeURL.notEmpty())
return false;
return this.crawler.cleanProfiles();

@ -197,7 +197,7 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
}
public String getLineMarked(final TreeSet<byte[]> queryHashes) {
if (line == null) return "";
if ((queryHashes == null) || (queryHashes.size() == 0)) return line.trim();
if ((queryHashes == null) || (queryHashes.isEmpty())) return line.trim();
if (line.endsWith(".")) line = line.substring(0, line.length() - 1);
final Iterator<byte[]> i = queryHashes.iterator();
byte[] h;
@ -310,7 +310,7 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
public static TextSnippet retrieveTextSnippet(final URIMetadataRow.Components comp, final TreeSet<byte[]> queryhashes, final boolean fetchOnline, final boolean pre, final int snippetMaxLength, final int maxDocLen, final boolean reindexing) {
// heise = "0OQUNU3JSs05"
final DigestURI url = comp.url();
if (queryhashes.size() == 0) {
if (queryhashes.isEmpty()) {
//System.out.println("found no queryhashes for URL retrieve " + url);
return new TextSnippet(url, null, ERROR_NO_HASH_GIVEN, queryhashes, "no query hashes given");
}
@ -427,7 +427,7 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
//if (hrefline != null) line += (line.length() == 0) ? hrefline : "<br />" + hrefline;
if (textline != null) line += (line.length() == 0) ? textline : "<br />" + textline;
if ((line == null) || (remainingHashes.size() > 0)) return new TextSnippet(url, null, ERROR_NO_MATCH, remainingHashes, "no matching snippet found",resFavicon);
if (line == null || !remainingHashes.isEmpty()) return new TextSnippet(url, null, ERROR_NO_MATCH, remainingHashes, "no matching snippet found",resFavicon);
if (line.length() > snippetMaxLength) line = line.substring(0, snippetMaxLength);
// finally store this snippet in our own cache
@ -451,7 +451,7 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
computeTextSnippet(final Iterator<StringBuilder> sentences, final TreeSet<byte[]> queryhashes, int maxLength) {
try {
if (sentences == null) return null;
if ((queryhashes == null) || (queryhashes.size() == 0)) return null;
if ((queryhashes == null) || (queryhashes.isEmpty())) return null;
Iterator<byte[]> j;
TreeMap<byte[], Integer> hs;
StringBuilder sentence;
@ -471,14 +471,14 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
String result;
TreeSet<byte[]> remaininghashes;
while (os.size() > 0) {
while (!os.isEmpty()) {
sentence = os.remove(os.lastKey()); // sentence with the biggest score
Object[] tsr = computeTextSnippet(sentence.toString(), queryhashes, maxLength);
if (tsr == null) continue;
result = (String) tsr[0];
if ((result != null) && (result.length() > 0)) {
remaininghashes = (TreeSet<byte[]>) tsr[1];
if (remaininghashes.size() == 0) {
if (remaininghashes.isEmpty()) {
// we have found the snippet
return new Object[]{result, remaininghashes};
} else if (remaininghashes.size() < queryhashes.size()) {
@ -510,7 +510,7 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
computeTextSnippet(String sentence, final TreeSet<byte[]> queryhashes, final int maxLength) {
try {
if (sentence == null) return null;
if ((queryhashes == null) || (queryhashes.size() == 0)) return null;
if ((queryhashes == null) || (queryhashes.isEmpty())) return null;
byte[] hash;
// find all hashes that appear in the sentence

@ -58,7 +58,7 @@ public class serverAccessTracker {
SortedMap<Long, String> track;
while (i.hasNext()) {
track = i.next().getValue();
if (track.tailMap(Long.valueOf(System.currentTimeMillis() - maxTrackingTime)).size() == 0) {
if (track.tailMap(Long.valueOf(System.currentTimeMillis() - maxTrackingTime)).isEmpty()) {
// all entries are too old. delete the whole track
i.remove();
} else {
@ -116,7 +116,7 @@ public class serverAccessTracker {
synchronized (access) {
if ((access = clearTooOldAccess(access)).size() != access.size()) {
// write back to tracker
if (access.size() == 0) {
if (access.isEmpty()) {
accessTracker.remove(host);
} else {
accessTracker.put(host, access);

@ -50,7 +50,7 @@ public class disorderHeap implements Serializable {
}
public synchronized String remove() {
if (list.size() == 0) return null;
if (list.isEmpty()) return null;
final int pos = (int) ((System.currentTimeMillis() / 13) % list.size());
return list.remove(pos);
}
@ -69,6 +69,9 @@ public class disorderHeap implements Serializable {
return list.size();
}
public synchronized boolean isEmpty() {
return list.isEmpty();
}
public static void main(final String[] args) {
final disorderHeap ul = new disorderHeap();

@ -28,7 +28,7 @@ import java.util.Set;
public class disorderSet extends HashSet<String> implements Set<String> {
private static final long serialVersionUID = 1L;
disorderHeap dh;
private disorderHeap dh;
public disorderSet() {
super();
@ -36,13 +36,13 @@ public class disorderSet extends HashSet<String> implements Set<String> {
}
public boolean hasAny() {
return (this.size() > 0);
return !this.isEmpty();
}
public String any() {
// return just any element
if ((dh == null) || (dh.size() == 0)) {
if (this.size() == 0) return null;
if (dh == null || dh.isEmpty()) {
if (this.isEmpty()) return null;
// fill up the queue
dh = new disorderHeap();
final Iterator<String> elements = this.iterator();

@ -65,14 +65,14 @@ public class enumerateFiles implements Enumeration<File> {
do {
// System.out.println("D " + hierarchy.toString());
t = null;
while ((t == null) && (hierarchy.size() > 0)) {
while ((t == null) && (!hierarchy.isEmpty())) {
t = hierarchy.get(hierarchy.size() - 1);
if (t.size() == 0) {
if (t.isEmpty()) {
hierarchy.remove(hierarchy.size() - 1); // we step up one hierarchy
t = null;
}
}
if ((hierarchy.size() == 0) || (t == null || t.size() == 0)) return null; // this is the end
if (hierarchy.isEmpty() || (t == null || t.isEmpty())) return null; // this is the end
// fetch value
if (incOrder) f = t.first(); else f = t.last();
t.remove(f);

@ -68,7 +68,7 @@ public abstract class loaderCore implements loaderProcess {
public boolean available() {
// true if it is ok to feed with feed()
return (status() == STATUS_READY) ||
((status() == STATUS_COMPLETED) && ((result == null) || (result.size() == 0)));
(status() == STATUS_COMPLETED && (result == null || result.isEmpty()));
}
public Exception error() {

@ -91,14 +91,14 @@ public class nxTools {
}
public static String tail1(final Vector<String> list) {
if ((list == null) || (list.size() == 0)) return "";
if (list == null || list.isEmpty()) return "";
return list.lastElement();
}
public static String tail1(final ArrayList<String> list) {
if ((list == null) || (list.size() == 0)) return "";
if (list == null || list.isEmpty()) return "";
return list.get(list.size()-1);
}
}
public static String awk(String sentence, final String separator, int count) {
// returns the nth word of sentence, where count is the counter and the first word has the number 1

@ -154,7 +154,7 @@ public class Dispatcher {
ArrayList<ReferenceContainer<WordReference>> containers = selectContainers(hash, limitHash, maxContainerCount, maxReferenceCount, maxtime, false);
// if ram does not provide any result, take from file
//if (containers.size() == 0) containers = selectContainers(hash, limitHash, maxContainerCount, maxtime, false);
//if (containers.isEmpty()) containers = selectContainers(hash, limitHash, maxContainerCount, maxtime, false);
return containers;
}
@ -180,11 +180,11 @@ public class Dispatcher {
(indexContainerIterator.hasNext()) &&
(System.currentTimeMillis() < timeout) &&
((container = indexContainerIterator.next()) != null) &&
((containers.size() == 0) ||
((containers.isEmpty()) ||
(Base64Order.enhancedCoder.compare(container.getTermHash(), limitHash) < 0))
) {
if (container.size() == 0) continue;
if (container.isEmpty()) continue;
refcount += container.size();
containers.add(container);
}
@ -201,7 +201,7 @@ public class Dispatcher {
urlHashes.add(it.next().metadataHash());
}
if (this.log.isFine()) this.log.logFine("selected " + urlHashes.size() + " urls for word '" + c.getTermHashAsString() + "'");
if (urlHashes.size() > 0) this.segment.termIndex().remove(c.getTermHash(), urlHashes);
if (!urlHashes.isEmpty()) this.segment.termIndex().remove(c.getTermHash(), urlHashes);
}
rc = containers;
} else {
@ -321,7 +321,7 @@ public class Dispatcher {
ArrayList<ReferenceContainer<WordReference>> selectedContainerCache = selectContainers(hash, limitHash, maxContainerCount, maxReferenceCount, maxtime);
this.log.logInfo("selectContainersToCache: selectedContainerCache was filled with " + selectedContainerCache.size() + " entries");
if (selectedContainerCache == null || selectedContainerCache.size() == 0) {
if (selectedContainerCache == null || selectedContainerCache.isEmpty()) {
this.log.logInfo("splitContainersFromCache: selectedContainerCache is empty, cannot do anything here.");
return false;
}

@ -184,7 +184,7 @@ public class Transmission {
}
public boolean transmit() {
if (this.targets.size() == 0) return false;
if (this.targets.isEmpty()) return false;
yacySeed target = this.targets.remove(0);
// transferring selected words to remote peer
if (target == seeds.mySeed() || target.hash.equals(seeds.mySeed().hash)) {

@ -257,7 +257,7 @@ public class WebStructureGraph {
}
}
}
if (h.size() == 0) return null;
if (h.isEmpty()) return null;
return new structureEntry(domhash, domain, date, h);
}

@ -319,7 +319,7 @@ public final class yacyClient {
final byte[] content = postToFile(target, "query.html", post, 10000);
final HashMap<String, String> result = FileUtils.table(content);
if (result == null || result.size() == 0) { return null; }
if (result == null || result.isEmpty()) { return null; }
//final Date remoteTime = yacyCore.parseUniversalDate((String) result.get(yacySeed.MYTIME)); // read remote time
return yacySeed.genRemoteSeed(result.get("response"), salt, false);
} catch (final Exception e) {
@ -341,7 +341,7 @@ public final class yacyClient {
final byte[] content = postToFile(target, "query.html", post, 5000);
final HashMap<String, String> result = FileUtils.table(content);
if (result == null || result.size() == 0) { return -1; }
if (result == null || result.isEmpty()) { return -1; }
return Integer.parseInt(result.get("response"));
} catch (final Exception e) {
yacyCore.log.logSevere("yacyClient.queryRWICount error:" + e.getMessage());
@ -364,7 +364,7 @@ public final class yacyClient {
final byte[] content = postToFile(target, "query.html", post, 5000);
final HashMap<String, String> result = FileUtils.table(content);
if ((result == null) || (result.size() == 0)) return -1;
if (result == null || result.isEmpty()) return -1;
final String resp = result.get("response");
if (resp == null) {
return -1;
@ -493,7 +493,7 @@ public final class yacyClient {
return null;
}
if ((result == null) || (result.size() == 0)) {
if (result == null || result.isEmpty()) {
if (yacyCore.log.isFine()) yacyCore.log.logFine("SEARCH failed FROM "
+ target.hash
+ ":"

@ -338,7 +338,7 @@ public class yacyCore {
seeds = PeerSelection.seedsByAge(sb.peers, false, attempts); // best for seed list maintenance/cleaning
}
if ((seeds == null) || seeds.size() == 0) { return 0; }
if (seeds == null || seeds.isEmpty()) { return 0; }
if (seeds.size() < attempts) { attempts = seeds.size(); }
// This will try to get Peers that are not currently in amIAccessibleDB

@ -308,7 +308,7 @@ public class yacyNewsPool {
public yacyNewsRecord myPublication() throws IOException {
// generate a record for next peer-ping
if (outgoingNews.size() == 0) return null;
if (outgoingNews.isEmpty()) return null;
final yacyNewsRecord record = outgoingNews.topInc();
if ((record != null) && (record.distributed() >= maxDistribution)) {
// move record to its final position. This is only for history

@ -99,23 +99,27 @@ public class yacyNewsQueue {
public int size() {
return queueStack.size();
}
public boolean isEmpty() {
return queueStack.isEmpty();
}
public synchronized void push(final yacyNewsRecord entry) throws IOException {
queueStack.push(r2b(entry, true));
}
public synchronized yacyNewsRecord pop() throws IOException {
if (queueStack.size() == 0) return null;
if (queueStack.isEmpty()) return null;
return b2r(queueStack.pop());
}
public synchronized yacyNewsRecord top() throws IOException {
if (queueStack.size() == 0) return null;
if (queueStack.isEmpty()) return null;
return b2r(queueStack.top());
}
public synchronized yacyNewsRecord topInc() throws IOException {
if (queueStack.size() == 0) return null;
if (queueStack.isEmpty()) return null;
final yacyNewsRecord entry = pop();
if (entry != null) {
entry.incDistribution();

@ -127,8 +127,8 @@ public final class yacyRelease extends yacyVersion {
// check if we know that there is a release that is more recent than that which we are using
final DevAndMainVersions releases = yacyRelease.allReleases(true, sb.getConfig("update.onlySignedFiles", "1").equals("1"));
final yacyRelease latestmain = (releases.main.size() == 0) ? null : releases.main.last();
final yacyRelease latestdev = (releases.dev.size() == 0) ? null : releases.dev.last();
final yacyRelease latestmain = (releases.main.isEmpty()) ? null : releases.main.last();
final yacyRelease latestdev = (releases.dev.isEmpty()) ? null : releases.dev.last();
final String concept = sb.getConfig("update.concept", "any");
String blacklist = sb.getConfig("update.blacklist", "...[123]");
if (blacklist.equals("....[123]")) {
@ -213,10 +213,10 @@ public final class yacyRelease extends yacyVersion {
DevAndMainVersions locLatestRelease = latestReleases.get(location);
if (force ||
(locLatestRelease == null) /*||
((latestRelease[0].size() == 0) &&
(latestRelease[1].size() == 0) &&
(latestRelease[2].size() == 0) &&
(latestRelease[3].size() == 0) )*/) {
((latestRelease[0].isEmpty()) &&
(latestRelease[1].isEmpty()) &&
(latestRelease[2].isEmpty()) &&
(latestRelease[3].isEmpty()) )*/) {
locLatestRelease = allReleaseFrom(location);
latestReleases.put(location, locLatestRelease);
}
@ -607,7 +607,7 @@ public final class yacyRelease extends yacyVersion {
}
// if we have some files
if(downloadedreleases.size() > 0) {
if (!downloadedreleases.isEmpty()) {
Log.logFine("STARTUP", "deleting downloaded releases older than "+ deleteAfterDays +" days");
// keep latest version

@ -677,7 +677,7 @@ public class yacySeed implements Cloneable {
// take one gap; prefer biggest but take also another smaller by chance
String interval = null;
final Random r = new Random();
while (gaps.size() > 0) {
while (!gaps.isEmpty()) {
interval = gaps.remove(gaps.lastKey());
if (r.nextBoolean()) break;
}

@ -215,7 +215,7 @@ public final class yacySeedDB implements AlternativeDomainNames {
}
public synchronized void removeMySeed() {
if ((seedActiveDB.size() == 0) && (seedPassiveDB.size() == 0) && (seedPotentialDB.size() == 0)) return; // avoid that the own seed is initialized too early
if (seedActiveDB.isEmpty() && seedPassiveDB.isEmpty() && seedPotentialDB.isEmpty()) return; // avoid that the own seed is initialized too early
if (this.mySeed == null) initMySeed();
try {
seedActiveDB.remove(mySeed.hash);

@ -436,7 +436,7 @@ public class dbtest {
for (int j = 0; j < readCount; j++) {
InstantBusyThread.oneTimeJob(new ReadJob(table_test, table_reference, random.nextLong() % writeCount), random.nextLong() % 1000, 20);
}
if ((ra.size() > 0) && (random.nextLong() % 7 == 0)) {
if (!ra.isEmpty() && random.nextLong() % 7 == 0) {
rc++;
p = Math.abs(random.nextInt() % ra.size());
R = ra.get(p);
@ -477,7 +477,7 @@ public class dbtest {
for (int j = 0; j < readCount; j++) {
new ReadJob(table_test, table_reference, random.nextLong() % writeCount).run();
}
if ((ra.size() > 0) && (random.nextLong() % 7 == 0)) {
if (!ra.isEmpty() && random.nextLong() % 7 == 0) {
rc++;
p = Math.abs(random.nextInt() % ra.size());
R = ra.get(p);

@ -117,10 +117,10 @@ public final class Condenser {
this.RESULT_FLAGS = new Bitfield(4);
// construct flag set for document
if (document.getImages().size() > 0) RESULT_FLAGS.set(flag_cat_hasimage, true);
if (document.getAudiolinks().size() > 0) RESULT_FLAGS.set(flag_cat_hasaudio, true);
if (document.getVideolinks().size() > 0) RESULT_FLAGS.set(flag_cat_hasvideo, true);
if (document.getApplinks().size() > 0) RESULT_FLAGS.set(flag_cat_hasapp, true);
if (!document.getImages().isEmpty()) RESULT_FLAGS.set(flag_cat_hasimage, true);
if (!document.getAudiolinks().isEmpty()) RESULT_FLAGS.set(flag_cat_hasaudio, true);
if (!document.getVideolinks().isEmpty()) RESULT_FLAGS.set(flag_cat_hasvideo, true);
if (!document.getApplinks().isEmpty()) RESULT_FLAGS.set(flag_cat_hasapp, true);
this.languageIdentificator = new Identificator();
@ -566,7 +566,7 @@ public final class Condenser {
sIndex = 0;
s.clear();
}
while (s.size() == 0) {
while (s.isEmpty()) {
if (!e.hasNext()) return null;
r = e.next();
if (r == null) return null;

@ -152,7 +152,7 @@ public class Document {
*/
public String dc_language() {
if (this.languages == null) return null;
if (this.languages.size() == 0) return null;
if (this.languages.isEmpty()) return null;
if (this.languages.size() == 1) return languages.iterator().next();
if (this.languages.contains(this.source.language())) return this.source.language();
// now we are confused: the declared languages differ all from the TLD
@ -203,7 +203,7 @@ dc_rights
s = (this.keywords.get(i)).trim();
if (s.length() > 0) hs.add(s.toLowerCase());
}
if (hs.size() == 0) return "";
if (hs.isEmpty()) return "";
// generate a new list
final StringBuilder sb = new StringBuilder(this.keywords.size() * 6);
final Iterator<String> i = hs.iterator();

@ -212,7 +212,7 @@ public final class TextParser {
final String documentCharset = htmlParser.patchCharsetEncoding(charset);
List<Idiom> idioms = idiomParser(location, mimeType);
if (idioms.size() == 0) {
if (idioms.isEmpty()) {
final String errorMsg = "No parser available to parse extension '" + location.getFileExtension() + "' or mimetype '" + mimeType + "'";
log.logInfo("Unable to parse '" + location + "'. " + errorMsg);
throw new ParserException(errorMsg, location);
@ -249,7 +249,7 @@ public final class TextParser {
try {
// try to get a parser. If this works, we don't need the parser itself, we just return null to show that everything is ok.
List<Idiom> idioms = idiomParser(url, mimeType);
return (idioms == null || idioms.size() == 0) ? "no parser found" : null;
return (idioms == null || idioms.isEmpty()) ? "no parser found" : null;
} catch (ParserException e) {
// in case that a parser is not available, return a error string describing the problem.
return e.getMessage();

@ -130,7 +130,7 @@ public final class Identificator {
}
}
if (relevantLanguages.size() == 0) return null;
if (relevantLanguages.isEmpty()) return null;
// compare characters in text with characters in statistics
final float[] offsetList = new float[relevantLanguages.size()];

@ -78,7 +78,7 @@ public class csvParser extends AbstractParser implements Idiom {
// the first row is used as headline
// all lines are artificially terminated by a '.' to separate them as sentence for the condenser.
List<String[]> table = getTable(location, mimeType, charset, source);
if (table.size() == 0) throw new ParserException("document has no lines", location);
if (table.isEmpty()) throw new ParserException("document has no lines", location);
StringBuilder sb = new StringBuilder();
for (String[] row: table) sb.append(concatRow(row)).append(' ');
try {

@ -290,7 +290,7 @@ public class ContentScraper extends AbstractScraper implements Scraper {
// otherwise take any headline
for (int i = 0; i < 4; i++) {
if (headlines[i].size() > 0) return headlines[i].get(0);
if (!headlines[i].isEmpty()) return headlines[i].get(0);
}
// take description tag
@ -393,7 +393,7 @@ public class ContentScraper extends AbstractScraper implements Scraper {
if (p > 0) cl[i] = cl[i].substring(0, p);
if (ISO639.exists(cl[i])) hs.add(cl[i]);
}
if (hs.size() == 0) return null;
if (hs.isEmpty()) return null;
return hs;
}

@ -77,13 +77,13 @@ public class ContentTransformer extends AbstractTransformer implements Transform
r.close();
} catch (final IOException e) {
}
// if (bluelist.size() == 0) System.out.println("BLUELIST is empty");
// if (bluelist.isEmpty()) System.out.println("BLUELIST is empty");
}
}
}
public boolean isIdentityTransformer() {
return (bluelist.size() == 0);
return bluelist.isEmpty();
}
private static char[] genBlueLetters(int length) {

@ -144,7 +144,7 @@ public final class TransformerWriter extends Writer {
}
public static char[] genTag0(final String tagname, final Properties tagopts, final char quotechar) {
final char[] tagoptsx = (tagopts.size() == 0) ? null : genOpts(tagopts, quotechar);
final char[] tagoptsx = (tagopts.isEmpty()) ? null : genOpts(tagopts, quotechar);
final CharBuffer bb = new CharBuffer(tagname.length() + ((tagoptsx == null) ? 0 : (tagoptsx.length + 1)) + tagname.length() + 2);
bb.append((int)'<').append(tagname);
if (tagoptsx != null) {

@ -133,17 +133,17 @@ public class rssParser extends AbstractParser implements Idiom {
FileUtils.copy(new ByteArrayInputStream(itemContent.getBytes("UTF-8")), writer, Charset.forName("UTF-8"));
final String itemHeadline = scraper.getTitle();
if ((itemHeadline != null) && (itemHeadline.length() > 0)) {
if (itemHeadline != null && !itemHeadline.isEmpty()) {
feedSections.add(itemHeadline);
}
final Map<DigestURI, String> itemLinks = scraper.getAnchors();
if ((itemLinks != null) && (itemLinks.size() > 0)) {
if (itemLinks != null && !itemLinks.isEmpty()) {
anchors.putAll(itemLinks);
}
final HashMap<String, ImageEntry> itemImages = scraper.getImages();
if ((itemImages != null) && (itemImages.size() > 0)) {
if (itemImages != null && !itemImages.isEmpty()) {
ContentScraper.addAllImages(images, itemImages);
}

@ -111,6 +111,10 @@ public class RSSFeed implements Iterable<RSSMessage> {
return messages.get(guid);
}
public boolean isEmpty() {
return messages.isEmpty();
}
public int size() {
return messages.size();
}
@ -121,7 +125,7 @@ public class RSSFeed implements Iterable<RSSMessage> {
public RSSMessage pollMessage() {
// retrieve and delete item
if (messageQueue.size() == 0) return null;
if (messageQueue.isEmpty()) return null;
final String nextGUID = messageQueue.poll();
if (nextGUID == null) return null;
return messages.remove(nextGUID);

@ -287,7 +287,7 @@ public class ArrayStack implements BLOB {
}
public synchronized File smallestBLOB(File excluding, long maxsize) {
if (this.blobs.size() == 0) return null;
if (this.blobs.isEmpty()) return null;
File bestFile = null;
long smallest = Long.MAX_VALUE;
File f = null;
@ -305,7 +305,7 @@ public class ArrayStack implements BLOB {
}
public synchronized File unmountOldestBLOB(boolean smallestFromFirst2) {
if (this.blobs.size() == 0) return null;
if (this.blobs.isEmpty()) return null;
int idx = 0;
if (smallestFromFirst2 && this.blobs.get(1).location.length() < this.blobs.get(0).location.length()) idx = 1;
return unmount(idx);
@ -313,7 +313,7 @@ public class ArrayStack implements BLOB {
/*
public synchronized File unmountSimilarSizeBLOB(long otherSize) {
if (this.blobs.size() == 0 || otherSize == 0) return null;
if (this.blobs.isEmpty() || otherSize == 0) return null;
blobItem b;
double delta, bestDelta = Double.MAX_VALUE;
int bestIndex = -1;
@ -365,10 +365,10 @@ public class ArrayStack implements BLOB {
private void executeLimits() {
// check if storage limits are reached and execute consequences
if (blobs.size() == 0) return;
if (blobs.isEmpty()) return;
// age limit:
while (blobs.size() > 0 && System.currentTimeMillis() - blobs.get(0).creation.getTime() - this.fileAgeLimit > this.repositoryAgeMax) {
while (!blobs.isEmpty() && System.currentTimeMillis() - blobs.get(0).creation.getTime() - this.fileAgeLimit > this.repositoryAgeMax) {
// too old
blobItem oldestBLOB = blobs.remove(0);
oldestBLOB.blob.close(false);
@ -377,7 +377,7 @@ public class ArrayStack implements BLOB {
}
// size limit
while (blobs.size() > 0 && length() > this.repositorySizeMax) {
while (!blobs.isEmpty() && length() > this.repositorySizeMax) {
// too large
blobItem oldestBLOB = blobs.remove(0);
oldestBLOB.blob.close(false);
@ -446,6 +446,11 @@ public class ArrayStack implements BLOB {
return s;
}
public synchronized boolean isEmpty() {
for (blobItem bi: blobs) if (!bi.blob.isEmpty()) return false;
return true;
}
/**
* ask for the number of blob entries in each blob of the blob array
* @return the number of entries in each blob
@ -676,7 +681,7 @@ public class ArrayStack implements BLOB {
* @throws IOException
*/
public synchronized void put(byte[] key, byte[] b) throws IOException {
blobItem bi = (blobs.size() == 0) ? null : blobs.get(blobs.size() - 1);
blobItem bi = (blobs.isEmpty()) ? null : blobs.get(blobs.size() - 1);
if (bi == null)
System.out.println("bi == null");
else if (System.currentTimeMillis() - bi.creation.getTime() > this.fileAgeLimit)

@ -64,6 +64,12 @@ public interface BLOB {
*/
public int size();
/**
* ask if the BLOB is empty
* @return true iff size() == 0
*/
public boolean isEmpty();
/**
* iterator over all keys
* @param up

@ -221,7 +221,7 @@ public class Compressor implements BLOB {
// check if the buffer is full or could be full after this write
if (this.bufferlength + b.length * 2 > this.maxbufferlength) {
// in case that we compress, just compress as much as is necessary to get enough room
while (this.bufferlength + b.length * 2 > this.maxbufferlength && this.buffer.size() > 0) {
while (this.bufferlength + b.length * 2 > this.maxbufferlength && !this.buffer.isEmpty()) {
flushOne();
}
// in case that this was not enough, just flush all
@ -245,6 +245,12 @@ public class Compressor implements BLOB {
return this.backend.size() + this.buffer.size();
}
public synchronized boolean isEmpty() {
if (!this.backend.isEmpty()) return false;
if (!this.buffer.isEmpty()) return false;
return true;
}
public synchronized CloneableIterator<byte[]> keys(boolean up, boolean rotating) throws IOException {
flushAll();
return this.backend.keys(up, rotating);
@ -256,7 +262,7 @@ public class Compressor implements BLOB {
}
private boolean flushOne() throws IOException {
if (this.buffer.size() == 0) return false;
if (this.buffer.isEmpty()) return false;
// depending on process case, write it to the file or compress it to the other queue
Map.Entry<String, byte[]> entry = this.buffer.entrySet().iterator().next();
this.buffer.remove(entry.getKey());
@ -268,7 +274,7 @@ public class Compressor implements BLOB {
}
private void flushAll() throws IOException {
while (this.buffer.size() > 0) {
while (!this.buffer.isEmpty()) {
if (!flushOne()) break;
}
assert this.bufferlength == 0;

@ -314,7 +314,7 @@ public final class Heap extends HeapModifier implements BLOB {
if (b.length == 0) return true;
// then look if we can use a free entry
if (this.free.size() == 0) return false;
if (this.free.isEmpty()) return false;
// find the largest entry
long lseek = -1;

@ -56,8 +56,6 @@ public class HeapModifier extends HeapReader implements BLOB {
super(heapFile, keylength, ordering);
}
/**
* clears the content of the database
* @throws IOException
@ -137,7 +135,7 @@ public class HeapModifier extends HeapReader implements BLOB {
// first find the gap entry for the closest gap in front of the give gap
SortedMap<Long, Integer> head = this.free.headMap(thisSeek);
if (head.size() == 0) return;
if (head.isEmpty()) return;
long previousSeek = head.lastKey().longValue();
int previousSize = head.get(previousSeek).intValue();
@ -214,7 +212,7 @@ public class HeapModifier extends HeapReader implements BLOB {
// find gaps at the end of the file and shrink the file by these gaps
if (this.free == null) return;
try {
while (this.free.size() > 0) {
while (!this.free.isEmpty()) {
Long seek = this.free.lastKey();
int size = this.free.get(seek).intValue();
if (seek.longValue() + size + 4 != this.file.length()) return;

@ -154,7 +154,7 @@ public class HeapReader {
FileUtils.deletedelete(fgf);
// everything is fine now
return this.index.size() > 0;
return !this.index.isEmpty();
}
private void initIndexReadFromHeap() throws IOException {
@ -260,6 +260,11 @@ public class HeapReader {
return (this.index == null) ? 0 : this.index.size();
}
public synchronized boolean isEmpty() {
if (this.index == null) return true;
return this.index.isEmpty();
}
/**
* test if a key is in the heap file. This does not need any IO, because it uses only the ram index
* @param key

@ -330,6 +330,10 @@ public class MapDataMining extends MapView {
return super.size();
}
public synchronized boolean isEmpty() {
return super.isEmpty();
}
public synchronized void close() {
// close cluster
if (sortClusterMap != null) {

@ -294,6 +294,10 @@ public class MapView {
return (blob == null) ? 0 : blob.size();
}
public synchronized boolean isEmpty() {
return (blob == null) ? true : blob.isEmpty();
}
/**
* close the Map table
*/

@ -482,6 +482,10 @@ public final class Cache implements ObjectIndex, Iterable<Row.Entry> {
return index.size();
}
public final boolean isEmpty() {
return index.isEmpty();
}
public final String filename() {
return index.filename();
}

@ -262,6 +262,10 @@ public final class HandleMap implements Iterable<Row.Entry> {
return index.size();
}
public final synchronized boolean isEmpty() {
return index.isEmpty();
}
public final synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) {
return index.keys(up, firstKey);
}

@ -143,7 +143,7 @@ public final class ObjectArrayCache {
}
// at this point index1 cannot be null
assert (index1 != null);
if (index1.size() == 0) return null;
if (index1.isEmpty()) return null;
final Row.Entry indexentry = index1.remove(key);
if (indexentry == null) return null;
return indexentry.getColBytes(1);
@ -226,7 +226,7 @@ public final class ObjectArrayCache {
jcontrol.add(Long.valueOf(r));
kcontrol.putb((int) r, "x".getBytes());
if (random.nextLong() % 5 == 0) ra.add(Long.valueOf(r));
if ((ra.size() > 0) && (random.nextLong() % 7 == 0)) {
if (!ra.isEmpty() && random.nextLong() % 7 == 0) {
rc++;
p = Math.abs(random.nextInt() % ra.size());
R = ra.get(p);

@ -42,6 +42,7 @@ public interface ObjectIndex {
public String filename(); // returns a unique identified for this index; can be a real or artificial file name
public int size();
public boolean isEmpty();
public Row row();
public boolean has(byte[] key); // use this only if there is no get in case that has returns true
public Row.Entry get(byte[] key) throws IOException;

@ -210,6 +210,20 @@ public final class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry>
return index0.size() + index1.size();
}
public final synchronized boolean isEmpty() {
if ((index0 != null) && (index1 == null)) {
return index0.isEmpty();
}
if ((index0 == null) && (index1 != null)) {
return index1.isEmpty();
}
assert ((index0 != null) && (index1 != null));
if (!index0.isEmpty()) return false;
if (!index1.isEmpty()) return false;
return true;
}
public final synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) {
// returns the key-iterator of the underlying kelondroIndex
if (index1 == null) {

@ -452,6 +452,10 @@ public class RowCollection implements Iterable<Row.Entry> {
return this.chunkcount;
}
public boolean isEmpty() {
return this.chunkcount == 0;
}
public int sorted() {
return this.sortBound;
}
@ -853,7 +857,7 @@ public class RowCollection implements Iterable<Row.Entry> {
removeRow(i + 1, false);
d++;
if (i + 1 < chunkcount - 1) u = false;
} else if (collection.size() > 0) {
} else if (!collection.isEmpty()) {
// finish collection of double occurrences
collection.addUnique(get(i + 1, false));
removeRow(i + 1, false);

@ -143,7 +143,7 @@ public final class RowSetArray implements ObjectIndex, Iterable<Row.Entry> {
for (int i = 0; i < this.array.length; i++) {
if (this.array[i] != null) {
col.addAll(this.array[i].removeDoubles());
if (this.array[i].size() == 0) this.array[i] = null;
if (this.array[i].isEmpty()) this.array[i] = null;
}
}
}
@ -155,7 +155,7 @@ public final class RowSetArray implements ObjectIndex, Iterable<Row.Entry> {
for (int i = 0; i < this.array.length; i++) {
if (this.array[i] != null) {
Entry entry = this.array[i].removeOne();
if (this.array[i].size() == 0) this.array[i] = null;
if (this.array[i].isEmpty()) this.array[i] = null;
return entry;
}
}
@ -202,6 +202,17 @@ public final class RowSetArray implements ObjectIndex, Iterable<Row.Entry> {
return c;
}
public final boolean isEmpty() {
synchronized (this.array) {
for (int i = 0; i < this.array.length; i++) {
if (this.array[i] != null) {
if (!this.array[i].isEmpty()) return false;
}
}
}
return true;
}
public final Iterator<Entry> iterator() {
return this.rows(true, null);
}

@ -136,7 +136,7 @@ public class MergeIterator<E> implements CloneableIterator<E> {
// this extends the ability to combine two iterators
// to the ability of combining a set of iterators
if (iterators == null) return null;
if (iterators.size() == 0) return null;
if (iterators.isEmpty()) return null;
return cascade(iterators.iterator(), c, merger, up);
}

@ -91,7 +91,7 @@ public class StackIterator<E> implements CloneableIterator<E> {
// this extends the ability to combine two iterators
// to the ability of combining a set of iterators
if (iterators == null) return null;
if (iterators.size() == 0) return null;
if (iterators.isEmpty()) return null;
return stack(iterators.iterator());
}

@ -58,7 +58,7 @@ public abstract class AbstractBufferedIndex<ReferenceType extends Reference> ext
// It must also be ensured that the counter is in/decreased every loop
while ((count > 0) && (i.hasNext())) {
container = i.next();
if ((container != null) && (container.size() > 0)) {
if (container != null && !container.isEmpty()) {
containers.add(container);
}
count--; // decrease counter even if the container was null or empty to ensure termination

@ -71,7 +71,7 @@ public abstract class AbstractIndex <ReferenceType extends Reference> implements
// It must also be ensured that the counter is in/decreased every loop
while ((count > 0) && (i.hasNext())) {
container = i.next();
if ((container != null) && (container.size() > 0)) {
if (container != null && !container.isEmpty()) {
containers.add(container);
}
count--; // decrease counter even if the container was null or empty to ensure termination
@ -117,7 +117,7 @@ public abstract class AbstractIndex <ReferenceType extends Reference> implements
}
// check result
if ((singleContainer == null || singleContainer.size() == 0)) return new HashMap<byte[], ReferenceContainer<ReferenceType>>(0);
if ((singleContainer == null || singleContainer.isEmpty())) return new HashMap<byte[], ReferenceContainer<ReferenceType>>(0);
containers.put(singleHash, singleContainer);
}
@ -154,13 +154,13 @@ public abstract class AbstractIndex <ReferenceType extends Reference> implements
}
// check result
if ((singleContainer == null || singleContainer.size() == 0)) return ReferenceContainer.emptyContainer(factory, null, 0);
if ((singleContainer == null || singleContainer.isEmpty())) return ReferenceContainer.emptyContainer(factory, null, 0);
if (resultContainer == null) resultContainer = singleContainer; else {
resultContainer = ReferenceContainer.joinConstructive(factory, resultContainer, singleContainer, maxDistance);
}
// finish if the result is empty
if (resultContainer.size() == 0) return resultContainer;
if (resultContainer.isEmpty()) return resultContainer;
}
return resultContainer;
}

@ -37,7 +37,7 @@ public abstract class AbstractReference implements Reference {
return l;
}
protected static int max(ArrayList<Integer> a) {
assert a.size() > 0;
assert !a.isEmpty();
if (a.size() == 1) return a.get(0);
if (a.size() == 2) return Math.max(a.get(0), a.get(1));
int r = a.get(0);
@ -45,7 +45,7 @@ public abstract class AbstractReference implements Reference {
return r;
}
protected static int min(ArrayList<Integer> a) {
assert a.size() > 0;
assert !a.isEmpty();
if (a.size() == 1) return a.get(0);
if (a.size() == 2) return Math.min(a.get(0), a.get(1));
int r = a.get(0);

@ -83,7 +83,7 @@ public class IODispatcher extends Thread {
public synchronized void dump(ReferenceContainerCache<? extends Reference> cache, File file, ReferenceContainerArray<? extends Reference> array) {
if (dumpQueue == null || controlQueue == null || !this.isAlive()) {
Log.logWarning("IODispatcher", "emergency dump of file " + file.getName());
if (cache.size() > 0) cache.dump(file, (int) Math.min(MemoryControl.available() / 3, writeBufferSize));
if (!cache.isEmpty()) cache.dump(file, (int) Math.min(MemoryControl.available() / 3, writeBufferSize));
} else {
DumpJob<? extends Reference> job = (DumpJob<? extends Reference>)new DumpJob(cache, file, array);
try {
@ -145,7 +145,7 @@ public class IODispatcher extends Thread {
controlQueue.acquire();
// prefer dump actions to flush memory to disc
if (dumpQueue.size() > 0) {
if (!dumpQueue.isEmpty()) {
File f = null;
try {
dumpJob = dumpQueue.take();
@ -162,7 +162,7 @@ public class IODispatcher extends Thread {
}
// otherwise do a merge operation
if (mergeQueue.size() > 0) {
if (!mergeQueue.isEmpty()) {
File f = null, f1 = null, f2 = null;
try {
mergeJob = mergeQueue.take();
@ -216,7 +216,7 @@ public class IODispatcher extends Thread {
}
public void dump() {
try {
if (cache.size() > 0) cache.dump(file, (int) Math.min(MemoryControl.available() / 3, writeBufferSize));
if (!cache.isEmpty()) cache.dump(file, (int) Math.min(MemoryControl.available() / 3, writeBufferSize));
array.mountBLOBFile(file);
} catch (IOException e) {
Log.logException(e);

@ -286,7 +286,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
* and is composed of the current date and the cell salt
*/
public synchronized void close() {
if (this.ram.size() > 0) this.ram.dump(this.array.newContainerBLOBFile(), (int) Math.min(MemoryControl.available() / 3, writeBufferSize));
if (!this.ram.isEmpty()) this.ram.dump(this.array.newContainerBLOBFile(), (int) Math.min(MemoryControl.available() / 3, writeBufferSize));
// close all
this.ram.close();
this.array.close();

@ -262,7 +262,7 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
singleContainer = i.next();
// check result
if ((singleContainer == null) || (singleContainer.size() == 0)) return null; // as this is a cunjunction of searches, we have no result if any word is not known
if (singleContainer == null || singleContainer.isEmpty()) return null; // as this is a cunjunction of searches, we have no result if any word is not known
// store result in order of result size
map.put(Long.valueOf(singleContainer.size() * 1000 + count), singleContainer);
@ -270,13 +270,13 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
}
// check if there is any result
if (map.size() == 0) return null; // no result, nothing found
if (map.isEmpty()) return null; // no result, nothing found
// the map now holds the search results in order of number of hits per word
// we now must pairwise build up a conjunction of these sets
Long k = map.firstKey(); // the smallest, which means, the one with the least entries
ReferenceContainer<ReferenceType> searchA, searchB, searchResult = map.remove(k);
while ((map.size() > 0) && (searchResult.size() > 0)) {
while (!map.isEmpty() && !searchResult.isEmpty()) {
// take the first element of map which is a result and combine it with result
k = map.firstKey(); // the next smallest...
searchA = searchResult;
@ -288,7 +288,7 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
}
// in 'searchResult' is now the combined search result
if (searchResult.size() == 0) return null;
if (searchResult.isEmpty()) return null;
return searchResult;
}
@ -298,12 +298,12 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
final Collection<ReferenceContainer<ReferenceType>> containers) {
// check if there is any result
if ((containers == null) || (containers.size() == 0)) return pivot; // no result, nothing found
if (containers == null || containers.isEmpty()) return pivot; // no result, nothing found
final Iterator<ReferenceContainer<ReferenceType>> i = containers.iterator();
while (i.hasNext()) {
pivot = excludeDestructive(factory, pivot, i.next());
if ((pivot == null) || (pivot.size() == 0)) return null;
if (pivot == null || pivot.isEmpty()) return null;
}
return pivot;
@ -322,7 +322,7 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
final ReferenceContainer<ReferenceType> i2,
final int maxDistance) {
if ((i1 == null) || (i2 == null)) return null;
if ((i1.size() == 0) || (i2.size() == 0)) return null;
if (i1.isEmpty() || i2.isEmpty()) return null;
// decide which method to use
final int high = ((i1.size() > i2.size()) ? i1.size() : i2.size());
@ -418,8 +418,8 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
final ReferenceContainer<ReferenceType> excl) {
if (pivot == null) return null;
if (excl == null) return pivot;
if (pivot.size() == 0) return null;
if (excl.size() == 0) return pivot;
if (pivot.isEmpty()) return null;
if (excl.isEmpty()) return pivot;
// decide which method to use
final int high = ((pivot.size() > excl.size()) ? pivot.size() : excl.size());

@ -146,7 +146,10 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
return (this.cache == null) ? 0 : this.cache.size();
}
public boolean isEmpty() {
if (this.cache == null) return true;
return this.cache.isEmpty();
}
public int maxReferences() {
// iterate to find the max score
@ -298,7 +301,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
final ReferenceContainer<ReferenceType> c = cache.get(tha);
if ((c != null) && (c.remove(urlHash) != null)) {
// removal successful
if (c.size() == 0) {
if (c.isEmpty()) {
delete(termHash);
} else {
cache.put(tha, c);
@ -311,14 +314,14 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
public int remove(final byte[] termHash, final Set<String> urlHashes) {
assert this.cache != null;
if (urlHashes.size() == 0) return 0;
if (urlHashes.isEmpty()) return 0;
ByteArray tha = new ByteArray(termHash);
int count;
synchronized (cache) {
final ReferenceContainer<ReferenceType> c = cache.get(tha);
if ((c != null) && ((count = c.removeEntries(urlHashes)) > 0)) {
// removal successful
if (c.size() == 0) {
if (c.isEmpty()) {
delete(termHash);
} else {
cache.put(tha, c);
@ -332,7 +335,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
public void add(final ReferenceContainer<ReferenceType> container) {
// this puts the entries into the cache
assert this.cache != null;
if (this.cache == null || container == null || container.size() == 0) return;
if (this.cache == null || container == null || container.isEmpty()) return;
// put new words into cache
ByteArray tha = new ByteArray(container.getTermHash());

@ -46,7 +46,7 @@ public class TermSearch <ReferenceType extends Reference> {
int maxDistance) {
this.inclusionContainers =
(queryHashes.size() == 0) ?
(queryHashes.isEmpty()) ?
new HashMap<byte[], ReferenceContainer<ReferenceType>>(0) :
base.searchConjunction(queryHashes, urlselection);
@ -55,7 +55,7 @@ public class TermSearch <ReferenceType extends Reference> {
inclusionContainers = new HashMap<byte[], ReferenceContainer<ReferenceType>>(0); // prevent that only a subset is returned
HashMap<byte[], ReferenceContainer<ReferenceType>> exclusionContainers =
(inclusionContainers.size() == 0) ?
(inclusionContainers.isEmpty()) ?
new HashMap<byte[], ReferenceContainer<ReferenceType>>(0) :
base.searchConjunction(excludeHashes, urlselection);

@ -237,7 +237,7 @@ public final class RecordStack extends Records {
private Node topNode() throws IOException {
// return node ontop of the stack
if (size() == 0) return null;
if (isEmpty()) return null;
final Records.Handle h = getHandle(toor);
if (h == null) return null;
return new Node(h);
@ -245,7 +245,7 @@ public final class RecordStack extends Records {
private Node botNode() throws IOException {
// return node on bottom of the stack
if (size() == 0) {
if (isEmpty()) {
Log.logInfo("Stack", "size() == 0");
return null;
}

@ -138,6 +138,10 @@ public class SQLTable implements ObjectIndex, Iterable<Row.Entry> {
}
}
public boolean isEmpty() {
return size() == 0;
}
public Row row() {
return this.rowdef;
}

@ -186,7 +186,7 @@ public class SplitTable implements ObjectIndex, Iterable<Row.Entry> {
String maxf;
long maxram;
ObjectIndex table;
while (t.size() > 0) {
while (!t.isEmpty()) {
// find maximum table
maxram = 0;
maxf = null;
@ -260,6 +260,12 @@ public class SplitTable implements ObjectIndex, Iterable<Row.Entry> {
return s;
}
public boolean isEmpty() {
final Iterator<ObjectIndex> i = tables.values().iterator();
while (i.hasNext()) if (!i.next().isEmpty()) return false;
return true;
}
public int writeBufferSize() {
int s = 0;
for (final ObjectIndex index : tables.values()) {

@ -200,7 +200,7 @@ public class Table implements ObjectIndex, Iterable<Row.Entry> {
final ArrayList<Long[]> doubles = index.removeDoubles();
//assert index.size() + doubles.size() + fail == i;
//System.out.println(" -removed " + doubles.size() + " doubles- done.");
if (doubles.size() > 0) {
if (!doubles.isEmpty()) {
Log.logInfo("TABLE", tablefile + ": WARNING - TABLE " + tablefile + " has " + doubles.size() + " doubles");
// from all the doubles take one, put it back to the index and remove the others from the file
// first put back one element each
@ -219,7 +219,7 @@ public class Table implements ObjectIndex, Iterable<Row.Entry> {
}
// now remove the entries in a sorted way (top-down)
Long top;
while (delpos.size() > 0) {
while (!delpos.isEmpty()) {
top = delpos.last();
delpos.remove(top);
removeInFile(top.intValue());
@ -337,7 +337,7 @@ public class Table implements ObjectIndex, Iterable<Row.Entry> {
}
// finally delete the affected rows, but start with largest id first, otherwise we overwrite wrong entries
Long s;
while (d.size() > 0) {
while (!d.isEmpty()) {
s = d.last();
d.remove(s);
this.removeInFile(s.intValue());
@ -629,6 +629,10 @@ public class Table implements ObjectIndex, Iterable<Row.Entry> {
return index.size();
}
public synchronized boolean isEmpty() {
return index.isEmpty();
}
public Iterator<Entry> iterator() {
try {
return rows();

@ -98,7 +98,7 @@ public class MemoryTracker extends Thread {
if (history.size() % 10 == 0) { // reduce number of System.currentTimeMillis() calls
Event e;
final long now = System.currentTimeMillis();
while (history.size() > 0) {
while (!history.isEmpty()) {
e = history.get(0);
if (now - e.time < 600000) break;
history.remove(0);

@ -58,7 +58,7 @@ public class ObjectSpace {
incAlive(len);
synchronized (objHeap) {
final ArrayList<byte[]> buf = objHeap.get(Integer.valueOf(len));
if ((buf == null) || (buf.size() == 0)) return new byte[len];
if (buf == null || buf.isEmpty()) return new byte[len];
return buf.remove(buf.size() - 1);
}
}

@ -176,6 +176,10 @@ public final class ScoreCluster<E> {
return refkeyDB.size();
}
public synchronized boolean isEmpty() {
return refkeyDB.isEmpty();
}
public synchronized void incScore(final E[] objs) {
for (int i = 0; i < objs.length; i++) addScore(objs[i], 1);
}
@ -293,22 +297,22 @@ public final class ScoreCluster<E> {
}
public synchronized int getMaxScore() {
if (refkeyDB.size() == 0) return -1;
if (refkeyDB.isEmpty()) return -1;
return (int) ((keyrefDB.lastKey().longValue() & 0xFFFFFFFF00000000L) >> 32);
}
public synchronized int getMinScore() {
if (refkeyDB.size() == 0) return -1;
if (refkeyDB.isEmpty()) return -1;
return (int) ((keyrefDB.firstKey().longValue() & 0xFFFFFFFF00000000L) >> 32);
}
public synchronized E getMaxObject() {
if (refkeyDB.size() == 0) return null;
if (refkeyDB.isEmpty()) return null;
return keyrefDB.get(keyrefDB.lastKey());
}
public synchronized E getMinObject() {
if (refkeyDB.size() == 0) return null;
if (refkeyDB.isEmpty()) return null;
return keyrefDB.get(keyrefDB.firstKey());
}
@ -368,7 +372,7 @@ public final class ScoreCluster<E> {
private void internalNext() {
Long key;
int score = (max + min) / 2;
while (keyrefDBcopy.size() > 0) {
while (!keyrefDBcopy.isEmpty()) {
key = ((up) ? keyrefDBcopy.firstKey() : keyrefDBcopy.lastKey());
n = keyrefDBcopy.remove(key);
score = (int) ((key.longValue() & 0xFFFFFFFF00000000L) >> 32);
@ -404,7 +408,7 @@ public final class ScoreCluster<E> {
}
public boolean hasNext() {
return view.size() > 0;
return !view.isEmpty();
}
public E next() {

@ -78,7 +78,7 @@ public class SetTools {
singleMap = i.next();
// check result
if ((singleMap == null) || (singleMap.size() == 0)) return new TreeMap<A, B>();
if ((singleMap == null) || (singleMap.isEmpty())) return new TreeMap<A, B>();
// store result in order of result size
orderMap.put(Long.valueOf(singleMap.size() * 1000 + count), singleMap);
@ -86,12 +86,12 @@ public class SetTools {
}
// check if there is any result
if (orderMap.size() == 0) return new TreeMap<A, B>();
if (orderMap.isEmpty()) return new TreeMap<A, B>();
// we now must pairwise build up a conjunction of these maps
Long k = orderMap.firstKey(); // the smallest, which means, the one with the least entries
TreeMap<A, B> mapA, mapB, joinResult = orderMap.remove(k);
while ((orderMap.size() > 0) && (joinResult.size() > 0)) {
while (!orderMap.isEmpty() && !joinResult.isEmpty()) {
// take the first element of map which is a result and combine it with result
k = orderMap.firstKey(); // the next smallest...
mapA = joinResult;
@ -103,7 +103,7 @@ public class SetTools {
}
// in 'searchResult' is now the combined search result
if (joinResult.size() == 0) return new TreeMap<A, B>();
if (joinResult.isEmpty()) return new TreeMap<A, B>();
return joinResult;
}
@ -111,7 +111,7 @@ public class SetTools {
// comparators must be equal
if ((map1 == null) || (map2 == null)) return null;
if (map1.comparator() != map2.comparator()) return null;
if ((map1.size() == 0) || (map2.size() == 0)) return new TreeMap<A, B>(map1.comparator());
if (map1.isEmpty() || map2.isEmpty()) return new TreeMap<A, B>(map1.comparator());
// decide which method to use
final int high = ((map1.size() > map2.size()) ? map1.size() : map2.size());
@ -183,7 +183,7 @@ public class SetTools {
// comparators must be equal
if ((set1 == null) || (set2 == null)) return null;
if (set1.comparator() != set2.comparator()) return null;
if ((set1.size() == 0) || (set2.size() == 0)) return new TreeSet<A>(set1.comparator());
if (set1.isEmpty() || set2.isEmpty()) return new TreeSet<A>(set1.comparator());
// decide which method to use
final int high = ((set1.size() > set2.size()) ? set1.size() : set2.size());
@ -241,7 +241,7 @@ public class SetTools {
// comparators must be equal
if ((set1 == null) || (set2 == null)) return false;
if (set1.comparator() != set2.comparator()) return false;
if ((set1.size() == 0) || (set2.size() == 0)) return false;
if (set1.isEmpty() || set2.isEmpty()) return false;
// decide which method to use
final int high = ((set1.size() > set2.size()) ? set1.size() : set2.size());
@ -297,7 +297,7 @@ public class SetTools {
public static <A, B> TreeMap<A, B> excludeConstructive(final TreeMap<A, B> map, final Set<A> set) {
if (map == null) return null;
if (set == null) return map;
if ((map.size() == 0) || (set.size() == 0)) return map;
if (map.isEmpty() || set.isEmpty()) return map;
assert !(set instanceof TreeSet) || map.comparator() == ((TreeSet<A>) set).comparator();
// if (map.comparator() != set.comparator()) return excludeConstructiveByTestMapInSet(map, set);
return excludeConstructiveByTestMapInSet(map, set);
@ -320,7 +320,7 @@ public class SetTools {
if (map == null) return;
if (set == null) return;
assert !(map instanceof TreeMap && set instanceof TreeSet) || ((TreeMap<A, B>) map).comparator() == ((TreeSet<A>) set).comparator();
if ((map.size() == 0) || (set.size() == 0)) return;
if (map.isEmpty() || set.isEmpty()) return;
if (map.size() < set.size())
excludeDestructiveByTestMapInSet(map, set);
@ -343,7 +343,7 @@ public class SetTools {
if (set1 == null) return;
if (set2 == null) return;
assert !(set1 instanceof TreeSet && set2 instanceof TreeSet) || ((TreeSet<A>) set1).comparator() == ((TreeSet<A>) set2).comparator();
if ((set1.size() == 0) || (set2.size() == 0)) return;
if (set1.isEmpty() || set2.isEmpty()) return;
if (set1.size() < set2.size())
excludeDestructiveByTestSmallInLarge(set1, set2);

@ -56,6 +56,11 @@ public class SortStack<E> {
this.maxsize = maxsize;
}
public boolean isEmpty() {
return this.instack.isEmpty();
}
public int size() {
return this.instack.size();
}
@ -82,8 +87,8 @@ public class SortStack<E> {
// check maximum size of the stack an remove elements if the stack gets too large
if (this.maxsize <= 0) return;
while ((this.onstack.size() > 0) && (this.onstack.size() > this.maxsize)) synchronized (this.onstack) {
if ((this.onstack.size() > 0) && (this.onstack.size() > this.maxsize)) {
while (!this.onstack.isEmpty() && this.onstack.size() > this.maxsize) synchronized (this.onstack) {
if (!this.onstack.isEmpty() && this.onstack.size() > this.maxsize) {
this.onstack.remove(this.onstack.lastKey());
}
}
@ -121,7 +126,7 @@ public class SortStack<E> {
final List<E> l = this.onstack.get(w);
element = l.remove(0);
this.instack.remove(element);
if (l.size() == 0) this.onstack.remove(w);
if (l.isEmpty()) this.onstack.remove(w);
}
return new stackElement(element, w);
}
@ -140,7 +145,7 @@ public class SortStack<E> {
while (i.hasNext()) {
if (i.next().equals(element)) {
i.remove();
if (entry.getValue().size() == 0) {
if (entry.getValue().isEmpty()) {
this.onstack.remove(entry.getKey());
}
return;
@ -152,7 +157,7 @@ public class SortStack<E> {
public boolean bottom(final long weight) {
// returns true if the element with that weight would be on the bottom of the stack after inserting
if (this.onstack.size() == 0) return true;
if (this.onstack.isEmpty()) return true;
Long l;
synchronized (this.onstack) {
l = this.onstack.lastKey();

@ -54,6 +54,11 @@ public class SortStore<E> extends SortStack<E> {
this.offset = new ConcurrentHashMap<E, Object>();
}
public boolean isEmpty() {
if (!super.isEmpty()) return false;
return this.offstack.isEmpty();
}
public int size() {
return super.size() + this.offstack.size();
}
@ -68,7 +73,7 @@ public class SortStore<E> extends SortStack<E> {
super.push(element, weight);
this.largest = Math.max(this.largest, weight.longValue());
if (this.maxsize <= 0) return;
while ((super.size() > 0) && (this.size() > this.maxsize)) {
while (!super.isEmpty() && this.size() > this.maxsize) {
this.pop();
}
}
@ -120,7 +125,7 @@ public class SortStore<E> extends SortStack<E> {
public ArrayList<stackElement> list(final int count) {
if (count < 0) {
// shift all elements
while (super.size() > 0) this.pop();
while (!super.isEmpty()) this.pop();
return this.offstack;
}
if (count > super.size() + this.offstack.size()) throw new RuntimeException("list(" + count + ") exceeded avaiable number of elements (" + size() + ")");

@ -85,6 +85,10 @@ public class WorkflowProcessor<J extends WorkflowJob> {
return this.input.size();
}
public boolean queueIsEmpty() {
return this.input.isEmpty();
}
public int queueSizeMax() {
return this.input.size() + this.input.remainingCapacity();
}
@ -116,11 +120,11 @@ public class WorkflowProcessor<J extends WorkflowJob> {
}
public synchronized void relaxCapacity() {
if (this.input.size() == 0) return;
if (this.input.isEmpty()) return;
if (this.input.remainingCapacity() > 1000) return;
BlockingQueue<J> i = new LinkedBlockingQueue<J>();
J e;
while (this.input.size() > 0) {
while (!this.input.isEmpty()) {
e = this.input.poll();
if (e == null) break;
i.add(e);

@ -219,14 +219,14 @@ public class Blacklist {
ArrayList<String> hostList = blacklistMap.get(host);
if(hostList != null) {
hostList.remove(path);
if (hostList.size() == 0)
if (hostList.isEmpty())
blacklistMap.remove(host);
}
final HashMap<String, ArrayList<String>> blacklistMapNotMatch = getBlacklistMap(blacklistType,false);
hostList = blacklistMapNotMatch.get(host);
if (hostList != null) {
hostList.remove(path);
if (hostList.size() == 0)
if (hostList.isEmpty())
blacklistMapNotMatch.remove(host);
}
}
@ -462,7 +462,7 @@ public class Blacklist {
public static final String defaultBlacklist(final File listsPath) {
List<String> dirlist = FileUtils.getDirListing(listsPath, Blacklist.BLACKLIST_FILENAME_FILTER);
if (dirlist.size() == 0) return null;
if (dirlist.isEmpty()) return null;
return dirlist.get(0);
}

@ -787,7 +787,7 @@ public final class yacy {
if (wordset.size() != count) {
count = count - wordset.size();
final BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(wordlist)));
while (wordset.size() > 0) {
while (!wordset.isEmpty()) {
word = wordset.first();
bw.write(word + "\n");
wordset.remove(word);

Loading…
Cancel
Save