Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added null or blank and exact type to int, long and date
- Loading branch information
1 parent
bb109e1
commit 4c928d0
Showing
16 changed files
with
417 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
common/core/src/main/java/zingg/common/core/similarity/function/CheckNullFunctionDate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import java.util.Date; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
public class CheckNullFunctionDate extends SimFunction<Date> { | ||
|
||
private static final long serialVersionUID = 1L; | ||
public static final Log LOG = LogFactory | ||
.getLog(CheckNullFunctionDate.class); | ||
|
||
public CheckNullFunctionDate() { | ||
super("CheckNullFunctionDate"); | ||
} | ||
|
||
public CheckNullFunctionDate(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public Double call(Date first, Date second) { | ||
if (first != null && second != null) { | ||
return 1d; | ||
} | ||
return 0d; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
common/core/src/main/java/zingg/common/core/similarity/function/CheckNullFunctionInt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
public class CheckNullFunctionInt extends SimFunction<Integer> { | ||
|
||
private static final long serialVersionUID = 1L; | ||
public static final Log LOG = LogFactory | ||
.getLog(CheckNullFunctionInt.class); | ||
|
||
public CheckNullFunctionInt() { | ||
super("CheckNullFunctionInt"); | ||
} | ||
|
||
public CheckNullFunctionInt(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public Double call(Integer first, Integer second) { | ||
if (first != null && second != null) { | ||
return 1d; | ||
} | ||
return 0d; | ||
} | ||
|
||
|
||
|
||
} |
30 changes: 30 additions & 0 deletions
30
common/core/src/main/java/zingg/common/core/similarity/function/CheckNullFunctionLong.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
public class CheckNullFunctionLong extends SimFunction<Long> { | ||
|
||
private static final long serialVersionUID = 1L; | ||
public static final Log LOG = LogFactory | ||
.getLog(CheckNullFunctionLong.class); | ||
|
||
public CheckNullFunctionLong() { | ||
super("CheckNullFunctionLong"); | ||
} | ||
|
||
public CheckNullFunctionLong(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public Double call(Long first, Long second) { | ||
if (first != null && second != null) { | ||
return 1d; | ||
} | ||
return 0d; | ||
} | ||
|
||
|
||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...core/src/main/java/zingg/common/core/similarity/function/DateSimilarityFunctionExact.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import java.util.Date; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
public class DateSimilarityFunctionExact extends SimFunction<Date> { | ||
private static final long serialVersionUID = 1L; | ||
public static final Log LOG = LogFactory | ||
.getLog(DateSimilarityFunctionExact.class); | ||
|
||
public DateSimilarityFunctionExact() { | ||
super("DateSimilarityFunctionExact"); | ||
} | ||
|
||
@Override | ||
public Double call(Date first, Date second) { | ||
if (first == null || second == null) return 1d; | ||
double score = first.equals(second) ? 1d : 0d; | ||
return score; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...e/src/main/java/zingg/common/core/similarity/function/IntegerSimilarityFunctionExact.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
public class IntegerSimilarityFunctionExact extends SimFunction<Integer> { | ||
private static final long serialVersionUID = 1L; | ||
public static final Log LOG = LogFactory | ||
.getLog(IntegerSimilarityFunctionExact.class); | ||
|
||
public IntegerSimilarityFunctionExact() { | ||
super("IntegerSimilarityFunctionExact"); | ||
} | ||
|
||
@Override | ||
public Double call(Integer first, Integer second) { | ||
if (first == null || second == null) return 1d; | ||
double score = first==second ? 1d : 0d; | ||
return score; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...core/src/main/java/zingg/common/core/similarity/function/LongSimilarityFunctionExact.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
public class LongSimilarityFunctionExact extends SimFunction<Long> { | ||
private static final long serialVersionUID = 1L; | ||
public static final Log LOG = LogFactory | ||
.getLog(LongSimilarityFunctionExact.class); | ||
|
||
public LongSimilarityFunctionExact() { | ||
super("LongSimilarityFunctionExact"); | ||
} | ||
|
||
@Override | ||
public Double call(Long first, Long second) { | ||
if (first == null || second == null) return 1d; | ||
double score = first==second ? 1d : 0d; | ||
return score; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...n/core/src/test/java/zingg/common/core/similarity/function/TestCheckNullFunctionDate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Date; | ||
|
||
import org.junit.jupiter.api.Test; | ||
public class TestCheckNullFunctionDate { | ||
|
||
|
||
@Test | ||
public void testFirstNull() { | ||
CheckNullFunctionDate isNull = new CheckNullFunctionDate(); | ||
assertEquals(0d, isNull.call(null, new Date(2))); | ||
} | ||
|
||
|
||
@Test | ||
public void testSecondNull() { | ||
CheckNullFunctionDate isNull = new CheckNullFunctionDate(); | ||
assertEquals(0d, isNull.call(new Date(1), null)); | ||
} | ||
|
||
@Test | ||
public void testBothNull() { | ||
CheckNullFunctionDate isNull = new CheckNullFunctionDate(); | ||
assertEquals(0d, isNull.call(null, null)); | ||
} | ||
|
||
@Test | ||
public void testBothNotNull() { | ||
CheckNullFunctionDate isNull = new CheckNullFunctionDate(); | ||
assertEquals(1d, isNull.call(new Date(1), new Date(2))); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...on/core/src/test/java/zingg/common/core/similarity/function/TestCheckNullFunctionInt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestCheckNullFunctionInt { | ||
|
||
|
||
@Test | ||
public void testFirstNull() { | ||
CheckNullFunctionInt isNull = new CheckNullFunctionInt(); | ||
assertEquals(0d, isNull.call(null, 2)); | ||
} | ||
|
||
|
||
@Test | ||
public void testSecondNull() { | ||
CheckNullFunctionInt isNull = new CheckNullFunctionInt(); | ||
assertEquals(0d, isNull.call(1, null)); | ||
} | ||
|
||
@Test | ||
public void testBothNull() { | ||
CheckNullFunctionInt isNull = new CheckNullFunctionInt(); | ||
assertEquals(0d, isNull.call(null, null)); | ||
} | ||
|
||
@Test | ||
public void testBothNotNull() { | ||
CheckNullFunctionInt isNull = new CheckNullFunctionInt(); | ||
assertEquals(1d, isNull.call(1, 2)); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...n/core/src/test/java/zingg/common/core/similarity/function/TestCheckNullFunctionLong.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestCheckNullFunctionLong { | ||
|
||
|
||
@Test | ||
public void testFirstNull() { | ||
CheckNullFunctionLong isNull = new CheckNullFunctionLong(); | ||
assertEquals(0d, isNull.call(null, 2l)); | ||
} | ||
|
||
|
||
@Test | ||
public void testSecondNull() { | ||
CheckNullFunctionLong isNull = new CheckNullFunctionLong(); | ||
assertEquals(0d, isNull.call(1l, null)); | ||
} | ||
|
||
@Test | ||
public void testBothNull() { | ||
CheckNullFunctionLong isNull = new CheckNullFunctionLong(); | ||
assertEquals(0d, isNull.call(null, null)); | ||
} | ||
|
||
@Test | ||
public void testBothNotNull() { | ||
CheckNullFunctionLong isNull = new CheckNullFunctionLong(); | ||
assertEquals(1d, isNull.call(1l, 2l)); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
.../src/test/java/zingg/common/core/similarity/function/TestDateSimilarityFunctionExact.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package zingg.common.core.similarity.function; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Date; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestDateSimilarityFunctionExact { | ||
|
||
|
||
@Test | ||
public void testFirstNull() { | ||
DateSimilarityFunctionExact exact = new DateSimilarityFunctionExact(); | ||
assertEquals(1d, exact.call(null, new Date(2))); | ||
} | ||
|
||
|
||
@Test | ||
public void testSecondNull() { | ||
DateSimilarityFunctionExact exact = new DateSimilarityFunctionExact(); | ||
assertEquals(1d, exact.call(new Date(1), null)); | ||
} | ||
|
||
@Test | ||
public void testBothNull() { | ||
DateSimilarityFunctionExact exact = new DateSimilarityFunctionExact(); | ||
assertEquals(1d, exact.call(null, null)); | ||
} | ||
|
||
@Test | ||
public void testNotEqual() { | ||
DateSimilarityFunctionExact exact = new DateSimilarityFunctionExact(); | ||
assertEquals(0d, exact.call(new Date(101), new Date(102))); | ||
} | ||
|
||
@Test | ||
public void testEqual() { | ||
DateSimilarityFunctionExact exact = new DateSimilarityFunctionExact(); | ||
assertEquals(1d, exact.call(new Date(101), new Date(101))); | ||
} | ||
|
||
} |
Oops, something went wrong.