Skip to content

Commit

Permalink
Add support for determining whether a set is infinite
Browse files Browse the repository at this point in the history
  • Loading branch information
dmfs committed Feb 17, 2024
1 parent 5452fbf commit de3baf0
Show file tree
Hide file tree
Showing 24 changed files with 770 additions and 174 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ dependencies {
api 'org.dmfs:rfc5545-datetime:0.3'
implementation 'org.dmfs:jems2:2.22.0'
testImplementation project("lib-recur-hamcrest")
testImplementation project("lib-recur-confidence")
testImplementation 'org.dmfs:jems2-testing:2.22.0'
testImplementation 'org.saynotobugs:confidence-core:0.42.0'
}
Expand Down
29 changes: 29 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[versions]
eclipse-jdt = "2.2.600"
hamcrest = "2.2"
jems2 = "2.22.0"
junit = "5.8.2"
junit-testkit = "1.9.2"
srcless = "0.3.0"
confidence = "0.42.0"

[libraries]
srcless-annotations = { module = "org.dmfs:srcless-annotations", version.ref = "srcless" }
srcless-processors = { module = "org.dmfs:srcless-processors", version.ref = "srcless" }
eclipse-jdt-anntation = { module = 'org.eclipse.jdt:org.eclipse.jdt.annotation', version.ref = "eclipse-jdt" }
nullless-processors = { module = "org.dmfs:nullless-processors", version.ref = "srcless" }

junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }

jems2 = { module = "org.dmfs:jems2", version.ref = "jems2" }
jems2-testing = { module = "org.dmfs:jems2-testing", version.ref = "jems2" }
jems2-confidence = { module = "org.dmfs:jems2-confidence", version.ref = "jems2" }

confidence-core = { module = "org.saynotobugs:confidence-core", version.ref = "confidence" }
confidence-test = { module = "org.saynotobugs:confidence-test", version.ref = "confidence" }

[bundles]
srcless-processors = ["srcless-processors", "nullless-processors"]

[plugins]
25 changes: 25 additions & 0 deletions lib-recur-confidence/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins {
id 'java-library'
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

dependencies {
compileOnly libs.eclipse.jdt.anntation
compileOnly libs.srcless.annotations
annotationProcessor libs.bundles.srcless.processors
api libs.confidence.core
implementation libs.jems2
implementation libs.jems2.confidence
api rootProject

testImplementation libs.confidence.test
testImplementation libs.jems2.testing
testImplementation libs.junit.jupiter.api
testRuntimeOnly libs.junit.jupiter.engine
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2024 Marten Gajda <marten@dmfs.org>
*
*
* 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 org.dmfs.rfc5545.confidence.quality;

import org.dmfs.jems2.confidence.optional.Absent;
import org.dmfs.rfc5545.RecurrenceSet;
import org.dmfs.srcless.annotations.staticfactory.StaticFactories;
import org.saynotobugs.confidence.description.Text;
import org.saynotobugs.confidence.quality.composite.AllOf;
import org.saynotobugs.confidence.quality.composite.Has;
import org.saynotobugs.confidence.quality.composite.Not;
import org.saynotobugs.confidence.quality.composite.QualityComposition;
import org.saynotobugs.confidence.quality.iterable.EmptyIterable;
import org.saynotobugs.confidence.quality.object.Satisfies;

@StaticFactories(value = "Recur", packageName = "org.dmfs.rfc5545.confidence")
public final class EmptyRecurrenceSet extends QualityComposition<RecurrenceSet>
{
public EmptyRecurrenceSet()
{
super(new AllOf<>(
new EmptyIterable(),
new Not<>(new Satisfies<>(RecurrenceSet::isInfinite, new Text("is infinite")))
));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2024 Marten Gajda <marten@dmfs.org>
*
*
* 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 org.dmfs.rfc5545.confidence.quality;

import org.dmfs.jems2.predicate.Not;
import org.dmfs.rfc5545.RecurrenceSet;
import org.dmfs.srcless.annotations.staticfactory.StaticFactories;
import org.saynotobugs.confidence.description.Text;
import org.saynotobugs.confidence.quality.composite.QualityComposition;
import org.saynotobugs.confidence.quality.object.Satisfies;

@StaticFactories(value = "Recur", packageName = "org.dmfs.rfc5545.confidence")
public final class Finite extends QualityComposition<RecurrenceSet>
{
public Finite()
{
super(new Satisfies<>(new Not<>(RecurrenceSet::isInfinite), new Text("finite")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2024 Marten Gajda <marten@dmfs.org>
*
*
* 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 org.dmfs.rfc5545.confidence.quality;

import org.dmfs.rfc5545.RecurrenceSet;
import org.dmfs.srcless.annotations.staticfactory.StaticFactories;
import org.saynotobugs.confidence.description.Text;
import org.saynotobugs.confidence.quality.composite.QualityComposition;
import org.saynotobugs.confidence.quality.object.Satisfies;

@StaticFactories(value = "Recur", packageName = "org.dmfs.rfc5545.confidence")
public final class Infinite extends QualityComposition<RecurrenceSet>
{
public Infinite()
{
super(new Satisfies<>(RecurrenceSet::isInfinite, new Text("infinite")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2024 Marten Gajda <marten@dmfs.org>
*
*
* 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 org.dmfs.rfc5545.confidence.quality;

import org.dmfs.jems2.iterable.First;
import org.dmfs.rfc5545.DateTime;
import org.dmfs.rfc5545.RecurrenceSet;
import org.dmfs.srcless.annotations.staticfactory.StaticFactories;
import org.saynotobugs.confidence.quality.composite.Has;
import org.saynotobugs.confidence.quality.composite.QualityComposition;
import org.saynotobugs.confidence.quality.iterable.Iterates;

@StaticFactories(value = "Recur", packageName = "org.dmfs.rfc5545.confidence")
public final class StartsWith extends QualityComposition<RecurrenceSet>
{
public StartsWith(DateTime... instances)
{
super(new Has<>("first " + instances.length + " instances",
candidate -> new First<>(instances.length, candidate), new Iterates<>(instances)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2024 Marten Gajda <marten@dmfs.org>
*
*
* 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 org.dmfs.rfc5545.confidence.quality;

import org.dmfs.rfc5545.RecurrenceSet;
import org.dmfs.rfc5545.instanceiterator.EmptyIterator;
import org.junit.jupiter.api.Test;

import static org.dmfs.jems2.mockito.Mock.*;
import static org.saynotobugs.confidence.Assertion.assertThat;
import static org.saynotobugs.confidence.quality.Core.allOf;

class EmptyRecurrenceSetTest
{
@Test
void test()
{
assertThat(new EmptyRecurrenceSet(),
allOf(
org.saynotobugs.confidence.test.quality.Test.<RecurrenceSet>passes(mock(RecurrenceSet.class,
with(RecurrenceSet::isInfinite, returning(false)),
with(RecurrenceSet::iterator, returning(new EmptyIterator())))),
org.saynotobugs.confidence.test.quality.Test.<RecurrenceSet>fails(mock(RecurrenceSet.class,
with(RecurrenceSet::isInfinite, returning(true)),
with(RecurrenceSet::iterator, returning(new EmptyIterator()))))));
}

}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
rootProject.name = 'lib-recur'
include 'lib-recur-confidence'
include 'lib-recur-hamcrest'
include 'benchmark'

7 changes: 7 additions & 0 deletions src/main/java/org/dmfs/rfc5545/RecurrenceSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.dmfs.rfc5545;


import org.dmfs.jems2.Optional;

/**
* A set of instances.
*/
Expand All @@ -27,4 +29,9 @@ public interface RecurrenceSet extends Iterable<DateTime>
* Returns an {@link InstanceIterator} for this {@link RecurrenceSet}.
*/
InstanceIterator iterator();

/**
* Returns whether this {@link RecurrenceSet} is infinite or not.
*/
boolean isInfinite();
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,10 @@ public InstanceIterator iterator()
iterator.fastForward(mTimeStamp);
return iterator;
}

@Override
public boolean isInfinite()
{
return mDelegate.isInfinite();
}
}
6 changes: 6 additions & 0 deletions src/main/java/org/dmfs/rfc5545/recurrenceset/FromList.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,10 @@ public InstanceIterator iterator()
? new FastForwardable(delegate.next(), delegate.hasNext() ? delegate : EmptyIterator.INSTANCE)
: EmptyIterator.INSTANCE;
}

@Override
public boolean isInfinite()
{
return false;
}
}
7 changes: 7 additions & 0 deletions src/main/java/org/dmfs/rfc5545/recurrenceset/FromRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@ public InstanceIterator iterator()
{
return mRecurrenceRule.iterator(mFirstInstance);
}

@Override
public boolean isInfinite()
{
return mRecurrenceRule.isInfinite();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.dmfs.rfc5545.DateTime;
import org.dmfs.rfc5545.InstanceIterator;
import org.dmfs.rfc5545.RecurrenceSet;
import org.dmfs.rfc5545.instanceiterator.Merged;
import org.dmfs.rfc5545.instanceiterator.CountLimitedRecurrenceRuleIterator;
import org.dmfs.rfc5545.instanceiterator.Merged;
import org.dmfs.rfc5545.recur.RecurrenceRule;
import org.dmfs.rfc5545.recur.RecurrenceRuleIterator;

Expand Down Expand Up @@ -61,4 +61,11 @@ public InstanceIterator iterator()
}
return ruleIterator;

Check warning on line 62 in src/main/java/org/dmfs/rfc5545/recurrenceset/FromRuleIncludingStart.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/dmfs/rfc5545/recurrenceset/FromRuleIncludingStart.java#L62

Added line #L62 was not covered by tests
}

@Override
public boolean isInfinite()
{
return mRecurrenceRule.isInfinite();

Check warning on line 68 in src/main/java/org/dmfs/rfc5545/recurrenceset/FromRuleIncludingStart.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/dmfs/rfc5545/recurrenceset/FromRuleIncludingStart.java#L68

Added line #L68 was not covered by tests
}

}
7 changes: 7 additions & 0 deletions src/main/java/org/dmfs/rfc5545/recurrenceset/FromRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,11 @@ public InstanceIterator iterator()
{
return mDelegate.iterator();

Check warning on line 57 in src/main/java/org/dmfs/rfc5545/recurrenceset/FromRules.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/dmfs/rfc5545/recurrenceset/FromRules.java#L57

Added line #L57 was not covered by tests
}

@Override
public boolean isInfinite()
{
return mDelegate.isInfinite();

Check warning on line 63 in src/main/java/org/dmfs/rfc5545/recurrenceset/FromRules.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/dmfs/rfc5545/recurrenceset/FromRules.java#L63

Added line #L63 was not covered by tests
}

}
Loading

0 comments on commit de3baf0

Please sign in to comment.