use of java.util.function.UnaryOperator in project grakn by graknlabs.
the class QueryVisitor method visitPropHas.
@Override
public UnaryOperator<VarPattern> visitPropHas(GraqlParser.PropHasContext ctx) {
Label type = visitLabel(ctx.label());
VarPattern relation = Optional.ofNullable(ctx.relation).map(this::getVariable).orElseGet(Graql::var);
VarPattern resource = Optional.ofNullable(ctx.resource).map(this::getVariable).orElseGet(Graql::var);
if (ctx.predicate() != null) {
resource = resource.val(visitPredicate(ctx.predicate()));
}
VarPattern finalResource = resource;
return var -> var.has(type, finalResource, relation);
}
use of java.util.function.UnaryOperator in project jdk8u_jdk by JetBrains.
the class SequentialOpTest method testLazy.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class, groups = { "serialization-hostile" })
public void testLazy(String name, TestData.OfRef<Integer> data) {
Function<Integer, Integer> id = LambdaTestHelpers.identity();
AtomicInteger counter = new AtomicInteger();
Supplier<Stream<Integer>>[] suppliers = new Supplier[] { () -> data.stream(), () -> data.parallelStream() };
UnaryOperator<Stream<Integer>>[] configs = new UnaryOperator[] { (UnaryOperator<Stream<Integer>>) s -> s.peek(e -> {
counter.incrementAndGet();
}), (UnaryOperator<Stream<Integer>>) s -> s.map(id).peek(e -> {
counter.incrementAndGet();
}).sequential().map(id), (UnaryOperator<Stream<Integer>>) s -> s.map(id).peek(e -> {
counter.incrementAndGet();
}).parallel().map(id), (UnaryOperator<Stream<Integer>>) s -> s.sequential().map(id).peek(e -> {
counter.incrementAndGet();
}).map(id), (UnaryOperator<Stream<Integer>>) s -> s.parallel().map(id).peek(e -> {
counter.incrementAndGet();
}).map(id) };
for (int i = 0; i < suppliers.length; i++) {
setContext("supplierIndex", i);
Supplier<Stream<Integer>> supp = suppliers[i];
for (int j = 0; j < configs.length; j++) {
setContext("configIndex", j);
UnaryOperator<Stream<Integer>> config = configs[j];
counter.set(0);
Stream<Integer> stream = config.apply(supp.get());
assertEquals(0, counter.get());
Iterator<Integer> iterator = stream.iterator();
assertEquals(0, counter.get());
if (iterator.hasNext())
iterator.next();
assertTrue(data.size() == 0 || counter.get() > 0);
counter.set(0);
stream = config.apply(supp.get());
Spliterator<Integer> spliterator = stream.spliterator();
assertEquals(0, counter.get());
spliterator.forEachRemaining(e -> {
});
assertTrue(data.size() == 0 || counter.get() > 0);
}
}
}
use of java.util.function.UnaryOperator in project lucene-solr by apache.
the class JsonLoaderTest method testFewParentsJsonDoc.
public void testFewParentsJsonDoc() throws Exception {
String json = PARENT_TWO_CHILDREN_JSON;
SolrQueryRequest req;
SolrQueryResponse rsp;
BufferingRequestProcessor p;
JsonLoader loader;
{
//multichild test case
final boolean array = random().nextBoolean();
StringBuilder b = new StringBuilder();
if (array) {
b.append("[");
}
final int passes = atLeast(2);
for (int i = 1; i <= passes; i++) {
b.append(json.replace("1", "" + i));
if (array) {
b.append(i < passes ? "," : "]");
}
}
req = req(PARENT_TWO_CHILDREN_PARAMS);
req.getContext().put("path", "/update/json/docs");
rsp = new SolrQueryResponse();
p = new BufferingRequestProcessor(null);
loader = new JsonLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream(b.toString()), p);
for (int i = 1; i <= passes; i++) {
final int ii = i;
UnaryOperator<String> s = (v) -> v.replace("1", "" + ii);
final SolrInputDocument parent = p.addCommands.get(i - 1).solrDoc;
assertOnlyValue(s.apply("1"), parent, "id");
assertOnlyValue("i am the parent", parent, "name");
assertOnlyValue("parent", parent, "cat");
assertEquals(2, parent.getChildDocuments().size());
{
final SolrInputDocument child1 = parent.getChildDocuments().get(0);
assertOnlyValue(s.apply("1.1"), child1, "id");
assertOnlyValue(s.apply("i am the 1st child"), child1, "name");
assertOnlyValue("child", child1, "cat");
}
{
final SolrInputDocument child2 = parent.getChildDocuments().get(1);
assertOnlyValue(s.apply("1.2"), child2, "id");
assertOnlyValue("i am the 2nd child", child2, "name");
assertOnlyValue("child", child2, "cat");
assertEquals(1, child2.getChildDocuments().size());
final SolrInputDocument grandChild = child2.getChildDocuments().get(0);
assertOnlyValue(s.apply("1.2.1"), grandChild, "id");
assertOnlyValue("i am the grandchild", grandChild, "name");
assertOnlyValue("grandchild", grandChild, "cat");
}
}
}
}
use of java.util.function.UnaryOperator in project trex-stateless-gui by cisco-system-traffic-generator.
the class MultiplierOption method buildUI.
/**
* Build multiplier view UI
*
* @param title
* @param group
*/
private void buildUI(String title, ToggleGroup group) {
// add radio button
selection = new RadioButton(title);
selection.setToggleGroup(group);
selection.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
if (newValue) {
multiplierSelectionEvent.onMultiplierSelect(type);
}
value.setDisable(!newValue);
});
setTooltip();
getChildren().add(selection);
MultiplierOption.setTopAnchor(selection, 15d);
MultiplierOption.setLeftAnchor(selection, 0d);
// text field
value = new TextField();
value.setPrefSize(120, 22);
value.setDisable(true);
value.addEventFilter(KeyEvent.KEY_RELEASED, multiplierSelectionEvent.validateInput());
String regex = unitRegex();
final UnaryOperator<TextFormatter.Change> keyPressFilter = c -> {
String text = c.getControlNewText();
if (text.matches(regex)) {
return c;
} else {
return null;
}
};
value.setTextFormatter(new TextFormatter<>(keyPressFilter));
getChildren().add(value);
MultiplierOption.setTopAnchor(value, 43d);
MultiplierOption.setLeftAnchor(value, 0d);
MultiplierOption.setBottomAnchor(value, 15d);
}
use of java.util.function.UnaryOperator in project algorithms by Iurii-Dziuban.
the class DefaultAndStaticInInterface method testDatePlusStream.
// --- End of Question 17.
// Java 8 certification Question 18.
/**
* Which of the following statements can fill in the blank to make the code compile successfully? (Choose all that apply.)
*
* Set[? extends RuntimeException] set = VALUE
*
* A. new HashSet[? extends RuntimeException]();
* B. new HashSet<Exception>();
* C. new TreeSet<RuntimeException>();
* D. new TreeSet<NullPointerException>();
* E. None of the above
*
* Answer: C,D . A is not possible on the right side of expression.
* B is not possible, cause Exception is higher in hierarchy
*/
// --- End of Question 18.
// Java 8 certification Question 19.
/**
* Which of the following position a ResultSet cursor to a location immediately before the
* first row? (Choose all that apply.)
* A. rs.absolute(-1)
* B. rs.absolute(0)
* C. rs.absolute(1)
* D. rs.beforeFirst()
* E. rs.first()
* F. rs.next()
*
* Answer: B, D. On scrollable ResultSet absolute -1 -> end row, 0 -> before first row, 1 -> the first row
* beforeFirst() is equivalent method
*/
// --- End of Question 19.
// Java 8 certification Question 20.
/**
* Assume that today is June 1, 2016. What is the result of the following?
*/
@Test
public void testDatePlusStream() {
LocalDate localDate = LocalDate.of(2016, 6, 1);
Stream<LocalDate> s = Stream.of(localDate);
UnaryOperator<LocalDate> u = l -> l;
s.filter(l -> l != null).map(u).peek(System.out::println);
assertThat(Stream.of(localDate).filter(l -> l != null).map(u).collect(Collectors.toList()).get(0)).isEqualTo(localDate);
}
Aggregations