Repository: kafka Updated Branches: refs/heads/trunk d05fa0a03 -> b390b15cd
MINOR: Remove unused DoublyLinkedList It used to be used by MirrorMaker but its usage was removed in KAFKA-1997. Author: Grant Henke <[email protected]> Reviewers: Jiangjie Qin Closes #638 from granthenke/remove-dll Project: http://git-wip-us.apache.org/repos/asf/kafka/repo Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/b390b15c Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/b390b15c Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/b390b15c Branch: refs/heads/trunk Commit: b390b15cdbf89f7ffce16dad2a20ee9330f82731 Parents: d05fa0a Author: Grant Henke <[email protected]> Authored: Mon Dec 7 23:15:04 2015 -0800 Committer: Guozhang Wang <[email protected]> Committed: Mon Dec 7 23:15:04 2015 -0800 ---------------------------------------------------------------------- .../scala/kafka/utils/DoublyLinkedList.scala | 126 ------------------- .../test/scala/unit/kafka/utils/UtilsTest.scala | 56 +-------- 2 files changed, 3 insertions(+), 179 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kafka/blob/b390b15c/core/src/main/scala/kafka/utils/DoublyLinkedList.scala ---------------------------------------------------------------------- diff --git a/core/src/main/scala/kafka/utils/DoublyLinkedList.scala b/core/src/main/scala/kafka/utils/DoublyLinkedList.scala deleted file mode 100644 index e637ef3..0000000 --- a/core/src/main/scala/kafka/utils/DoublyLinkedList.scala +++ /dev/null @@ -1,126 +0,0 @@ -/** - * 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 kafka.utils - -/** - * Simple doubly LinkedList node - * @param element The element - * @tparam T The type of element - */ -class DoublyLinkedListNode[T] (val element: T) { - var prev: DoublyLinkedListNode[T] = null - var next: DoublyLinkedListNode[T] = null -} - -/** - * A simple doubly linked list util to allow O(1) remove. - * @tparam T type of element in nodes - */ -@threadsafe -class DoublyLinkedList[T] { - private var head: DoublyLinkedListNode[T] = null - private var tail: DoublyLinkedListNode[T] = null - @volatile private var listSize: Int = 0 - - /** - * Add offset to the tail of the list - * @param node the node to be added to the tail of the list - */ - def add (node: DoublyLinkedListNode[T]) { - this synchronized { - if (head == null) { - // empty list - head = node - tail = node - node.prev = null - node.next = null - } else { - // add to tail - tail.next = node - node.next = null - node.prev = tail - tail = node - } - listSize += 1 - } - } - - /** - * Remove a node from the list. The list will not check if the node is really in the list. - * @param node the node to be removed from the list - */ - def remove (node: DoublyLinkedListNode[T]) { - this synchronized { - if (node ne head) - node.prev.next = node.next - else - head = node.next - - if (node ne tail) - node.next.prev = node.prev - else - tail = node.prev - - node.prev = null - node.next = null - - listSize -= 1 - } - } - - /** - * Remove the first node in the list and return it if the list is not empty. - * @return The first node in the list if the list is not empty. Return Null if the list is empty. - */ - def remove(): DoublyLinkedListNode[T] = { - this synchronized { - if (head != null) { - val node = head - remove(head) - node - } else { - null - } - } - } - - /** - * Get the first node in the list without removing it. - * @return the first node in the list. - */ - def peek(): DoublyLinkedListNode[T] = head - - def size: Int = listSize - - def iterator: Iterator[DoublyLinkedListNode[T]] = { - new IteratorTemplate[DoublyLinkedListNode[T]] { - var current = head - override protected def makeNext(): DoublyLinkedListNode[T] = { - this synchronized { - if (current != null) { - val nextNode = current - current = current.next - nextNode - } else { - allDone() - } - } - } - } - } -} http://git-wip-us.apache.org/repos/asf/kafka/blob/b390b15c/core/src/test/scala/unit/kafka/utils/UtilsTest.scala ---------------------------------------------------------------------- diff --git a/core/src/test/scala/unit/kafka/utils/UtilsTest.scala b/core/src/test/scala/unit/kafka/utils/UtilsTest.scala index 9e8869c..f42f0ff 100755 --- a/core/src/test/scala/unit/kafka/utils/UtilsTest.scala +++ b/core/src/test/scala/unit/kafka/utils/UtilsTest.scala @@ -5,7 +5,7 @@ * 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 @@ -28,10 +28,9 @@ import kafka.utils.CoreUtils.inLock import org.junit.Test import org.apache.kafka.common.utils.Utils - class UtilsTest extends JUnitSuite { - - private val logger = Logger.getLogger(classOf[UtilsTest]) + + private val logger = Logger.getLogger(classOf[UtilsTest]) @Test def testSwallow() { @@ -152,53 +151,4 @@ class UtilsTest extends JUnitSuite { assertFalse("Should be unlocked", lock.isLocked) } - @Test - def testDoublyLinkedList() { - val list = new DoublyLinkedList[Int] - - // test remove from a single-entry list. - list.add(new DoublyLinkedListNode[Int](0)) - list.remove() - assert(list.size == 0) - assert(list.peek() == null) - - // test add - for (i <- 0 to 2) { - list.add(new DoublyLinkedListNode[Int](i)) - } - val toBeRemoved1 = new DoublyLinkedListNode[Int](3) - list.add(toBeRemoved1) - for (i <- 4 to 6) { - list.add(new DoublyLinkedListNode[Int](i)) - } - val toBeRemoved2 = new DoublyLinkedListNode[Int](7) - list.add(toBeRemoved2) - - // test iterator - val iter = list.iterator - for (i <- 0 to 7) { - assert(iter.hasNext) - assert(iter.next().element == i) - } - assert(!iter.hasNext) - - // remove from head - list.remove() - assert(list.peek().element == 1) - // remove from middle - list.remove(toBeRemoved1) - // remove from tail - list.remove(toBeRemoved2) - - // List = [1,2,4,5,6] - val iter2 = list.iterator - for (i <- Array[Int](1,2,4,5,6)) { - assert(iter2.hasNext) - assert(iter2.next().element == i) - } - - // test size - assert(list.size == 5) - } - }
