Search in sources :

Example 86 with Spliterator

use of java.util.Spliterator in project webprotege by protegeproject.

the class TagRepositoryImpl method saveTags.

public void saveTags(@Nonnull Iterable<Tag> tags) {
    writeLock.lock();
    try {
        checkNotNull(tags);
        Spliterator<Tag> spliterator = tags.spliterator();
        List<WriteModel<Document>> updates = stream(spliterator, false).map(tag -> new ReplaceOneModel<>(toFilter(tag), toDocument(tag), upsert())).collect(toList());
        BulkWriteResult bulkWriteResult = getCollection().bulkWrite(updates);
    } finally {
        writeLock.unlock();
    }
}
Also used : Document(org.bson.Document) ReplaceOneModel(com.mongodb.client.model.ReplaceOneModel) MongoCollection(com.mongodb.client.MongoCollection) Repository(edu.stanford.bmir.protege.web.server.persistence.Repository) MongoDatabase(com.mongodb.client.MongoDatabase) WriteModel(com.mongodb.client.model.WriteModel) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Inject(javax.inject.Inject) Nonnull(javax.annotation.Nonnull) UpdateOptions(com.mongodb.client.model.UpdateOptions) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ProjectSingleton(edu.stanford.bmir.protege.web.shared.inject.ProjectSingleton) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Tag(edu.stanford.bmir.protege.web.shared.tag.Tag) IndexOptions(com.mongodb.client.model.IndexOptions) TagId(edu.stanford.bmir.protege.web.shared.tag.TagId) List(java.util.List) Lock(java.util.concurrent.locks.Lock) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) StreamSupport.stream(java.util.stream.StreamSupport.stream) BulkWriteResult(com.mongodb.bulk.BulkWriteResult) FindIterable(com.mongodb.client.FindIterable) Optional(java.util.Optional) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Spliterator(java.util.Spliterator) ReplaceOneModel(com.mongodb.client.model.ReplaceOneModel) Tag(edu.stanford.bmir.protege.web.shared.tag.Tag) WriteModel(com.mongodb.client.model.WriteModel) BulkWriteResult(com.mongodb.bulk.BulkWriteResult)

Example 87 with Spliterator

use of java.util.Spliterator in project nexus-public by sonatype.

the class OrientMetadataRebuilderTest method infiniteIterator.

private Iterable infiniteIterator(final Object returnItem) {
    Iterable iterable = mock(Iterable.class);
    Iterator iterator = mock(Iterator.class);
    Spliterator spliterator = mock(Spliterator.class);
    when(iterable.spliterator()).thenReturn(spliterator);
    when(iterable.iterator()).thenReturn(iterator);
    when(iterator.hasNext()).thenReturn(true);
    when(iterator.next()).thenReturn(returnItem);
    return iterable;
}
Also used : Iterator(java.util.Iterator) Spliterator(java.util.Spliterator)

Example 88 with Spliterator

use of java.util.Spliterator in project nexus-public by sonatype.

the class OrientMetadataRebuilderTest method iteratorWithItems.

private Iterable iteratorWithItems(final Object... returnItems) {
    int numItems = returnItems.length;
    Iterable iterable = mock(Iterable.class);
    Iterator iterator = mock(Iterator.class);
    Spliterator spliterator = Spliterators.spliterator(returnItems, 0);
    final int[] iteratorCounter = { 0 };
    when(iterable.spliterator()).thenReturn(spliterator);
    when(iterable.iterator()).thenReturn(iterator);
    when(iterator.hasNext()).thenAnswer((Answer<Boolean>) invocation -> iteratorCounter[0] < numItems);
    when(iterator.next()).thenAnswer((Answer<?>) invocation -> returnItems[iteratorCounter[0]++]);
    return iterable;
}
Also used : Coordinates(org.sonatype.nexus.repository.maven.MavenPath.Coordinates) StorageFacet(org.sonatype.nexus.repository.storage.StorageFacet) EntityAdapter(org.sonatype.nexus.orient.entity.EntityAdapter) Spliterators(java.util.Spliterators) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) LoggerFactory(org.slf4j.LoggerFactory) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) TestSupport(org.sonatype.goodies.testsupport.TestSupport) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) ROOT_LOGGER_NAME(org.slf4j.Logger.ROOT_LOGGER_NAME) Map(java.util.Map) After(org.junit.After) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Thread.sleep(java.lang.Thread.sleep) Assert.fail(org.junit.Assert.fail) NestedAttributesMap(org.sonatype.nexus.common.collect.NestedAttributesMap) OrientMavenFacet(org.sonatype.nexus.orient.maven.OrientMavenFacet) Mockito.doReturn(org.mockito.Mockito.doReturn) MavenPath(org.sonatype.nexus.repository.maven.MavenPath) Collections.emptyList(java.util.Collections.emptyList) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) Asset(org.sonatype.nexus.repository.storage.Asset) Content(org.sonatype.nexus.repository.view.Content) List(java.util.List) Logger(ch.qos.logback.classic.Logger) Matchers.is(org.hamcrest.Matchers.is) AttachedEntityMetadata(org.sonatype.nexus.orient.entity.AttachedEntityMetadata) Spliterator(java.util.Spliterator) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Mock(org.mockito.Mock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MultipleFailureException(org.junit.runners.model.MultipleFailureException) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) Component(org.sonatype.nexus.repository.storage.Component) ArgumentCaptor(org.mockito.ArgumentCaptor) Repository(org.sonatype.nexus.repository.Repository) Appender(ch.qos.logback.core.Appender) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Before(org.junit.Before) Iterator(java.util.Iterator) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) P_BASE_VERSION(org.sonatype.nexus.repository.maven.internal.Attributes.P_BASE_VERSION) Mockito.verify(org.mockito.Mockito.verify) MavenPathParser(org.sonatype.nexus.repository.maven.MavenPathParser) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Level(ch.qos.logback.classic.Level) OType(com.orientechnologies.orient.core.metadata.schema.OType) EntityMetadata(org.sonatype.nexus.common.entity.EntityMetadata) CancelableHelper(org.sonatype.nexus.scheduling.CancelableHelper) InputStream(java.io.InputStream) Bucket(org.sonatype.nexus.repository.storage.Bucket) TaskInterruptedException(org.sonatype.nexus.scheduling.TaskInterruptedException) Iterator(java.util.Iterator) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Spliterator(java.util.Spliterator)

Example 89 with Spliterator

use of java.util.Spliterator in project openj9 by eclipse-openj9.

the class StringStreams method testStringCharsSpliterator.

@Test
public void testStringCharsSpliterator() {
    Spliterator.OfInt s = DIGITS.codePoints().spliterator();
    final ArrayList<Integer> actualIntegers = new ArrayList<>();
    s.forEachRemaining((IntConsumer) i -> actualIntegers.add(Integer.valueOf(i)));
    for (int c = 0; c < DIGITS.length(); ++c) {
        assertEquals(actualIntegers.get(c), Integer.valueOf(DIGITS.codePointAt(c)), // $NON-NLS-1$
        "Wrong value at position " + c);
    }
}
Also used : HashSet(java.util.HashSet) Objects(java.util.Objects) List(java.util.List) OfInt(java.util.Spliterator.OfInt) IntConsumer(java.util.function.IntConsumer) Assert.assertEquals(org.testng.Assert.assertEquals) Assert.assertTrue(org.testng.Assert.assertTrue) Set(java.util.Set) VersionCheck(org.openj9.test.util.VersionCheck) Test(org.testng.annotations.Test) Spliterator(java.util.Spliterator) ArrayList(java.util.ArrayList) OfInt(java.util.Spliterator.OfInt) ArrayList(java.util.ArrayList) Spliterator(java.util.Spliterator) Test(org.testng.annotations.Test)

Example 90 with Spliterator

use of java.util.Spliterator in project openj9 by eclipse-openj9.

the class StringStreams method testStringCodePointsSpliterator.

@Test
public void testStringCodePointsSpliterator() {
    Spliterator.OfInt s = DIGITS.chars().spliterator();
    final ArrayList<Integer> actualIntegers = new ArrayList<>();
    s.forEachRemaining((IntConsumer) i -> actualIntegers.add(Integer.valueOf(i)));
    checkDigitsOrdered(DIGITS, actualIntegers);
}
Also used : HashSet(java.util.HashSet) Objects(java.util.Objects) List(java.util.List) OfInt(java.util.Spliterator.OfInt) IntConsumer(java.util.function.IntConsumer) Assert.assertEquals(org.testng.Assert.assertEquals) Assert.assertTrue(org.testng.Assert.assertTrue) Set(java.util.Set) VersionCheck(org.openj9.test.util.VersionCheck) Test(org.testng.annotations.Test) Spliterator(java.util.Spliterator) ArrayList(java.util.ArrayList) OfInt(java.util.Spliterator.OfInt) ArrayList(java.util.ArrayList) Spliterator(java.util.Spliterator) Test(org.testng.annotations.Test)

Aggregations

Spliterator (java.util.Spliterator)124 List (java.util.List)47 ArrayList (java.util.ArrayList)41 HashSet (java.util.HashSet)36 IntConsumer (java.util.function.IntConsumer)35 Set (java.util.Set)31 Objects (java.util.Objects)25 Collectors (java.util.stream.Collectors)25 Spliterators (java.util.Spliterators)24 Function (java.util.function.Function)24 Iterator (java.util.Iterator)23 Consumer (java.util.function.Consumer)23 Stream (java.util.stream.Stream)23 Map (java.util.Map)22 Arrays (java.util.Arrays)20 LongConsumer (java.util.function.LongConsumer)20 Collections (java.util.Collections)19 StreamSupport (java.util.stream.StreamSupport)19 Comparator (java.util.Comparator)18 Test (org.junit.Test)18