001    /*
002     * $RCSfile: QueryResultToolkit.java,v $
003     *
004     * Created on April 2, 2006, 4:52 PM
005     *
006     * This file is part of the STAR Scheduler.
007     * Copyright (c) 2002-2003 STAR Collaboration - Brookhaven National Laboratory
008     *
009     * STAR Scheduler is free software; you can redistribute it and/or modify
010     * it under the terms of the GNU General Public License as published by
011     * the Free Software Foundation; either version 2 of the License, or
012     * (at your option) any later version.
013     *
014     * STAR Scheduler is distributed in the hope that it will be useful,
015     * but WITHOUT ANY WARRANTY; without even the implied warranty of
016     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017     * GNU General Public License for more details.
018     *
019     * You should have received a copy of the GNU General Public License
020     * along with STAR Scheduler; if not, write to the Free Software
021     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
022     */
023    
024    package gov.bnl.star.offline.scheduler.policy;
025    
026    import gov.bnl.star.offline.scheduler.catalog.PhysicalFile;
027    import gov.bnl.star.offline.scheduler.catalog.QueryResult;
028    import java.util.*;
029    
030    /**
031     *
032     * @author Gabriele Carcassi
033     * @version $Revision: 1.6 $ $Date: 2006/11/21 00:41:31 $
034     */
035    public class QueryResultToolkit {
036        
037        private QueryResultToolkit() {
038        }
039        
040        public static List getFilesOnOneLocation(QueryResult fileList){
041            List singleCopy = new ArrayList();
042            Set files = fileList.getLogicalNames();
043            Iterator iter = files.iterator();
044            while (iter.hasNext()) {
045                Object file = iter.next();
046                List copies = fileList.getCopies(file);
047                if (copies.size() == 1)
048                    singleCopy.add(file);
049            }
050            return singleCopy;
051        }
052        
053        public static List getFileOnLocation(QueryResult fileList, Location location) {
054            List locationCopies = new ArrayList();
055            Set files = fileList.getLogicalNames();
056            Iterator iter = files.iterator();
057            while (iter.hasNext()) {
058                Object file = iter.next();
059                List copies = fileList.getCopies(file);
060                Iterator iter2 = copies.iterator();
061                while (iter2.hasNext()) {
062                    PhysicalFile copy = (PhysicalFile) iter2.next();
063                    if (Location.getLocation(copy.asURL()).equals(location)) {
064                        locationCopies.add(file);
065                    }
066                }
067            }
068            return locationCopies;
069        }
070        
071    }