Java 8 Function - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Function class.

This code example shows how to use the following methods:apply
		return true; 
	} 
 
	@Override 
	public <R> LazySeq<R> map(Function<? super E, ? extends R> mapper) {
		return cons(mapper.apply(head), tail.map(mapper));
	} 
 
	@Override 
	public LazySeq<E> filter(Predicate<? super E> predicate) {
		if (predicate.test(head)) {
			return cons(head, tail.filter(predicate));
		} else { 
			return tail.filter(predicate);
		} 
	} 
 
	@Override 
	public <R> LazySeq<R> flatMap(Function<? super E, ? extends Iterable<? extends R>> mapper) {
		final ArrayList<R> result = new ArrayList<>();
5
CodeRank
This code example shows how to use the following methods:apply
        return new ValuesProcessor() 
        { 
            @Override 
            public <T> T transform(Function<Ranges, T> rangesFunction, Function<DiscreteValues, T> valuesFunction, Function<AllOrNone, T> allOrNoneFunction)
            { 
                return rangesFunction.apply(getRanges());
            } 
 
            @Override 
            public void consume(Consumer<Ranges> rangesConsumer, Consumer<DiscreteValues> valuesConsumer, Consumer<AllOrNone> allOrNoneConsumer)
            { 
                rangesConsumer.accept(getRanges());
            } 
        }; 
    } 
 
    @Override 
    public SortedRangeSet intersect(ValueSet other)
    { 
        SortedRangeSet otherRangeSet = checkCompatibility(other);
4
CodeRank
This code example shows how to use the following methods:apply
This code example shows how to use the following methods:apply
This code example shows how to use the following methods:apply
This code example shows how to use the following methods:apply
        return new ValuesProcessor() 
        { 
            @Override 
            public <T> T transform(Function<Ranges, T> rangesFunction, Function<DiscreteValues, T> valuesFunction, Function<AllOrNone, T> allOrNoneFunction)
            { 
                return allOrNoneFunction.apply(getAllOrNone());
            } 
 
            @Override 
            public void consume(Consumer<Ranges> rangesConsumer, Consumer<DiscreteValues> valuesConsumer, Consumer<AllOrNone> allOrNoneConsumer)
            { 
                allOrNoneConsumer.accept(getAllOrNone());
            } 
        }; 
    } 
 
    @Override 
    public ValueSet intersect(ValueSet other)
    { 
        AllOrNoneValueSet otherValueSet = checkCompatibility(other);
4
CodeRank
This code example shows how to use the following methods:apply
        return new ValuesProcessor() 
        { 
            @Override 
            public <T> T transform(Function<Ranges, T> rangesFunction, Function<DiscreteValues, T> valuesFunction, Function<AllOrNone, T> allOrNoneFunction)
            { 
                return valuesFunction.apply(getDiscreteValues());
            } 
 
            @Override 
            public void consume(Consumer<Ranges> rangesConsumer, Consumer<DiscreteValues> valuesConsumer, Consumer<AllOrNone> allOrNoneConsumer)
            { 
                valuesConsumer.accept(getDiscreteValues());
            } 
        }; 
    } 
 
    @Override 
    public EquatableValueSet intersect(ValueSet other)
    { 
        EquatableValueSet otherValueSet = checkCompatibility(other);
4
CodeRank
This code example shows how to use the following methods:apply, compose
    } 
 
    @Test
    public void test1() { 
        Function<Integer,Integer> f = ((Integer)0)::compareTo;
        f = f.compose(f);
 
        Assert.assertEquals(Integer.valueOf(0), f.apply(0));
        Assert.assertEquals(Integer.valueOf(1), f.apply(100));
        Assert.assertEquals(Integer.valueOf(-1), f.apply(-100));
    } 
 
    @Test
    public void test2() { 
        Function<Integer,Integer> f = ((Function<Integer,Integer>)((Integer)0)::compareTo).compose(((Integer)0)::compareTo);
        Assert.assertEquals(Integer.valueOf(0), f.apply(0));
        Assert.assertEquals(Integer.valueOf(1), f.apply(100));
        Assert.assertEquals(Integer.valueOf(-1), f.apply(-100));
    } 
 
5
CodeRank
This code example shows how to use the following methods:apply
        if (page.getPositionCount() == 0) {
            return; 
        } 
        checkState(blocked == NOT_BLOCKED, "output is already blocked");
 
        page = pagePreprocessor.apply(page);
 
        ListenableFuture<?> future = outputBuffer.enqueue(page);
        if (!future.isDone()) {
            this.blocked = future;
        } 
        operatorContext.recordGeneratedOutput(page.getSizeInBytes(), page.getPositionCount());
    } 
 
    @Override 
    public Page getOutput()
    { 
        return null; 
    } 
} 
4
CodeRank
This code example shows how to use the following methods:apply
    @SuppressWarnings("unchecked") 
    public <T> T getUserObject(Class<T> clazz) {
        if (userSupplier == null) { 
            return null; 
        } 
        Object user = userSupplier.apply(this);
        if (user != null && clazz.isAssignableFrom(user.getClass())) {
            return (T) user; 
        } 
        return null; 
    } 
 
    public Set<String> getPermissions() {
        return Collections.unmodifiableSet(permissions);
    } 
} 
3
CodeRank
See Code Examples for Java 8 Function Methods: