Author: tchemit Date: 2011-08-01 17:40:21 +0200 (Mon, 01 Aug 2011) New Revision: 2160 Url: http://nuiton.org/repositories/revision/nuiton-utils/2160 Log: Evolution #1650: Remove deprecated api Removed: trunk/nuiton-utils/src/main/java/org/nuiton/util/StreamKeywordTokenizer.java trunk/nuiton-utils/src/main/java/org/nuiton/util/TimeTrace.java trunk/nuiton-utils/src/test/java/org/nuiton/util/StreamKeywordTokenizerTest.java Deleted: trunk/nuiton-utils/src/main/java/org/nuiton/util/StreamKeywordTokenizer.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/StreamKeywordTokenizer.java 2011-08-01 15:18:00 UTC (rev 2159) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/StreamKeywordTokenizer.java 2011-08-01 15:40:21 UTC (rev 2160) @@ -1,101 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/* * - * StreamKeywordTokenizer.java - * - * Created: 27 mai 2004 - * - * @author Benjamin Poussin <poussin@codelutin.com> - * Copyright Code Lutin - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : */ - -package org.nuiton.util; - -import java.io.StreamTokenizer; -import java.util.HashSet; -import java.io.IOException; -import java.io.Reader; - -/** - * TODO What is it for ? - * @deprecated since 2.2 : unused, undocumented - */ -@Deprecated -public class StreamKeywordTokenizer extends StreamTokenizer { // StreamKeywordTokenizer - - public static final int TT_KEYWORD = -101; - public static final int TT_VARIABLE = -102; - protected HashSet<String> keywords = new HashSet<String>(); - protected boolean lowerCaseKeyword; - protected int quoteCharVariable = -1; - - public StreamKeywordTokenizer(Reader in){ - super(in); - } - - public int nextToken() throws IOException { - super.nextToken(); - if(ttype == TT_WORD){ - String keyword = sval; - if(lowerCaseKeyword){ - keyword = keyword.toLowerCase(); - } - if(keywords.contains(keyword)){ - sval = keyword; - ttype = TT_KEYWORD; - } - }else if(ttype == quoteCharVariable){ - ttype = TT_VARIABLE; - } - return ttype; - } - - public void addKeyword(String keyword){ - if(lowerCaseKeyword){ - keywords.add(keyword.toLowerCase()); - }else{ - keywords.add(keyword); - } - } - - /** - * This method must be call before addKeyword. - * @param fl - */ - public void lowerCaseKeyword(boolean fl){ - lowerCaseKeyword = fl; - } - - public void quoteCharVariable(int c){ - quoteChar(c); - quoteCharVariable = c; - } - -} // StreamKeywordTokenizer - Deleted: trunk/nuiton-utils/src/main/java/org/nuiton/util/TimeTrace.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/TimeTrace.java 2011-08-01 15:18:00 UTC (rev 2159) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/TimeTrace.java 2011-08-01 15:40:21 UTC (rev 2160) @@ -1,174 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.util; - -import java.util.HashMap; -import java.util.Map; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Cette classe permet de facilement trace le temps d'execution entre deux points - * - * usage - * <pre> - * TimeTrace timeTrace = new TimeTrace(5000, 1000); - * - * - * long start = timeTrace.getTime(); - * ... - * // do some work - * ... - * timeTrace.add(start, "do some work"); - * - * - * System.out.println ("time: " + timeTrace.getCallCount()); - * </pre> - * - * @see CallAnalyse - * @author poussin - * @version $Revision$ - * @deprecated since 2.1 use {@link org.nuiton.util.TimeLog} - * - * Last update: $Date$ - * by : $Author$ - */ -@Deprecated -public class TimeTrace { - - /** Logger. */ - private Log log = LogFactory.getLog(TimeTrace.class); - - static public class CallStat { - long callNumber = 0; - long callTime = 0; - - @Override - public String toString() { - String callTimeString = - StringUtil.convertTime(callTime); - String avgTimeString = - StringUtil.convertTime((callTime/ callNumber)); - return String.format("total call %s, total time %s, avg time %s", - callNumber, callTimeString, avgTimeString); - } - - } - - /** time to trigger log time in info level (ns) (default: 1s) */ - protected long timeToLogInfo = 1000l * 1000000l; - /** time to trigger log time in warn level (ns) (default: 3s) */ - protected long timeToLogWarn = 3000l * 1000000l; - - /** for each method of all proxies, keep number of call */ - protected Map<String, CallStat> callCount = new HashMap<String, CallStat>(); - - public TimeTrace() { - } - - /** - * - * @param timeToLogInfo time in milliseconde after that we log info - * @param timeToLogWarn time in milliseconde after that we log warn - */ - public TimeTrace(long timeToLogInfo, long timeToLogWarn) { - setTimeToLogInfo(timeToLogInfo); - setTimeToLogWarn(timeToLogWarn); - } - - /** - * - * @param timeToLogInfoMs time in milliseconde after that we log info - */ - public void setTimeToLogInfo(long timeToLogInfoMs) { - this.timeToLogInfo = timeToLogInfoMs * 1000000l; // convert ms -> ns - } - - /** - * - * @param timeToWarnInfoMs time in milliseconde after that we log warn - */ - public void setTimeToLogWarn(long timeToLogWarnMs) { - this.timeToLogWarn = timeToLogWarnMs * 1000000l; // convert ms -> ns - } - - public Map<String, CallStat> getCallCount() { - return callCount; - } - - /** - * return time in format acceptable for {@link #add(timeToLogInfo, timeToLogInfo, null)} - * @return - */ - static public long getTime() { - return System.nanoTime(); - } - - /** - * add new trace, stop time is automaticaly computed - * - * @param startNs time returned by {@link #getTime()} method - * @param methodName key name to store this time - */ - public void add(long startNs, String methodName) { - add(startNs, getTime(), methodName); - } - - /** - * add new trace - * - * @param startNs time returned by {@link #getTime()} method - * @param stopNs time returned by {@link #getTime()} method - * @param methodName key name to store this time - */ - public void add(long startNs, long stopNs, String methodName) { - long time = stopNs - startNs; - - // incremente le nombre d'appel pour cette methode - CallStat calls = callCount.get(methodName); - if (calls == null) { - // is not thread safe, but if we lose one or two call, is not importante - calls = new CallStat(); - callCount.put(methodName, calls); - } - calls.callNumber++; - calls.callTime += time; - - // affiche le temps de l'appel si necessaire - String timeString = StringUtil.convertTime(time); - String msg = String.format("[%s] for method %s (%s)", - timeString, methodName, calls); - - if (time > timeToLogWarn && log.isWarnEnabled()) { - log.warn(msg); - } else if (time > timeToLogInfo && log.isInfoEnabled()) { - log.info(msg); - } else if (log.isDebugEnabled()) { - log.debug(msg); - } - - } - -} Deleted: trunk/nuiton-utils/src/test/java/org/nuiton/util/StreamKeywordTokenizerTest.java =================================================================== --- trunk/nuiton-utils/src/test/java/org/nuiton/util/StreamKeywordTokenizerTest.java 2011-08-01 15:18:00 UTC (rev 2159) +++ trunk/nuiton-utils/src/test/java/org/nuiton/util/StreamKeywordTokenizerTest.java 2011-08-01 15:40:21 UTC (rev 2160) @@ -1,111 +0,0 @@ -/* - * #%L - * Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/* * - * StreamKeywordTokenizer.java - * - * Created: 27 mai 2004 - * - * @author Benjamin Poussin <poussin@codelutin.com> - * Copyright Code Lutin - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : */ - -package org.nuiton.util; - -import junit.framework.TestCase; -import java.io.StringReader; - -public class StreamKeywordTokenizerTest extends TestCase { // StreamKeywordTokenizer - - public void testKeywordLower() throws Exception { - StringReader in = new StringReader("Coucou tOUt TouT lE MONDE"); - StreamKeywordTokenizer parser = new StreamKeywordTokenizer(in); - parser.resetSyntax(); - parser.commentChar('#'); - parser.eolIsSignificant(false); - parser.lowerCaseMode(false); - parser.parseNumbers(); - parser.quoteChar('"'); - parser.slashSlashComments(true); - parser.slashStarComments(true); - parser.whitespaceChars(0, ' '); - parser.wordChars('A', 'Z'); - parser.wordChars('a', 'z'); - - parser.lowerCaseKeyword(true); - parser.addKeyword("Coucou"); - parser.addKeyword("TouT"); - parser.addKeyword("mondE"); - - assertTrue(StreamKeywordTokenizer.TT_KEYWORD == parser.nextToken() - && parser.sval.equals("coucou")); - assertTrue(StreamKeywordTokenizer.TT_KEYWORD == parser.nextToken() - && parser.sval.equals("tout")); - assertTrue(StreamKeywordTokenizer.TT_KEYWORD == parser.nextToken() - && parser.sval.equals("tout")); - assertTrue(StreamKeywordTokenizer.TT_WORD == parser.nextToken() - && parser.sval.equals("lE")); - assertTrue(StreamKeywordTokenizer.TT_KEYWORD == parser.nextToken() - && parser.sval.equals("monde")); - - } - - public void testKeyword() throws Exception { - StringReader in = new StringReader("Coucou tOUt TouT lE MONDE"); - StreamKeywordTokenizer parser = new StreamKeywordTokenizer(in); - parser.resetSyntax(); - parser.commentChar('#'); - parser.eolIsSignificant(false); - parser.lowerCaseMode(false); - parser.parseNumbers(); - parser.quoteChar('"'); - parser.slashSlashComments(true); - parser.slashStarComments(true); - parser.whitespaceChars(0, ' '); - parser.wordChars('A', 'Z'); - parser.wordChars('a', 'z'); - - parser.lowerCaseKeyword(false); - parser.addKeyword("Coucou"); - parser.addKeyword("TouT"); - parser.addKeyword("mondE"); - - assertTrue(StreamKeywordTokenizer.TT_KEYWORD == parser.nextToken() - && parser.sval.equals("Coucou")); - assertTrue(StreamKeywordTokenizer.TT_WORD == parser.nextToken() - && parser.sval.equals("tOUt")); - assertTrue(StreamKeywordTokenizer.TT_KEYWORD == parser.nextToken() - && parser.sval.equals("TouT")); - assertTrue(StreamKeywordTokenizer.TT_WORD == parser.nextToken() - && parser.sval.equals("lE")); - assertTrue(StreamKeywordTokenizer.TT_WORD == parser.nextToken() - && parser.sval.equals("MONDE")); - } - -} // StreamKeywordTokenizer -