Skip to content

Commit

Permalink
eclipse#705 Add specialised interfaces for MultiReader List Set and Bag
Browse files Browse the repository at this point in the history
  • Loading branch information
canthonyl committed May 1, 2019
1 parent fa40c9a commit abd552c
Show file tree
Hide file tree
Showing 19 changed files with 347 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.eclipse.collections.api.bag;

import org.eclipse.collections.api.block.procedure.Procedure;
/**
* A MultiReaderBag provides thread-safe iteration for a bag through methods {@code withReadLockAndDelegate()} and {@code withWriteLockAndDelegate()}.
*
*/
public interface MultiReaderBag<T> extends MutableBag<T> {

void withReadLockAndDelegate(Procedure<MutableBag<T>> procedure);

void withWriteLockAndDelegate(Procedure<MutableBag<T>> procedure);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2019 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/

package org.eclipse.collections.api.factory.bag;

import java.util.stream.Stream;

import org.eclipse.collections.api.bag.MultiReaderBag;

/**
* A factory which creates instances of type {@link MultiReaderBag}.
*/
public interface MultiReaderBagFactory
{
/**
* @since 6.0
*/
<T> MultiReaderBag<T> empty();

/**
* Same as {@link #empty()}.
*/
default <T> MultiReaderBag<T> of()
{
return this.empty();
}

/**
* Same as {@link #empty()}.
*/
default <T> MultiReaderBag<T> with()
{
return this.empty();
}

/**
* Same as {@link #with(Object[])}.
*/
default <T> MultiReaderBag<T> of(T... elements)
{
return this.with(elements);
}

<T> MultiReaderBag<T> with(T... elements);

/**
* Same as {@link #withAll(Iterable)}.
*/
default <T> MultiReaderBag<T> ofAll(Iterable<? extends T> items)
{
return this.withAll(items);
}

<T> MultiReaderBag<T> withAll(Iterable<? extends T> items);

/**
* @since 10.0.
*/
<T> MultiReaderBag<T> fromStream(Stream<? extends T> stream);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2019 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/

package org.eclipse.collections.api.factory.list;

import java.util.stream.Stream;

import org.eclipse.collections.api.block.function.Function0;
import org.eclipse.collections.api.list.MultiReaderList;
import org.eclipse.collections.api.list.MutableList;

public interface MultiReaderListFactory
{
/**
* @since 6.0
*/
<T> MultiReaderList<T> empty();

/**
* Same as {@link #empty()}.
*/
default <T> MultiReaderList<T> of()
{
return this.empty();
}

/**
* Same as {@link #empty()}.
*/
default <T> MultiReaderList<T> with()
{
return this.empty();
}

/**
* Same as {@link #with(Object[])}.
*/
default <T> MultiReaderList<T> of(T... items)
{
return this.with(items);
}

<T> MultiReaderList<T> with(T... items);

/**
* Same as {@link #empty()}. but takes in initial capacity.
*/
default <T> MultiReaderList<T> ofInitialCapacity(int capacity)
{
return this.withInitialCapacity(capacity);
}

/**
* Same as {@link #empty()}. but takes in initial capacity.
*/
<T> MultiReaderList<T> withInitialCapacity(int capacity);

/**
* Same as {@link #withAll(Iterable)}.
*/
default <T> MultiReaderList<T> ofAll(Iterable<? extends T> iterable)
{
return this.withAll(iterable);
}

<T> MultiReaderList<T> withAll(Iterable<? extends T> iterable);

/**
* @since 10.0.
*/
<T> MultiReaderList<T> fromStream(Stream<? extends T> stream);

<T> MultiReaderList<T> withNValues(int size, Function0<? extends T> factory);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2019 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/

package org.eclipse.collections.api.factory.set;

import java.util.stream.Stream;

import org.eclipse.collections.api.set.MultiReaderSet;

public interface MultiReaderSetFactory
{
/**
* @since 6.0
*/
<T> MultiReaderSet<T> empty();

/**
* Same as {@link #empty()}.
*/
default <T> MultiReaderSet<T> of()
{
return this.empty();
}

/**
* Same as {@link #empty()}.
*/
default <T> MultiReaderSet<T> with()
{
return this.empty();
}

/**
* Same as {@link #with(Object[])}.
*/
default <T> MultiReaderSet<T> of(T... items)
{
return this.with(items);
}

<T> MultiReaderSet<T> with(T... items);

/**
* Same as {@link #empty()}. but takes in initial capacity.
*/
default <T> MultiReaderSet<T> ofInitialCapacity(int capacity)
{
return this.withInitialCapacity(capacity);
}

/**
* Same as {@link #empty()}. but takes in initial capacity.
*/
<T> MultiReaderSet<T> withInitialCapacity(int capacity);

/**
* Same as {@link #withAll(Iterable)}.
*/
default <T> MultiReaderSet<T> ofAll(Iterable<? extends T> items)
{
return this.withAll(items);
}

<T> MultiReaderSet<T> withAll(Iterable<? extends T> items);

/**
* @since 10.0.
*/
<T> MultiReaderSet<T> fromStream(Stream<? extends T> stream);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.eclipse.collections.api.list;


import org.eclipse.collections.api.block.procedure.Procedure;

/**
* A MultiReaderList provides thread-safe iteration for a list through methods {@code withReadLockAndDelegate()} and {@code withWriteLockAndDelegate()}.
*
*/
public interface MultiReaderList<T> extends MutableList<T>{

void withReadLockAndDelegate(Procedure<MutableList<T>> procedure);

void withWriteLockAndDelegate(Procedure<MutableList<T>> procedure);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.eclipse.collections.api.set;

import org.eclipse.collections.api.block.procedure.Procedure;

/**
* A MultiReaderSet provides thread-safe iteration for a set through methods {@code withReadLockAndDelegate()} and {@code withWriteLockAndDelegate()}.
*
*/
public interface MultiReaderSet<T> extends MutableSet<T> {


void withReadLockAndDelegate(Procedure<MutableSet<T>> procedure);

void withWriteLockAndDelegate(Procedure<MutableSet<T>> procedure);
}
15 changes: 14 additions & 1 deletion eclipse-collections-forkjoin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<!-- Testing Dependencies -->

<dependency>
<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections-testutils</artifactId>
<version>${project.version}</version>
Expand All @@ -54,8 +54,21 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!--
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
-->
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.collections.api.LazyIterable;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.bag.ImmutableBag;
import org.eclipse.collections.api.bag.MultiReaderBag;
import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.bag.primitive.MutableBooleanBag;
import org.eclipse.collections.api.bag.primitive.MutableByteBag;
Expand Down Expand Up @@ -80,7 +81,7 @@
*/
public final class MultiReaderHashBag<T>
extends AbstractMultiReaderMutableCollection<T>
implements Externalizable, MutableBag<T>
implements Externalizable, MultiReaderBag<T>
{
private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,35 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.collections.api.bag.MultiReaderBag;
import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.factory.bag.MultiReaderBagFactory;
import org.eclipse.collections.api.factory.bag.MutableBagFactory;

public enum MultiReaderMutableBagFactory implements MutableBagFactory
public enum MultiReaderMutableBagFactory implements MultiReaderBagFactory
{
INSTANCE;

@Override
public <T> MutableBag<T> empty()
public <T> MultiReaderBag<T> empty()
{
return MultiReaderHashBag.newBag();
}

@Override
public <T> MutableBag<T> with(T... items)
public <T> MultiReaderBag<T> with(T... items)
{
return MultiReaderHashBag.newBagWith(items);
}

@Override
public <T> MutableBag<T> withAll(Iterable<? extends T> iterable)
public <T> MultiReaderBag<T> withAll(Iterable<? extends T> iterable)
{
return MultiReaderHashBag.newBag((Iterable<T>) iterable);
}

@Override
public <T> MutableBag<T> fromStream(Stream<? extends T> stream)
public <T> MultiReaderBag<T> fromStream(Stream<? extends T> stream)
{
return stream.collect(Collectors.toCollection(MultiReaderHashBag::newBag));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.collections.impl.factory;

import org.eclipse.collections.api.factory.bag.ImmutableBagFactory;
import org.eclipse.collections.api.factory.bag.MultiReaderBagFactory;
import org.eclipse.collections.api.factory.bag.MutableBagFactory;
import org.eclipse.collections.impl.bag.immutable.ImmutableBagFactoryImpl;
import org.eclipse.collections.impl.bag.mutable.MultiReaderMutableBagFactory;
Expand Down Expand Up @@ -41,7 +42,7 @@ public final class Bags
{
public static final ImmutableBagFactory immutable = ImmutableBagFactoryImpl.INSTANCE;
public static final MutableBagFactory mutable = MutableBagFactoryImpl.INSTANCE;
public static final MutableBagFactory multiReader = MultiReaderMutableBagFactory.INSTANCE;
public static final MultiReaderBagFactory multiReader = MultiReaderMutableBagFactory.INSTANCE;

private Bags()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.eclipse.collections.api.factory.list.FixedSizeListFactory;
import org.eclipse.collections.api.factory.list.ImmutableListFactory;
import org.eclipse.collections.api.factory.list.MultiReaderListFactory;
import org.eclipse.collections.api.factory.list.MutableListFactory;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.impl.list.fixed.FixedSizeListFactoryImpl;
Expand Down Expand Up @@ -55,7 +56,7 @@ public final class Lists
public static final ImmutableListFactory immutable = ImmutableListFactoryImpl.INSTANCE;
public static final MutableListFactory mutable = MutableListFactoryImpl.INSTANCE;
public static final FixedSizeListFactory fixedSize = FixedSizeListFactoryImpl.INSTANCE;
public static final MutableListFactory multiReader = MultiReaderMutableListFactory.INSTANCE;
public static final MultiReaderListFactory multiReader = MultiReaderMutableListFactory.INSTANCE;

private Lists()
{
Expand Down

0 comments on commit abd552c

Please sign in to comment.