2.funtions

The most crucial distinguish between functional interface invoking and traditional method invoking is that transforming behavious or params it is.However,Transforming behavior is more encapsulated and abstract.The logic methods does not implement predicatbly.We can get any result while invoking method by transforming behavious.

Example of some crucial functional interface:

1. public interface Function<T, R>

the mainly method:

/**
     * Applies this function to the given argument.
     *
     * @param t the function argument
     * @return the function result
     */
    R apply(T t);

ex:

 list.stream().map(item -> item.toUpperCase()).forEach(item -> System.out.println(item)); 

equals:

 list.stream().map(String::toUpperCase).forEach(System.out::println); 

In String class (invoke object is param):

 public String toUpperCase() { return toUpperCase(Locale.getDefault()); } 

In PrintStream(System.out) class:

 public void println(String x) { synchronized (this) { print(x); newLine(); } } 

And  public interface BiFunction<T, U, R> 
  /**
     * Applies this function to the given arguments.
     *
     * @param t the first function argument
     * @param u the second function argument
     * @return the function result
     */
    R apply(T t, U u);

Some functions that have the prefix of Bi is possessing two params and a result.

2. public interface Consumer<T>

the mainly method:

  /**
     * Performs this operation on the given argument.
     *
     * @param t the input argument
     */
    void accept(T t);

3. public interface Supplier<T>

the mainly method:

/**
     * Gets a result.
     *
     * @return a result
     */
    T get();

And  public interface BinaryOperator<T> extends BiFunction<T,T,T>

  /**
     * Returns a {@link BinaryOperator} which returns the lesser of two elements
     * according to the specified {@code Comparator}.
     *
     * @param <T> the type of the input arguments of the comparator
     * @param comparator a {@code Comparator} for comparing the two values
     * @return a {@code BinaryOperator} which returns the lesser of its operands,
     *         according to the supplied {@code Comparator}
     * @throws NullPointerException if the argument is null
     */
    public static <T> BinaryOperator<T> minBy(Comparator<? super T> comparator) {
        Objects.requireNonNull(comparator);
        return (a, b) -> comparator.compare(a, b) <= 0 ? a : b;
    }

4. public interface Predicate<T>

  /**
     * Evaluates this predicate on the given argument.
     *
     * @param t the input argument
     * @return {@code true} if the input argument matches the predicate,
     * otherwise {@code false}
     */
    boolean test(T t);

ex:

stream().filter(item -> item>2)...

时间: 2024-11-18 04:32:16

2.funtions的相关文章

tengine/nginx服务启动管理脚本(未使用系统funtions函数)

tengine是淘宝对于nginx1.6.2的一个二次开发,性能比原生态nginx更好,这几天在做测试,想应用到现有的架构里.源码包安装后就牵涉到一个添加到系统服务方便管理问题,到网上搜nginx启动脚本一大堆,但不是自己写的总归不放心,再者好多用的是系统的/etc/rc.d/init.d/funtions函数来实现的,虽然看着很健壮,但想到出了问题后又得研究怎么排查,一不做二不休干脆写一个,把脚本和添加到系统服务的过程分享一下. 功能主要有:service tengine start serv

Python中的内建函数(Built_in Funtions)

前言 在Python官方文档的标准库章节中,第一节是简介,第二节就是Built_in Functions,可见内建函数是Python标准库的重要组成部分,而有很多内建函数我们平时却很少用到或根本就不知道原来还有这么好用的函数居然直接就可以拿来用. Built_in Funtions 接下来为大家介绍一些我认为被大家忽略掉的内建函数. all 如果列表或迭代器中所有值都为真或为空返回True,相当于 def all(iterable):    for element in iterable:  

Learn Python 014: Funtions

def weight_converter(gram): total_weight = gram / 1000 return str(total_weight) + 'KG' the_weight = weight_converter(3000) print(the_weight)

BMP Header Structure

1 /* ***** BEGIN LICENSE BLOCK ***** 2 * 3 * $Id: bitmap.h,v 1.3 2004/06/30 16:44:52 asuraparaju Exp $ $Name: Dirac_1_0_2 $ 4 * 5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 6 * 7 * The contents of this file are subject to the Mozilla Public License 8 * Vers

初次接触JQuery

初次接触JQuery 1. 综述 JQuery,是一个JavaScript库,给JavaScript开发带来了极大的便利.它有以下好处:减少了JavaScript的代码量:分离了JavaScript和HTML,在页面里只需要定义id即可:方便地为网站提供Ajax交互. 2. JQuery代码 2.1 函数调用 $(this).hide(); 对当前HTML元素,调用hide函数,即隐藏他. $("p").hide(); 对所有的<p>元素,调用hide函数,即隐藏他. $(

SRAM的读写操作

自己写的SRAM的程序,主要在于实用性,适应工作的工程需要.使用芯片为: 芯片时序图为: 代码: /********************************Copyright************************************** **----------------------------File information-------------------------- ** File name : ZF_SRAM.v ** CreateDate :2014.11

YASM User Manual

This document is the user manual for the Yasm assembler. It is intended as both an introduction and a general-purpose reference for all Yasm users. 1.?Introduction Yasm is a BSD-licensed assembler that is designed from the ground up to allow for mult

知识点

1 2008r2-sp1 更新2 改名,强密码,改端口,开防火墙3 组策略 对计算机及其相关硬件非常了解(包括但不限于pc机,服务器,小型机,存储器,交换机,路由器,防火墙,负载器,行为管理等)对操作系统(包括windows,unix/linux两大派别)有较深的理解,linux更熟悉一些对数据库(包括MSSQL,Mysql)管理也很精通,单机上的安装配置,管理维护,监控调优对计算机网络的历史,原理,技术对存储设备对底层架构之上的应用层面--即与广大用户最近的,熟悉C/S,B/S正则流派grep

黄聪:WordPress 多站点建站教程(六):使用WP_Query、switch_to_blog函数实现获取子站点分类中的文章

首先在你使用主题的funtions.php里面添加下代码: //根据时间显示最新的分类文章内容,每个站点显示一篇内容 //$blog_id 子站点ID //$catid 分类ID wp_reset_query(); switch_to_blog($blog_id); global $post;?> $my_query2 = new WP_Query('showposts=1&order=desc&orderby=date&cat='.$catid); while ($my_q