Clover coverage report -
Coverage timestamp: jeu. juin 15 2006 08:24:33 CEST
file stats: LOC: 148   Methods: 10
NCLOC: 106   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
InstanceReader.java 40% 48% 40% 44,4%
coverage coverage
 1    /*
 2    * Created on 3 juin 2004
 3    *
 4    * To change the template for this generated file go to Window - Preferences -
 5    * Java - Code Generation - Code and Comments
 6    */
 7    package org.sat4j.reader;
 8   
 9    import java.io.FileNotFoundException;
 10    import java.io.IOException;
 11    import java.net.URL;
 12   
 13    import org.sat4j.specs.ContradictionException;
 14    import org.sat4j.specs.IProblem;
 15    import org.sat4j.specs.ISolver;
 16   
 17    /**
 18    * An reader having the responsability to choose the right reader according to
 19    * the input.
 20    *
 21    * @author leberre
 22    */
 23    public class InstanceReader extends Reader {
 24   
 25    // private final DimacsReader dimacs;
 26    private LecteurDimacs dimacs;
 27   
 28    private GoodOPBReader opb;
 29   
 30    private ExtendedDimacsReader edimacs;
 31   
 32    private CSPReader csp;
 33   
 34    private CSPReader csp2;
 35   
 36    private CSPReader csp3;
 37   
 38    private Reader reader = null;
 39   
 40    private final ISolver solver;
 41   
 42  2499 public InstanceReader(ISolver solver) {
 43    // dimacs = new DimacsReader(solver);
 44  2499 this.solver = solver;
 45    }
 46   
 47  1663 private Reader getDefaultSATReader() {
 48  1663 if (dimacs == null) {
 49  1663 dimacs = new LecteurDimacs(solver);
 50    }
 51  1663 return dimacs;
 52    }
 53   
 54  828 private Reader getDefaultOPBReader() {
 55  828 if (opb == null) {
 56  828 opb = new GoodOPBReader(solver);
 57    }
 58  828 return opb;
 59    }
 60   
 61  0 private Reader getDefaultExtendedDimacsReader() {
 62  0 if (edimacs == null) {
 63  0 edimacs = new ExtendedDimacsReader(solver);
 64    }
 65  0 return edimacs;
 66    }
 67   
 68  0 private Reader getCSPReader1() {
 69  0 if (csp == null) {
 70  0 csp = new CSPReader(solver);
 71    }
 72  0 return csp;
 73    }
 74   
 75  0 private Reader getCSPReader2() {
 76  0 if (csp2 == null) {
 77  0 csp2 = new CSPSupportReader(solver);
 78    }
 79  0 return csp2;
 80    }
 81   
 82  0 private Reader getCSPReader3() {
 83  0 if (csp3 == null) {
 84  0 csp3 = new CSPExtSupportReader(solver);
 85    }
 86  0 return csp3;
 87    }
 88   
 89  2491 @Override
 90    public IProblem parseInstance(String filename)
 91    throws FileNotFoundException, ParseFormatException, IOException,
 92    ContradictionException {
 93  2491 String fname;
 94  2491 boolean isHttp = false;
 95  2491 String tempFileName = "";
 96  2491 String prefix = "";
 97   
 98  2491 if (filename.startsWith("http://")) {
 99  0 isHttp = true;
 100  0 tempFileName = filename;
 101  0 filename = filename.substring(filename.lastIndexOf('/'), filename.length() - 1);
 102    }
 103   
 104  2491 if (filename.indexOf(':') != -1) {
 105   
 106  0 String[] parts = filename.split(":");
 107  0 filename = parts[1];
 108  0 prefix = parts[0].toUpperCase();
 109   
 110    }
 111   
 112  2491 if (filename.endsWith(".gz")) {
 113  0 fname = filename.substring(0, filename.lastIndexOf('.'));
 114    } else {
 115  2491 fname = filename;
 116    }
 117  2491 if ("CSP".equals(prefix)) {
 118  0 reader = getCSPReader1();
 119  2491 } else if ("CSP3".equals(prefix)) {
 120  0 reader = getCSPReader3();
 121  2491 } else if (fname.endsWith(".txt") || "CSP2".equals(prefix)) {
 122  0 reader = getCSPReader2();
 123  2491 } else if (fname.endsWith(".opb") || "PB".equals(prefix)) {
 124  828 reader = getDefaultOPBReader();
 125  1663 } else if (fname.endsWith(".edimacs") || fname.endsWith(".ncnf")
 126    || "EDIMACS".equals(prefix)) {
 127  0 reader = getDefaultExtendedDimacsReader();
 128    } else {
 129  1663 reader = getDefaultSATReader();
 130    }
 131   
 132  2491 if (isHttp) {
 133  0 return reader.parseInstance((new URL(tempFileName)).openStream());
 134    }
 135  2491 return reader.parseInstance(filename);
 136    }
 137   
 138  0 @Override
 139    public String decode(int[] model) {
 140  0 return reader.decode(model);
 141    }
 142   
 143   
 144  0 @Override
 145    public IProblem parseInstance(java.io.Reader in) throws ParseFormatException, ContradictionException, IOException {
 146  0 throw new UnsupportedOperationException();
 147    }
 148    }