Skip to content

Commit

Permalink
Move interfaces back to Java to avoid -Xjvm-default compiler arg
Browse files Browse the repository at this point in the history
  • Loading branch information
leomillon committed Sep 11, 2019
1 parent ec246ba commit e282a13
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 159 deletions.
1 change: 0 additions & 1 deletion jcv-assertj/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ val javadocJar by tasks.registering(Jar::class) {
tasks {
withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjvm-default=compatibility")
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
Expand Down
1 change: 0 additions & 1 deletion jcv-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ val javadocJar by tasks.registering(Jar::class) {
tasks {
withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjvm-default=compatibility")
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2019 ekino (https://www.ekino.com/)
*/
package com.ekino.oss.jcv.core;

/**
* Matcher used to identify a specific field.
*
* @author Leo Millon
*/
@FunctionalInterface
public interface JsonContextMatcher {

/**
* Evaluates the current json parsing context.
*
* @param prefix the current json field path
* @param expectedValue the expected field value
* @param actualValue the actual field value
*
* @return {@code true} if the context matches, otherwise {@code false}
*/
boolean matches(String prefix, Object expectedValue, Object actualValue);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* Copyright (c) 2019 ekino (https://www.ekino.com/)
*/
package com.ekino.oss.jcv.core
package com.ekino.oss.jcv.core;

import org.skyscreamer.jsonassert.ValueMatcher
import org.skyscreamer.jsonassert.ValueMatcher;

/**
* A validator composed of a matcher and a value comparator.
Expand All @@ -12,19 +12,19 @@
*
* @author Leo Millon
*/
interface JsonValidator<T> {
public interface JsonValidator<T> {

/**
* The context matcher.
*
* @return the matcher
*/
val contextMatcher: JsonContextMatcher
JsonContextMatcher getContextMatcher();

/**
* The field value comparator.
*
* @return the comparator
*/
val valueComparator: ValueMatcher<T>
ValueMatcher<T> getValueComparator();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2019 ekino (https://www.ekino.com/)
*/
package com.ekino.oss.jcv.core;

import org.skyscreamer.jsonassert.ValueMatcher;

/**
* A JSON value comparator.
*
* @param <T> the field value type
*
* @author Leo Millon
*/
@FunctionalInterface
public interface JsonValueComparator<T> extends ValueMatcher<T> {

@Override
default boolean equal(T o1, T o2) {
return hasCorrectValue(o1, o2);
}

/**
* Evaluates actual field value against the expected one.
*
* @param actual field actual value
* @param expected field expected value
*
* @return {@code true} if the actual is valid against the expected one, otherwise {@code false}
*/
boolean hasCorrectValue(T actual, T expected);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2019 ekino (https://www.ekino.com/)
*/
package com.ekino.oss.jcv.core.initializer;

import org.skyscreamer.jsonassert.ValueMatcher;

/**
* Comparator intializer.
*
* @param <T> the field value type
*
* @author Leo Millon
*/
@FunctionalInterface
public interface NoParameterComparatorInitializer<T> {

/**
* Init a comparator without template parameter.
*
* @return the initalized comparator
*/
ValueMatcher<T> initComparator();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2019 ekino (https://www.ekino.com/)
*/
package com.ekino.oss.jcv.core.initializer;

import org.skyscreamer.jsonassert.ValueMatcher;

/**
* Comparator intializer given tempated validator with 1 parameter information.
*
* @param <T> the field value type
*
* @author Leo Millon
*/
@FunctionalInterface
public interface OneParameterComparatorInitializer<T> {

/**
* Init a comparator using the current templated validator info.
*
* @param parameter the first parameter of the templated validator
*
* @return the initalized comparator
*/
ValueMatcher<T> initComparator(String parameter);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* Copyright (c) 2019 ekino (https://www.ekino.com/)
*/
package com.ekino.oss.jcv.core.initializer
package com.ekino.oss.jcv.core.initializer;

import com.ekino.oss.jcv.core.validator.ValidatorTemplateManager
import org.skyscreamer.jsonassert.ValueMatcher
import com.ekino.oss.jcv.core.validator.ValidatorTemplateManager;
import org.skyscreamer.jsonassert.ValueMatcher;

/**
* Comparator intializer given tempated validator information.
Expand All @@ -14,7 +14,7 @@
* @author Leo Millon
*/
@FunctionalInterface
interface TemplatedComparatorInitializer<T> {
public interface TemplatedComparatorInitializer<T> {

/**
* Init a comparator using the current templated validator info.
Expand All @@ -23,5 +23,5 @@ interface TemplatedComparatorInitializer<T> {
*
* @return the initalized comparator
*/
fun initComparator(validatorTemplateManager: ValidatorTemplateManager): ValueMatcher<T>
ValueMatcher<T> initComparator(ValidatorTemplateManager validatorTemplateManager);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* Copyright (c) 2019 ekino (https://www.ekino.com/)
*/
package com.ekino.oss.jcv.core.initializer
package com.ekino.oss.jcv.core.initializer;

import org.skyscreamer.jsonassert.ValueMatcher
import org.skyscreamer.jsonassert.ValueMatcher;

/**
* Comparator intializer given tempated validator with 2 parameters information.
Expand All @@ -13,7 +13,7 @@
* @author Leo Millon
*/
@FunctionalInterface
interface TwoParametersComparatorInitializer<T> {
public interface TwoParametersComparatorInitializer<T> {

/**
* Init a comparator using the current templated validator info.
Expand All @@ -23,5 +23,5 @@ interface TwoParametersComparatorInitializer<T> {
*
* @return the initalized comparator
*/
fun initComparator(param1: String?, param2: String?): ValueMatcher<T>
ValueMatcher<T> initComparator(String param1, String param2);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,17 @@ object Initializers {

@JvmStatic
fun <T> comparatorWithoutParameter(initializer: NoParameterComparatorInitializer<T>): TemplatedComparatorInitializer<T> =
object : TemplatedComparatorInitializer<T> {
override fun initComparator(validatorTemplateManager: ValidatorTemplateManager): ValueMatcher<T> =
initializer.initComparator()
}
TemplatedComparatorInitializer<T> { initializer.initComparator() }

@JvmStatic
@JvmOverloads
fun <T> comparatorWith1Parameter(
required: Boolean = true,
initializer: OneParameterComparatorInitializer<T>
): TemplatedComparatorInitializer<T> =
object : TemplatedComparatorInitializer<T> {
override fun initComparator(validatorTemplateManager: ValidatorTemplateManager): ValueMatcher<T> {
val parameter = getOrThrowParameter(0, required, validatorTemplateManager)
return initializer.initComparator(parameter)
}
TemplatedComparatorInitializer<T> { validatorTemplateManager ->
val parameter = getOrThrowParameter(0, required, validatorTemplateManager)
initializer.initComparator(parameter)
}

@JvmStatic
Expand All @@ -52,12 +47,10 @@ object Initializers {
param2Required: Boolean = true,
initializer: TwoParametersComparatorInitializer<T>
): TemplatedComparatorInitializer<T> {
return object : TemplatedComparatorInitializer<T> {
override fun initComparator(validatorTemplateManager: ValidatorTemplateManager): ValueMatcher<T> {
val parameter1 = getOrThrowParameter(0, param1Required, validatorTemplateManager)
val parameter2 = getOrThrowParameter(1, param2Required, validatorTemplateManager)
return initializer.initComparator(parameter1, parameter2)
}
return TemplatedComparatorInitializer<T> { validatorTemplateManager ->
val parameter1 = getOrThrowParameter(0, param1Required, validatorTemplateManager)
val parameter2 = getOrThrowParameter(1, param2Required, validatorTemplateManager)
initializer.initComparator(parameter1, parameter2)
}
}

Expand All @@ -76,26 +69,22 @@ object Initializers {
@JvmStatic
@SafeVarargs
fun <T> allOf(vararg initializers: TemplatedComparatorInitializer<in T>): TemplatedComparatorInitializer<T> =
object : TemplatedComparatorInitializer<T> {
override fun initComparator(validatorTemplateManager: ValidatorTemplateManager): ValueMatcher<T> {
return ValueMatcher { actual, expected ->
sequenceOf(*initializers)
.map { it.initComparator(validatorTemplateManager) }
.all { it.equal(actual, expected) }
}
TemplatedComparatorInitializer<T> { validatorTemplateManager ->
ValueMatcher { actual, expected ->
sequenceOf(*initializers)
.map { it.initComparator(validatorTemplateManager) }
.all { it.equal(actual, expected) }
}
}

@JvmStatic
@SafeVarargs
fun <T> anyOf(vararg initializers: TemplatedComparatorInitializer<in T>): TemplatedComparatorInitializer<T> =
object : TemplatedComparatorInitializer<T> {
override fun initComparator(validatorTemplateManager: ValidatorTemplateManager): ValueMatcher<T> {
return ValueMatcher { actual, expected ->
sequenceOf(*initializers)
.map { it.initComparator(validatorTemplateManager) }
.any { it.equal(actual, expected) }
}
TemplatedComparatorInitializer<T> { validatorTemplateManager ->
ValueMatcher { actual, expected ->
sequenceOf(*initializers)
.map { it.initComparator(validatorTemplateManager) }
.any { it.equal(actual, expected) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,7 @@ package com.ekino.oss.jcv.core.initializer

import org.skyscreamer.jsonassert.ValueMatcher

/**
* Comparator intializer.
*
* @param <T> the field value type
*
* @author Leo Millon
*/
@FunctionalInterface
interface NoParameterComparatorInitializer<T> {

/**
* Init a comparator without template parameter.
*
* @return the initalized comparator
*/
fun initComparator(): ValueMatcher<T>
}

typealias KNoParameterComparatorInitializer<T> = () -> ValueMatcher<T>

fun <T> asNoParameterComparatorInitializer(initializer: KNoParameterComparatorInitializer<T>) =
object : NoParameterComparatorInitializer<T> {
override fun initComparator(): ValueMatcher<T> = initializer()
}
NoParameterComparatorInitializer<T> { initializer() }
Loading

0 comments on commit e282a13

Please sign in to comment.