LDENPointNoiseMapFactory implements PointNoiseMap.PropagationProcessDataFactory, PointNoiseMap.IComputeRaysOutFactory { @Override public void initialize(Connection connection, PointNoiseMap pointNoiseMap) throws SQLException { if(ldenConfig.input_mode == LDENConfig.INPUT_MODE.INPUT_MODE_LW_DEN) { List<String> sourceField = JDBCUtilities.getFieldNames(connection.getMetaData(), pointNoiseMap.getSourcesTableName()); List<Integer> frequencyValues = new ArrayList<>(); List<Integer> allFrequencyValues = Arrays.asList(PropagationProcessPathData.DEFAULT_FREQUENCIES_THIRD_OCTAVE); String period = ""; if (ldenConfig.computeLDay || ldenConfig.computeLDEN) { period = "D"; } else if (ldenConfig.computeLEvening) { period = "E"; } else if (ldenConfig.computeLNight) { period = "N"; } String freqField = ldenConfig.lwFrequencyPrepend + period; if (!period.isEmpty()) { for (String fieldName : sourceField) { if (fieldName.startsWith(freqField)) { int freq = Integer.parseInt(fieldName.substring(freqField.length())); int index = allFrequencyValues.indexOf(freq); if (index >= 0) { frequencyValues.add(freq); } } } } Collections.sort(frequencyValues); List<Double> exactFrequencies = new ArrayList<>(); List<Double> aWeighting = new ArrayList<>(); for (int freq : frequencyValues) { int index = allFrequencyValues.indexOf(freq); exactFrequencies.add(PropagationProcessPathData.DEFAULT_FREQUENCIES_EXACT_THIRD_OCTAVE[index]); aWeighting.add(PropagationProcessPathData.DEFAULT_FREQUENCIES_A_WEIGHTING_THIRD_OCTAVE[index]); } if(frequencyValues.isEmpty()) { throw new SQLException("Source table "+pointNoiseMap.getSourcesTableName()+" does not contains any frequency bands"); } if(pointNoiseMap.getPropagationProcessPathData() == null) { ldenConfig.setPropagationProcessPathData(new PropagationProcessPathData(frequencyValues, exactFrequencies, aWeighting)); pointNoiseMap.setPropagationProcessPathData(ldenConfig.propagationProcessPathData); } else { pointNoiseMap.getPropagationProcessPathData().setFrequencies(frequencyValues); pointNoiseMap.getPropagationProcessPathData().setFrequenciesExact(exactFrequencies); pointNoiseMap.getPropagationProcessPathData().setFrequenciesAWeighting(aWeighting); ldenConfig.setPropagationProcessPathData(pointNoiseMap.getPropagationProcessPathData()); } } else { if(pointNoiseMap.getPropagationProcessPathData() == null) { ldenConfig.setPropagationProcessPathData(new PropagationProcessPathData(false)); pointNoiseMap.setPropagationProcessPathData(ldenConfig.propagationProcessPathData); } else { ldenConfig.setPropagationProcessPathData(pointNoiseMap.getPropagationProcessPathData()); } } } LDENPointNoiseMapFactory(Connection connection, LDENConfig ldenConfig); @Override void initialize(Connection connection, PointNoiseMap pointNoiseMap); boolean isKeepRays(); void setKeepRays(boolean keepRays); void start(); void stop(); void cancel(); @Override LDENPropagationProcessData create(FastObstructionTest freeFieldFinder); @Override IComputeRaysOut create(PropagationProcessData threadData, PropagationProcessPathData pathData);  }
@Test public void testReadFrequencies() throws SQLException, IOException { SHPRead.readShape(connection, LDENPointNoiseMapFactoryTest.class.getResource("lw_roads.shp").getFile()); SHPRead.readShape(connection, LDENPointNoiseMapFactoryTest.class.getResource("buildings.shp").getFile()); SHPRead.readShape(connection, LDENPointNoiseMapFactoryTest.class.getResource("receivers.shp").getFile()); LDENConfig ldenConfig = new LDENConfig(LDENConfig.INPUT_MODE.INPUT_MODE_LW_DEN); LDENPointNoiseMapFactory factory = new LDENPointNoiseMapFactory(connection, ldenConfig); PointNoiseMap pointNoiseMap = new PointNoiseMap("BUILDINGS", "LW_ROADS", "RECEIVERS"); pointNoiseMap.setComputeRaysOutFactory(factory); pointNoiseMap.setPropagationProcessDataFactory(factory); pointNoiseMap.initialize(connection, new EmptyProgressVisitor()); assertNotNull(ldenConfig.propagationProcessPathData); assertEquals(8, ldenConfig.propagationProcessPathData.freq_lvl.size()); try(Statement st = connection.createStatement()) { st.execute("ALTER TABLE lw_roads drop column LWD63"); st.execute("ALTER TABLE lw_roads drop column LWD125"); st.execute("ALTER TABLE lw_roads drop column LWD250"); st.execute("ALTER TABLE lw_roads drop column LWD500"); st.execute("ALTER TABLE lw_roads drop column LWD2000"); st.execute("ALTER TABLE lw_roads drop column LWD4000"); st.execute("ALTER TABLE lw_roads drop column LWD8000"); st.execute("ALTER TABLE lw_roads drop column LWE63"); st.execute("ALTER TABLE lw_roads drop column LWE125"); st.execute("ALTER TABLE lw_roads drop column LWE250"); st.execute("ALTER TABLE lw_roads drop column LWE500"); st.execute("ALTER TABLE lw_roads drop column LWE1000"); st.execute("ALTER TABLE lw_roads drop column LWE2000"); st.execute("ALTER TABLE lw_roads drop column LWE4000"); st.execute("ALTER TABLE lw_roads drop column LWE8000"); st.execute("ALTER TABLE lw_roads drop column LWN63"); st.execute("ALTER TABLE lw_roads drop column LWN125"); st.execute("ALTER TABLE lw_roads drop column LWN250"); st.execute("ALTER TABLE lw_roads drop column LWN500"); st.execute("ALTER TABLE lw_roads drop column LWN1000"); st.execute("ALTER TABLE lw_roads drop column LWN2000"); st.execute("ALTER TABLE lw_roads drop column LWN4000"); st.execute("ALTER TABLE lw_roads drop column LWN8000"); } pointNoiseMap.initialize(connection, new EmptyProgressVisitor()); assertEquals(1, ldenConfig.propagationProcessPathData.freq_lvl.size()); assertEquals(1000, (int)ldenConfig.propagationProcessPathData.freq_lvl.get(0)); }