package com.macmillan.nmeyers; import java.util.*; /* * ThreadInfo.java: Part of the PerfAnal tool * * This class encapsulates per-thread information. * * Author: Nathan Meyers, nmeyers@javalinux.net * $Id: ThreadInfo.java,v 1.3 1999/11/10 03:36:14 nathanm Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, 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 Public License for more details. * * You should have received a copy of the GNU General Public License * with this program. If not, the license is available from the * GNU project, at http://www.gnu.org. */ class ThreadInfo implements Comparable { public String threadName; public int threadNumber; public int count = 0; public boolean enabled = true; ThreadInfo(String str, int n) { threadName = str; threadNumber = n; } static ThreadInfo parse(String str) { int idx = str.indexOf("id = "); if (idx == -1) return null; int comma = str.indexOf(',', idx); if (comma == -1) return null; int threadNumber = Integer.parseInt(str.substring(idx + 5, comma)); int quote1 = str.indexOf("\""); if (quote1 == -1) return null; int quote2 = str.indexOf("\"", ++quote1); if (quote2 == -1) return null; String threadName = str.substring(quote1, quote2); return new ThreadInfo(threadName, threadNumber); } public int compareTo(Object o) { return threadNumber - ((ThreadInfo)o).threadNumber; } public boolean equals(Object o) { return threadNumber == ((ThreadInfo)o).threadNumber; } public String toString() { return "Thread #" + threadNumber + ": " + threadName + " (" + count + " ticks)"; } }