Browse Source
This interface has been deprecated for a while now. Applications can use a TreeWalk instead. Change-Id: I751d6e919e4b501c36fc36e5f816b8a8c5379cb9 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>stable-0.12
Shawn O. Pearce
14 years ago
4 changed files with 0 additions and 670 deletions
@ -1,140 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com> |
|
||||||
* Copyright (C) 2006, Shawn O. Pearce <spearce@spearce.org> |
|
||||||
* and other copyright owners as documented in the project's IP log. |
|
||||||
* |
|
||||||
* This program and the accompanying materials are made available |
|
||||||
* under the terms of the Eclipse Distribution License v1.0 which |
|
||||||
* accompanies this distribution, is reproduced below, and is |
|
||||||
* available at http://www.eclipse.org/org/documents/edl-v10.php
|
|
||||||
* |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or |
|
||||||
* without modification, are permitted provided that the following |
|
||||||
* conditions are met: |
|
||||||
* |
|
||||||
* - Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* |
|
||||||
* - Redistributions in binary form must reproduce the above |
|
||||||
* copyright notice, this list of conditions and the following |
|
||||||
* disclaimer in the documentation and/or other materials provided |
|
||||||
* with the distribution. |
|
||||||
* |
|
||||||
* - Neither the name of the Eclipse Foundation, Inc. nor the |
|
||||||
* names of its contributors may be used to endorse or promote |
|
||||||
* products derived from this software without specific prior |
|
||||||
* written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
||||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
||||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.eclipse.jgit.lib; |
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals; |
|
||||||
import static org.junit.Assert.assertFalse; |
|
||||||
import static org.junit.Assert.assertTrue; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
public class TreeIteratorLeafOnlyTest extends RepositoryTestCase { |
|
||||||
|
|
||||||
/** Empty tree */ |
|
||||||
@Test |
|
||||||
public void testEmpty() { |
|
||||||
Tree tree = new Tree(db); |
|
||||||
TreeIterator i = makeIterator(tree); |
|
||||||
assertFalse(i.hasNext()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* one file |
|
||||||
* |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
@Test |
|
||||||
public void testSimpleF1() throws IOException { |
|
||||||
Tree tree = new Tree(db); |
|
||||||
tree.addFile("x"); |
|
||||||
TreeIterator i = makeIterator(tree); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("x", i.next().getName()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* two files |
|
||||||
* |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
@Test |
|
||||||
public void testSimpleF2() throws IOException { |
|
||||||
Tree tree = new Tree(db); |
|
||||||
tree.addFile("a"); |
|
||||||
tree.addFile("x"); |
|
||||||
TreeIterator i = makeIterator(tree); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a", i.next().getName()); |
|
||||||
assertEquals("x", i.next().getName()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Empty tree |
|
||||||
* |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
@Test |
|
||||||
public void testSimpleT() throws IOException { |
|
||||||
Tree tree = new Tree(db); |
|
||||||
tree.addTree("a"); |
|
||||||
TreeIterator i = makeIterator(tree); |
|
||||||
assertFalse(i.hasNext()); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testTricky() throws IOException { |
|
||||||
Tree tree = new Tree(db); |
|
||||||
tree.addFile("a.b"); |
|
||||||
tree.addFile("a.c"); |
|
||||||
tree.addFile("a/b.b/b"); |
|
||||||
tree.addFile("a/b"); |
|
||||||
tree.addFile("a/c"); |
|
||||||
tree.addFile("a=c"); |
|
||||||
tree.addFile("a=d"); |
|
||||||
|
|
||||||
TreeIterator i = makeIterator(tree); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a.b", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a.c", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a/b", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a/b.b/b", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a/c", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a=c", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a=d", i.next().getFullName()); |
|
||||||
assertFalse(i.hasNext()); |
|
||||||
} |
|
||||||
|
|
||||||
private TreeIterator makeIterator(Tree tree) { |
|
||||||
return new TreeIterator(tree); |
|
||||||
} |
|
||||||
} |
|
@ -1,158 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com> |
|
||||||
* Copyright (C) 2006, Shawn O. Pearce <spearce@spearce.org> |
|
||||||
* and other copyright owners as documented in the project's IP log. |
|
||||||
* |
|
||||||
* This program and the accompanying materials are made available |
|
||||||
* under the terms of the Eclipse Distribution License v1.0 which |
|
||||||
* accompanies this distribution, is reproduced below, and is |
|
||||||
* available at http://www.eclipse.org/org/documents/edl-v10.php
|
|
||||||
* |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or |
|
||||||
* without modification, are permitted provided that the following |
|
||||||
* conditions are met: |
|
||||||
* |
|
||||||
* - Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* |
|
||||||
* - Redistributions in binary form must reproduce the above |
|
||||||
* copyright notice, this list of conditions and the following |
|
||||||
* disclaimer in the documentation and/or other materials provided |
|
||||||
* with the distribution. |
|
||||||
* |
|
||||||
* - Neither the name of the Eclipse Foundation, Inc. nor the |
|
||||||
* names of its contributors may be used to endorse or promote |
|
||||||
* products derived from this software without specific prior |
|
||||||
* written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
||||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
||||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.eclipse.jgit.lib; |
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals; |
|
||||||
import static org.junit.Assert.assertFalse; |
|
||||||
import static org.junit.Assert.assertTrue; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
public class TreeIteratorPostOrderTest extends RepositoryTestCase { |
|
||||||
|
|
||||||
/** Empty tree */ |
|
||||||
@Test |
|
||||||
public void testEmpty() { |
|
||||||
Tree tree = new Tree(db); |
|
||||||
TreeIterator i = makeIterator(tree); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("", i.next().getFullName()); |
|
||||||
assertFalse(i.hasNext()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* one file |
|
||||||
* |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
@Test |
|
||||||
public void testSimpleF1() throws IOException { |
|
||||||
Tree tree = new Tree(db); |
|
||||||
tree.addFile("x"); |
|
||||||
TreeIterator i = makeIterator(tree); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("x", i.next().getName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("", i.next().getFullName()); |
|
||||||
assertFalse(i.hasNext()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* two files |
|
||||||
* |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
@Test |
|
||||||
public void testSimpleF2() throws IOException { |
|
||||||
Tree tree = new Tree(db); |
|
||||||
tree.addFile("a"); |
|
||||||
tree.addFile("x"); |
|
||||||
TreeIterator i = makeIterator(tree); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a", i.next().getName()); |
|
||||||
assertEquals("x", i.next().getName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("", i.next().getFullName()); |
|
||||||
assertFalse(i.hasNext()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Empty tree |
|
||||||
* |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
@Test |
|
||||||
public void testSimpleT() throws IOException { |
|
||||||
Tree tree = new Tree(db); |
|
||||||
tree.addTree("a"); |
|
||||||
TreeIterator i = makeIterator(tree); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("", i.next().getFullName()); |
|
||||||
assertFalse(i.hasNext()); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testTricky() throws IOException { |
|
||||||
Tree tree = new Tree(db); |
|
||||||
tree.addFile("a.b"); |
|
||||||
tree.addFile("a.c"); |
|
||||||
tree.addFile("a/b.b/b"); |
|
||||||
tree.addFile("a/b"); |
|
||||||
tree.addFile("a/c"); |
|
||||||
tree.addFile("a=c"); |
|
||||||
tree.addFile("a=d"); |
|
||||||
|
|
||||||
TreeIterator i = makeIterator(tree); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a.b", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a.c", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a/b", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a/b.b/b", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a/b.b", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a/c", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a=c", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a=d", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("", i.next().getFullName()); |
|
||||||
assertFalse(i.hasNext()); |
|
||||||
} |
|
||||||
|
|
||||||
private TreeIterator makeIterator(Tree tree) { |
|
||||||
return new TreeIterator(tree, TreeIterator.Order.POSTORDER); |
|
||||||
} |
|
||||||
} |
|
@ -1,158 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com> |
|
||||||
* Copyright (C) 2006, Shawn O. Pearce <spearce@spearce.org> |
|
||||||
* and other copyright owners as documented in the project's IP log. |
|
||||||
* |
|
||||||
* This program and the accompanying materials are made available |
|
||||||
* under the terms of the Eclipse Distribution License v1.0 which |
|
||||||
* accompanies this distribution, is reproduced below, and is |
|
||||||
* available at http://www.eclipse.org/org/documents/edl-v10.php
|
|
||||||
* |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or |
|
||||||
* without modification, are permitted provided that the following |
|
||||||
* conditions are met: |
|
||||||
* |
|
||||||
* - Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* |
|
||||||
* - Redistributions in binary form must reproduce the above |
|
||||||
* copyright notice, this list of conditions and the following |
|
||||||
* disclaimer in the documentation and/or other materials provided |
|
||||||
* with the distribution. |
|
||||||
* |
|
||||||
* - Neither the name of the Eclipse Foundation, Inc. nor the |
|
||||||
* names of its contributors may be used to endorse or promote |
|
||||||
* products derived from this software without specific prior |
|
||||||
* written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
||||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
||||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.eclipse.jgit.lib; |
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals; |
|
||||||
import static org.junit.Assert.assertFalse; |
|
||||||
import static org.junit.Assert.assertTrue; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
public class TreeIteratorPreOrderTest extends RepositoryTestCase { |
|
||||||
|
|
||||||
/** Empty tree */ |
|
||||||
@Test |
|
||||||
public void testEmpty() { |
|
||||||
Tree tree = new Tree(db); |
|
||||||
TreeIterator i = makeIterator(tree); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("", i.next().getFullName()); |
|
||||||
assertFalse(i.hasNext()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* one file |
|
||||||
* |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
@Test |
|
||||||
public void testSimpleF1() throws IOException { |
|
||||||
Tree tree = new Tree(db); |
|
||||||
tree.addFile("x"); |
|
||||||
TreeIterator i = makeIterator(tree); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("x", i.next().getName()); |
|
||||||
assertFalse(i.hasNext()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* two files |
|
||||||
* |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
@Test |
|
||||||
public void testSimpleF2() throws IOException { |
|
||||||
Tree tree = new Tree(db); |
|
||||||
tree.addFile("a"); |
|
||||||
tree.addFile("x"); |
|
||||||
TreeIterator i = makeIterator(tree); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a", i.next().getName()); |
|
||||||
assertEquals("x", i.next().getName()); |
|
||||||
assertFalse(i.hasNext()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Empty tree |
|
||||||
* |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
@Test |
|
||||||
public void testSimpleT() throws IOException { |
|
||||||
Tree tree = new Tree(db); |
|
||||||
tree.addTree("a"); |
|
||||||
TreeIterator i = makeIterator(tree); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a", i.next().getFullName()); |
|
||||||
assertFalse(i.hasNext()); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testTricky() throws IOException { |
|
||||||
Tree tree = new Tree(db); |
|
||||||
tree.addFile("a.b"); |
|
||||||
tree.addFile("a.c"); |
|
||||||
tree.addFile("a/b.b/b"); |
|
||||||
tree.addFile("a/b"); |
|
||||||
tree.addFile("a/c"); |
|
||||||
tree.addFile("a=c"); |
|
||||||
tree.addFile("a=d"); |
|
||||||
|
|
||||||
TreeIterator i = makeIterator(tree); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a.b", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a.c", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a/b", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a/b.b", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a/b.b/b", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a/c", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a=c", i.next().getFullName()); |
|
||||||
assertTrue(i.hasNext()); |
|
||||||
assertEquals("a=d", i.next().getFullName()); |
|
||||||
assertFalse(i.hasNext()); |
|
||||||
} |
|
||||||
|
|
||||||
private TreeIterator makeIterator(Tree tree) { |
|
||||||
return new TreeIterator(tree, TreeIterator.Order.PREORDER); |
|
||||||
} |
|
||||||
} |
|
@ -1,214 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com> |
|
||||||
* Copyright (C) 2006, Shawn O. Pearce <spearce@spearce.org> |
|
||||||
* and other copyright owners as documented in the project's IP log. |
|
||||||
* |
|
||||||
* This program and the accompanying materials are made available |
|
||||||
* under the terms of the Eclipse Distribution License v1.0 which |
|
||||||
* accompanies this distribution, is reproduced below, and is |
|
||||||
* available at http://www.eclipse.org/org/documents/edl-v10.php
|
|
||||||
* |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or |
|
||||||
* without modification, are permitted provided that the following |
|
||||||
* conditions are met: |
|
||||||
* |
|
||||||
* - Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* |
|
||||||
* - Redistributions in binary form must reproduce the above |
|
||||||
* copyright notice, this list of conditions and the following |
|
||||||
* disclaimer in the documentation and/or other materials provided |
|
||||||
* with the distribution. |
|
||||||
* |
|
||||||
* - Neither the name of the Eclipse Foundation, Inc. nor the |
|
||||||
* names of its contributors may be used to endorse or promote |
|
||||||
* products derived from this software without specific prior |
|
||||||
* written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
||||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
||||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.eclipse.jgit.lib; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
import java.util.Iterator; |
|
||||||
|
|
||||||
import org.eclipse.jgit.JGitText; |
|
||||||
|
|
||||||
/** |
|
||||||
* A tree iterator iterates over a tree and all its members recursing into |
|
||||||
* subtrees according to order. |
|
||||||
* |
|
||||||
* Default is to only visit leafs. An {@link Order} value can be supplied to |
|
||||||
* make the iteration include Tree nodes as well either before or after the |
|
||||||
* child nodes have been visited. |
|
||||||
* |
|
||||||
* @deprecated Use {@link org.eclipse.jgit.treewalk.TreeWalk} instead. |
|
||||||
*/ |
|
||||||
@Deprecated |
|
||||||
public class TreeIterator implements Iterator<TreeEntry> { |
|
||||||
|
|
||||||
private Tree tree; |
|
||||||
|
|
||||||
private int index; |
|
||||||
|
|
||||||
private TreeIterator sub; |
|
||||||
|
|
||||||
private Order order; |
|
||||||
|
|
||||||
private boolean visitTreeNodes; |
|
||||||
|
|
||||||
private boolean hasVisitedTree; |
|
||||||
|
|
||||||
/** |
|
||||||
* Traversal order |
|
||||||
*/ |
|
||||||
public enum Order { |
|
||||||
/** |
|
||||||
* Visit node first, then leaves |
|
||||||
*/ |
|
||||||
PREORDER, |
|
||||||
|
|
||||||
/** |
|
||||||
* Visit leaves first, then node |
|
||||||
*/ |
|
||||||
POSTORDER |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Construct a {@link TreeIterator} for visiting all non-tree nodes. |
|
||||||
* |
|
||||||
* @param start |
|
||||||
*/ |
|
||||||
public TreeIterator(Tree start) { |
|
||||||
this(start, Order.PREORDER, false); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Construct a {@link TreeIterator} visiting all nodes in a tree in a given |
|
||||||
* order. |
|
||||||
* |
|
||||||
* @param start Root node |
|
||||||
* @param order {@link Order} |
|
||||||
*/ |
|
||||||
public TreeIterator(Tree start, Order order) { |
|
||||||
this(start, order, true); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Construct a {@link TreeIterator} |
|
||||||
* |
|
||||||
* @param start First node to visit |
|
||||||
* @param order Visitation {@link Order} |
|
||||||
* @param visitTreeNode True to include tree node |
|
||||||
*/ |
|
||||||
private TreeIterator(Tree start, Order order, boolean visitTreeNode) { |
|
||||||
this.tree = start; |
|
||||||
this.visitTreeNodes = visitTreeNode; |
|
||||||
this.index = -1; |
|
||||||
this.order = order; |
|
||||||
if (!visitTreeNodes) |
|
||||||
this.hasVisitedTree = true; |
|
||||||
try { |
|
||||||
step(); |
|
||||||
} catch (IOException e) { |
|
||||||
throw new Error(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public TreeEntry next() { |
|
||||||
try { |
|
||||||
TreeEntry ret = nextTreeEntry(); |
|
||||||
step(); |
|
||||||
return ret; |
|
||||||
} catch (IOException e) { |
|
||||||
throw new Error(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private TreeEntry nextTreeEntry() throws IOException { |
|
||||||
TreeEntry ret; |
|
||||||
if (sub != null) |
|
||||||
ret = sub.nextTreeEntry(); |
|
||||||
else { |
|
||||||
if (index < 0 && order == Order.PREORDER) { |
|
||||||
return tree; |
|
||||||
} |
|
||||||
if (order == Order.POSTORDER && index == tree.memberCount()) { |
|
||||||
return tree; |
|
||||||
} |
|
||||||
ret = tree.members()[index]; |
|
||||||
} |
|
||||||
return ret; |
|
||||||
} |
|
||||||
|
|
||||||
public boolean hasNext() { |
|
||||||
try { |
|
||||||
return hasNextTreeEntry(); |
|
||||||
} catch (IOException e) { |
|
||||||
throw new Error(e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private boolean hasNextTreeEntry() throws IOException { |
|
||||||
if (tree == null) |
|
||||||
return false; |
|
||||||
return sub != null |
|
||||||
|| index < tree.memberCount() |
|
||||||
|| order == Order.POSTORDER && index == tree.memberCount(); |
|
||||||
} |
|
||||||
|
|
||||||
private boolean step() throws IOException { |
|
||||||
if (tree == null) |
|
||||||
return false; |
|
||||||
|
|
||||||
if (sub != null) { |
|
||||||
if (sub.step()) |
|
||||||
return true; |
|
||||||
sub = null; |
|
||||||
} |
|
||||||
|
|
||||||
if (index < 0 && !hasVisitedTree && order == Order.PREORDER) { |
|
||||||
hasVisitedTree = true; |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
while (++index < tree.memberCount()) { |
|
||||||
TreeEntry e = tree.members()[index]; |
|
||||||
if (e instanceof Tree) { |
|
||||||
sub = new TreeIterator((Tree) e, order, visitTreeNodes); |
|
||||||
if (sub.hasNextTreeEntry()) |
|
||||||
return true; |
|
||||||
sub = null; |
|
||||||
continue; |
|
||||||
} |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
if (index == tree.memberCount() && !hasVisitedTree |
|
||||||
&& order == Order.POSTORDER) { |
|
||||||
hasVisitedTree = true; |
|
||||||
return true; |
|
||||||
} |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
public void remove() { |
|
||||||
throw new IllegalStateException( |
|
||||||
JGitText.get().treeIteratorDoesNotSupportRemove); |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue