Java Code Examples for com.annimon.stream.Stream#of()

The following examples show how to use com.annimon.stream.Stream#of() . 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: DirectoryHelperV1.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@SuppressLint("CheckResult")
private static @NonNull List<RecipientId> refreshDirectory(@NonNull Context context, @NonNull SignalServiceAccountManager accountManager) throws IOException {
  if (TextUtils.isEmpty(TextSecurePreferences.getLocalNumber(context))) {
    return Collections.emptyList();
  }

  if (!Permissions.hasAll(context, Manifest.permission.WRITE_CONTACTS)) {
    return Collections.emptyList();
  }

  RecipientDatabase recipientDatabase                       = DatabaseFactory.getRecipientDatabase(context);
  Set<String>       allRecipientNumbers                     = recipientDatabase.getAllPhoneNumbers();
  Stream<String>    eligibleRecipientDatabaseContactNumbers = Stream.of(allRecipientNumbers);
  Stream<String>    eligibleSystemDatabaseContactNumbers    = Stream.of(ContactAccessor.getInstance().getAllContactsWithNumbers(context));
  Set<String>       eligibleContactNumbers                  = Stream.concat(eligibleRecipientDatabaseContactNumbers, eligibleSystemDatabaseContactNumbers).collect(Collectors.toSet());
  Set<String>       storedNumbers                           = Stream.of(allRecipientNumbers).collect(Collectors.toSet());
  DirectoryResult   directoryResult                         = getDirectoryResult(context, accountManager, recipientDatabase, storedNumbers, eligibleContactNumbers);

  return directoryResult.getNewlyActiveRecipients();
}
 
Example 2
Source File: MergeTest.java    From Lightweight-Stream-API with Apache License 2.0 5 votes vote down vote up
@Test
public void testMergeAsConcat1() {
    Stream<Integer> stream1 = Stream.of(0, 3, 1);
    Stream<Integer> stream2 = Stream.of(2, 5, 6, 1);
    Stream.merge(stream1, stream2, only(ObjMerge.MergeResult.TAKE_FIRST))
            .custom(assertElements(contains(
                    0, 3, 1, 2, 5, 6, 1
            )));
}
 
Example 3
Source File: MergeTest.java    From Lightweight-Stream-API with Apache License 2.0 5 votes vote down vote up
@Test
public void testMerge2() {
    Stream<Integer> stream1 = Stream.of(2, 5, 6, 12);
    Stream<Integer> stream2 = Stream.of(1, 3, 8, 10);
    Stream.merge(stream1, stream2, selectorFunction())
            .custom(assertElements(contains(
                  1, 2, 3, 5, 6, 8, 10, 12
            )));
}
 
Example 4
Source File: MergeTest.java    From Lightweight-Stream-API with Apache License 2.0 5 votes vote down vote up
@Test
public void testMerge1() {
    Stream<Integer> stream1 = Stream.of(1, 3, 8, 10);
    Stream<Integer> stream2 = Stream.of(2, 5, 6, 12);
    Stream.merge(stream1, stream2, selectorFunction())
            .custom(assertElements(contains(
                  1, 2, 3, 5, 6, 8, 10, 12
            )));
}
 
Example 5
Source File: MergeTest.java    From Lightweight-Stream-API with Apache License 2.0 5 votes vote down vote up
@Test
public void testMergeAsConcat2() {
    Stream<Integer> stream1 = Stream.of(0, 3, 1);
    Stream<Integer> stream2 = Stream.of(2, 5, 6, 1);
    Stream.merge(stream1, stream2, only(ObjMerge.MergeResult.TAKE_SECOND))
            .custom(assertElements(contains(
                    2, 5, 6, 1, 0, 3, 1
            )));
}
 
Example 6
Source File: ConcatTest.java    From Lightweight-Stream-API with Apache License 2.0 5 votes vote down vote up
@Test
public void testConcat() {
    Stream<String> stream1 = Stream.of("a", "b", "c", "d");
    Stream<String> stream2 = Stream.of("e", "f", "g", "h");
    Stream.concat(stream1, stream2)
            .custom(assertElements(contains(
                    "a", "b", "c", "d",
                    "e", "f", "g", "h"
            )));
}
 
Example 7
Source File: MergeTest.java    From Lightweight-Stream-API with Apache License 2.0 5 votes vote down vote up
@Test
public void testMergeAsConcat2() {
    Stream<Integer> stream1 = Stream.of(0, 3, 1);
    Stream<Integer> stream2 = Stream.of(2, 5, 6, 1);
    Stream.merge(stream1, stream2, only(ObjMerge.MergeResult.TAKE_SECOND))
            .custom(assertElements(contains(
                    2, 5, 6, 1, 0, 3, 1
            )));
}
 
Example 8
Source File: MergeTest.java    From Lightweight-Stream-API with Apache License 2.0 5 votes vote down vote up
@Test
public void testMerge2() {
    Stream<Integer> stream1 = Stream.of(2, 5, 6, 12);
    Stream<Integer> stream2 = Stream.of(1, 3, 8, 10);
    Stream.merge(stream1, stream2, selectorFunction())
            .custom(assertElements(contains(
                  1, 2, 3, 5, 6, 8, 10, 12
            )));
}
 
Example 9
Source File: MergeTest.java    From Lightweight-Stream-API with Apache License 2.0 5 votes vote down vote up
@Test
public void testMerge1() {
    Stream<Integer> stream1 = Stream.of(1, 3, 8, 10);
    Stream<Integer> stream2 = Stream.of(2, 5, 6, 12);
    Stream.merge(stream1, stream2, selectorFunction())
            .custom(assertElements(contains(
                  1, 2, 3, 5, 6, 8, 10, 12
            )));
}
 
Example 10
Source File: ConcatTest.java    From Lightweight-Stream-API with Apache License 2.0 5 votes vote down vote up
@Test
public void testConcatOfFlatMap() {
    final Function<Integer, Stream<Integer>> flatmapFunc = new Function<Integer, Stream<Integer>>() {
        @Override
        public Stream<Integer> apply(Integer value) {
            return Stream.of(value, value);
        }
    };
    Stream<Integer> stream1 = Stream.range(1, 3).flatMap(flatmapFunc); // 1122
    Stream<Integer> stream2 = Stream.range(3, 5).flatMap(flatmapFunc); // 3344
    Stream.concat(stream1, stream2)
            .custom(assertElements(contains(
                    1, 1, 2, 2, 3, 3, 4, 4
            )));
}
 
Example 11
Source File: ConcatTest.java    From Lightweight-Stream-API with Apache License 2.0 5 votes vote down vote up
@Test
public void testConcat() {
    Stream<String> stream1 = Stream.of("a", "b", "c", "d");
    Stream<String> stream2 = Stream.of("e", "f", "g", "h");
    Stream.concat(stream1, stream2)
            .custom(assertElements(contains(
                    "a", "b", "c", "d",
                    "e", "f", "g", "h"
            )));
}
 
Example 12
Source File: MergeTest.java    From Lightweight-Stream-API with Apache License 2.0 5 votes vote down vote up
@Test
public void testMergeAsConcat1() {
    Stream<Integer> stream1 = Stream.of(0, 3, 1);
    Stream<Integer> stream2 = Stream.of(2, 5, 6, 1);
    Stream.merge(stream1, stream2, only(ObjMerge.MergeResult.TAKE_FIRST))
            .custom(assertElements(contains(
                    0, 3, 1, 2, 5, 6, 1
            )));
}
 
Example 13
Source File: OfMapTest.java    From Lightweight-Stream-API with Apache License 2.0 4 votes vote down vote up
@Test(expected = NullPointerException.class)
public void testStreamOfMapNull() {
    Stream.of((Map<?, ?>)null);
}
 
Example 14
Source File: OfIteratorTest.java    From Lightweight-Stream-API with Apache License 2.0 4 votes vote down vote up
@Test(expected = NullPointerException.class)
public void testStreamOfIteratorNull() {
    Stream.of((Iterator<?>)null);
}
 
Example 15
Source File: OfIterableTest.java    From Lightweight-Stream-API with Apache License 2.0 4 votes vote down vote up
@Test(expected = NullPointerException.class)
public void testStreamOfIterableNull() {
    Stream.of((Iterable<?>)null);
}
 
Example 16
Source File: ObjectBoxDB.java    From Hentoid with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("squid:S2184")
    // In our case, limit() argument has to be human-readable -> no issue concerning its type staying in the int range
List<Attribute> selectAvailableAttributes(
        @NonNull AttributeType type,
        List<Attribute> attributeFilter,
        String filter,
        boolean filterFavourites,
        int sortOrder,
        int page,
        int itemsPerPage) {
    long[] filteredContent = selectFilteredContent(attributeFilter, filterFavourites);
    List<Long> filteredContentAsList = Helper.getListFromPrimitiveArray(filteredContent);
    List<Attribute> result = queryAvailableAttributes(type, filter, filteredContent).find();

    // Compute attribute count for sorting
    int count;
    for (Attribute a : result) {
        if (0 == filteredContent.length) count = a.contents.size();
        else {
            count = 0;
            for (Content c : a.contents)
                if (filteredContentAsList.contains(c.getId())) count++;
        }
        a.setCount(count);
    }

    // Apply sort order
    Stream<Attribute> s = Stream.of(result);
    if (Preferences.Constant.ORDER_ATTRIBUTES_ALPHABETIC == sortOrder) {
        s = s.sortBy(a -> -a.getCount()).sortBy(Attribute::getName);
    } else {
        s = s.sortBy(Attribute::getName).sortBy(a -> -a.getCount());
    }

    // Apply paging
    if (itemsPerPage > 0) {
        int start = (page - 1) * itemsPerPage;
        s = s.limit(page * itemsPerPage).skip(start); // squid:S2184 here because int * int -> int (not long)
    }
    return s.collect(toList());
}
 
Example 17
Source File: OfIterableTest.java    From Lightweight-Stream-API with Apache License 2.0 4 votes vote down vote up
@Test(expected = NullPointerException.class)
public void testStreamOfIterableNull() {
    Stream.of((Iterable<?>)null);
}
 
Example 18
Source File: OfIteratorTest.java    From Lightweight-Stream-API with Apache License 2.0 4 votes vote down vote up
@Test(expected = NullPointerException.class)
public void testStreamOfIteratorNull() {
    Stream.of((Iterator<?>)null);
}
 
Example 19
Source File: ShakespearePlaysScrabbleWithNonParallelLSA.java    From akarnokd-misc with Apache License 2.0 4 votes vote down vote up
@Override
Stream<String> buildShakerspeareWordsStream() {
    return Stream.of(shakespeareWords) ;
}
 
Example 20
Source File: ShakespearePlaysScrabbleWithNonParallelLSABeta.java    From akarnokd-misc with Apache License 2.0 4 votes vote down vote up
@Override
Stream<String> buildShakerspeareWordsStream() {
    return Stream.of(shakespeareWords) ;
}