generated from Nekojimi/JavaMavenTemplate
Update test program.
This commit is contained in:
parent
b8c3972f54
commit
4df2f55922
|
@ -19,6 +19,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import moe.nekojimi.musicsearcher.providers.MetaSearcher;
|
||||
import moe.nekojimi.musicsearcher.providers.Searcher;
|
||||
|
||||
/**
|
||||
|
@ -35,39 +36,31 @@ public class Main
|
|||
public static void main(String[] args) throws IOException
|
||||
{
|
||||
// System.out.println("Hello world!");
|
||||
YamlInput input = Yaml.createYamlInput(new File("searchproviders.yml"));
|
||||
YamlSequence seq = input.readYamlSequence();
|
||||
for (int i = 0; i < seq.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
YamlMapping map = seq.yamlMapping(i);
|
||||
String type = map.string("type");
|
||||
Class<? extends Searcher> clazz = (Class<? extends Searcher>) Class.forName("moe.nekojimi.musicsearcher.providers." + type);
|
||||
Constructor<? extends Searcher> constructor = clazz.getConstructor(YamlMapping.class);
|
||||
Searcher searcher = constructor.newInstance(map);
|
||||
searchers.put(searcher.getName(), searcher);
|
||||
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(searchers);
|
||||
String query = "everybodys circulation";
|
||||
for (Searcher searcher: searchers.values())
|
||||
{
|
||||
System.out.println("Searching " + searcher.getName() + " for " + query);
|
||||
String query = "eminem lose yourself";
|
||||
|
||||
MetaSearcher metaSearch = MetaSearcher.loadYAML(new File("searchproviders.yml"));
|
||||
|
||||
try
|
||||
{
|
||||
List<Result> results = searcher.searchAndWait(Query.fullText(query));
|
||||
List<Result> results = metaSearch.searchAndWait(Query.fullText(query));
|
||||
// for (Searcher searcher: searchers.values())
|
||||
// {
|
||||
// System.out.println("Searching " + searcher.getName() + " for " + query);
|
||||
// try
|
||||
// {
|
||||
// List<Result> results = searcher.searchAndWait(Query.fullText(query));
|
||||
for (Result result : results)
|
||||
{
|
||||
System.out.println("\t" + result);
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
// } catch (InterruptedException | ExecutionException ex) {
|
||||
// Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
||||
// }
|
||||
// }
|
||||
} catch (ExecutionException | InterruptedException ex)
|
||||
{
|
||||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue