Menu

[r70]: / GraphScript / trunk / ls / util / Utils.java  Maximize  Restore  History

Download this file

103 lines (90 with data), 2.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
package ls.util;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import ls.util.msg.ErrorHandler;
import ls.util.msg.IOStreamErrorHandler;
import ls.util.msg.IOStreamMessageHandler;
import ls.util.msg.MessageHandler;
import ls.util.msg.MessageManager;
/*
* Created on 07/06/2004
*/
/**
*
*
* @author Lior Schejter
*/
public class Utils
{
private static MessageManager messageManager = new MessageManager();
// private static IOStreamErrorHandler errorHandler = new IOStreamErrorHandler("ls");
// private static IOStreamMessageHandler msgHandler = new IOStreamMessageHandler();
public static void addMessageHandler(MessageHandler handler)
{
if (handler == null) return;
messageManager.registerMessageHandler(handler);
}
public static void addErrorHandler(ErrorHandler eh)
{
if (eh == null) return;
messageManager.registerErrorHandler(eh);
}
/* (non-Javadoc)
* @see ls.util.msg.ErrorHandler#handleException(java.lang.Exception)
*/
public static void exn(Exception exn)
{
messageManager.exn(exn);
}
public static void err(String errMsg)
{
messageManager.err("Error: " + errMsg);
}
/* (non-Javadoc)
* @see ls.util.msg.MessageHandler#handleMsg(java.lang.String)
*/
public static void msg(String _msg)
{
messageManager.msg(_msg);
}
public static final String EMPTY_STRING = "";
/**
* Return a new collection, with all the elements in the given iterator
* @param iter
* @return
*/
public static <E> Collection<E> collectionFromIterator(Iterator<E> iter)
{
Collection<E> ret = new ArrayList<E>();
if (iter != null)
{
for (;iter.hasNext();)
{
ret.add(iter.next());
}
}
return ret;
}
/**
* Add the elments provided by the given iterator to the given collection
* @param coll
* @param iter
*/
public static <E> void addToCollection(Collection<E> coll,Iterator<? extends E> iter)
{
if (coll == null || iter == null) return;
for (; iter.hasNext();)
coll.add(iter.next());
}
public static String fileExtension(File f) throws IOException
{
if (f == null) return null;
String filename = f.getCanonicalPath();
int lastDotInd = filename.lastIndexOf('.');
if (lastDotInd < 0) return "";
return filename.substring(lastDotInd+1);
}
}
MongoDB Logo MongoDB