• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Sequence类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.googlecode.totallylazy.Sequence的典型用法代码示例。如果您正苦于以下问题:Java Sequence类的具体用法?Java Sequence怎么用?Java Sequence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Sequence类属于com.googlecode.totallylazy包,在下文中一共展示了Sequence类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: zipExample

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
/**
 * Zipping
 * -------
 * 
 * Two sequences can be zipped into a single collection of pairs:
 */
@Test
public void zipExample() {
    Sequence<String> firstNames = sequence("Marge", "Maude");
    Sequence<String> lastNames = sequence("Simpson", "Flanders");

    Sequence<Pair<String, String>> namePairs = firstNames.zip(lastNames);
    assertEquals("Marge", namePairs.get(0).first());
    assertEquals("Simpson", namePairs.get(0).second());

    assertEquals("Maude", namePairs.get(1).first());
    assertEquals("Flanders", namePairs.get(1).second());

    // A more intersting way to use this feature:

    Sequence<String> fullNames = namePairs.map(pair -> pair.first() + " " + pair.second());
    assertEquals("Marge Simpson", fullNames.first());
    assertEquals("Maude Flanders", fullNames.second());
}
 
开发者ID:fleipold,项目名称:totally-lazy-tutorial,代码行数:25,代码来源:IntroductionTest.java


示例2: showGroupBy

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
/**
 * Grouping
 * --------
 * 
 * Sequences can be grouped by a key (function), like so:
 */
@Test
public void showGroupBy() {

    Sequence<Person> people = sequence(
        new Person("Homer", "Simpson"),
        new Person("Marge", "Simpson"),
        new Person("Ned", "Flanders"),
        new Person("Maude", "Flanders")
    );

    Sequence<Group<String, Person>> groups = people.groupBy(person -> person.lastname);

    assertEquals("Simpson", groups.get(0).key());

    assertEquals("Homer", groups.get(0).get(0).firstname);
    assertEquals("Marge", groups.get(0).get(1).firstname);

    assertEquals("Flanders", groups.get(1).key());

    assertEquals("Ned", groups.get(1).get(0).firstname);
    assertEquals("Maude", groups.get(1).get(1).firstname);
}
 
开发者ID:fleipold,项目名称:totally-lazy-tutorial,代码行数:29,代码来源:IntroductionTest.java


示例3: init

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
public static void init(Activity activity, ObjectMapper objectMapper) throws IOException {

        InputStream inputStream = activity.getResources().openRawResource(R.raw.beers);

        beersObservable = Observable
                .<Sequence<Beer>>create((subscriber) -> {
                    try {
                        Sequence<Beer> beerSeq = objectMapper.readValue(inputStream, new TypeReference<Sequence<Beer>>() {
                        });
                        subscriber.onNext(beerSeq);
                        subscriber.onCompleted();
                    } catch (IOException e) {
                        subscriber.onError(e);
                    }
                })
                .cache()
                .subscribeOn(Schedulers.io());
    }
 
开发者ID:blomqvie,项目名称:training-totally-lazy,代码行数:19,代码来源:Beers.java


示例4: collectTestMethods

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
private static Sequence<TestMethod> collectTestMethods(Class aClass, Sequence<Method> methods) throws IOException {
    final Option<JavaClass> javaClass = getJavaClass(aClass);
    if (javaClass.isEmpty()) {
        return empty();
    }

    Map<String, List<JavaMethod>> sourceMethodsByName = getMethods(javaClass.get()).toMap(sourceMethodName());
    Map<String, List<Method>> reflectionMethodsByName = methods.toMap(reflectionMethodName());

    List<TestMethod> testMethods = new ArrayList<TestMethod>();
    TestMethodExtractor extractor = new TestMethodExtractor();
    for (String name : sourceMethodsByName.keySet()) {
        List<JavaMethod> javaMethods = sourceMethodsByName.get(name);
        List<Method> reflectionMethods = reflectionMethodsByName.get(name);
        testMethods.add(extractor.toTestMethod(aClass, javaMethods.get(0), reflectionMethods.get(0)));
        // TODO: If people overload test methods we will have to use the full name rather than the short name
    }

    Sequence<TestMethod> myTestMethods = sequence(testMethods);
    Sequence<TestMethod> parentTestMethods = collectTestMethods(aClass.getSuperclass(), methods);

    return myTestMethods.join(parentTestMethods);
}
 
开发者ID:bodar,项目名称:yatspec,代码行数:24,代码来源:TestParser.java


示例5: supportsRelative

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
@Test
public void supportsRelative() throws Exception {
    String xml = "<stream><user><first>Dan &amp; Bod</first><dob>1977</dob></user><user><first>Jason</first><dob>1978</dob></user></stream>";
    Document document = document(xml);

    Sequence<Node> userNodes = selectNodes(document, "descendant::user");

    Sequence<Context> usersContexts = contexts(xml).
            filter(xpath(descendant(name("user"))));
    assertThat(usersContexts.size(), is(userNodes.size()));

    Context danContext = usersContexts.head();
    Sequence<Context> relative = danContext.relative();
    assertThat(relative.toString("\n"), is("<first>\n" +
            "<first>/Dan & Bod\n" +
            "<dob>\n" +
            "<dob>/1977"));
}
 
开发者ID:bodar,项目名称:totallylazy,代码行数:19,代码来源:ContextTest.java


示例6: showMap

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
/**
 * Mapping
 * -------
 * 
 * The `map` method applies a function to every element of the
 * sequence and returns a sequence of these results:
 */
@Test
public void showMap() {
    Sequence<Integer> originalSequence = sequence(1, 2, 3);
    Sequence<Integer> squares = originalSequence.map(x -> x * x);

    assertEquals(sequence(1, 4, 9), squares);
}
 
开发者ID:fleipold,项目名称:totally-lazy-tutorial,代码行数:15,代码来源:IntroductionTest.java


示例7: showMapWithDifferentType

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
/**
 * The `map` method can apply a function that has a different return
 * type than the original element type:
 */
@Test
public void showMapWithDifferentType() {
    Sequence<Integer> originalSequence = sequence(1, 2, 3);
    Sequence<String> stringSequence = originalSequence.map(x -> String.format("%d", x));

    assertEquals(sequence("1", "2", "3"), stringSequence);
}
 
开发者ID:fleipold,项目名称:totally-lazy-tutorial,代码行数:12,代码来源:IntroductionTest.java


示例8: showElementAccess

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
/**
 * Accessing Elements and Subranges
 * --------------------------------
 * 
 * There are a couple of ways to access elements of a sequence.
 * Note that an index lookup can be expensive (rather than iterating over indices
 * consider map or fold operations):
 */

@Test
public void showElementAccess() {
    Sequence<String> strings = sequence("1", "2", "3", "4");

    assertEquals("1", strings.first());
    assertEquals("2", strings.second());
    assertEquals("4", strings.last());
    assertEquals("3", strings.get(2));
}
 
开发者ID:fleipold,项目名称:totally-lazy-tutorial,代码行数:19,代码来源:IntroductionTest.java


示例9: showSubRanges

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
/**
 * There are a number of ways to get subranges of Sequences.
 * It is important to know that Sequences are immutable, i.e.
 * all these operations return new objects.
 * 
 * Here some examples:
 */
@Test
public void showSubRanges() {
    Sequence<String> strings = sequence("1", "2", "3", "A", "B");

    assertEquals(sequence("2", "3", "A", "B"), strings.tail());
    assertEquals(sequence("1", "2"), strings.take(2));
    assertEquals(sequence("1", "2", "3"), strings.takeWhile(s -> Character.isDigit(s.charAt(0))));
    assertEquals(sequence("3", "A", "B"), strings.drop(2));
    assertEquals(sequence("A", "B"), strings.dropWhile(s -> Character.isDigit(s.charAt(0))));
}
 
开发者ID:fleipold,项目名称:totally-lazy-tutorial,代码行数:18,代码来源:IntroductionTest.java


示例10: zipWithIndexExample

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
/**
 * A very common usecase is that while we iterate (or map!) over a sequence we need
 * the current element and its index. This is what the `zipWithIndex` method is for:
 */
@Test
public void zipWithIndexExample() {
    Sequence<String> names = sequence("Mark", "Luke", "John", "Matthew");
    Sequence<String> namesWithIndex = names
        .zipWithIndex()
        .map(pair -> pair.first() + ". " + pair.second());

    assertEquals("0. Mark", namesWithIndex.get(0));
    assertEquals("1. Luke", namesWithIndex.get(1));
    assertEquals("2. John", namesWithIndex.get(2));
    assertEquals("3. Matthew", namesWithIndex.get(3));
}
 
开发者ID:fleipold,项目名称:totally-lazy-tutorial,代码行数:17,代码来源:IntroductionTest.java


示例11: testProperResultOnMinMaxOperationsWithImplicitMoneyContext

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
@Test
public void testProperResultOnMinMaxOperationsWithImplicitMoneyContext() {
  CurrencyExchangeRate r1 = new CurrencyExchangeRate(USD(1), JPY(100));
  CurrencyExchangeRate r2 = new CurrencyExchangeRate(USD(1), EUR(.75));
  Sequence<CurrencyExchangeRate> rates = sequence(r1, r2);

  MoneyContext.set(USD, Market.defaultCurrencySet, rates.toList());
  
  Money x = USD(100);
  Money y = JPY(100);
  assertThat(x.max(y), is(x));
  assertThat(y.min(x), is(y));
  
  MoneyContext.remove();    
}
 
开发者ID:synapplix,项目名称:jquants,代码行数:16,代码来源:MoneyTest.java


示例12: _deserializeContents

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
@Override
protected T _deserializeContents(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    JsonDeserializer<?> valueDes = _valueDeserializer;
    JsonToken t;
    final TypeDeserializer typeDeser = _typeDeserializerForValue;
    // No way to pass actual type parameter; but does not matter, just
    // compiler-time fluff:
    Sequence<Object> sequence = Sequences.sequence();

    while ((t = jp.nextToken()) != JsonToken.END_ARRAY) {
        Object value;

        if (t == JsonToken.VALUE_NULL) {
            value = null;
        } else if (typeDeser == null) {
            value = valueDes.deserialize(jp, ctxt);
        } else {
            value = valueDes.deserializeWithType(jp, ctxt, typeDeser);
        }
        sequence = sequence.append(value);
    }
    // No class outside of the package will be able to subclass us,
    // and we provide the proper builder for the subclasses we implement.
    @SuppressWarnings("unchecked")
    T collection = (T) sequence;
    return collection;
}
 
开发者ID:blomqvie,项目名称:android-rxjava-training,代码行数:29,代码来源:SequenceDeserializer.java


示例13: getBeers

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
@Override
public Sequence<Beer> getBeers(Sequence<Beer> beers) {
    // TODO:
    // 1. get beers with abv greater than 10
    // 2. sort the beers by name
    // 3. return the first 10 results
    //
    return beers;
}
 
开发者ID:blomqvie,项目名称:training-totally-lazy,代码行数:10,代码来源:Exercise1.java


示例14: getString

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
@Override
public String getString(Sequence<Beer> beers) {
    // TODO:
    // return a string that has all the names and abvs of brewery id 1142
    return beers
            .take(2)
            .map((beer) -> "make a string here")
            .toString(", ");
}
 
开发者ID:blomqvie,项目名称:training-totally-lazy,代码行数:10,代码来源:Exercise3.java


示例15: getBeers

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
@Override
public Sequence<Beer> getBeers(Sequence<Beer> beers) {
    // TODO:
    // 1) return beers with abv between 8 and 10
    // 2) also sort by descending abv (sortBy)
    // 3) make the beer name ALL UPPERCASE
    // tip: https://code.google.com/p/totallylazy/wiki/Sequence
    return beers;
}
 
开发者ID:blomqvie,项目名称:training-totally-lazy,代码行数:10,代码来源:Exercise2.java


示例16: onViewCreated

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    Exercise exercise = Exercises.getExerciseBySection(getArguments().getInt(SECTION_NUMBER));
    Observable<Sequence<Beer>> suitableBeers = Beers.beers().map(exercise::getBeers);
    subscription = AppObservable.bindFragment(this, suitableBeers).subscribe(beers -> {
        adapter = new BeerAdapter(beers, whenItemIsClicked);
        label = exercise.getLabel();
        setupView(view, label, adapter);
    });
}
 
开发者ID:blomqvie,项目名称:training-totally-lazy,代码行数:11,代码来源:LazyListFragment.java


示例17: messages

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
public Iterable<SequenceDiagramMessage> messages(CapturedInputAndOutputs inputAndOutputs) {
    Sequence<SequenceDiagramMessage> result = Sequences.empty();
    Set<String> keys = inputAndOutputs.getTypes().keySet();
    for (String key : keys) {
        Matcher matcher = pattern.matcher(key);
        if (matcher.matches()) {
            final String what = matcher.group(1).trim();
            final String from = matcher.group(2).trim();
            final String to = matcher.group(3).trim();
            result = result.append(new SequenceDiagramMessage(from, to, what, key.replaceAll(" ","_").replaceAll("\\(","_").replaceAll("\\)","_")));
        }
    }
    return result;
}
 
开发者ID:bodar,项目名称:yatspec,代码行数:15,代码来源:ByNamingConventionMessageProducer.java


示例18: removeIndentation

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
private String removeIndentation(String value) {
    Sequence<String> lines = lines(value);
    String indentation = lines.
            find(not(blankLine())).
            map(indentation()).getOrElse("");
    return lines.map(remove(indentation)).toString(lineSeparator());
}
 
开发者ID:bodar,项目名称:yatspec,代码行数:8,代码来源:JavaSourceRenderer.java


示例19: tagModels

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
private Sequence<Model> tagModels(Index index) {
    return index.
            entries().
            flatMap(testMethods()).
            flatMap(methodTags()).
            groupBy(first(String.class)).
            sortBy(groupKey(String.class)).
            map(toTagModel());
}
 
开发者ID:bodar,项目名称:yatspec,代码行数:10,代码来源:HtmlTagIndexRenderer.java


示例20: createPossiblyVarargValueFrom

import com.googlecode.totallylazy.Sequence; //导入依赖的package包/类
private List<String> createPossiblyVarargValueFrom(List<String> newValues, List<String> oldValues) {
    Sequence<String> actualValues = sequence(newValues);
    if (oldValues.size() > newValues.size()) {
        actualValues = sequence(newValues).join(sequence("[]").cycle()).take(oldValues.size());
    } else if (newValues.size() > oldValues.size()) {
        actualValues = actualValues.take(oldValues.size() - 1).append(actualValues.drop(oldValues.size() - 1).toString("[", ", ", "]"));
    }
    return actualValues.toList();
}
 
开发者ID:bodar,项目名称:yatspec,代码行数:10,代码来源:TestMethod.java



注:本文中的com.googlecode.totallylazy.Sequence类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Plan类代码示例发布时间:2022-05-23
下一篇:
Java YLayoutStyle类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap