Java Code Examples for com.googlecode.totallylazy.Sequence#map()

The following examples show how to use com.googlecode.totallylazy.Sequence#map() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DomConverterTest.java    From totallylazy with Apache License 2.0 5 votes vote down vote up
@Test
public void works() throws Exception {
    String xml = "<stream>Hello &amp; World</stream>";
    Sequence<Context> contexts = contexts(xml).filter(xpath(child(name("stream"))));
    Sequence<Node> stream = contexts.map(DomConverter::convert);
    assertThat(stream.size(), is(1));
    assertThat(Xml.asString(stream.head()), is("<stream>Hello &amp; World</stream>"));
}
 
Example 2
Source File: CompletionResult.java    From java-repl with Apache License 2.0 5 votes vote down vote up
public static CompletionResult fromJson(String json) {
    Map<String, Object> jsonMap = map(Json.map(json));

    Sequence<Map<String, Object>> candidates = CANDIDATES.map(Sequences::sequence).apply(jsonMap);

    return new CompletionResult(
            EXPRESSION.apply(jsonMap),
            POSITION.map(Integer::valueOf).apply(jsonMap),
            candidates.map(candidate -> new CompletionCandidate(VALUE.apply(candidate), FORMS.map(Sequences::sequence).apply(candidate)))
    );
}
 
Example 3
Source File: Xml.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
public static Sequence<String> contentsSequence(Sequence<Node> nodes) {
    return nodes.map(contents());
}
 
Example 4
Source File: Xml.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
public static Sequence<String> textContents(Sequence<Node> nodes) {
    return nodes.map(textContent());
}
 
Example 5
Source File: FileSource.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
private FileSource(final Sequence<Pair<String, File>> sources) {
    closeables = closeableList(InputStream.class);
    this.sources = sources.map(pair ->
            Source.source(pair.first(), () -> new Date(pair.second().lastModified()), () -> inputStream(pair.second()), pair.second().isDirectory()));
}
 
Example 6
Source File: FieldOnTest.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
@Test
public void canMapWithAField() throws Exception {
    Sequence<User> users = sequence(user("Dan", "Bodart"), user("Matt", "Savage"));
    Sequence<String> firstNames = users.map(new FieldOn<User, String>() { { get(instance.firstName); } });
    assertThat(firstNames, hasExactly("Dan", "Matt"));
}
 
Example 7
Source File: CallTest.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
@Test
public void canMapAMethod() throws Exception {
    Sequence<User> users = sequence(user("Dan", "Bodart"), user("Matt", "Savage"));
    Sequence<String> firstNames = users.map(method(on(User.class).firstName()));
    assertThat(firstNames, hasExactly("Dan", "Matt"));
}
 
Example 8
Source File: CallTest.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
@Test
public void canMapAMethodWithAnArgument() throws Exception {
    Sequence<User> users = sequence(user("Dan", "Bodart"), user("Matt", "Savage"));
    Sequence<String> firstNames = users.map(method(on(User.class).say("Hello")));
    assertThat(firstNames, hasExactly("Dan says 'Hello'", "Matt says 'Hello'"));
}
 
Example 9
Source File: CallOnTest.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
@Test
public void canUseInstanceInsteadOfCallForReadability() throws Exception {
    Sequence<User> users = sequence(user("Dan", "Bodart"), user("Matt", "Savage"));
    Sequence<String> firstNames = users.map(new CallOn<User, String>(){{instance.firstName();}});
    assertThat(firstNames, hasExactly("Dan", "Matt"));
}
 
Example 10
Source File: CallOnTest.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
@Test
public void canMapAMethod() throws Exception {
    Sequence<User> users = sequence(user("Dan", "Bodart"), user("Matt", "Savage"));
    Sequence<String> firstNames = users.map(new CallOn<User, String>(){{call.firstName();}});
    assertThat(firstNames, hasExactly("Dan", "Matt"));
}
 
Example 11
Source File: CallOnTest.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
@Test
public void canMapAMethodWithAnArgument() throws Exception {
    Sequence<User> users = sequence(user("Dan", "Bodart"), user("Matt", "Savage"));
    Sequence<String> firstNames = users.map(new CallOn<User, String>(){{call.say("Hello");}});
    assertThat(firstNames, hasExactly("Dan says 'Hello'", "Matt says 'Hello'"));
}
 
Example 12
Source File: Commands.java    From java-repl with Apache License 2.0 4 votes vote down vote up
private Sequence<Command> commandInstances(Sequence<Class<? extends Command>> commands) {
    return commands.map(context::create);
}