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

io.edurt.gcm.common.jdk.ObjectBuilder Maven / Gradle / Ivy

There is a newer version: 1.2.6
Show newest version
/*
 * 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.
 */
package io.edurt.gcm.common.jdk;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class ObjectBuilder
{
    private final Supplier supplier;
    private List> modifiers = new ArrayList<>();

    public ObjectBuilder(Supplier supplier)
    {
        this.supplier = supplier;
    }

    public static  ObjectBuilder of(Supplier supplier)
    {
        return new ObjectBuilder<>(supplier);
    }

    public 

ObjectBuilder with(Consumers consumer, P p) { Consumer c = instance -> consumer.accept(instance, p); modifiers.add(c); return this; } /** * builder class instance * * @return instance */ public T build() { T value = supplier.get(); modifiers.forEach(modifier -> modifier.accept(value)); modifiers.clear(); return value; } @FunctionalInterface public interface Consumers { void accept(T t, P p); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy