Skip to content

Commit

Permalink
#1 - Added initial version of object predicates
Browse files Browse the repository at this point in the history
  • Loading branch information
avegera committed Jun 4, 2024
1 parent 69ed157 commit 31513db
Show file tree
Hide file tree
Showing 11 changed files with 1,080 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Shell script files must always be normalized
*.sh text eol=lf
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#Maven
target/

#IntelliJ
/.idea
*.iml
*.ipr
*.iws
gradle-wrapper.jar

#Eclipse
/.classpath
/.settings/
/.project
/bin/

#Misc
*.log
.gradle
276 changes: 276 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.github.avegera</groupId>
<artifactId>predicate4j</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
<description>Human readable fluent API for predicates in Java</description>
<url>https://github.com/avegera/predicate4j</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- Test Dependencies -->
<junit-jupiter.version>5.10.2</junit-jupiter.version>
<asserj.version>3.26.0</asserj.version>

<!-- Plugins -->
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.7.0</maven-javadoc-plugin.version>
<maven-gpg-plugin.version>3.2.4</maven-gpg-plugin.version>
<nexus-staging-maven-plugin.version>1.7.0</nexus-staging-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.12</jacoco-maven-plugin.version>
</properties>

<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>

<developers>
<developer>
<id>avegera</id>
<name>Artem Vegera</name>
<organizationUrl>https://github.com/avegera</organizationUrl>
</developer>
</developers>

<scm>
<connection>scm:git:git://github.com/avegera/predicate4j.git</connection>
<developerConnection>scm:git:ssh://github.com:avegera/predicate4j.git</developerConnection>
<url>https://github.com/avegera/predicate4j/tree/main</url>
</scm>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${asserj.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
<source>8</source>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>CLASS</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.9</minimum>
</limit>
<limit>
<counter>METHOD</counter>
<value>COVEREDRATIO</value>
<minimum>0.9</minimum>
</limit>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.9</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.9</minimum>
</limit>
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.9</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>${nexus-staging-maven-plugin.version}</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>java-code-coverage</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>sign</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
46 changes: 46 additions & 0 deletions src/main/java/io/github/avegera/predicate4j/Predicates.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.github.avegera.predicate4j;

import java.util.Objects;
import java.util.function.Predicate;

/**
* This class contains library of common java predicates.
*/
public class Predicates {

private Predicates() {
//private constructor
}

public static <T> Predicate<T> isEqualTo(T object) {
return it -> Objects.equals(it, object);
}

public static <T> Predicate<T> notEqualTo(T object) {
return it -> !Objects.equals(it, object);
}

public static <T> Predicate<T> isNull() {
return Objects::isNull;
}

public static <T> Predicate<T> notNull() {
return Objects::nonNull;
}

public static <T> Predicate<T> isInstanceOf(Class<?> clazz) {
return obj -> clazz != null && clazz.isInstance(obj);
}

public static <T> Predicate<T> notInstanceOf(Class<?> clazz) {
return obj -> clazz == null || !clazz.isInstance(obj);
}

public static <T> Predicate<T> alwaysTrue() {
return it -> true;
}

public static <T> Predicate<T> alwaysFalse() {
return it -> false;
}
}
17 changes: 17 additions & 0 deletions src/main/java/io/github/avegera/predicate4j/Where.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.avegera.predicate4j;

import io.github.avegera.predicate4j.api.WhereObject;
import io.github.avegera.predicate4j.impl.WhereObjectImpl;

import java.util.function.Function;

public class Where {

private Where() {
//private constructor
}

public static <T, R> WhereObject<T, R> where(Function<T, R> mapper) {
return new WhereObjectImpl<>(mapper);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.github.avegera.predicate4j.api;

import java.util.function.Predicate;

public interface RichPredicate<T> extends Predicate<T> {
}
16 changes: 16 additions & 0 deletions src/main/java/io/github/avegera/predicate4j/api/WhereObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.github.avegera.predicate4j.api;

public interface WhereObject<T, R> {

RichPredicate<T> isEqualTo(R value);

RichPredicate<T> isInstanceOf(Class<?> clazz);

RichPredicate<T> isNull();

RichPredicate<T> notEqualTo(R value);

RichPredicate<T> notInstanceOf(Class<?> clazz);

RichPredicate<T> notNull();
}
Loading

0 comments on commit 31513db

Please sign in to comment.