List of usage examples for java.util.function Supplier get
T get();
From source file:enumj.EnumeratorTest.java
@Test public void testContains() { System.out.println("contains"); Supplier<Enumerator<Integer>> supplier = () -> Enumerator.rangeInt(0, 10); for (Integer i : supplier.get().asEnumerable()) { assertTrue(supplier.get().contains(i)); assertTrue(!supplier.get().contains(-i - 1)); }/*ww w . jav a 2 s . com*/ }
From source file:enumj.EnumeratorTest.java
@Test public void testElementAt() { System.out.println("elementAt"); Supplier<Enumerator<Integer>> supply = () -> Enumerator.rangeInt(0, 10); for (int i = 0; i < supply.get().count(); ++i) { assertEquals(Integer.valueOf(i), supply.get().elementAt(i).get()); }//w w w . j av a2 s . co m }
From source file:com.skelril.skree.content.zone.group.jungleraid.JungleRaidInstance.java
private void addPlayer(Player player, Supplier<Location<World>> startingPos, Color teamColor, JungleRaidClass jrClass) {// w w w . ja v a 2 s.c o m giveBaseEquipment(player, jrClass); giveTeamEquipment(player, teamColor); resetPlayerProperties(player); player.setLocation(startingPos.get()); }
From source file:com.ikanow.aleph2.graph.titan.utils.TestMiscTitanProperties.java
@SuppressWarnings("unchecked") //@org.junit.Test public void test_concurrentChanges_nonConflicting() throws IOException { // Test some graph errors TitanGraph titan = TitanFactory.build().set("storage.backend", "inmemory").set("query.force-index", false) //(not supported) .open();//from w w w. ja v a 2s .c o m buildSmallGraph(titan); final Supplier<TitanTransaction> build_trans = () -> { final TitanTransaction tx = titan.buildTransaction().start(); Optionals.<TitanVertex>streamOf(tx.query().has("type", "rabbit").vertices(), false) .forEach(v -> v.property("change", "something")); return tx; }; final TitanTransaction tx1 = build_trans.get(); final TitanTransaction tx2 = titan.buildTransaction().start(); Optionals.<TitanVertex>streamOf(tx2.query().hasNot("type", "rabbit").vertices(), false) .forEach(v -> v.property("change", "something_else")); { System.out.println("---- entire graph ... tx1 ------"); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); titan.io(IoCore.graphson()).writer().create().writeGraph(baos, tx1); System.out.println(baos.toString()); } { System.out.println("---- entire graph ... tx2 ------"); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); titan.io(IoCore.graphson()).writer().create().writeGraph(baos, tx2); System.out.println(baos.toString()); } tx2.commit(); // I was expecting this to work, but it still fails ... might be an issue with the inmemory storage again? try { tx1.commit(); fail("Should have thrown"); } catch (TitanException e) { System.out.println("Threw expected titan exception: " + e.getClass().toString() + " / cause = " + e.getCause() + " .. " + e.getCause().getCause()); assertEquals(com.thinkaurelius.titan.diskstorage.locking.PermanentLockingException.class, e.getCause().getCause().getClass()); } }
From source file:com.ikanow.aleph2.graph.titan.utils.TestMiscTitanProperties.java
@SuppressWarnings("unchecked") @org.junit.Test/* ww w .j a v a 2s .co m*/ public void test_concurrentChanges_conflicting_threadedTrans() throws IOException { // Test some graph errors TitanGraph titan = TitanFactory.build().set("storage.backend", "inmemory").set("query.force-index", false) //(not supported) .open(); buildSmallGraph(titan); final Supplier<TitanTransaction> build_trans = () -> { final TitanTransaction tx = titan.newTransaction(); tx.addVertex("test_label"); Optionals.<TitanVertex>streamOf(tx.query().has("type", "rabbit").vertices(), false) .forEach(v -> v.property("change", "something")); return tx; }; final TitanTransaction tx1 = build_trans.get(); final TitanTransaction tx2 = titan.newTransaction(); Optionals.<TitanVertex>streamOf(tx2.query().has("type", "rabbit").vertices(), false) .forEach(v -> v.property("change", "something_else")); tx2.addVertex("test_label"); tx2.commit(); try { tx1.commit(); fail("Should have thrown"); } catch (TitanException e) { System.out.println("Threw expected titan exception: " + e.getClass().toString() + " / cause = " + e.getCause() + " .. " + e.getCause().getCause()); assertEquals(com.thinkaurelius.titan.diskstorage.locking.PermanentLockingException.class, e.getCause().getCause().getClass()); } // Check can retry: build_trans.get().commit(); }
From source file:com.ikanow.aleph2.graph.titan.utils.TestMiscTitanProperties.java
@SuppressWarnings("unchecked") //@org.junit.Test public void test_concurrentChanges_conflicting() throws IOException { // Test some graph errors TitanGraph titan = TitanFactory.build().set("storage.backend", "inmemory").set("query.force-index", false) //(not supported) .open();// w ww . ja v a2s.c om buildSmallGraph(titan); final Supplier<TitanTransaction> build_trans = () -> { final TitanTransaction tx = titan.buildTransaction().start(); tx.addVertex("test_label"); Optionals.<TitanVertex>streamOf(tx.query().has("type", "rabbit").vertices(), false) .forEach(v -> v.property("change", "something")); return tx; }; final TitanTransaction tx1 = build_trans.get(); final TitanTransaction tx2 = titan.buildTransaction().start(); Optionals.<TitanVertex>streamOf(tx2.query().has("type", "rabbit").vertices(), false) .forEach(v -> v.property("change", "something_else")); tx2.addVertex("test_label"); tx2.commit(); try { tx1.commit(); fail("Should have thrown"); } catch (TitanException e) { System.out.println("Threw expected titan exception: " + e.getClass().toString() + " / cause = " + e.getCause() + " .. " + e.getCause().getCause()); assertEquals(com.thinkaurelius.titan.diskstorage.locking.PermanentLockingException.class, e.getCause().getCause().getClass()); } // Check can retry: build_trans.get().commit(); }
From source file:de.fosd.jdime.artifact.file.FileArtifact.java
/** * Constructs a new <code>FileArtifact</code> representing the given <code>File</code>. If <code>file</code> is a * directory then <code>FileArtifact</code>s representing its contents will be added as children to this * <code>FileArtifact</code>. * * @param revision/*from w ww. jav a 2 s . co m*/ * the <code>Revision</code> the artifact belongs to * @param number * supplies first the number for this artifact and then in DFS order the number for its children * @param file * the <code>File</code> in which the artifact is stored * @param recursive * If <code>file</code> is a directory then <code>FileArtifact</code>s representing its contents will be * added as children to this <code>FileArtifact</code>. * @throws IllegalArgumentException * if {@code file} does not exist */ private FileArtifact(Revision revision, Supplier<Integer> number, File file, boolean recursive) { super(revision, number.get()); if (!file.exists()) { throw new IllegalArgumentException("File '" + file + "' does not exist."); } if (file.isFile()) { this.type = FileType.FILE; } else if (file.isDirectory()) { this.type = FileType.DIR; } else { throw new IllegalArgumentException("File '" + file + "' is not a normal file or directory."); } this.original = file; this.file = file; if (recursive && isDirectory()) { modifyChildren(children -> { children.addAll(getDirContent(number)); children.sort(comp); }); } }
From source file:com.github.erchu.beancp.DeclarativeMapImpl.java
@Override public <T> DeclarativeMap<S, D> bind(final Supplier<T> fromFunction, final Consumer<T> toMember, final BindingOption<S, D, T>... options) { notNull(fromFunction, "fromFunction"); notNull(toMember, "toMember"); if (mode == MapMode.CONFIGURATION) { if (_afterMapExecuted) { throw new MapperConfigurationException(INVALID_STATEMENT_ORDER_MESSAGE); }//from w ww . ja v a 2 s . co m _bindBindConstantOrMapExecuted = true; } if (mode == MapMode.EXECUTION) { boolean map = shouldBeMapped(options); if (map) { T getValue = fromFunction.get(); if (getValue == null) { for (BindingOption<S, D, T> i : options) { if (i.getNullSubstitution() != null) { getValue = i.getNullSubstitution(); break; } } } toMember.accept(getValue); } } return this; }
From source file:de.fosd.jdime.artifact.Artifact.java
/** * Sets the number of all <code>Artifact</code>s contained in the tree rooted at this artifact to the number * supplied by <code>number</code> when traversing the tree in depth-first order. * * @param number// w w w .java 2 s. co m * the supplier for the new numbers */ private void renumber(Supplier<Integer> number) { this.number = number.get(); for (Artifact<T> child : children) { child.renumber(number); } }
From source file:com.github.erchu.beancp.DeclarativeMapImpl.java
@Override public <SI, DI> DeclarativeMap<S, D> mapInner(final Supplier<SI> supplierFunction, final Consumer<DI> toMember, final Supplier<DI> toMemberGetter, final Class<DI> toMemberClass, final BindingOption<S, D, DI>... options) { notNull(supplierFunction, "supplierFunction"); notNull(toMember, "toMember"); if (mode == MapMode.CONFIGURATION) { if (_afterMapExecuted) { throw new MapperConfigurationException(INVALID_STATEMENT_ORDER_MESSAGE); }//from w w w .ja v a 2 s .com _bindBindConstantOrMapExecuted = true; } if (mode == MapMode.EXECUTION) { SI currentSourceValue = supplierFunction.get(); if (currentSourceValue == null) { toMember.accept(null); } else { DI currentDestinationMemberValue; if (toMemberGetter == null) { currentDestinationMemberValue = null; } else { currentDestinationMemberValue = toMemberGetter.get(); } if (currentDestinationMemberValue == null) { DI mapResult = _executionPhaseMapper.map(currentSourceValue, toMemberClass); toMember.accept(mapResult); } else { _executionPhaseMapper.map(currentSourceValue, currentDestinationMemberValue); } } } return this; }