001 /* 002 * EntryCounter.java 003 * 004 * Created on August 8, 2006, 1:38 PM 005 * 006 * 007 * This file is part of the STAR Scheduler. 008 * Copyright (c) 2002-2006 STAR Collaboration - Brookhaven National Laboratory 009 * 010 * STAR Scheduler is free software; you can redistribute it and/or modify 011 * it under the terms of the GNU General Public License as published by 012 * the Free Software Foundation; either version 2 of the License, or 013 * (at your option) any later version. 014 * 015 * STAR Scheduler is distributed in the hope that it will be useful, 016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 018 * GNU General Public License for more details. 019 * 020 * You should have received a copy of the GNU General Public License 021 * along with STAR Scheduler; if not, write to the Free Software 022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 023 */ 024 025 package gov.bnl.star.offline.scheduler.dataset; 026 027 import java.io.BufferedReader; 028 import java.io.FileNotFoundException; 029 import java.io.FileReader; 030 import java.io.IOException; 031 032 /** 033 * This class is used to quickly count and display the number of entries in 034 * the total dataset. These are printed to the screen. It wallows verification 035 * the entries are not dropped in error the after a dataset manipulation. 036 * 037 * @author Levente B. Hajdu 038 */ 039 public class EntryCounter { 040 041 /** Creates a new instance of EntryCounter */ 042 public EntryCounter() {} 043 044 private static int lastcout = 0; 045 046 /** 047 *Print the total number of entries in the dataset to the screen. 048 * 049 * @param dataset The filled dataset object from which the entries will be counted. 050 * @param printChangeOnly If this value is true it will only print the changes if 051 * there is a chnage in the number of entries in the datset. 052 **/ 053 public static void countAndPrint(Dataset dataset, boolean printChangeOnly){ 054 String datsetEntry; 055 int count = 0; 056 try { 057 058 BufferedReader currentDataset = new BufferedReader( new FileReader(dataset.getDatasetName() )); 059 while ((datsetEntry = currentDataset.readLine()) != null){ 060 if(! datsetEntry.matches(dataset.getSplitRegX()) ) count ++; 061 } 062 063 } catch (FileNotFoundException ex) { 064 ex.printStackTrace(); 065 } catch (IOException ex) { 066 ex.printStackTrace(); 067 } 068 069 070 if((count != lastcout)&&(lastcout != 0)){ //files where dropped 071 System.out.println("Started with " + lastcout + "files, current size is " + count + "files, " + (lastcout - count) + "files dropped."); 072 }else if(! printChangeOnly){ 073 System.out.println("Dataset size is " + count + "files"); 074 } 075 076 if(count == 0){ 077 throw new RuntimeException("The dataset(file) size is zero."); 078 } 079 080 lastcout = count; 081 count = 0; 082 return; 083 084 } 085 086 087 088 089 090 091 }