cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r915564 - in /incubator/cassandra/branches/cassandra-0.5: src/java/org/apache/cassandra/dht/ test/unit/org/apache/cassandra/dht/
Date Tue, 23 Feb 2010 22:45:03 GMT
Author: eevans
Date: Tue Feb 23 22:45:03 2010
New Revision: 915564

URL: http://svn.apache.org/viewvc?rev=915564&view=rev
Log:
add missing licensing headers

Modified:
    incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/dht/AbstractBounds.java
    incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/dht/Bounds.java
    incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/dht/BoundsTest.java
    incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/dht/RangeIntersectionTest.java

Modified: incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/dht/AbstractBounds.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/dht/AbstractBounds.java?rev=915564&r1=915563&r2=915564&view=diff
==============================================================================
--- incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/dht/AbstractBounds.java
(original)
+++ incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/dht/AbstractBounds.java
Tue Feb 23 22:45:03 2010
@@ -1,71 +1,92 @@
-package org.apache.cassandra.dht;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.cassandra.io.ICompactSerializer2;
-
-public abstract class AbstractBounds implements Serializable
-{
-    private static AbstractBoundsSerializer serializer = new AbstractBoundsSerializer();
-
-    public static ICompactSerializer2<AbstractBounds> serializer()
-    {
-        return serializer;
-    }
-
-    private enum Type
-    {
-        RANGE,
-        BOUNDS
-    }
-
-    public final Token left;
-    public final Token right;
-
-    protected transient final IPartitioner partitioner;
-
-    public AbstractBounds(Token left, Token right, IPartitioner partitioner)
-    {
-        this.left = left;
-        this.right = right;
-        this.partitioner = partitioner;
-    }
-
-    @Override
-    public int hashCode()
-    {
-        return toString().hashCode();
-    }
-
-    @Override
-    public abstract boolean equals(Object obj);
-
-    public abstract boolean contains(Token start);
-
-    public abstract Set<AbstractBounds> restrictTo(Range range);
-
-    public abstract List<AbstractBounds> unwrap();
-
-    private static class AbstractBoundsSerializer implements ICompactSerializer2<AbstractBounds>
-    {
-        public void serialize(AbstractBounds range, DataOutput out) throws IOException
-        {
-            out.writeInt(range instanceof Range ? Type.RANGE.ordinal() : Type.BOUNDS.ordinal());
-            Token.serializer().serialize(range.left, out);
-            Token.serializer().serialize(range.right, out);
-        }
-
-        public AbstractBounds deserialize(DataInput in) throws IOException
-        {
-            if (in.readInt() == Type.RANGE.ordinal())
-                return new Range(Token.serializer().deserialize(in), Token.serializer().deserialize(in));
-            return new Bounds(Token.serializer().deserialize(in), Token.serializer().deserialize(in));
-        }
-    }
-}
-
+package org.apache.cassandra.dht;
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ * 
+ */
+
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.cassandra.io.ICompactSerializer2;
+
+public abstract class AbstractBounds implements Serializable
+{
+    private static AbstractBoundsSerializer serializer = new AbstractBoundsSerializer();
+
+    public static ICompactSerializer2<AbstractBounds> serializer()
+    {
+        return serializer;
+    }
+
+    private enum Type
+    {
+        RANGE,
+        BOUNDS
+    }
+
+    public final Token left;
+    public final Token right;
+
+    protected transient final IPartitioner partitioner;
+
+    public AbstractBounds(Token left, Token right, IPartitioner partitioner)
+    {
+        this.left = left;
+        this.right = right;
+        this.partitioner = partitioner;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return toString().hashCode();
+    }
+
+    @Override
+    public abstract boolean equals(Object obj);
+
+    public abstract boolean contains(Token start);
+
+    public abstract Set<AbstractBounds> restrictTo(Range range);
+
+    public abstract List<AbstractBounds> unwrap();
+
+    private static class AbstractBoundsSerializer implements ICompactSerializer2<AbstractBounds>
+    {
+        public void serialize(AbstractBounds range, DataOutput out) throws IOException
+        {
+            out.writeInt(range instanceof Range ? Type.RANGE.ordinal() : Type.BOUNDS.ordinal());
+            Token.serializer().serialize(range.left, out);
+            Token.serializer().serialize(range.right, out);
+        }
+
+        public AbstractBounds deserialize(DataInput in) throws IOException
+        {
+            if (in.readInt() == Type.RANGE.ordinal())
+                return new Range(Token.serializer().deserialize(in), Token.serializer().deserialize(in));
+            return new Bounds(Token.serializer().deserialize(in), Token.serializer().deserialize(in));
+        }
+    }
+}
+

Modified: incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/dht/Bounds.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/dht/Bounds.java?rev=915564&r1=915563&r2=915564&view=diff
==============================================================================
--- incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/dht/Bounds.java
(original)
+++ incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/dht/Bounds.java
Tue Feb 23 22:45:03 2010
@@ -1,73 +1,94 @@
-package org.apache.cassandra.dht;
-
-import java.util.*;
-
-import org.apache.cassandra.service.StorageService;
-
-public class Bounds extends AbstractBounds
-{
-    public Bounds(Token left, Token right)
-    {
-        this(left, right, StorageService.getPartitioner());
-    }
-
-    Bounds(Token left, Token right, IPartitioner partitioner)
-    {
-        super(left, right, partitioner);
-        // unlike a Range, a Bounds may not wrap
-        assert left.compareTo(right) <= 0 || right.equals(partitioner.getMinimumToken())
: "[" + left + "," + right + "]";
-    }
-
-    @Override
-    public boolean contains(Token token)
-    {
-        return Range.contains(left, right, token) || left.equals(token);
-    }
-
-    public Set<AbstractBounds> restrictTo(Range range)
-    {
-        Token min = partitioner.getMinimumToken();
-
-        // special case Bounds where left=right (single Token)
-        if (this.left.equals(this.right) && !this.right.equals(min))
-            return range.contains(this.left)
-                   ? Collections.unmodifiableSet(new HashSet<AbstractBounds>(Arrays.asList(this)))
-                   : Collections.<AbstractBounds>emptySet();
-
-        // get the intersection of a Range w/ same left & right
-        Set<Range> ranges = range.intersectionWith(new Range(this.left, this.right));
-        // if range doesn't contain left token anyway, that's the correct answer
-        if (!range.contains(this.left))
-            return (Set) ranges;
-        // otherwise, add back in the left token
-        Set<AbstractBounds> S = new HashSet<AbstractBounds>(ranges.size());
-        for (Range restricted : ranges)
-        {
-            if (restricted.left.equals(this.left))
-                S.add(new Bounds(restricted.left, restricted.right));
-            else
-                S.add(restricted);
-        }
-        return Collections.unmodifiableSet(S);
-    }
-
-    public List<AbstractBounds> unwrap()
-    {
-        // Bounds objects never wrap
-        return (List)Arrays.asList(this);
-    }
-
-    @Override
-    public boolean equals(Object o)
-    {
-        if (!(o instanceof Bounds))
-            return false;
-        Bounds rhs = (Bounds)o;
-        return left.equals(rhs.left) && right.equals(rhs.right);
-    }
-
-    public String toString()
-    {
-        return "[" + left + "," + right + "]";
-    }
-}
+package org.apache.cassandra.dht;
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ * 
+ */
+
+
+import java.util.*;
+
+import org.apache.cassandra.service.StorageService;
+
+public class Bounds extends AbstractBounds
+{
+    public Bounds(Token left, Token right)
+    {
+        this(left, right, StorageService.getPartitioner());
+    }
+
+    Bounds(Token left, Token right, IPartitioner partitioner)
+    {
+        super(left, right, partitioner);
+        // unlike a Range, a Bounds may not wrap
+        assert left.compareTo(right) <= 0 || right.equals(partitioner.getMinimumToken())
: "[" + left + "," + right + "]";
+    }
+
+    @Override
+    public boolean contains(Token token)
+    {
+        return Range.contains(left, right, token) || left.equals(token);
+    }
+
+    public Set<AbstractBounds> restrictTo(Range range)
+    {
+        Token min = partitioner.getMinimumToken();
+
+        // special case Bounds where left=right (single Token)
+        if (this.left.equals(this.right) && !this.right.equals(min))
+            return range.contains(this.left)
+                   ? Collections.unmodifiableSet(new HashSet<AbstractBounds>(Arrays.asList(this)))
+                   : Collections.<AbstractBounds>emptySet();
+
+        // get the intersection of a Range w/ same left & right
+        Set<Range> ranges = range.intersectionWith(new Range(this.left, this.right));
+        // if range doesn't contain left token anyway, that's the correct answer
+        if (!range.contains(this.left))
+            return (Set) ranges;
+        // otherwise, add back in the left token
+        Set<AbstractBounds> S = new HashSet<AbstractBounds>(ranges.size());
+        for (Range restricted : ranges)
+        {
+            if (restricted.left.equals(this.left))
+                S.add(new Bounds(restricted.left, restricted.right));
+            else
+                S.add(restricted);
+        }
+        return Collections.unmodifiableSet(S);
+    }
+
+    public List<AbstractBounds> unwrap()
+    {
+        // Bounds objects never wrap
+        return (List)Arrays.asList(this);
+    }
+
+    @Override
+    public boolean equals(Object o)
+    {
+        if (!(o instanceof Bounds))
+            return false;
+        Bounds rhs = (Bounds)o;
+        return left.equals(rhs.left) && right.equals(rhs.right);
+    }
+
+    public String toString()
+    {
+        return "[" + left + "," + right + "]";
+    }
+}

Modified: incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/dht/BoundsTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/dht/BoundsTest.java?rev=915564&r1=915563&r2=915564&view=diff
==============================================================================
--- incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/dht/BoundsTest.java
(original)
+++ incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/dht/BoundsTest.java
Tue Feb 23 22:45:03 2010
@@ -1,73 +1,94 @@
-package org.apache.cassandra.dht;
-
-import java.util.*;
-
-import junit.framework.TestCase;
-import org.apache.cassandra.utils.FBUtilities;
-
-public class BoundsTest extends TestCase
-{
-    public void testRestrictTo() throws Exception
-    {
-        IPartitioner p = new OrderPreservingPartitioner();
-        Token min = p.getMinimumToken();
-        Range wraps = new Range(new StringToken("m"), new StringToken("e"));
-        Range normal = new Range(wraps.right, wraps.left);
-        Bounds all = new Bounds(min, min, p);
-        Bounds almostAll = new Bounds(new StringToken("a"), min, p);
-
-        Set<AbstractBounds> S;
-        Set<AbstractBounds> S2;
-
-        S = all.restrictTo(wraps);
-        assert S.equals(new HashSet<AbstractBounds>(Arrays.asList(wraps)));
-
-        S = almostAll.restrictTo(wraps);
-        S2 = new HashSet<AbstractBounds>(Arrays.asList(new Bounds(new StringToken("a"),
new StringToken("e"), p),
-                                                       new Range(new StringToken("m"), min)));
-        assert S.equals(S2);
-
-        S = all.restrictTo(normal);
-        assert S.equals(new HashSet<AbstractBounds>(Arrays.asList(normal)));
-    }
-
-    public void testNoIntersectionWrapped()
-    {
-        IPartitioner p = new OrderPreservingPartitioner();
-        Range node = new Range(new StringToken("z"), new StringToken("a"));
-        Bounds bounds;
-
-        bounds = new Bounds(new StringToken("m"), new StringToken("n"), p);
-        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
-
-        bounds = new Bounds(new StringToken("b"), node.left, p);
-        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
-    }
-
-    public void testSmallBoundsFullRange()
-    {
-        IPartitioner p = new OrderPreservingPartitioner();
-        Range node;
-        Bounds bounds = new Bounds(new StringToken("b"), new StringToken("c"), p);
-
-        node = new Range(new StringToken("d"), new StringToken("d"));
-        assert bounds.restrictTo(node).equals(new HashSet(Arrays.asList(bounds)));
-    }
-
-    public void testNoIntersectionUnwrapped()
-    {
-        IPartitioner p = new OrderPreservingPartitioner();
-        Token min = p.getMinimumToken();
-        Range node = new Range(new StringToken("m"), new StringToken("n"));
-        Bounds bounds;
-
-        bounds = new Bounds(new StringToken("z"), min, p);
-        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
-
-        bounds = new Bounds(new StringToken("a"), node.left, p);
-        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
-
-        bounds = new Bounds(min, new StringToken("b"), p);
-        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
-    }
-}
+package org.apache.cassandra.dht;
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ * 
+ */
+
+
+import java.util.*;
+
+import junit.framework.TestCase;
+import org.apache.cassandra.utils.FBUtilities;
+
+public class BoundsTest extends TestCase
+{
+    public void testRestrictTo() throws Exception
+    {
+        IPartitioner p = new OrderPreservingPartitioner();
+        Token min = p.getMinimumToken();
+        Range wraps = new Range(new StringToken("m"), new StringToken("e"));
+        Range normal = new Range(wraps.right, wraps.left);
+        Bounds all = new Bounds(min, min, p);
+        Bounds almostAll = new Bounds(new StringToken("a"), min, p);
+
+        Set<AbstractBounds> S;
+        Set<AbstractBounds> S2;
+
+        S = all.restrictTo(wraps);
+        assert S.equals(new HashSet<AbstractBounds>(Arrays.asList(wraps)));
+
+        S = almostAll.restrictTo(wraps);
+        S2 = new HashSet<AbstractBounds>(Arrays.asList(new Bounds(new StringToken("a"),
new StringToken("e"), p),
+                                                       new Range(new StringToken("m"), min)));
+        assert S.equals(S2);
+
+        S = all.restrictTo(normal);
+        assert S.equals(new HashSet<AbstractBounds>(Arrays.asList(normal)));
+    }
+
+    public void testNoIntersectionWrapped()
+    {
+        IPartitioner p = new OrderPreservingPartitioner();
+        Range node = new Range(new StringToken("z"), new StringToken("a"));
+        Bounds bounds;
+
+        bounds = new Bounds(new StringToken("m"), new StringToken("n"), p);
+        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
+
+        bounds = new Bounds(new StringToken("b"), node.left, p);
+        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
+    }
+
+    public void testSmallBoundsFullRange()
+    {
+        IPartitioner p = new OrderPreservingPartitioner();
+        Range node;
+        Bounds bounds = new Bounds(new StringToken("b"), new StringToken("c"), p);
+
+        node = new Range(new StringToken("d"), new StringToken("d"));
+        assert bounds.restrictTo(node).equals(new HashSet(Arrays.asList(bounds)));
+    }
+
+    public void testNoIntersectionUnwrapped()
+    {
+        IPartitioner p = new OrderPreservingPartitioner();
+        Token min = p.getMinimumToken();
+        Range node = new Range(new StringToken("m"), new StringToken("n"));
+        Bounds bounds;
+
+        bounds = new Bounds(new StringToken("z"), min, p);
+        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
+
+        bounds = new Bounds(new StringToken("a"), node.left, p);
+        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
+
+        bounds = new Bounds(min, new StringToken("b"), p);
+        assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
+    }
+}

Modified: incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/dht/RangeIntersectionTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/dht/RangeIntersectionTest.java?rev=915564&r1=915563&r2=915564&view=diff
==============================================================================
--- incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/dht/RangeIntersectionTest.java
(original)
+++ incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/dht/RangeIntersectionTest.java
Tue Feb 23 22:45:03 2010
@@ -1,131 +1,152 @@
-package org.apache.cassandra.dht;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.commons.lang.StringUtils;
-import org.junit.Test;
-
-public class RangeIntersectionTest
-{
-    static void assertIntersection(Range one, Range two, Range ... ranges)
-    {
-        Set<Range> correct = Range.rangeSet(ranges);
-        Set<Range> result1 = one.intersectionWith(two);
-        assert result1.equals(correct) : String.format("%s != %s",
-                                                       StringUtils.join(result1, ","),
-                                                       StringUtils.join(correct, ","));
-        Set<Range> result2 = two.intersectionWith(one);
-        assert result2.equals(correct) : String.format("%s != %s",
-                                                       StringUtils.join(result2, ","),
-                                                       StringUtils.join(correct, ","));
-    }
-
-    private void assertNoIntersection(Range wraps1, Range nowrap3)
-    {
-        assertIntersection(wraps1, nowrap3);
-    }
-
-    @Test
-    public void testIntersectionWithAll()
-    {
-        Range all0 = new Range(new BigIntegerToken("0"), new BigIntegerToken("0"));
-        Range all10 = new Range(new BigIntegerToken("10"), new BigIntegerToken("10"));
-        Range all100 = new Range(new BigIntegerToken("100"), new BigIntegerToken("100"));
-        Range all1000 = new Range(new BigIntegerToken("1000"), new BigIntegerToken("1000"));
-        Range wraps = new Range(new BigIntegerToken("100"), new BigIntegerToken("10"));
-
-        assertIntersection(all0, wraps, wraps);
-        assertIntersection(all10, wraps, wraps);
-        assertIntersection(all100, wraps, wraps);
-        assertIntersection(all1000, wraps, wraps);
-    }
-
-    @Test
-    public void testIntersectionContains()
-    {
-        Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("10"));
-        Range wraps2 = new Range(new BigIntegerToken("90"), new BigIntegerToken("20"));
-        Range wraps3 = new Range(new BigIntegerToken("90"), new BigIntegerToken("0"));
-        Range nowrap1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("110"));
-        Range nowrap2 = new Range(new BigIntegerToken("0"), new BigIntegerToken("10"));
-        Range nowrap3 = new Range(new BigIntegerToken("0"), new BigIntegerToken("9"));
-
-        assertIntersection(wraps1, wraps2, wraps1);
-        assertIntersection(wraps3, wraps2, wraps3);
-
-        assertIntersection(wraps1, nowrap1, nowrap1);
-        assertIntersection(wraps1, nowrap2, nowrap2);
-        assertIntersection(nowrap2, nowrap3, nowrap3);
-
-        assertIntersection(wraps1, wraps1, wraps1);
-        assertIntersection(nowrap1, nowrap1, nowrap1);
-        assertIntersection(nowrap2, nowrap2, nowrap2);
-        assertIntersection(wraps3, wraps3, wraps3);
-    }
-
-    @Test
-    public void testNoIntersection()
-    {
-        Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("10"));
-        Range wraps2 = new Range(new BigIntegerToken("100"), new BigIntegerToken("0"));
-        Range nowrap1 = new Range(new BigIntegerToken("0"), new BigIntegerToken("100"));
-        Range nowrap2 = new Range(new BigIntegerToken("100"), new BigIntegerToken("200"));
-        Range nowrap3 = new Range(new BigIntegerToken("10"), new BigIntegerToken("100"));
-
-        assertNoIntersection(wraps1, nowrap3);
-        assertNoIntersection(wraps2, nowrap1);
-        assertNoIntersection(nowrap1, nowrap2);
-    }
-
-    @Test
-    public void testIntersectionOneWraps()
-    {
-        Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("10"));
-        Range wraps2 = new Range(new BigIntegerToken("100"), new BigIntegerToken("0"));
-        Range nowrap1 = new Range(new BigIntegerToken("0"), new BigIntegerToken("200"));
-        Range nowrap2 = new Range(new BigIntegerToken("0"), new BigIntegerToken("100"));
-
-        assertIntersection(wraps1,
-                           nowrap1,
-                           new Range(new BigIntegerToken("0"), new BigIntegerToken("10")),
-                           new Range(new BigIntegerToken("100"), new BigIntegerToken("200")));
-        assertIntersection(wraps2,
-                           nowrap1,
-                           new Range(new BigIntegerToken("100"), new BigIntegerToken("200")));
-        assertIntersection(wraps1,
-                           nowrap2,
-                           new Range(new BigIntegerToken("0"), new BigIntegerToken("10")));
-    }
-
-    @Test
-    public void testIntersectionTwoWraps()
-    {
-        Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("20"));
-        Range wraps2 = new Range(new BigIntegerToken("120"), new BigIntegerToken("90"));
-        Range wraps3 = new Range(new BigIntegerToken("120"), new BigIntegerToken("110"));
-        Range wraps4 = new Range(new BigIntegerToken("10"), new BigIntegerToken("0"));
-        Range wraps5 = new Range(new BigIntegerToken("10"), new BigIntegerToken("1"));
-        Range wraps6 = new Range(new BigIntegerToken("30"), new BigIntegerToken("10"));
-
-        assertIntersection(wraps1,
-                           wraps2,
-                           new Range(new BigIntegerToken("120"), new BigIntegerToken("20")));
-        assertIntersection(wraps1,
-                           wraps3,
-                           new Range(new BigIntegerToken("120"), new BigIntegerToken("20")),
-                           new Range(new BigIntegerToken("100"), new BigIntegerToken("110")));
-        assertIntersection(wraps1,
-                           wraps4,
-                           new Range(new BigIntegerToken("10"), new BigIntegerToken("20")),
-                           new Range(new BigIntegerToken("100"), new BigIntegerToken("0")));
-        assertIntersection(wraps1,
-                           wraps5,
-                           new Range(new BigIntegerToken("10"), new BigIntegerToken("20")),
-                           new Range(new BigIntegerToken("100"), new BigIntegerToken("1")));
-        assertIntersection(wraps1,
-                           wraps6,
-                           new Range(new BigIntegerToken("100"), new BigIntegerToken("10")));
-    }
-}
+package org.apache.cassandra.dht;
+/*
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ * 
+ */
+
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
+import org.junit.Test;
+
+public class RangeIntersectionTest
+{
+    static void assertIntersection(Range one, Range two, Range ... ranges)
+    {
+        Set<Range> correct = Range.rangeSet(ranges);
+        Set<Range> result1 = one.intersectionWith(two);
+        assert result1.equals(correct) : String.format("%s != %s",
+                                                       StringUtils.join(result1, ","),
+                                                       StringUtils.join(correct, ","));
+        Set<Range> result2 = two.intersectionWith(one);
+        assert result2.equals(correct) : String.format("%s != %s",
+                                                       StringUtils.join(result2, ","),
+                                                       StringUtils.join(correct, ","));
+    }
+
+    private void assertNoIntersection(Range wraps1, Range nowrap3)
+    {
+        assertIntersection(wraps1, nowrap3);
+    }
+
+    @Test
+    public void testIntersectionWithAll()
+    {
+        Range all0 = new Range(new BigIntegerToken("0"), new BigIntegerToken("0"));
+        Range all10 = new Range(new BigIntegerToken("10"), new BigIntegerToken("10"));
+        Range all100 = new Range(new BigIntegerToken("100"), new BigIntegerToken("100"));
+        Range all1000 = new Range(new BigIntegerToken("1000"), new BigIntegerToken("1000"));
+        Range wraps = new Range(new BigIntegerToken("100"), new BigIntegerToken("10"));
+
+        assertIntersection(all0, wraps, wraps);
+        assertIntersection(all10, wraps, wraps);
+        assertIntersection(all100, wraps, wraps);
+        assertIntersection(all1000, wraps, wraps);
+    }
+
+    @Test
+    public void testIntersectionContains()
+    {
+        Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("10"));
+        Range wraps2 = new Range(new BigIntegerToken("90"), new BigIntegerToken("20"));
+        Range wraps3 = new Range(new BigIntegerToken("90"), new BigIntegerToken("0"));
+        Range nowrap1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("110"));
+        Range nowrap2 = new Range(new BigIntegerToken("0"), new BigIntegerToken("10"));
+        Range nowrap3 = new Range(new BigIntegerToken("0"), new BigIntegerToken("9"));
+
+        assertIntersection(wraps1, wraps2, wraps1);
+        assertIntersection(wraps3, wraps2, wraps3);
+
+        assertIntersection(wraps1, nowrap1, nowrap1);
+        assertIntersection(wraps1, nowrap2, nowrap2);
+        assertIntersection(nowrap2, nowrap3, nowrap3);
+
+        assertIntersection(wraps1, wraps1, wraps1);
+        assertIntersection(nowrap1, nowrap1, nowrap1);
+        assertIntersection(nowrap2, nowrap2, nowrap2);
+        assertIntersection(wraps3, wraps3, wraps3);
+    }
+
+    @Test
+    public void testNoIntersection()
+    {
+        Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("10"));
+        Range wraps2 = new Range(new BigIntegerToken("100"), new BigIntegerToken("0"));
+        Range nowrap1 = new Range(new BigIntegerToken("0"), new BigIntegerToken("100"));
+        Range nowrap2 = new Range(new BigIntegerToken("100"), new BigIntegerToken("200"));
+        Range nowrap3 = new Range(new BigIntegerToken("10"), new BigIntegerToken("100"));
+
+        assertNoIntersection(wraps1, nowrap3);
+        assertNoIntersection(wraps2, nowrap1);
+        assertNoIntersection(nowrap1, nowrap2);
+    }
+
+    @Test
+    public void testIntersectionOneWraps()
+    {
+        Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("10"));
+        Range wraps2 = new Range(new BigIntegerToken("100"), new BigIntegerToken("0"));
+        Range nowrap1 = new Range(new BigIntegerToken("0"), new BigIntegerToken("200"));
+        Range nowrap2 = new Range(new BigIntegerToken("0"), new BigIntegerToken("100"));
+
+        assertIntersection(wraps1,
+                           nowrap1,
+                           new Range(new BigIntegerToken("0"), new BigIntegerToken("10")),
+                           new Range(new BigIntegerToken("100"), new BigIntegerToken("200")));
+        assertIntersection(wraps2,
+                           nowrap1,
+                           new Range(new BigIntegerToken("100"), new BigIntegerToken("200")));
+        assertIntersection(wraps1,
+                           nowrap2,
+                           new Range(new BigIntegerToken("0"), new BigIntegerToken("10")));
+    }
+
+    @Test
+    public void testIntersectionTwoWraps()
+    {
+        Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("20"));
+        Range wraps2 = new Range(new BigIntegerToken("120"), new BigIntegerToken("90"));
+        Range wraps3 = new Range(new BigIntegerToken("120"), new BigIntegerToken("110"));
+        Range wraps4 = new Range(new BigIntegerToken("10"), new BigIntegerToken("0"));
+        Range wraps5 = new Range(new BigIntegerToken("10"), new BigIntegerToken("1"));
+        Range wraps6 = new Range(new BigIntegerToken("30"), new BigIntegerToken("10"));
+
+        assertIntersection(wraps1,
+                           wraps2,
+                           new Range(new BigIntegerToken("120"), new BigIntegerToken("20")));
+        assertIntersection(wraps1,
+                           wraps3,
+                           new Range(new BigIntegerToken("120"), new BigIntegerToken("20")),
+                           new Range(new BigIntegerToken("100"), new BigIntegerToken("110")));
+        assertIntersection(wraps1,
+                           wraps4,
+                           new Range(new BigIntegerToken("10"), new BigIntegerToken("20")),
+                           new Range(new BigIntegerToken("100"), new BigIntegerToken("0")));
+        assertIntersection(wraps1,
+                           wraps5,
+                           new Range(new BigIntegerToken("10"), new BigIntegerToken("20")),
+                           new Range(new BigIntegerToken("100"), new BigIntegerToken("1")));
+        assertIntersection(wraps1,
+                           wraps6,
+                           new Range(new BigIntegerToken("100"), new BigIntegerToken("10")));
+    }
+}



Mime
View raw message