LandsatQAFactory { static LandsatQA create(File mtlFile) throws IOException { boolean isCollectionProduct = false; boolean isOLI = false; boolean isMSS = false; boolean isTM = false; BufferedReader reader = null; try { FileReader fileReader = new FileReader(mtlFile); reader = new BufferedReader(fileReader); String line = reader.readLine(); while (line != null) { if (line.contains("COLLECTION_NUMBER")) { isCollectionProduct = true; } if (line.contains("SENSOR_ID")) { if (line.contains("OLI")) { isOLI = true; } else if (line.contains("MSS")) { isMSS = true; } else if (line.contains("TM")) { isTM = true; } } if(isCollectionProduct && isMSS) return new CollectionMSSLandsatQA(); if(isCollectionProduct && isOLI) return new CollectionOLILandsatQA(); if(isCollectionProduct && isTM) return new CollectionTMLandsatQA(); if(!isCollectionProduct && isOLI) return new PreCollectionLandsatQA(); line = reader.readLine(); } } finally { if (reader != null) { reader.close(); } } return null; }    }
@Test public void testPreCollectionQA() throws Exception { File testFile = getTestFile("test_L8_MTL.txt"); LandsatQA landsatQA = LandsatQAFactory.create(testFile); assertTrue(landsatQA instanceof PreCollectionLandsatQA); }
@Test public void testCollectionOLIQA() throws Exception { File testFile = getTestFile("test_CollectionOLI.txt"); LandsatQA landsatQA = LandsatQAFactory.create(testFile); assertTrue(landsatQA instanceof CollectionOLILandsatQA); }
@Test public void testNoQA() throws Exception { File testFile = getTestFile("test_7_reproc_MTL.txt"); LandsatQA landsatQA = LandsatQAFactory.create(testFile); assertNull(landsatQA); }