📄 printing.java
字号:
package com.reddragon2046.base.utilities.data.algorithms;
import com.reddragon2046.base.utilities.data.InputIterator;
import com.reddragon2046.base.utilities.data.util.IteratorFactory;
import java.io.PrintStream;
import java.util.Collection;
import java.util.Iterator;
public final class Printing
{
private Printing()
{
}
public static String toString(Collection collection, String name)
{
return name + toString(IteratorFactory.start(collection), IteratorFactory.finish(collection));
}
public static String toString(Collection collection)
{
return toString(collection, "");
}
private static String toString(InputIterator first, InputIterator last)
{
if(!first.isCompatibleWith(last))
{
String msg = "\"first\" iterator and \"last\" iterator not compatible (" + first.getClass().getName() + ", " + last.getClass().getName() + ")";
throw new IllegalArgumentException(msg);
}
if(first.atEnd())
return "[]";
InputIterator firstx = (InputIterator)first.clone();
StringBuffer buffer = new StringBuffer();
buffer.append("[");
boolean firstone = true;
for(; !firstx.equals(last); buffer.append(firstx.next()))
if(firstone)
firstone = false;
else
buffer.append(", ");
buffer.append("]");
return buffer.toString();
}
private static void print(InputIterator first, InputIterator last)
{
System.out.print(toString(first, last));
}
public static void print(Collection collection)
{
System.out.print(toString(IteratorFactory.start(collection), IteratorFactory.finish(collection)));
}
private static void println(InputIterator first, InputIterator last)
{
System.out.println(toString(first, last));
}
public static void println(Collection collection)
{
System.out.println(toString(IteratorFactory.start(collection), IteratorFactory.finish(collection)));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -