本文整理汇总了Java中com.googlecode.concurrenttrees.common.PrettyPrinter.prettyPrint方法的典型用法代码示例。如果您正苦于以下问题:Java PrettyPrinter.prettyPrint方法的具体用法?Java PrettyPrinter.prettyPrint怎么用?Java PrettyPrinter.prettyPrint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.concurrenttrees.common.PrettyPrinter
的用法示例。
在下文中一共展示了PrettyPrinter.prettyPrint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.googlecode.concurrenttrees.common.PrettyPrinter; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
ConcurrentSuffixTree<String> tree = new ConcurrentSuffixTree<String>(new DefaultCharSequenceNodeFactory());
for (String file : files) {
String manuscript = IOUtil.loadTextFileFromClasspath(file, true, true, true); // true = convert to lowercase
String manuscriptName = file.replaceAll("/.*/.*/", "").replace(".txt", "");
tree.put(manuscript, manuscriptName);
System.out.println("Added " + manuscriptName);
}
System.out.println("Built Suffix Tree. Estimating size on disk...");
Thread.sleep(30000);
DummyAppendable dummyAppendable = new DummyAppendable();
PrettyPrinter.prettyPrint(tree, dummyAppendable);
System.out.println("Done. Size on disk estimate:");
System.out.println("Lines: " + dummyAppendable.lineCount);
System.out.println("Characters: " + dummyAppendable.charCount);
}
示例2: testPut_ReplaceValue
import com.googlecode.concurrenttrees.common.PrettyPrinter; //导入方法依赖的package包/类
@Test
public void testPut_ReplaceValue() throws Exception {
ConcurrentSuffixTree<Integer> tree = newConcurrentSuffixTreeForUnitTests();
tree.put("BANANA", 1);
tree.put("BANANA", 2);
String expected =
"○\n" +
"├── ○ A ([BANANA])\n" +
"│ └── ○ NA ([BANANA])\n" +
"│ └── ○ NA ([BANANA])\n" +
"├── ○ BANANA ([BANANA])\n" +
"└── ○ NA ([BANANA])\n" +
" └── ○ NA ([BANANA])\n";
String actual = PrettyPrinter.prettyPrint(tree);
assertEquals(expected, actual);
assertEquals(Integer.valueOf(2), tree.getValueForExactKey("BANANA"));
}
示例3: testPut_SplitAndMove
import com.googlecode.concurrenttrees.common.PrettyPrinter; //导入方法依赖的package包/类
@Test
public void testPut_SplitAndMove() {
ConcurrentRadixTree<Integer> tree = new ConcurrentRadixTree<Integer>(getNodeFactory());
tree.put("TEST", 1);
tree.put("TEAM", 2);
tree.put("TOAST", 3);
String expected =
"○\n" +
"└── ○ T\n" + // implicit node added automatically
" ├── ○ E\n" + // implicit node added automatically
" │ ├── ○ AM (2)\n" +
" │ └── ○ ST (1)\n" +
" └── ○ OAST (3)\n";
String actual = PrettyPrinter.prettyPrint(tree);
assertEquals(expected, actual);
}
示例4: testRemove_NoSuchKey
import com.googlecode.concurrenttrees.common.PrettyPrinter; //导入方法依赖的package包/类
@Test
public void testRemove_NoSuchKey() {
ConcurrentRadixTree<Integer> tree = new ConcurrentRadixTree<Integer>(getNodeFactory());
tree.put("FOO", 1);
tree.put("BAR", 2);
String expected, actual;
expected =
"○\n" +
"├── ○ BAR (2)\n" +
"└── ○ FOO (1)\n";
actual = PrettyPrinter.prettyPrint(tree);
assertEquals(expected, actual);
boolean removed = tree.remove("BAZ");
assertFalse(removed);
expected =
"○\n" + // we expect no change
"├── ○ BAR (2)\n" +
"└── ○ FOO (1)\n";
actual = PrettyPrinter.prettyPrint(tree);
assertEquals(expected, actual);
}
示例5: main
import com.googlecode.concurrenttrees.common.PrettyPrinter; //导入方法依赖的package包/类
public static void main(String[] args) {
// A file system to store Brochure objects...
InMemoryFileSystem<Brochure> fileSystem = new ConcurrentRadixTreeInMemoryFileSystem<Brochure>();
Brochure fordFocusBrochure = new Brochure("Marketing stuff for Ford Focus");
Brochure fordF150Brochure = new Brochure("Marketing stuff for Ford F150");
Brochure hondaCivicBrochure = new Brochure("Marketing stuff for Honda Civic");
fileSystem.addFile("/brochures/ford/", "ford_focus_brochure.txt", fordFocusBrochure);
fileSystem.addFile("/brochures/ford/", "ford_f150_brochure.txt", fordF150Brochure);
fileSystem.addFile("/brochures/honda/", "honda_civic_brochure.txt", hondaCivicBrochure);
System.out.println("Internal file system representation (not public):-");
PrettyPrinter.prettyPrint((PrettyPrintable) fileSystem, System.out);
System.out.println();
System.out.println("Retrieve Ford brochure names in directory: " + fileSystem.getFileNamesInDirectory("/brochures/ford/"));
System.out.println("Retrieve Honda brochure names in directory: " + fileSystem.getFileNamesInDirectory("/brochures/honda/"));
System.out.println("Retrieve All brochure names recursively: " + fileSystem.getFileNamesInDirectoryRecursive("/brochures/"));
System.out.println();
Brochure fordF150BrochureRetrieved = fileSystem.getFile("/brochures/ford/", "ford_f150_brochure.txt");
System.out.println("Retrieve Ford F150 brochure contents using exact file name: " + fordF150BrochureRetrieved);
System.out.println();
System.out.println("Retrieve all Ford brochure contents in directory:-");
Collection<Brochure> fordBrochuresRetrieved = fileSystem.getFilesInDirectory("/brochures/ford/");
for (Brochure fordBrochure : fordBrochuresRetrieved) {
System.out.println(fordBrochure);
}
System.out.println();
System.out.println("Retrieve contents from entire file system recursively:-");
Collection<Brochure> allFiles = fileSystem.getFilesInDirectoryRecursive("/");
for (Brochure file : allFiles) {
System.out.println(file);
}
}
示例6: main
import com.googlecode.concurrenttrees.common.PrettyPrinter; //导入方法依赖的package包/类
public static void main(String[] args) {
System.out.println("Suffixes for 'TEST': " + Iterables.toString(CharSequences.generateSuffixes("TEST")));
System.out.println("Suffixes for 'TOAST': " + Iterables.toString(CharSequences.generateSuffixes("TOAST")));
System.out.println("Suffixes for 'TEAM': " + Iterables.toString(CharSequences.generateSuffixes("TEAM")));
SuffixTree<Integer> tree = new ConcurrentSuffixTree<Integer>(new DefaultCharArrayNodeFactory());
tree.put("TEST", 1);
tree.put("TOAST", 2);
tree.put("TEAM", 3);
System.out.println();
System.out.println("Tree structure:");
// PrettyPrintable is a non-public API for testing, prints semi-graphical representations of trees...
PrettyPrinter.prettyPrint((PrettyPrintable) tree, System.out);
System.out.println();
System.out.println("Value for 'TEST' (exact match): " + tree.getValueForExactKey("TEST"));
System.out.println("Value for 'TOAST' (exact match): " + tree.getValueForExactKey("TOAST"));
System.out.println();
System.out.println("Keys ending with 'ST': " + Iterables.toString(tree.getKeysEndingWith("ST")));
System.out.println("Keys ending with 'M': " + Iterables.toString(tree.getKeysEndingWith("M")));
System.out.println("Values for keys ending with 'ST': " + Iterables.toString(tree.getValuesForKeysEndingWith("ST")));
System.out.println("Key-Value pairs for keys ending with 'ST': " + Iterables.toString(tree.getKeyValuePairsForKeysEndingWith("ST")));
System.out.println();
System.out.println("Keys containing 'TE': " + Iterables.toString(tree.getKeysContaining("TE")));
System.out.println("Keys containing 'A': " + Iterables.toString(tree.getKeysContaining("A")));
System.out.println("Values for keys containing 'A': " + Iterables.toString(tree.getValuesForKeysContaining("A")));
System.out.println("Key-Value pairs for keys containing 'A': " + Iterables.toString(tree.getKeyValuePairsForKeysContaining("A")));
}
示例7: testRemove_ZeroChildEdges_DirectChildOfRoot
import com.googlecode.concurrenttrees.common.PrettyPrinter; //导入方法依赖的package包/类
@Test
public void testRemove_ZeroChildEdges_DirectChildOfRoot() {
ConcurrentRadixTree<Integer> tree = new ConcurrentRadixTree<Integer>(getNodeFactory());
tree.put("FOO", 1);
tree.put("BAR", 2);
// ○
// ├── ○ BAR (2)
// └── ○ FOO (1)
String expected, actual;
expected =
"○\n" +
"├── ○ BAR (2)\n" +
"└── ○ FOO (1)\n";
actual = PrettyPrinter.prettyPrint(tree);
assertEquals(expected, actual);
boolean removed = tree.remove("FOO");
assertTrue(removed);
// ○ // FOO removed, which involved recreating the root to change its child edges
// └── ○ BAR (2)
expected =
"○\n" +
"└── ○ BAR (2)\n";
actual = PrettyPrinter.prettyPrint(tree);
assertEquals(expected, actual);
}
示例8: testRemove_RemoveNonExistentKey
import com.googlecode.concurrenttrees.common.PrettyPrinter; //导入方法依赖的package包/类
@Test
public void testRemove_RemoveNonExistentKey() throws Exception {
ConcurrentSuffixTree<Integer> tree = newConcurrentSuffixTreeForUnitTests();
String expected, actual;
tree.put("BANANA", 1);
tree.put("BANDANA", 2);
expected =
"○\n" +
"├── ○ A ([BANANA, BANDANA])\n" +
"│ └── ○ N\n" +
"│ ├── ○ A ([BANANA, BANDANA])\n" +
"│ │ └── ○ NA ([BANANA])\n" +
"│ └── ○ DANA ([BANDANA])\n" +
"├── ○ BAN\n" +
"│ ├── ○ ANA ([BANANA])\n" +
"│ └── ○ DANA ([BANDANA])\n" +
"├── ○ DANA ([BANDANA])\n" +
"└── ○ N\n" +
" ├── ○ A ([BANANA, BANDANA])\n" +
" │ └── ○ NA ([BANANA])\n" +
" └── ○ DANA ([BANDANA])\n";
actual = PrettyPrinter.prettyPrint(tree);
assertEquals(expected, actual);
boolean removed = tree.remove("APPLE");
assertFalse(removed);
actual = PrettyPrinter.prettyPrint(tree);
assertEquals(expected, actual);
}
示例9: testRemove_MergeSplitNode
import com.googlecode.concurrenttrees.common.PrettyPrinter; //导入方法依赖的package包/类
@Test
public void testRemove_MergeSplitNode() {
ConcurrentRadixTree<Integer> tree = new ConcurrentRadixTree<Integer>(getNodeFactory());
tree.put("TEST", 1);
tree.put("TEAM", 2);
tree.put("TOAST", 3);
String expected, actual;
expected =
"○\n" +
"└── ○ T\n" +
" ├── ○ E\n" +
" │ ├── ○ AM (2)\n" +
" │ └── ○ ST (1)\n" +
" └── ○ OAST (3)\n";
actual = PrettyPrinter.prettyPrint(tree);
assertEquals(expected, actual);
boolean removed = tree.remove("TEST");
assertTrue(removed);
expected =
"○\n" +
"└── ○ T\n" +
" ├── ○ EAM (2)\n" +
" └── ○ OAST (3)\n";
actual = PrettyPrinter.prettyPrint(tree);
assertEquals(expected, actual);
}
示例10: main
import com.googlecode.concurrenttrees.common.PrettyPrinter; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
ConcurrentSuffixTree<String> tree = new ConcurrentSuffixTree<String>(new DefaultCharSequenceNodeFactory());
for (String file : files) {
String manuscript = IOUtil.loadTextFileFromClasspath(file, true, true, true); // true = convert to lowercase
String manuscriptName = file.replaceAll("/.*/.*/", "").replace(".txt", "");
tree.put(manuscript, manuscriptName);
System.out.println("Added " + manuscriptName);
}
System.out.println("Built Suffix Tree. Estimating size on disk...");
DummyAppendable dummyAppendable = new DummyAppendable();
PrettyPrinter.prettyPrint(tree, dummyAppendable);
System.out.println("Done. Size on disk estimate:");
System.out.println("Lines: " + dummyAppendable.lineCount);
System.out.println("Characters: " + dummyAppendable.charCount);
}
示例11: main
import com.googlecode.concurrenttrees.common.PrettyPrinter; //导入方法依赖的package包/类
public static void main(String[] args) {
ConcurrentRadixTree<WordValue> tree = new ConcurrentRadixTree<WordValue>(new DefaultCharArrayNodeFactory());
for (String file : files) {
Set<String> wordsInFile = IOUtil.loadWordsFromTextFileOnClasspath(file, true); // true = convert to lowercase
for (String word : wordsInFile) {
WordValue wordValue = tree.getValueForExactKey(word);
if (wordValue == null) {
wordValue = new WordValue(word);
tree.put(word, wordValue); // not using concurrency support here
}
wordValue.manuscriptsContainingWord.add(file.replaceAll("/.*/.*/", "").replace(".txt", ""));
}
}
final String radixTreePrinted = PrettyPrinter.prettyPrint(tree);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JTextArea textArea = new JTextArea();
textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));
textArea.setText(radixTreePrinted);
JScrollPane scrollPane = new JScrollPane(textArea);
textArea.setEditable(false);
JFrame frame = new JFrame("Shakespeare Radix Tree");
frame.add(scrollPane);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setSize(640, 480);
frame.setVisible(true);
}
});
}
示例12: testRemove_DoNotRemoveSplitNode
import com.googlecode.concurrenttrees.common.PrettyPrinter; //导入方法依赖的package包/类
@Test
public void testRemove_DoNotRemoveSplitNode() {
ConcurrentRadixTree<Integer> tree = new ConcurrentRadixTree<Integer>(getNodeFactory());
tree.put("FOOBAR", 1);
tree.put("FOOD", 2);
// ○
// └── ○ FOO // implicit node added automatically
// ├── ○ BAR (1)
// └── ○ D (2)
String expected, actual;
expected =
"○\n" +
"└── ○ FOO\n" +
" ├── ○ BAR (1)\n" +
" └── ○ D (2)\n";
actual = PrettyPrinter.prettyPrint(tree);
assertEquals(expected, actual);
boolean removed = tree.remove("FOO");
assertFalse(removed);
expected =
"○\n" +
"└── ○ FOO\n" + // we expect no change
" ├── ○ BAR (1)\n" +
" └── ○ D (2)\n";
actual = PrettyPrinter.prettyPrint(tree);
assertEquals(expected, actual);
}
示例13: testPut_AddToRoot
import com.googlecode.concurrenttrees.common.PrettyPrinter; //导入方法依赖的package包/类
@Test
public void testPut_AddToRoot() {
ConcurrentRadixTree<Integer> tree = new ConcurrentRadixTree<Integer>(getNodeFactory());
tree.put("A", 1);
String expected =
"○\n" +
"└── ○ A (1)\n";
String actual = PrettyPrinter.prettyPrint(tree);
assertEquals(expected, actual);
}
示例14: testPut_AppendChild
import com.googlecode.concurrenttrees.common.PrettyPrinter; //导入方法依赖的package包/类
@Test
public void testPut_AppendChild() {
ConcurrentRadixTree<Integer> tree = new ConcurrentRadixTree<Integer>(getNodeFactory());
tree.put("FOO", 1);
tree.put("FOOBAR", 2);
String expected =
"○\n" +
"└── ○ FOO (1)\n" +
" └── ○ BAR (2)\n";
String actual = PrettyPrinter.prettyPrint(tree);
assertEquals(expected, actual);
}
示例15: testPut_SplitEdge
import com.googlecode.concurrenttrees.common.PrettyPrinter; //导入方法依赖的package包/类
@Test
public void testPut_SplitEdge() {
ConcurrentRadixTree<Integer> tree = new ConcurrentRadixTree<Integer>(getNodeFactory());
tree.put("FOOBAR", 1);
tree.put("FOO", 2);
String expected =
"○\n" +
"└── ○ FOO (2)\n" +
" └── ○ BAR (1)\n";
String actual = PrettyPrinter.prettyPrint(tree);
assertEquals(expected, actual);
}