List of usage examples for com.google.common.collect Sets.SetView toString
public String toString()
From source file:org.apache.storm.command.AdminCommands.java
private static Iterator<String> listCorruptTopologies() { Set<String> blobStoreTopologyIds = nimbusBlobStore.filterAndListKeys(new KeyFilter<String>() { @Override/* w ww.j a v a 2 s .com*/ public String filter(String key) { return ConfigUtils.getIdFromBlobKey(key); } }); Set<String> activeTopologyIds = new HashSet<>(stormClusterState.activeStorms()); Sets.SetView<String> diffTopology = Sets.difference(activeTopologyIds, blobStoreTopologyIds); LOG.info("active-topology-ids [{}] blob-topology-ids [{}] diff-topology [{}]", activeTopologyIds.toString(), blobStoreTopologyIds.toString(), diffTopology.toString()); return diffTopology.iterator(); }
From source file:org.jpmml.evaluator.ModelEvaluationExample.java
static private List<Map<FieldName, FieldValue>> prepareAll(Evaluator evaluator, CsvUtil.Table table) { List<FieldName> names = new ArrayList<FieldName>(); List<FieldName> activeFields = evaluator.getActiveFields(); List<FieldName> groupFields = evaluator.getGroupFields(); header: {// w ww . j a va 2 s . c o m List<String> headerRow = table.get(0); for (int column = 0; column < headerRow.size(); column++) { FieldName name = FieldName.create(headerRow.get(column)); if (!(activeFields.contains(name) || groupFields.contains(name))) { name = null; } names.add(name); } Sets.SetView<FieldName> missingActiveFields = difference(activeFields, names); if (missingActiveFields.size() > 0) { throw new IllegalArgumentException("Missing active field(s): " + missingActiveFields.toString()); } Sets.SetView<FieldName> missingGroupFields = difference(groupFields, names); if (missingGroupFields.size() > 0) { throw new IllegalArgumentException("Missing group field(s): " + missingGroupFields.toString()); } } List<Map<FieldName, Object>> stringRows = new ArrayList<Map<FieldName, Object>>(); body: for (int i = 1; i < table.size(); i++) { List<String> bodyRow = table.get(i); Map<FieldName, Object> stringRow = new LinkedHashMap<FieldName, Object>(); for (int column = 0; column < bodyRow.size(); column++) { FieldName name = names.get(column); if (name == null) { continue; } String value = bodyRow.get(column); if (("").equals(value) || ("NA").equals(value) || ("N/A").equals(value)) { value = null; } stringRow.put(name, value); } stringRows.add(stringRow); } if (groupFields.size() == 1) { FieldName groupField = groupFields.get(0); stringRows = EvaluatorUtil.groupRows(groupField, stringRows); } else if (groupFields.size() > 1) { throw new EvaluationException(); } List<Map<FieldName, FieldValue>> fieldValueRows = new ArrayList<Map<FieldName, FieldValue>>(); for (Map<FieldName, Object> stringRow : stringRows) { Map<FieldName, FieldValue> fieldValueRow = new LinkedHashMap<FieldName, FieldValue>(); Collection<Map.Entry<FieldName, Object>> entries = stringRow.entrySet(); for (Map.Entry<FieldName, Object> entry : entries) { FieldName name = entry.getKey(); FieldValue value = EvaluatorUtil.prepare(evaluator, name, entry.getValue()); fieldValueRow.put(name, value); } fieldValueRows.add(fieldValueRow); } return fieldValueRows; }
From source file:se.sics.kompics.fsm.FSMBuilder.java
private static FSMachineDef fsmDef(FSMIdentifierFactory fsmIdFactory, String fsmName, StructuralDefinition m, SemanticDefinition h) throws FSMException { if (!m.transitionTable.containsRow(FSMBasicStateNames.START)) { throw new FSMException("START state not defined"); }//from w w w.j av a 2s . c o m if (!m.transitionTable.containsColumn(FSMBasicStateNames.FINAL)) { throw new FSMException("FINAL state not defined"); } Sets.SetView<FSMStateName> deadState = Sets.difference(m.transitionTable.columnKeySet(), m.transitionTable.rowKeySet()); if (deadState.size() > 1) { throw new FSMException("states:" + deadState.toString() + "are dead end states. Only FINAL allowed as dead end state."); } for (Map.Entry<FSMStateName, FSMStateDef> stateDef : m.states.entrySet()) { stateDef.getValue().setNegativeBasicHandlers(h.negativeBasicEventHandlers.column(stateDef.getKey())); stateDef.getValue().setPositiveBasicHandlers(h.positiveBasicEventHandlers.column(stateDef.getKey())); stateDef.getValue() .setNegativePatternHandlers(h.negativePatternEventHandlers.column(stateDef.getKey())); stateDef.getValue() .setPositivePatternHandlers(h.positivePatternEventHandlers.column(stateDef.getKey())); } FSMachineDef fsmDef = FSMachineDef.definition(fsmIdFactory, fsmName, m.states, m.transitionTable, h.defaultFallbackBasicEvent, h.defaultFallbackPatternEvent, h.positiveBasicFallbackHandlers, h.negativeBasicFallback, h.positivePatternFallback, h.negativePatternFallback); return fsmDef; }
From source file:org.adridadou.ethereum.EthereumContractInvocationHandler.java
private void verifyContract(SmartContract smartContract, Class<?> contractInterface) { Set<Method> interfaceMethods = Sets.newHashSet(contractInterface.getMethods()); Set<CallTransaction.Function> solidityMethods = smartContract.getFunctions().stream().filter(f -> f != null) .collect(Collectors.toSet()); Set<String> interfaceMethodNames = interfaceMethods.stream().map(Method::getName) .collect(Collectors.toSet()); Set<String> solidityFuncNames = solidityMethods.stream().map(d -> d.name).collect(Collectors.toSet()); Sets.SetView<String> superfluous = Sets.difference(interfaceMethodNames, solidityFuncNames); if (!superfluous.isEmpty()) { throw new EthereumApiException("superflous function definition in interface " + contractInterface.getName() + ":" + superfluous.toString()); }/*from ww w . j a v a2s .co m*/ Map<String, Method> methods = interfaceMethods.stream() .collect(Collectors.toMap(Method::getName, Function.identity())); for (CallTransaction.Function func : solidityMethods) { if (methods.get(func.name) != null && func.inputs.length != methods.get(func.name).getParameterCount()) { throw new EthereumApiException("parameter count mismatch for " + func.name + " on contract " + contractInterface.getName()); } } }
From source file:com.addthis.hydra.task.pipeline.PipelineTask.java
public void validateWritableRootPaths() { if (!validateDirs) { return;// w ww . ja v a2s .c om } for (StreamMapper phase : phases) { phase.validateWritableRootPaths(); } Set<Path>[] outputDirs = new Set[phases.length]; StringBuilder builder = new StringBuilder(); for (int i = 0; i < phases.length; i++) { if ((disable != null) && disable[i]) { continue; } outputDirs[i] = new HashSet<>(); outputDirs[i].addAll(phases[i].writableRootPaths()); for (int j = 0; j < i; j++) { Sets.SetView<Path> intersect = Sets.intersection(outputDirs[i], outputDirs[j]); if (intersect.size() > 0) { String message = String.format("Phases %d and %d have overlapping output directories: \"%s\"\n", (j + 1), (i + 1), intersect.toString()); builder.append(message); } } } if (builder.length() > 0) { throw new IllegalArgumentException(builder.toString()); } }
From source file:org.kamanja.pmml.testtool.PmmlTestTool.java
@Override public void execute() throws Exception { MetricRegistry metricRegistry = new MetricRegistry(); ConsoleReporter reporter = ConsoleReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS).build(); CsvUtil.Table inputTable = readTable(this._dataset, this.separator); Function<String, String> parseFunction = new Function<String, String>() { @Override//from w ww . j av a2 s . com public String apply(String string) { if (("").equals(string) || ("N/A").equals(string) || ("NA").equals(string)) { return null; } // Remove leading and trailing quotation marks string = stripQuotes(string, '\"'); string = stripQuotes(string, '\"'); // Standardize European-style decimal marks (',') to US-style decimal marks ('.') if (string.indexOf(',') > -1) { String usString = string.replace(',', '.'); try { Double.parseDouble(usString); string = usString; } catch (NumberFormatException nfe) { // Ignored } } return string; } private String stripQuotes(String string, char quoteChar) { if (string.length() > 1 && ((string.charAt(0) == quoteChar) && (string.charAt(string.length() - 1) == quoteChar))) { return string.substring(1, string.length() - 1); } return string; } }; List<? extends Map<FieldName, ?>> inputRecords = BatchUtil.parseRecords(inputTable, parseFunction); PMML pmml = readPMML(this._pmmlSrc); // 1320, 1313 Changes begin if (pmml.getHeader().getApplication().getName().contains("SAS")) { Visitor visitor = new org.jpmml.sas.visitors.ExpressionCorrector(); visitor.applyTo(pmml); } // 1320, 1313 Changes end ModelEvaluatorFactory modelEvaluatorFactory = ModelEvaluatorFactory.newInstance(); Evaluator evaluator = modelEvaluatorFactory.newModelManager(pmml); // Perform self-testing evaluator.verify(); List<FieldName> activeFields = evaluator.getActiveFields(); List<FieldName> groupFields = evaluator.getGroupFields(); if (inputRecords.size() > 0) { Map<FieldName, ?> inputRecord = inputRecords.get(0); Sets.SetView<FieldName> missingActiveFields = Sets.difference(new LinkedHashSet<>(activeFields), inputRecord.keySet()); if (missingActiveFields.size() > 0) { throw new IllegalArgumentException("Missing active field(s): " + missingActiveFields.toString()); } Sets.SetView<FieldName> missingGroupFields = Sets.difference(new LinkedHashSet<>(groupFields), inputRecord.keySet()); if (missingGroupFields.size() > 0) { throw new IllegalArgumentException("Missing group field(s): " + missingGroupFields.toString()); } } if (groupFields.size() == 1) { FieldName groupField = groupFields.get(0); inputRecords = org.jpmml.evaluator.EvaluatorUtil.groupRows(groupField, inputRecords); } else if (groupFields.size() > 1) { throw new EvaluationException(); } List<Map<FieldName, ?>> outputRecords = new ArrayList<>(); Timer timer = new Timer(new SlidingWindowReservoir(this._loop)); metricRegistry.register("main", timer); int epoch = 0; do { Timer.Context context = timer.time(); try { for (Map<FieldName, ?> inputRecord : inputRecords) { Map<FieldName, FieldValue> arguments = new LinkedHashMap<>(); for (FieldName activeField : activeFields) { FieldValue activeValue = org.jpmml.evaluator.EvaluatorUtil.prepare(evaluator, activeField, inputRecord.get(activeField)); arguments.put(activeField, activeValue); } Map<FieldName, ?> result = evaluator.evaluate(arguments); outputRecords.add(result); } } finally { context.close(); } epoch++; } while (epoch < this._loop); List<FieldName> targetFields = evaluator.getTargetFields(); List<FieldName> outputFields = evaluator.getOutputFields(); Function<Object, String> formatFunction = new Function<Object, String>() { @Override public String apply(Object object) { object = org.jpmml.evaluator.EvaluatorUtil.decode(object); if (object == null) { return "N/A"; } return object.toString(); } }; CsvUtil.Table outputTable = new CsvUtil.Table(); outputTable.setSeparator(inputTable.getSeparator()); outputTable.addAll(BatchUtil.formatRecords(outputRecords, Lists.newArrayList(Iterables.concat(targetFields, outputFields)), formatFunction)); if (!_omitInputs) { if (inputTable.size() == outputTable.size()) { /** insert the inputs in front of any target and output fields */ for (int i = 0; i < inputTable.size(); i++) { List<String> inputRow = inputTable.get(i); List<String> outputRow = outputTable.get(i); outputRow.addAll(0, inputRow); } } } writeTable(outputTable, this.outputPath); if (this._loop > 1) { reporter.report(); } reporter.close(); }
From source file:org.jpmml.evaluator.EvaluationExample.java
@Override public void execute() throws Exception { MetricRegistry metricRegistry = new MetricRegistry(); ConsoleReporter reporter = ConsoleReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS).build(); CsvUtil.Table inputTable = readTable(this.input, this.separator); List<? extends Map<FieldName, ?>> inputRecords = BatchUtil.parseRecords(inputTable, Example.CSV_PARSER); if (this.waitBefore) { waitForUserInput();// w w w. j ava 2 s . c o m } PMML pmml = readPMML(this.model); if (this.cacheBuilderSpec != null) { CacheBuilderSpec cacheBuilderSpec = CacheBuilderSpec.parse(this.cacheBuilderSpec); CacheUtil.setCacheBuilderSpec(cacheBuilderSpec); } // End if if (this.optimize) { List<? extends Visitor> optimizers = Arrays.asList(new ExpressionOptimizer(), new FieldOptimizer(), new PredicateOptimizer(), new GeneralRegressionModelOptimizer(), new NaiveBayesModelOptimizer(), new RegressionModelOptimizer()); for (Visitor optimizer : optimizers) { optimizer.applyTo(pmml); } } ModelEvaluatorFactory modelEvaluatorFactory = ModelEvaluatorFactory.newInstance(); Evaluator evaluator = modelEvaluatorFactory.newModelEvaluator(pmml); // Perform self-testing evaluator.verify(); List<InputField> inputFields = evaluator.getInputFields(); List<InputField> groupFields = Collections.emptyList(); if (evaluator instanceof HasGroupFields) { HasGroupFields hasGroupfields = (HasGroupFields) evaluator; groupFields = hasGroupfields.getGroupFields(); } // End if if (inputRecords.size() > 0) { Map<FieldName, ?> inputRecord = inputRecords.get(0); Sets.SetView<FieldName> missingInputFields = Sets .difference(new LinkedHashSet<>(EvaluatorUtil.getNames(inputFields)), inputRecord.keySet()); if ((missingInputFields.size() > 0) && !this.sparse) { throw new IllegalArgumentException("Missing input field(s): " + missingInputFields.toString()); } Sets.SetView<FieldName> missingGroupFields = Sets .difference(new LinkedHashSet<>(EvaluatorUtil.getNames(groupFields)), inputRecord.keySet()); if (missingGroupFields.size() > 0) { throw new IllegalArgumentException("Missing group field(s): " + missingGroupFields.toString()); } } // End if if (evaluator instanceof HasGroupFields) { HasGroupFields hasGroupFields = (HasGroupFields) evaluator; inputRecords = EvaluatorUtil.groupRows(hasGroupFields, inputRecords); } List<Map<FieldName, ?>> outputRecords = new ArrayList<>(inputRecords.size()); Timer timer = new Timer(new SlidingWindowReservoir(this.loop)); metricRegistry.register("main", timer); int epoch = 0; do { Timer.Context context = timer.time(); try { outputRecords.clear(); Map<FieldName, FieldValue> arguments = new LinkedHashMap<>(); for (Map<FieldName, ?> inputRecord : inputRecords) { arguments.clear(); for (InputField inputField : inputFields) { FieldName name = inputField.getName(); FieldValue value = EvaluatorUtil.prepare(inputField, inputRecord.get(name)); arguments.put(name, value); } Map<FieldName, ?> result = evaluator.evaluate(arguments); outputRecords.add(result); } } finally { context.close(); } epoch++; } while (epoch < this.loop); if (this.waitAfter) { waitForUserInput(); } List<TargetField> targetFields = evaluator.getTargetFields(); List<OutputField> outputFields = evaluator.getOutputFields(); List<? extends ResultField> resultFields = Lists.newArrayList(Iterables.concat(targetFields, outputFields)); CsvUtil.Table outputTable = new CsvUtil.Table(); outputTable.setSeparator(inputTable.getSeparator()); outputTable.addAll(BatchUtil.formatRecords(outputRecords, EvaluatorUtil.getNames(resultFields), Example.CSV_FORMATTER)); if ((inputTable.size() == outputTable.size()) && this.copyColumns) { for (int i = 0; i < inputTable.size(); i++) { List<String> inputRow = inputTable.get(i); List<String> outputRow = outputTable.get(i); outputRow.addAll(0, inputRow); } } writeTable(outputTable, this.output); if (this.loop > 1) { reporter.report(); } reporter.close(); }
From source file:com.addthis.hydra.task.map.StreamMapper.java
public void validateWritableRootPaths() { if (!validateDirs) { return;//from w w w . ja va 2 s. c om } StringBuilder builder = new StringBuilder(); ImmutableList<Path> sources = source.writableRootPaths(); ImmutableList<Path> sinks = output.writableRootPaths(); Set<Path> sourcesSet = new HashSet<>(); Set<Path> sinksSet = new HashSet<>(); for (Path source : sources) { if (!sourcesSet.add(source)) { String message = String.format("The writable directory is used in more than one location " + "in the input section: \"%s\"\n", source); builder.append(message); } } for (Path sink : sinks) { if (!sinksSet.add(sink)) { String message = String.format("The writable directory is used in more than one location " + "in the output section: \"%s\"\n", sink); builder.append(message); } } Sets.SetView<Path> intersect = Sets.intersection(sourcesSet, sinksSet); if (intersect.size() > 0) { String message = String.format("The following one or more directories are used in both an input " + "section and an output section: \"%s\"\n", intersect.toString()); builder.append(message); } if (builder.length() > 0) { throw new IllegalArgumentException(builder.toString()); } }