Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
jacocoAggregation projects.purefunStream
jacocoAggregation projects.purefunTransformer
jacocoAggregation projects.purefunTypeclasses
jacocoAggregation projects.purefunRefined

testReportAggregation projects.purefunControl
testReportAggregation projects.purefunCore
Expand All @@ -38,6 +39,7 @@ dependencies {
testReportAggregation projects.purefunStream
testReportAggregation projects.purefunTransformer
testReportAggregation projects.purefunTypeclasses
testReportAggregation projects.purefunRefined
}

reporting {
Expand Down
3 changes: 3 additions & 0 deletions refined/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
api projects.purefunCore
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2018-2023, Antonio Gabriel Muñoz Conejo <antoniogmc at gmail dot com>
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.purefun.refined;

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.SOURCE;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

@Retention(SOURCE)
@Target(TYPE)
public @interface RefinedDouble {

double min() default Double.MIN_VALUE;
double max() default Double.MAX_VALUE;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2018-2023, Antonio Gabriel Muñoz Conejo <antoniogmc at gmail dot com>
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.purefun.refined;

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.SOURCE;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

@Retention(SOURCE)
@Target(TYPE)
public @interface RefinedInteger {

int min() default Integer.MIN_VALUE;
int max() default Integer.MAX_VALUE;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2018-2023, Antonio Gabriel Muñoz Conejo <antoniogmc at gmail dot com>
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.purefun.refined;

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.SOURCE;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

@Retention(SOURCE)
@Target(TYPE)
public @interface RefinedString {

int minSize() default 0;
int maxSize() default Integer.MAX_VALUE;
String regex() default "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.tonivade.purefun.refined;

import java.io.Serializable;

@RefinedInteger(min = 0)
public interface TestInt extends Comparable<TestIntImpl>, Serializable {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.github.tonivade.purefun.refined;

import java.io.Serial;
import java.util.Objects;

import javax.annotation.processing.Generated;

import com.github.tonivade.purefun.Precondition;

@Generated("xxx")
public final class TestIntImpl extends Number implements TestInt {

@Serial
private static final long serialVersionUID = 2426275725152618668L;

private final int value;

public TestIntImpl(int value) {
this.value = Precondition.checkPositive(value);
}

@Override
public int intValue() {
return value;
}

@Override
public long longValue() {
return value;
}

@Override
public float floatValue() {
return value;
}

@Override
public double doubleValue() {
return value;
}

@Override
public int compareTo(TestIntImpl other) {
return this.value - other.value;
}

@Override
public int hashCode() {
return Objects.hash(value);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TestIntImpl other = (TestIntImpl) obj;
return value == other.value;
}

@Override
public String toString() {
return String.valueOf(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.tonivade.purefun.refined;

import java.io.Serializable;

@RefinedString(minSize = 12, maxSize = 12)
public interface TestString extends Comparable<TestString>, Serializable, CharSequence {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2018-2023, Antonio Gabriel Muñoz Conejo <antoniogmc at gmail dot com>
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.purefun.refined;

import java.io.Serial;
import java.util.Arrays;

import javax.annotation.processing.Generated;

import com.github.tonivade.purefun.Precondition;

@Generated("xxx")
public final class TestStringImpl implements TestString {

@Serial
private static final long serialVersionUID = 3297705339043486610L;

private final byte[] value;

public TestStringImpl(String value) {
this.value = Precondition.checkNonEmpty(value).getBytes();
}

@Override
public int length() {
return toString().length();
}

@Override
public char charAt(int index) {
return toString().charAt(index);
}

@Override
public CharSequence subSequence(int start, int end) {
return toString().subSequence(start, end);
}

@Override
public int compareTo(TestString other) {
return this.toString().compareTo(other.toString());
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.hashCode(value);
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TestStringImpl other = (TestStringImpl) obj;
return Arrays.equals(value, other.value);
}

@Override
public String toString() {
return new String(value);
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rootProject.name = 'purefun-parent'
include "core", "monad", "stream", "typeclasses",
"optics", "effect", "free", "transformer",
"instances", "annotation", "processor",
"generic", "control"
"generic", "control", "refined"

rootProject.children.each { it.name = "purefun-" + it.name }

Expand Down