diff --git a/prj/coherence-core/src/main/java/com/tangosol/util/filter/InFilter.java b/prj/coherence-core/src/main/java/com/tangosol/util/filter/InFilter.java index 6236ec3aa9ff8..2be91f512a5fd 100644 --- a/prj/coherence-core/src/main/java/com/tangosol/util/filter/InFilter.java +++ b/prj/coherence-core/src/main/java/com/tangosol/util/filter/InFilter.java @@ -106,8 +106,33 @@ public String toStringValue() public int calculateEffectiveness(Map mapIndexes, Set setKeys) { MapIndex index = (MapIndex) mapIndexes.get(getValueExtractor()); - return index == null ? calculateIteratorEffectiveness(setKeys.size()) - : ((Collection) getValue()).size(); + if (index == null) + { + // there is no relevant index + return -1; + } + else + { + // calculating the exact number of keys retained is too expensive; + // ignore the fact that there may be duplicates and simply return + // the worst possible number of keys retained, as if they were unique + + Collection colValues = getValue(); + Map mapContents = index.getIndexContents(); + int cMatch = 0; + + for (Object oValue : colValues) + { + Set setEQ = (Set) mapContents.get(oValue); + + if (setEQ != null) + { + cMatch += setEQ.size(); + } + } + + return Math.min(cMatch, setKeys.size()); + } } /** diff --git a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/AllFilterTest.java b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/AllFilterTest.java index 1dfaa45f33c6b..732fc59a732eb 100644 --- a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/AllFilterTest.java +++ b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/AllFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2023, Oracle and/or its affiliates. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. * * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. @@ -41,7 +41,7 @@ public AllFilterTest(boolean fOrdered, boolean fPartial) m_fPartial = fPartial; } - @Parameterized.Parameters + @Parameterized.Parameters(name ="ordered={0} partial={1}") public static Collection data() { Object[][] data = new Object[][] { new Object[] {Boolean.FALSE, Boolean.FALSE}, @@ -86,6 +86,8 @@ public void testApplyIndex() } // begin test + assertEquals(3, filter.calculateEffectiveness(mapIndexes, setKeys)); + filter.applyIndex(mapIndexes, setKeys); assertEquals("Two keys should remain in the set of keys.", diff --git a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/AndFilterTest.java b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/AndFilterTest.java index 7990a46c109d4..822330c6fe326 100644 --- a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/AndFilterTest.java +++ b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/AndFilterTest.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2000, 2022, Oracle and/or its affiliates. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. * * Licensed under the Universal Permissive License v 1.0 as shown at - * http://oss.oracle.com/licenses/upl. + * https://oss.oracle.com/licenses/upl. */ package com.tangosol.util.filter; @@ -39,7 +39,7 @@ public AndFilterTest(boolean fOrdered, boolean fPartial) m_fPartial = fPartial; } - @Parameterized.Parameters + @Parameterized.Parameters(name ="ordered={0} partial={1}") public static Collection data() { Object[][] data = new Object[][] { new Object[] {Boolean.FALSE, Boolean.FALSE}, @@ -93,6 +93,8 @@ public void testApplyIndex() when(index.getIndexContents()).thenReturn(mapInverse); // begin test + assertEquals(3, filter.calculateEffectiveness(mapIndexes, setKeys)); + filter.applyIndex(mapIndexes, setKeys); assertEquals("Two keys should remain in the set of keys.", diff --git a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/AnyFilterTest.java b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/AnyFilterTest.java index 62c06704b7a20..ad2f737301ead 100644 --- a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/AnyFilterTest.java +++ b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/AnyFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2023, Oracle and/or its affiliates. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. * * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. @@ -39,7 +39,7 @@ public AnyFilterTest(boolean fOrdered, boolean fPartial) m_fPartial = fPartial; } - @Parameterized.Parameters + @Parameterized.Parameters(name ="ordered={0} partial={1}") public static Collection data() { Object[][] data = new Object[][] { new Object[] {Boolean.FALSE, Boolean.FALSE}, @@ -93,6 +93,8 @@ public void testApplyIndex() when(index.getIndexContents()).thenReturn(mapInverse); // begin test + assertEquals(2, filter.calculateEffectiveness(mapIndexes, setKeys)); + filter.applyIndex(mapIndexes, setKeys); assertEquals("Two keys should remain in the set of keys.", diff --git a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/ContainsAllFilterTest.java b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/ContainsAllFilterTest.java index 3153883c5e40a..028a91137199c 100644 --- a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/ContainsAllFilterTest.java +++ b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/ContainsAllFilterTest.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2000, 2022, Oracle and/or its affiliates. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. * * Licensed under the Universal Permissive License v 1.0 as shown at - * http://oss.oracle.com/licenses/upl. + * https://oss.oracle.com/licenses/upl. */ package com.tangosol.util.filter; @@ -39,7 +39,7 @@ public ContainsAllFilterTest(boolean fOrdered, boolean fPartial) m_fPartial = fPartial; } - @Parameterized.Parameters + @Parameterized.Parameters(name ="ordered={0} partial={1}") public static Collection data() { Object[][] data = new Object[][] { new Object[] {Boolean.FALSE, Boolean.FALSE}, @@ -94,6 +94,8 @@ public void testApplyIndex() when(index.getIndexContents()).thenReturn(mapInverse); // begin test + assertEquals(2, filter.calculateEffectiveness(mapIndexes, setKeys)); + filter.applyIndex(mapIndexes, setKeys); assertEquals(2, setKeys.size()); diff --git a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/ContainsAnyFilterTest.java b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/ContainsAnyFilterTest.java index 701ca6448817c..67c0b11f8feae 100644 --- a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/ContainsAnyFilterTest.java +++ b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/ContainsAnyFilterTest.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2000, 2022, Oracle and/or its affiliates. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. * * Licensed under the Universal Permissive License v 1.0 as shown at - * http://oss.oracle.com/licenses/upl. + * https://oss.oracle.com/licenses/upl. */ package com.tangosol.util.filter; @@ -39,7 +39,7 @@ public ContainsAnyFilterTest(boolean fOrdered, boolean fPartial) m_fPartial = fPartial; } - @Parameterized.Parameters + @Parameterized.Parameters(name ="ordered={0} partial={1}") public static Collection data() { Object[][] data = new Object[][] { new Object[] {Boolean.FALSE, Boolean.FALSE}, @@ -94,6 +94,8 @@ public void testApplyIndex() when(index.getIndexContents()).thenReturn(mapInverse); // begin test + assertEquals(6, filter.calculateEffectiveness(mapIndexes, setKeys)); + filter.applyIndex(mapIndexes, setKeys); assertEquals(4, setKeys.size()); diff --git a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/ContainsFilterTest.java b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/ContainsFilterTest.java index d36764f4261f3..87a039bc5ebf9 100644 --- a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/ContainsFilterTest.java +++ b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/ContainsFilterTest.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2000, 2022, Oracle and/or its affiliates. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. * * Licensed under the Universal Permissive License v 1.0 as shown at - * http://oss.oracle.com/licenses/upl. + * https://oss.oracle.com/licenses/upl. */ package com.tangosol.util.filter; @@ -39,7 +39,7 @@ public ContainsFilterTest(boolean fOrdered, boolean fPartial) m_fPartial = fPartial; } - @Parameterized.Parameters + @Parameterized.Parameters(name ="ordered={0} partial={1}") public static Collection data() { Object[][] data = new Object[][] { new Object[] {Boolean.FALSE, Boolean.FALSE}, @@ -94,6 +94,8 @@ public void testApplyIndex() when(index.getIndexContents()).thenReturn(mapInverse); // begin test + assertEquals(3, filter.calculateEffectiveness(mapIndexes, setKeys)); + filter.applyIndex(mapIndexes, setKeys); assertEquals(3, setKeys.size()); diff --git a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/EqualsFilterTest.java b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/EqualsFilterTest.java index 185697b67c5d0..06affad0a22ff 100644 --- a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/EqualsFilterTest.java +++ b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/EqualsFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2023, Oracle and/or its affiliates. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. * * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. @@ -47,7 +47,7 @@ public EqualsFilterTest(boolean fOrdered, boolean fPartial) m_fPartial = fPartial; } - @Parameterized.Parameters + @Parameterized.Parameters(name ="ordered={0} partial={1}") public static Collection data() { Object[][] data = new Object[][] { new Object[] {Boolean.FALSE, Boolean.FALSE}, @@ -99,6 +99,8 @@ public void testApplyIndex() when(index.getIndexContents()).thenReturn(mapInverse); // begin test + assertEquals(1, filter.calculateEffectiveness(mapIndexes, setKeys)); + filter.applyIndex(mapIndexes, setKeys); assertEquals("One key should remain in the set of keys.", diff --git a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/InFilterTest.java b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/InFilterTest.java index 3d9d60dafba95..8054597ebad70 100644 --- a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/InFilterTest.java +++ b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/InFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2023, Oracle and/or its affiliates. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. * * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. @@ -43,7 +43,7 @@ public InFilterTest(boolean fOrdered, boolean fPartial) m_fPartial = fPartial; } - @Parameterized.Parameters + @Parameterized.Parameters(name ="ordered={0} partial={1}") public static Collection data() { Object[][] data = new Object[][] { new Object[] {Boolean.FALSE, Boolean.FALSE}, @@ -93,6 +93,8 @@ public void testApplyIndex() // begin test Set setKeys = new HashSet<>(map.keySet()); + assertEquals(4, filter.calculateEffectiveness(mapIndexes, setKeys)); + filter.applyIndex(mapIndexes, setKeys); assertEquals(4, setKeys.size()); diff --git a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/KeyFilterTest.java b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/KeyFilterTest.java index 8e7c59fb10f45..bf466c657689d 100644 --- a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/KeyFilterTest.java +++ b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/KeyFilterTest.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2000, 2022, Oracle and/or its affiliates. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. * * Licensed under the Universal Permissive License v 1.0 as shown at - * http://oss.oracle.com/licenses/upl. + * https://oss.oracle.com/licenses/upl. */ package com.tangosol.util.filter; @@ -38,7 +38,7 @@ public KeyFilterTest(boolean fOrdered, boolean fPartial) m_fPartial = fPartial; } - @Parameterized.Parameters + @Parameterized.Parameters(name ="ordered={0} partial={1}") public static Collection data() { Object[][] data = new Object[][] { new Object[] {Boolean.FALSE, Boolean.FALSE}, @@ -90,6 +90,8 @@ public void testApplyIndex() when(index.getIndexContents()).thenReturn(mapInverse); // begin test + assertEquals(2, filter.calculateEffectiveness(mapIndexes, setKeys)); + filter.applyIndex(mapIndexes, setKeys); assertEquals("Two keys should remain in the set of keys.", diff --git a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/LikeFilterTest.java b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/LikeFilterTest.java index de9d8fe6064e5..07051dc08566a 100644 --- a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/LikeFilterTest.java +++ b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/LikeFilterTest.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2000, 2022, Oracle and/or its affiliates. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. * * Licensed under the Universal Permissive License v 1.0 as shown at - * http://oss.oracle.com/licenses/upl. + * https://oss.oracle.com/licenses/upl. */ package com.tangosol.util.filter; @@ -39,7 +39,7 @@ public LikeFilterTest(boolean fOrdered, boolean fPartial) m_fPartial = fPartial; } - @Parameterized.Parameters + @Parameterized.Parameters(name ="ordered={0} partial={1}") public static Collection data() { Object[][] data = new Object[][] { new Object[] {Boolean.FALSE, Boolean.FALSE}, @@ -106,6 +106,8 @@ public void testApplyIndex() when(index.getIndexContents()).thenReturn(mapInverse); // begin test + assertEquals(2, filter.calculateEffectiveness(mapIndexes, setKeys)); + filter.applyIndex(mapIndexes, setKeys); assertEquals("Two keys should remain in the set of keys.", diff --git a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/NotEqualsFilterTest.java b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/NotEqualsFilterTest.java index 976b2192ef04d..18ea626f8bf1a 100644 --- a/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/NotEqualsFilterTest.java +++ b/prj/test/unit/coherence-tests/src/test/java/com/tangosol/util/filter/NotEqualsFilterTest.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2000, 2022, Oracle and/or its affiliates. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. * * Licensed under the Universal Permissive License v 1.0 as shown at - * http://oss.oracle.com/licenses/upl. + * https://oss.oracle.com/licenses/upl. */ package com.tangosol.util.filter; @@ -38,7 +38,7 @@ public NotEqualsFilterTest(boolean fOrdered, boolean fPartial) m_fPartial = fPartial; } - @Parameterized.Parameters + @Parameterized.Parameters(name ="ordered={0} partial={1}") public static Collection data() { Object[][] data = new Object[][] { new Object[] {Boolean.FALSE, Boolean.FALSE}, @@ -89,6 +89,8 @@ public void testApplyIndex() when(index.getIndexContents()).thenReturn(mapInverse); // begin test + assertEquals(3 + (m_fPartial ? 4 : 0), filter.calculateEffectiveness(mapIndexes, setKeys)); + filter.applyIndex(mapIndexes, setKeys); assertEquals("One key should have been removed from the set of keys.",