You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by el...@apache.org on 2013/04/02 17:44:39 UTC
svn commit: r1463603 - in
/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src:
main/java/org/apache/mavibot/btree/store/
test/java/org/apache/mavibot/btree/comparator/
Author: elecharny
Date: Tue Apr 2 15:44:39 2013
New Revision: 1463603
URL: http://svn.apache.org/r1463603
Log:
Added the RevisionName class, and a comparator and its tests
Added:
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/store/RevisionName.java
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/store/RevisionNameComparator.java
labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/RevisionNameComparatorTest.java
Added: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/store/RevisionName.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/store/RevisionName.java?rev=1463603&view=auto
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/store/RevisionName.java (added)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/store/RevisionName.java Tue Apr 2 15:44:39 2013
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.mavibot.btree.store;
+
+
+/**
+ * A data structure that stores a revision associated to a BTree name. We use
+ * it to allow the access to old revisions.
+ *
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class RevisionName
+{
+ /** The revision number on the BTree */
+ private long revision;
+
+ /** The BTree name */
+ private String name;
+
+
+ /**
+ * A constructor for the RevisionName class
+ * @param revision The revision
+ * @param name The BTree name
+ */
+ public RevisionName( long revision, String name )
+ {
+ this.revision = revision;
+ this.name = name;
+ }
+
+
+ /**
+ * @return the revision
+ */
+ public long getRevision()
+ {
+ return revision;
+ }
+
+
+ /**
+ * @param revision the revision to set
+ */
+ public void setRevision( long revision )
+ {
+ this.revision = revision;
+ }
+
+
+ /**
+ * @return the btree name
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+
+ /**
+ * @param name the btree name to set
+ */
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ return "[" + name + ":" + revision + "]";
+ }
+}
Added: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/store/RevisionNameComparator.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/store/RevisionNameComparator.java?rev=1463603&view=auto
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/store/RevisionNameComparator.java (added)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/main/java/org/apache/mavibot/btree/store/RevisionNameComparator.java Tue Apr 2 15:44:39 2013
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.mavibot.btree.store;
+
+
+import java.util.Comparator;
+
+
+/**
+ * A comparator for the RevisionName class
+ *
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class RevisionNameComparator implements Comparator<RevisionName>
+{
+ /**
+ * {@inheritDoc}
+ */
+ public int compare( RevisionName rn1, RevisionName rn2 )
+ {
+ if ( rn1 == rn2 )
+ {
+ return 0;
+ }
+
+ // First compare the revisions
+ if ( rn1.getRevision() < rn2.getRevision() )
+ {
+ return -1;
+ }
+ else if ( rn1.getRevision() > rn2.getRevision() )
+ {
+ return 1;
+ }
+
+ // The revision are equal : check the name
+ return rn1.getName().compareTo( rn2.getName() );
+ }
+}
Added: labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/RevisionNameComparatorTest.java
URL: http://svn.apache.org/viewvc/labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/RevisionNameComparatorTest.java?rev=1463603&view=auto
==============================================================================
--- labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/RevisionNameComparatorTest.java (added)
+++ labs/mavibot/branches/mavibot-multivalue-support/mavibot/src/test/java/org/apache/mavibot/btree/comparator/RevisionNameComparatorTest.java Tue Apr 2 15:44:39 2013
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.mavibot.btree.comparator;
+
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.mavibot.btree.store.RevisionName;
+import org.apache.mavibot.btree.store.RevisionNameComparator;
+import org.junit.Test;
+
+
+/**
+ * Test the RevisionNameComparator class
+ *
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class RevisionNameComparatorTest
+{
+ @Test
+ public void testRevisionNameComparator()
+ {
+ RevisionNameComparator comparator = new RevisionNameComparator();
+
+ assertEquals( 0, comparator.compare( null, null ) );
+ assertEquals( 0, comparator.compare( new RevisionName( 0L, "test" ), new RevisionName( 0L, "test" ) ) );
+ assertEquals( 1, comparator.compare( new RevisionName( 3L, "test" ), new RevisionName( 0L, "test" ) ) );
+ assertEquals( -1, comparator.compare( new RevisionName( 3L, "test" ), new RevisionName( 5L, "test" ) ) );
+ assertEquals( 1, comparator.compare( new RevisionName( 3L, "test2" ), new RevisionName( 3L, "test1" ) ) );
+ assertEquals( -1, comparator.compare( new RevisionName( 3L, "test" ), new RevisionName( 3L, "test2" ) ) );
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org