-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIx #1201: Break down KaizenHarvester into simpler pieces
Introduce KaizenQuery class to support different methods to store queries that Kaizen needs to process
- Loading branch information
1 parent
d202df9
commit 905f096
Showing
2 changed files
with
104 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.loklak.harvester.strategy; | ||
|
||
import java.util.HashSet; | ||
|
||
/** | ||
* KaizenQueries are objects that holds the query strings for KaizenHarvester. | ||
*/ | ||
public abstract class KaizenQueries { | ||
|
||
public abstract boolean addQuery(String query); | ||
|
||
public abstract String getQuery(); | ||
|
||
public abstract int getSize(); | ||
|
||
public abstract int getMaxSize(); | ||
|
||
public boolean isEmpty() { | ||
return this.getSize() == 0; | ||
} | ||
|
||
public static KaizenQueries getDefaultKaizenQueries(int qLimit) { | ||
return new KaizenQueries() { | ||
|
||
HashSet<String> queries = new HashSet<>(); | ||
int queryLimit = qLimit; | ||
|
||
@Override | ||
public boolean addQuery(String query) { | ||
if (this.queryLimit > 0 && this.queries.size() > this.queryLimit) | ||
return false; | ||
|
||
if (queries.contains(query)) | ||
return false; | ||
|
||
this.queries.add(query); | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getQuery() { | ||
String query = this.queries.iterator().next(); | ||
this.queries.remove(query); | ||
return query; | ||
} | ||
|
||
@Override | ||
public int getSize() { | ||
return this.queries.size(); | ||
} | ||
|
||
@Override | ||
public int getMaxSize() { | ||
return this.queryLimit; | ||
} | ||
}; | ||
} | ||
} |