All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.shepherdviolet.glacimon.java.misc.LambdaBuildable Maven / Gradle / Ivy

/*
 * Copyright (C) 2022-2022 S.Violet
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Project GitHub: https://github.com/shepherdviolet/glacimon
 * Email: [email protected]
 */

package com.github.shepherdviolet.glacimon.java.misc;

import java.util.*;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
 * [JAVA8+]用Lambda表达式创建Map/Set/Object/List
 *
 * @since 1.8
 */
public interface LambdaBuildable {

    /**
     * 创建HashMap
     *
     * 
     *         Map map = buildHashMap(i -> {
     *             i.put("a", "b");
     *             i.put("c", "d");
     *         });
     * 
* * @since 1.8 */ default Map buildHashMap(Consumer> supplier) { return LambdaBuilder.hashMap(supplier); } /** * 创建LinkedHashMap * *
     *         Map map = buildLinkedHashMap(i -> {
     *             i.put("a", "b");
     *             i.put("c", "d");
     *         });
     * 
* * @since 1.8 */ default Map buildLinkedHashMap(Consumer> supplier) { return LambdaBuilder.linkedHashMap(supplier); } /** * 创建HashSet * *
     *         Set set = buildHashSet(i -> {
     *             i.add("a");
     *             i.add("c");
     *         });
     * 
* * @since 1.8 */ default Set buildHashSet(Consumer> supplier) { return LambdaBuilder.hashSet(supplier); } /** * 创建Object * *
     *         Bean bean = buildObject(() -> {
     *             Bean obj = new Bean();
     *             obj.setName("123");
     *             obj.setId("456");
     *             return obj;
     *         });
     * 
* * @since 1.8 */ default T buildObject(Supplier supplier) { return LambdaBuilder.object(supplier); } /** * 创建ArrayList, 一般情况下用Arrays.asList * *
     *     Arrays.asList(
     *          item1,
     *          item2
     *     );
     * 
* *
     *         List list = buildArrayList(i -> {
     *            i.add("a");
     *            i.add("b");
     *         });
     * 
* * @since 1.8 */ default List buildArrayList(Consumer> supplier) { return LambdaBuilder.arrayList(supplier); } /** * 创建LinkedList, 一般情况下用Arrays.asList * *
     *         List list = buildLinkedList(i -> {
     *            i.add("a");
     *            i.add("b");
     *         });
     * 
* * @since 1.8 */ default List buildLinkedList(Consumer> supplier) { return LambdaBuilder.linkedList(supplier); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy