List of usage examples for org.apache.commons.configuration Configuration getList
List getList(String key);
From source file:es.udc.gii.common.eaf.factory.XMLSimpleFactory.java
@Override public OperatorChain<ReproductionOperator> createReproductionChain() { Configuration conf = EAFConfiguration.getInstance().subset("OperatorChains.ReproductionChain"); OperatorChain<ReproductionOperator> oChain = null; List ops = conf.getList("Operator.Class"); if (ops.size() > 0) { oChain = new OperatorChain<ReproductionOperator>(); for (int i = 0; i < ops.size(); i++) { try { ReproductionOperator op = (ReproductionOperator) Class.forName((String) ops.get(i)) .newInstance();/*from w w w .j a va 2 s.co m*/ op.configure(conf.subset("Operator(" + i + ")")); oChain.addOperators(op); } catch (Exception ex) { throw new ConfigurationException("Wrong reproduction operator configuration for " + (String) ops.get(i) + " ?" + " \n Thrown exception: \n" + ex); } } } return oChain; }
From source file:es.udc.gii.common.eaf.factory.XMLSimpleFactory.java
@Override public Individual createIndividual(FitnessComparator<Individual> comparator) { Configuration conf = EAFConfiguration.getInstance().subset("Population.Individual"); try {/*from w w w .ja v a2 s .c om*/ Individual ind = (Individual) Class.forName(conf.getString("Class")).newInstance(); List chromosomes = conf.getList("Chromosome[@size]"); if (chromosomes.isEmpty()) { throw new ConfigurationException("No chromosome specified."); } DoubleArray[] chrms = new DoubleArray[chromosomes.size()]; for (int i = 0; i < chromosomes.size(); i++) { int chrom_size = conf.getInt("Chromosome(" + i + ")[@size]"); chrms[i] = new ResizableDoubleArray(chrom_size); for (int j = 0; j < chrom_size; j++) { chrms[i].addElement(0.0); } } ind.setChromosomes(chrms); ind.setComparator(comparator); ind.configure(conf); // ind.generate(); return ind; } catch (Exception ex) { throw new ConfigurationException("Wrong individual configuration for " + conf.getString("Class") + " ?" + " \n Thrown exception: \n" + ex); } }
From source file:net.sf.jclal.activelearning.algorithm.ClassicalALAlgorithm.java
/** * Establishes the configuration of the stop criterion * * @param configuration/*from w ww .ja v a2 s . c o m*/ * The configuration object to use */ public void setStopCriterionConfigure(Configuration configuration) { // Number of defined stopCriterio int stopCriterioValue = configuration.getList("stop-criterion[@type]").size(); // For each listener in list for (int i = 0; i < stopCriterioValue; i++) { String header = "stop-criterion(" + i + ")"; // stopCriterio String stopError = "stop-criterion type= "; try { // stopCriterio classname String stopCriterioClassname = configuration.getString(header + "[@type]"); stopError += stopCriterioClassname; // stopCriterio class Class<? extends IStopCriterion> stopCriterioClass = (Class<? extends IStopCriterion>) Class .forName(stopCriterioClassname); // stopCriterio instance IStopCriterion stopCriterio = stopCriterioClass.newInstance(); // Configure stopCriterio (if necessary) if (stopCriterio instanceof IConfigure) { ((IConfigure) stopCriterio).configure(configuration.subset(header)); } // Add this stopCriterio to the algorithm addStopCriterion(stopCriterio); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException("\nIllegal stopCriterion classname: " + stopError, e); } catch (InstantiationException e) { throw new ConfigurationRuntimeException("\nIllegal stopCriterion classname: " + stopError, e); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException("\nIllegal stopCriterion classname: " + stopError, e); } } }
From source file:com.appeligo.channelfeed.CaptureApp.java
private void configureLogging(Configuration config, PatternLayout pattern) { Logger.getRootLogger().setLevel(Level.WARN); String logEmail = config.getString("logEmail[@address]"); if ((logEmail == null) || (logEmail.trim().length() == 0)) { logEmail = "root@localhost"; }/* w w w. j av a 2s . c o m*/ log.info("logEmail = " + logEmail); configureFatalLogging(pattern, logEmail); int loggerCount = config.getList("loggers.logger[@name]").size(); for (int i = 0; i < loggerCount; i++) { Configuration logger = config.subset("loggers.logger(" + i + ")"); String loggerName = logger.getString("[@name]"); String loggerLevel = logger.getString("[@level]"); log.info("Setting logger " + loggerName + " to level " + loggerLevel); Logger newlog = Logger.getLogger(loggerName); Level level = Level.toLevel(loggerLevel, null); if (level == null) { log.error("Invalid log level '" + loggerLevel + "' in: " + configFile); } else { newlog.setLevel(level); } } }
From source file:keel.Algorithms.Neural_Networks.NNEP_Common.NeuralNetIndividualSpecies.java
/** * <p>//from w w w . j a v a 2 s .c o m * Configuration parameters for this species are: * * * input-layer.number-of-inputs (int) * Number of inputs. Number of inputs of this species neural nets. * * output-layer.number-of-outputs (int) * Number of inputs. Number of outputs of this species neural nets. * * hidden-layer(i).weight-range (complex) * Weigth range of the hidden layer number "i". * * output-layer.weight-range (complex) * Weigth range of the outputlayer. * * hidden-layer(i).maximum-number-of-neurons (int) * Maximum number of neurons of hidden layer number "i". * * hidden-layer(i).initial-number-of-neurons (int) * Initial number of neurons of hidden layer number "i". * * hidden-layer(i)[@type] (string) * Layer type of the hidden layer number "i". * * output-layer[@type] (string) * Layer type of the output layer. * * hidden-layer(i)[@biased] (string) * Boolean indicating if hidden layer number "i" is biased. * * output-layer[@type] (string) * Boolean indicating if the output layer is biased. * * @param configutation Configuration if the Individual * </p> */ @SuppressWarnings("unchecked") public void configure(Configuration configuration) { // -------------------------------------- Setup neuralNetType neuralNetType = configuration.getString("neural-net-type"); // -------------------------------------- Setup nOfHiddenLayers nOfHiddenLayers = configuration.getList("hidden-layer[@type]").size(); // -------------------------------------- Setup nOfInputs //nOfInputs = configuration.getInt("input-layer.number-of-inputs"); // -------------------------------------- Setup nOfOutputs //nOfOutputs = configuration.getInt("output-layer.number-of-outputs"); // Initialize arrays maxNofneurons = new int[nOfHiddenLayers]; minNofneurons = new int[nOfHiddenLayers]; initialMaxNofneurons = new int[nOfHiddenLayers]; type = new String[nOfHiddenLayers + 1]; initiator = new String[nOfHiddenLayers + 1]; biased = new boolean[nOfHiddenLayers + 1]; weightRanges = new Interval[nOfHiddenLayers + 1][]; neuronTypes = new String[nOfHiddenLayers + 1][]; percentages = new double[nOfHiddenLayers + 1][]; initiatorNeuronTypes = new String[nOfHiddenLayers + 1][]; for (int i = 0; i < nOfHiddenLayers + 1; i++) { String header; if (i != nOfHiddenLayers) { header = "hidden-layer(" + i + ")"; // ---------------------------------- Setup maxNofneurons array maxNofneurons[i] = configuration.getInt(header + ".maximum-number-of-neurons"); // ---------------------------------- Setup minNofneurons array minNofneurons[i] = configuration.getInt(header + ".minimum-number-of-neurons"); // ---------------------------------- Setup initialMaxNofneurons array initialMaxNofneurons[i] = configuration.getInt(header + ".initial-maximum-number-of-neurons"); // ---------------------------------- Setup initiator array initiator[i] = configuration.getString(header + ".initiator-of-links"); } else { header = "output-layer"; // ---------------------------------- Setup initiator array initiator[i] = configuration.getString(header + ".initiator-of-links"); } // ----------------------------------------- Setup type array type[i] = configuration.getString(header + "[@type]"); // ----------------------------------------- Setup biased array biased[i] = configuration.getBoolean(header + "[@biased]"); // -------------------------------------- Setup weight ranges array weightRanges[i] = new Interval[1]; try { // Range name String rangeName = header + ".weight-range"; // Range classname String rangeClassname = configuration.getString(rangeName + "[@type]"); // Range class Class<Interval> rangeClass = (Class<Interval>) Class.forName(rangeClassname); // Range instance Interval range = rangeClass.newInstance(); // Configura range range.configure(configuration.subset(rangeName)); // Set range if (i != nOfHiddenLayers) setHiddenLayerWeightRange(i, 0, range); else setOutputLayerWeightRange(0, range); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException("Illegal range classname"); } catch (InstantiationException e) { throw new ConfigurationRuntimeException("Problems creating an instance of range", e); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException("Problems creating an instance of range", e); } } }
From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java
@Test public void testString() throws Exception { Configuration config = new ZookeeperConfiguration(zkConnection, 5000, "/test"); final String key = UUID.randomUUID().toString(); final String val1 = "This is a test value with some spcial ? " + "- to check serialization, deserialisation and encoding.", val2 = "An extended List, with several, commas, that should stay within, the, same value,"; assertThat(config.getString(key), nullValue(String.class)); config.setProperty(key, val1); assertThat(config.getString(key), equalTo(val1)); assertThat(config.getList(key), hasSize(1)); config.setProperty(key, val2); assertThat(config.getString(key), equalTo(val2)); assertThat(config.getList(key), hasSize(1)); }
From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java
@Test public void testList() throws Exception { Configuration config = new ZookeeperConfiguration(zkConnection, 5000, "/test"); final String key = UUID.randomUUID().toString(); final String val = "An extended List, with several, commas, that should stay within, the, same value,"; final List<?> list = Lists.transform(Arrays.asList(val.split(",")), new Function<String, String>() { @Override/* w ww .j av a 2s .com*/ public String apply(String input) { return input.trim(); } }); assertThat(config.getProperty(key), nullValue()); config.setProperty(key, list); assertThat(config.getList(key), IsIterableContainingInOrder.contains(list.toArray())); assertThat(config.getString(key), is(val.split(",")[0].trim())); config.setProperty(key, val.split(",")); assertThat(config.getString(key), is(val.split(",")[0])); assertThat(config.getList(key), CoreMatchers.<Object>hasItems(val.split(","))); assertThat(config.getStringArray(key), arrayContaining(val.split(","))); assertThat(config.getStringArray(key), arrayWithSize(val.split(",").length)); }
From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java
@Test public void testBasicCRUD() throws IOException { Configuration config = new ZookeeperConfiguration(zkConnection, 5000, "/test"); final String key = UUID.randomUUID().toString(); final String v1 = UUID.randomUUID().toString(), v2 = UUID.randomUUID().toString(), v3 = UUID.randomUUID().toString(), v4 = UUID.randomUUID().toString(), v5 = UUID.randomUUID().toString(); assertNull(config.getString(key));//from w ww . j a v a 2 s . co m assertEquals(v5, config.getString(key, v5)); config.setProperty(key, v1); assertEquals(v1, config.getString(key, v5)); config.addProperty(key, v2); assertEquals(v1, config.getString(key, v5)); assertThat(config.getList(key), CoreMatchers.<Object>hasItems(v1, v2)); config.addProperty(key, v3); config.addProperty(key, v4); assertEquals(v1, config.getString(key, v5)); assertThat(config.getList(key), CoreMatchers.<Object>hasItems(v1, v2, v3, v4)); config.clearProperty(key); assertNull(config.getString(key)); assertEquals(v5, config.getString(key, v5)); config.addProperty(key, v5); assertEquals(v5, config.getString(key)); config.clearProperty(key); config.setProperty(key, Arrays.asList(v3, v2, v4, v1, v5)); assertEquals(v3, config.getString(key)); assertThat(config.getList(key), CoreMatchers.<Object>hasItems(v3, v2, v4, v1, v5)); }
From source file:net.sf.jclal.util.mail.SenderEmail.java
/** * * @param configuration The configuration of SenderEmail. * *The XML labels supported are:/*from w w w . jav a2s. c om*/ * * <ul> * <li>smtp-host= ip</li> * <li>smtp-port= int</li> * <li>to= email</li> * <li>from= email</li> * <li>attach-report-file=boolean</li> * <li>user=String</li> * <li>pass=String</li> * </ul> */ @Override public void configure(Configuration configuration) { String hostT = configuration.getString("smtp-host", ""); if (hostT.isEmpty()) { throw new ConfigurationRuntimeException("\nThe tag <smtp-host></smtp-host> is empty."); } setHost(hostT); int portT = configuration.getInt("smtp-port", 21); setPort(portT); String fromT = configuration.getString("from", ""); if (fromT.isEmpty()) { throw new ConfigurationRuntimeException("\nThe tag <from></from> is empty. "); } setFrom(fromT); // Number of defined recipients int numberRecipients = configuration.getList("to").size(); if (numberRecipients == 0) { throw new ConfigurationRuntimeException("\nAt least one <to></to> tag must be defined. "); } // For each recipients in list for (int i = 0; i < numberRecipients; i++) { String header = "to(" + i + ")"; // recipient String recipientName = configuration.getString(header, ""); // Add this recipient toRecipients.append(recipientName).append(";"); } toRecipients.deleteCharAt(toRecipients.length() - 1); boolean attach = configuration.getBoolean("attach-report-file", false); setAttachReporFile(attach); String userT = configuration.getString("user", ""); if (userT.isEmpty()) { throw new ConfigurationRuntimeException("\nThe tag <user></user> is empty. "); } setUser(userT); String passT = configuration.getString("pass", ""); if (passT.isEmpty()) { throw new ConfigurationRuntimeException("\nThe tag <pass></pass> is empty. "); } setPass(passT); }
From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java
@Test public void testCuncurrent() throws IOException { Configuration con1 = new ZookeeperConfiguration(zkConnection, 5000, "/concurrent/"); Configuration con2 = new ZookeeperConfiguration(zkConnection, 5000, "/concurrent/"); final String key = UUID.randomUUID().toString(); final String v1 = UUID.randomUUID().toString(), v2 = UUID.randomUUID().toString(), v3 = UUID.randomUUID().toString(), v4 = UUID.randomUUID().toString(), v5 = UUID.randomUUID().toString(); assertNull(con1.getString(key));//from w ww . j av a 2 s . c o m assertNull(con2.getString(key)); assertEquals(v5, con1.getString(key, v5)); assertEquals(v5, con2.getString(key, v5)); con1.setProperty(key, v1); assertEquals(v1, con2.getString(key, v5)); assertEquals(v1, con1.getString(key, v5)); con2.addProperty(key, v2); assertEquals(v1, con1.getString(key, v5)); assertEquals(v1, con2.getString(key, v5)); assertThat(con2.getList(key), CoreMatchers.<Object>hasItems(v1, v2)); assertThat(con1.getList(key), CoreMatchers.<Object>hasItems(v1, v2)); con2.addProperty(key, v3); con1.addProperty(key, v4); assertEquals(v1, con2.getString(key, v5)); assertEquals(v1, con1.getString(key, v5)); assertThat(con2.getList(key), CoreMatchers.<Object>hasItems(v1, v2, v3, v4)); assertThat(con1.getList(key), CoreMatchers.<Object>hasItems(v1, v2, v3, v4)); con2.clearProperty(key); assertNull(con2.getString(key)); assertNull(con1.getString(key)); assertEquals(v5, con1.getString(key, v5)); assertEquals(v5, con2.getString(key, v5)); con1.addProperty(key, v5); assertEquals(v5, con2.getString(key)); con1.clearProperty(key); con2.setProperty(key, Arrays.asList(v3, v2, v4, v1, v5)); assertEquals(v3, con1.getString(key)); assertThat(con2.getList(key), CoreMatchers.<Object>hasItems(v3, v2, v4, v1, v5)); }