]> source.dussan.org Git - jgit.git/commitdiff
Exposed the constructor of Note class 04/2304/3
authorSasa Zivkov <sasa.zivkov@sap.com>
Fri, 21 Jan 2011 16:04:24 +0000 (17:04 +0100)
committerChris Aniszczyk <caniszczyk@gmail.com>
Tue, 25 Jan 2011 22:33:29 +0000 (16:33 -0600)
Additionally, defined the NoteMap.getNote method which returns a Note
instance.  These changes were necessary to enable implementation of
the NoteMerger interface (the merge method needs to instantiate a
Note) and to enable direct use of NoteMerger which expects instances
of Note class as its paramters.  Implementing creation of code review
summary notes in Gerrit [1] will make use of both of these features.

[1] https://review.source.android.com/#change,20045

Change-Id: I627aefcedcd3434deecd63fa1d3e90e303b385ac
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/LeafBucketTest.java
org.eclipse.jgit/src/org/eclipse/jgit/notes/FanoutBucket.java
org.eclipse.jgit/src/org/eclipse/jgit/notes/LeafBucket.java
org.eclipse.jgit/src/org/eclipse/jgit/notes/Note.java
org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteBucket.java
org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteMap.java

index 7c40695531ced1d86f7de5a856797c1c5dd64890..881cf9e8fd695c5b618f672635b085ba9edcff95 100644 (file)
@@ -57,9 +57,9 @@ public class LeafBucketTest {
        @Test
        public void testEmpty() {
                LeafBucket b = new LeafBucket(0);
-               assertNull(b.get(id(0x00), null));
-               assertNull(b.get(id(0x01), null));
-               assertNull(b.get(id(0xfe), null));
+               assertNull(b.getNote(id(0x00), null));
+               assertNull(b.getNote(id(0x01), null));
+               assertNull(b.getNote(id(0xfe), null));
        }
 
        @Test
@@ -72,13 +72,13 @@ public class LeafBucketTest {
                b.parseOneEntry(id(0x44), id(0x84));
                b.parseOneEntry(id(0x55), id(0x85));
 
-               assertNull(b.get(id(0x01), null));
-               assertEquals(id(0x81), b.get(id(0x11), null));
-               assertEquals(id(0x82), b.get(id(0x22), null));
-               assertEquals(id(0x83), b.get(id(0x33), null));
-               assertEquals(id(0x84), b.get(id(0x44), null));
-               assertEquals(id(0x85), b.get(id(0x55), null));
-               assertNull(b.get(id(0x66), null));
+               assertNull(b.getNote(id(0x01), null));
+               assertEquals(id(0x81), b.getNote(id(0x11), null).getData());
+               assertEquals(id(0x82), b.getNote(id(0x22), null).getData());
+               assertEquals(id(0x83), b.getNote(id(0x33), null).getData());
+               assertEquals(id(0x84), b.getNote(id(0x44), null).getData());
+               assertEquals(id(0x85), b.getNote(id(0x55), null).getData());
+               assertNull(b.getNote(id(0x66), null));
        }
 
        @Test
@@ -91,13 +91,13 @@ public class LeafBucketTest {
                assertSame(b, b.set(id(0x44), id(0x84), null));
                assertSame(b, b.set(id(0x55), id(0x85), null));
 
-               assertNull(b.get(id(0x01), null));
-               assertEquals(id(0x81), b.get(id(0x11), null));
-               assertEquals(id(0x82), b.get(id(0x22), null));
-               assertEquals(id(0x83), b.get(id(0x33), null));
-               assertEquals(id(0x84), b.get(id(0x44), null));
-               assertEquals(id(0x85), b.get(id(0x55), null));
-               assertNull(b.get(id(0x66), null));
+               assertNull(b.getNote(id(0x01), null));
+               assertEquals(id(0x81), b.getNote(id(0x11), null).getData());
+               assertEquals(id(0x82), b.getNote(id(0x22), null).getData());
+               assertEquals(id(0x83), b.getNote(id(0x33), null).getData());
+               assertEquals(id(0x84), b.getNote(id(0x44), null).getData());
+               assertEquals(id(0x85), b.getNote(id(0x55), null).getData());
+               assertNull(b.getNote(id(0x66), null));
        }
 
        @Test
@@ -110,13 +110,13 @@ public class LeafBucketTest {
                assertSame(b, b.set(id(0x22), id(0x82), null));
                assertSame(b, b.set(id(0x11), id(0x81), null));
 
-               assertNull(b.get(id(0x01), null));
-               assertEquals(id(0x81), b.get(id(0x11), null));
-               assertEquals(id(0x82), b.get(id(0x22), null));
-               assertEquals(id(0x83), b.get(id(0x33), null));
-               assertEquals(id(0x84), b.get(id(0x44), null));
-               assertEquals(id(0x85), b.get(id(0x55), null));
-               assertNull(b.get(id(0x66), null));
+               assertNull(b.getNote(id(0x01), null));
+               assertEquals(id(0x81), b.getNote(id(0x11), null).getData());
+               assertEquals(id(0x82), b.getNote(id(0x22), null).getData());
+               assertEquals(id(0x83), b.getNote(id(0x33), null).getData());
+               assertEquals(id(0x84), b.getNote(id(0x44), null).getData());
+               assertEquals(id(0x85), b.getNote(id(0x55), null).getData());
+               assertNull(b.getNote(id(0x66), null));
        }
 
        @Test
@@ -130,13 +130,13 @@ public class LeafBucketTest {
                assertSame(b, b.set(id(0x22), id(0x82), null));
                assertSame(b, b.set(id(0x44), id(0x84), null));
 
-               assertNull(b.get(id(0x01), null));
-               assertEquals(id(0x81), b.get(id(0x11), null));
-               assertEquals(id(0x82), b.get(id(0x22), null));
-               assertEquals(id(0x83), b.get(id(0x33), null));
-               assertEquals(id(0x84), b.get(id(0x44), null));
-               assertEquals(id(0x85), b.get(id(0x55), null));
-               assertNull(b.get(id(0x66), null));
+               assertNull(b.getNote(id(0x01), null));
+               assertEquals(id(0x81), b.getNote(id(0x11), null).getData());
+               assertEquals(id(0x82), b.getNote(id(0x22), null).getData());
+               assertEquals(id(0x83), b.getNote(id(0x33), null).getData());
+               assertEquals(id(0x84), b.getNote(id(0x44), null).getData());
+               assertEquals(id(0x85), b.getNote(id(0x55), null).getData());
+               assertNull(b.getNote(id(0x66), null));
        }
 
        @Test
@@ -144,18 +144,18 @@ public class LeafBucketTest {
                LeafBucket b = new LeafBucket(0);
 
                assertSame(b, b.set(id(0x11), id(0x81), null));
-               assertEquals(id(0x81), b.get(id(0x11), null));
+               assertEquals(id(0x81), b.getNote(id(0x11), null).getData());
 
                assertSame(b, b.set(id(0x11), id(0x01), null));
-               assertEquals(id(0x01), b.get(id(0x11), null));
+               assertEquals(id(0x01), b.getNote(id(0x11), null).getData());
        }
 
        @Test
        public void testRemoveMissingNote() throws IOException {
                LeafBucket b = new LeafBucket(0);
-               assertNull(b.get(id(0x11), null));
+               assertNull(b.getNote(id(0x11), null));
                assertSame(b, b.set(id(0x11), null, null));
-               assertNull(b.get(id(0x11), null));
+               assertNull(b.getNote(id(0x11), null));
        }
 
        @Test
@@ -170,13 +170,13 @@ public class LeafBucketTest {
 
                assertSame(b, b.set(id(0x11), null, null));
 
-               assertNull(b.get(id(0x01), null));
-               assertNull(b.get(id(0x11), null));
-               assertEquals(id(0x82), b.get(id(0x22), null));
-               assertEquals(id(0x83), b.get(id(0x33), null));
-               assertEquals(id(0x84), b.get(id(0x44), null));
-               assertEquals(id(0x85), b.get(id(0x55), null));
-               assertNull(b.get(id(0x66), null));
+               assertNull(b.getNote(id(0x01), null));
+               assertNull(b.getNote(id(0x11), null));
+               assertEquals(id(0x82), b.getNote(id(0x22), null).getData());
+               assertEquals(id(0x83), b.getNote(id(0x33), null).getData());
+               assertEquals(id(0x84), b.getNote(id(0x44), null).getData());
+               assertEquals(id(0x85), b.getNote(id(0x55), null).getData());
+               assertNull(b.getNote(id(0x66), null));
        }
 
        @Test
@@ -191,13 +191,13 @@ public class LeafBucketTest {
 
                assertSame(b, b.set(id(0x33), null, null));
 
-               assertNull(b.get(id(0x01), null));
-               assertEquals(id(0x81), b.get(id(0x11), null));
-               assertEquals(id(0x82), b.get(id(0x22), null));
-               assertNull(b.get(id(0x33), null));
-               assertEquals(id(0x84), b.get(id(0x44), null));
-               assertEquals(id(0x85), b.get(id(0x55), null));
-               assertNull(b.get(id(0x66), null));
+               assertNull(b.getNote(id(0x01), null));
+               assertEquals(id(0x81), b.getNote(id(0x11), null).getData());
+               assertEquals(id(0x82), b.getNote(id(0x22), null).getData());
+               assertNull(b.getNote(id(0x33), null));
+               assertEquals(id(0x84), b.getNote(id(0x44), null).getData());
+               assertEquals(id(0x85), b.getNote(id(0x55), null).getData());
+               assertNull(b.getNote(id(0x66), null));
        }
 
        @Test
@@ -212,13 +212,13 @@ public class LeafBucketTest {
 
                assertSame(b, b.set(id(0x55), null, null));
 
-               assertNull(b.get(id(0x01), null));
-               assertEquals(id(0x81), b.get(id(0x11), null));
-               assertEquals(id(0x82), b.get(id(0x22), null));
-               assertEquals(id(0x83), b.get(id(0x33), null));
-               assertEquals(id(0x84), b.get(id(0x44), null));
-               assertNull(b.get(id(0x55), null));
-               assertNull(b.get(id(0x66), null));
+               assertNull(b.getNote(id(0x01), null));
+               assertEquals(id(0x81), b.getNote(id(0x11), null).getData());
+               assertEquals(id(0x82), b.getNote(id(0x22), null).getData());
+               assertEquals(id(0x83), b.getNote(id(0x33), null).getData());
+               assertEquals(id(0x84), b.getNote(id(0x44), null).getData());
+               assertNull(b.getNote(id(0x55), null));
+               assertNull(b.getNote(id(0x66), null));
        }
 
        @Test
@@ -226,10 +226,10 @@ public class LeafBucketTest {
                LeafBucket b = new LeafBucket(0);
 
                assertSame(b, b.set(id(0x11), id(0x81), null));
-               assertEquals(id(0x81), b.get(id(0x11), null));
+               assertEquals(id(0x81), b.getNote(id(0x11), null).getData());
 
                assertNull(b.set(id(0x11), null, null));
-               assertNull(b.get(id(0x11), null));
+               assertNull(b.getNote(id(0x11), null));
        }
 
        private static AnyObjectId id(int first) {
index 953929464aa68120d7d8ada0083ba3229a581c43..ea904cd1dbd03f92744a92d583bcf102dbd8f82c 100644 (file)
@@ -110,9 +110,10 @@ class FanoutBucket extends InMemoryNoteBucket {
        }
 
        @Override
-       ObjectId get(AnyObjectId objId, ObjectReader or) throws IOException {
+       Note getNote(AnyObjectId objId, ObjectReader or) throws IOException {
                NoteBucket b = table[cell(objId)];
-               return b != null ? b.get(objId, or) : null;
+               return b != null ? b.getNote(objId, or) : null;
+
        }
 
        NoteBucket getBucket(int cell) {
@@ -337,8 +338,8 @@ class FanoutBucket extends InMemoryNoteBucket {
                }
 
                @Override
-               ObjectId get(AnyObjectId objId, ObjectReader or) throws IOException {
-                       return load(objId, or).get(objId, or);
+               Note getNote(AnyObjectId objId, ObjectReader or) throws IOException {
+                       return load(objId, or).getNote(objId, or);
                }
 
                @Override
index 886684983767ea3886e1f78fbce17363d9e05cb3..ea4d7bc866f4af645f8c3d2e65520a831dbdb9cc 100644 (file)
@@ -102,9 +102,10 @@ class LeafBucket extends InMemoryNoteBucket {
                return -(low + 1);
        }
 
-       ObjectId get(AnyObjectId objId, ObjectReader or) {
+       @Override
+       Note getNote(AnyObjectId objId, ObjectReader or) {
                int idx = search(objId);
-               return 0 <= idx ? notes[idx].getData() : null;
+               return 0 <= idx ? notes[idx] : null;
        }
 
        Note get(int index) {
index 00b32132e2fc3e96762239f4dd75d0a63da7fd99..ddff52e74efdf0fde1a9a025ae7e08f2f2d5058d 100644 (file)
@@ -58,7 +58,7 @@ public class Note extends ObjectId {
         * @param noteData
         *            the actual note data contained in this note
         */
-       Note(AnyObjectId noteOn, ObjectId noteData) {
+       public Note(AnyObjectId noteOn, ObjectId noteData) {
                super(noteOn);
                data = noteData;
        }
index 5c7b325f0d22da698408fa23e840c86b580ab752..dd17ad532ac6009858c0412fcee775abf60977fd 100644 (file)
@@ -58,7 +58,7 @@ import org.eclipse.jgit.lib.ObjectReader;
  * @see LeafBucket
  */
 abstract class NoteBucket {
-       abstract ObjectId get(AnyObjectId objId, ObjectReader reader)
+       abstract Note getNote(AnyObjectId objId, ObjectReader reader)
                        throws IOException;
 
        abstract Iterator<Note> iterator(AnyObjectId objId, ObjectReader reader)
index 591b1aeb1950d4ca1bb80693417034d7557ba48d..0d4d6b9147c2e1df9750976ce02d8746157d49aa 100644 (file)
@@ -206,7 +206,21 @@ public class NoteMap implements Iterable<Note> {
         *             a portion of the note space is not accessible.
         */
        public ObjectId get(AnyObjectId id) throws IOException {
-               return root.get(id, reader);
+               Note n = root.getNote(id, reader);
+               return n == null ? null : n.getData();
+       }
+
+       /**
+        * Lookup a note for a specific ObjectId.
+        *
+        * @param id
+        *            the object to look for.
+        * @return the note for the given object id, or null if no note exists.
+        * @throws IOException
+        *             a portion of the note space is not accessible.
+        */
+       public Note getNote(AnyObjectId id) throws IOException {
+               return root.getNote(id, reader);
        }
 
        /**