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

name.remal.gradle_plugins.toolkit.issues.Utils Maven / Gradle / Ivy

There is a newer version: 0.68.0
Show newest version
package name.remal.gradle_plugins.toolkit.issues;

import static lombok.AccessLevel.PRIVATE;

import java.util.function.Consumer;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import javax.annotation.Nullable;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.Contract;

@NoArgsConstructor(access = PRIVATE)
abstract class Utils {

    public static > int compareOptionals(@Nullable T o1, @Nullable T o2) {
        if (o1 != null && o2 != null) {
            return o1.compareTo(o2);
        } else if (o1 != null) {
            return -1;
        } else if (o2 != null) {
            return 1;
        } else {
            return 0;
        }
    }

    public static Stream streamIssues(Iterable issues) {
        return StreamSupport.stream(issues.spliterator(), false)
            .distinct()
            .sorted()
            .map(Issue.class::cast);
    }

    public static  void ifPresent(@Nullable T value, Consumer consumer) {
        if (value != null) {
            consumer.accept(value);
        }
    }

    @Contract("_,_ -> param1")
    public static StringBuilder appendDelimiter(StringBuilder sb, String delimiter) {
        if (sb.length() > 0) {
            sb.append(delimiter);
        }
        return sb;
    }

    @Contract("_ -> param1")
    public static StringBuilder appendDelimiter(StringBuilder sb) {
        appendDelimiter(sb, " ");
        return sb;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy