List of usage examples for org.apache.commons.lang3.tuple Pair getValue
@Override
public R getValue()
Gets the value from this pair.
This method implements the Map.Entry interface returning the right element as the value.
From source file:richtercloud.document.scanner.gui.OCRPanel.java
/** * Creates new form OCRResultPanel// w ww .j a va 2 s. co m * @param reflectionFormPanelMap A map with references to the * {@link ReflectionFormPanel} for each entity class which is manipulated by * the context menu items */ public OCRPanel(Set<Class<?>> entityClasses, Map<Class<?>, ReflectionFormPanel<?>> reflectionFormPanelMap, Map<Class<? extends JComponent>, ValueSetter<?, ?>> valueSetterMapping, EntityManager entityManager, MessageHandler messageHandler, ReflectionFormBuilder reflectionFormBuilder, DocumentScannerConf documentScannerConf) { this.initComponents(); if (messageHandler == null) { throw new IllegalArgumentException("messageHandler mustn't be null"); } this.messageHandler = messageHandler; if (documentScannerConf == null) { throw new IllegalArgumentException("documentScannerConf mustn't be " + "null"); } this.documentScannerConf = documentScannerConf; List<Class<?>> entityClassesSort = EntityPanel.sortEntityClasses(entityClasses); for (Class<?> entityClass : entityClassesSort) { ReflectionFormPanel<?> reflectionFormPanel = reflectionFormPanelMap.get(entityClass); if (reflectionFormPanel == null) { throw new IllegalArgumentException( String.format("entityClass %s has no %s mapped in reflectionFormPanelMap", entityClass, ReflectionFormPanel.class)); } String className; ClassInfo classInfo = entityClass.getAnnotation(ClassInfo.class); if (classInfo != null) { className = classInfo.name(); } else { className = entityClass.getSimpleName(); } JMenu entityClassMenu = new JMenu(className); List<Field> relevantFields = reflectionFormBuilder.getFieldRetriever() .retrieveRelevantFields(entityClass); for (Field relevantField : relevantFields) { String fieldName; FieldInfo fieldInfo = relevantField.getAnnotation(FieldInfo.class); if (fieldInfo != null) { fieldName = fieldInfo.name(); } else { fieldName = relevantField.getName(); } JMenuItem relevantFieldMenuItem = new JMenuItem(fieldName); relevantFieldMenuItem.addActionListener( new FieldActionListener(reflectionFormPanel, relevantField, valueSetterMapping)); entityClassMenu.add(relevantFieldMenuItem); } this.oCRResultPopupPasteIntoMenu.add(entityClassMenu); } Map<String, Pair<NumberFormat, Set<Locale>>> numberFormats = new HashMap<>(); Map<String, Pair<NumberFormat, Set<Locale>>> percentFormats = new HashMap<>(); Map<String, Pair<NumberFormat, Set<Locale>>> currencyFormats = new HashMap<>(); Iterator<Locale> localeIterator = new ArrayList<>(Arrays.asList(Locale.getAvailableLocales())).iterator(); Locale firstLocale = localeIterator.next(); String numberString = NumberFormat.getNumberInstance(firstLocale).format(FORMAT_VALUE); String percentString = NumberFormat.getPercentInstance(firstLocale).format(FORMAT_VALUE); String currencyString = NumberFormat.getCurrencyInstance(firstLocale).format(FORMAT_VALUE); numberFormats.put(numberString, new ImmutablePair<NumberFormat, Set<Locale>>( NumberFormat.getNumberInstance(firstLocale), new HashSet<>(Arrays.asList(firstLocale)))); percentFormats.put(percentString, new ImmutablePair<NumberFormat, Set<Locale>>( NumberFormat.getPercentInstance(firstLocale), new HashSet<>(Arrays.asList(firstLocale)))); currencyFormats.put(currencyString, new ImmutablePair<NumberFormat, Set<Locale>>( NumberFormat.getCurrencyInstance(firstLocale), new HashSet<>(Arrays.asList(firstLocale)))); while (localeIterator.hasNext()) { Locale locale = localeIterator.next(); numberString = NumberFormat.getNumberInstance(locale).format(FORMAT_VALUE); percentString = NumberFormat.getPercentInstance(locale).format(FORMAT_VALUE); currencyString = NumberFormat.getCurrencyInstance(locale).format(FORMAT_VALUE); Pair<NumberFormat, Set<Locale>> numberFormatsPair = numberFormats.get(numberString); if (numberFormatsPair == null) { numberFormatsPair = new ImmutablePair<NumberFormat, Set<Locale>>( NumberFormat.getNumberInstance(locale), new HashSet<Locale>()); numberFormats.put(numberString, numberFormatsPair); } Set<Locale> numberFormatsLocales = numberFormatsPair.getValue(); numberFormatsLocales.add(locale); Pair<NumberFormat, Set<Locale>> percentFormatsPair = percentFormats.get(percentString); if (percentFormatsPair == null) { percentFormatsPair = new ImmutablePair<NumberFormat, Set<Locale>>( NumberFormat.getPercentInstance(locale), new HashSet<Locale>()); percentFormats.put(percentString, percentFormatsPair); } Set<Locale> percentFormatsLocales = percentFormatsPair.getValue(); percentFormatsLocales.add(locale); Pair<NumberFormat, Set<Locale>> currencyFormatsPair = currencyFormats.get(currencyString); if (currencyFormatsPair == null) { currencyFormatsPair = new ImmutablePair<NumberFormat, Set<Locale>>( NumberFormat.getCurrencyInstance(locale), new HashSet<Locale>()); currencyFormats.put(currencyString, currencyFormatsPair); } Set<Locale> currencyFormatsLocales = currencyFormatsPair.getValue(); currencyFormatsLocales.add(locale); } for (Map.Entry<String, Pair<NumberFormat, Set<Locale>>> numberFormat : numberFormats.entrySet()) { JRadioButtonMenuItem menuItem = new NumberFormatMenuItem(numberFormat.getValue().getKey()); numberFormatPopup.add(menuItem); numberFormatPopupButtonGroup.add(menuItem); if (numberFormat.getValue().getValue().contains(this.documentScannerConf.getLocale())) { menuItem.setSelected(true); } } for (Map.Entry<String, Pair<NumberFormat, Set<Locale>>> percentFormat : percentFormats.entrySet()) { JRadioButtonMenuItem menuItem = new NumberFormatMenuItem(percentFormat.getValue().getKey()); percentFormatPopup.add(menuItem); percentFormatPopupButtonGroup.add(menuItem); if (percentFormat.getValue().getValue().contains(this.documentScannerConf.getLocale())) { menuItem.setSelected(true); } } for (Map.Entry<String, Pair<NumberFormat, Set<Locale>>> currencyFormat : currencyFormats.entrySet()) { JRadioButtonMenuItem menuItem = new NumberFormatMenuItem(currencyFormat.getValue().getKey()); currencyFormatPopup.add(menuItem); currencyFormatPopupButtonGroup.add(menuItem); if (currencyFormat.getValue().getValue().contains(this.documentScannerConf.getLocale())) { menuItem.setSelected(true); } } }
From source file:richtercloud.reflection.form.builder.fieldhandler.ResettableFieldHandler.java
@Override @SuppressWarnings("FinalMethod") //enforce everything being handled in handle0 public final JComponent handle(final Field field, final Object instance, FieldUpdateListener<E> updateListener, R reflectionFormBuilder) throws IllegalArgumentException, IllegalAccessException, FieldHandlingException, InvocationTargetException, NoSuchMethodException, InstantiationException { Pair<JComponent, ComponentHandler<?>> retValueEntry = handle0(field, instance, updateListener, reflectionFormBuilder);/*from w ww . j av a 2 s . c om*/ if (retValueEntry == null) { JLabel retValue = new JLabel(field.getType().getSimpleName()); this.componentMapping.put(retValue, JLABEL_COMPONENT_RESETTABLE); return retValue; } ComponentHandler<?> componentResettable = retValueEntry.getValue(); if (componentResettable == null) { throw new IllegalArgumentException("ComponentResettable in Pair returned by handle0 mustn't be null"); } JComponent retValue = retValueEntry.getKey(); this.componentMapping.put(retValue, componentResettable); return retValue; }
From source file:richtercloud.reflection.form.builder.typehandler.MappingTypeHandler.java
@Override @SuppressWarnings("FinalMethod") //enforce everything being handled in handle0 public final Pair<JComponent, ComponentHandler<?>> handle(Type type, T fieldValue, String fieldName, Class<?> declaringClass, FieldUpdateListener<E> updateListener, R reflectionFormBuilder) throws IllegalArgumentException, IllegalAccessException, FieldHandlingException, InstantiationException, InvocationTargetException { Pair<JComponent, ComponentHandler<?>> retValueEntry = handle0(type, fieldValue, fieldName, declaringClass, updateListener, reflectionFormBuilder); if (retValueEntry == null) { throw new IllegalArgumentException("handle0 mustn't return null"); }// www.j a va 2s . co m ComponentHandler<?> componentResettable = retValueEntry.getValue(); if (componentResettable == null) { throw new IllegalArgumentException("ComponentResettable in Pair returned by handle0 mustn't be null"); } JComponent retValue = retValueEntry.getKey(); this.componentMapping.put(retValue, componentResettable); return retValueEntry; }
From source file:sadl.anomalydetecion.AnomalyDetection.java
public ExperimentResult trainTest(Path dataFile, boolean skipFirstElement) throws IOException { checkFileExistance(dataFile);//from w ww.j a v a 2s . c o m final Pair<TimedInput, TimedInput> trainTest = IoUtils.readTrainTestFile(dataFile, skipFirstElement); return trainTest(trainTest.getKey(), trainTest.getValue()); }
From source file:sadl.detectors.AggSublistsTest.java
@Test public void test() throws URISyntaxException, IOException { final PdttaLearner learner = new PdttaLearner(new AlergiaRedBlue(0.05, true)); final MinimalFeatureCreator featureCreator = new MinimalFeatureCreator(); final ThresholdClassifier classifier = new ThresholdClassifier(Math.exp(-5), Math.exp(-8)); final VectorDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY, featureCreator, classifier, false); final VectorDetector detector2 = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY, featureCreator, classifier, true); final SmallFeatureCreator featureCreator3 = new SmallFeatureCreator(); final ThresholdClassifier classifier3 = new ThresholdClassifier(Math.exp(-5), Math.exp(-8), Math.exp(-5), Math.exp(-8));/* www . ja v a2 s .co m*/ final VectorDetector detector3 = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY, featureCreator3, classifier3, true); final UberFeatureCreator featureCreator4 = new UberFeatureCreator(); final LibSvmClassifier classifier4 = new LibSvmClassifier(1, 0.2, 0.1, 1, 0.001, 3, ScalingMethod.NONE); final VectorDetector detector4 = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY, featureCreator4, classifier4, true); final AnomalyDetection detection = new AnomalyDetection(detector, learner); final AnomalyDetection detection2 = new AnomalyDetection(detector2, learner); final AnomalyDetection detection3 = new AnomalyDetection(detector3, learner); final AnomalyDetection detection4 = new AnomalyDetection(detector4, learner); final Path p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI()); Pair<TimedInput, TimedInput> inputSets = IoUtils.readTrainTestFile(p); inputSets.getKey().decreaseSamples(0.2); final ExperimentResult actual = detection.trainTest(inputSets.getKey(), inputSets.getValue()); final ExperimentResult expected = new ExperimentResult(467, 4174, 359, 0); assertEquals(expected, actual); inputSets = IoUtils.readTrainTestFile(p); inputSets.getKey().decreaseSamples(0.2); final ExperimentResult actual2 = detection2.trainTest(inputSets.getKey(), inputSets.getValue()); final ExperimentResult expected2 = new ExperimentResult(4, 4164, 369, 463); assertEquals(expected2, actual2); inputSets = IoUtils.readTrainTestFile(p); inputSets.getKey().decreaseSamples(0.2); final ExperimentResult actual3 = detection3.trainTest(inputSets.getKey(), inputSets.getValue()); final ExperimentResult expected3 = new ExperimentResult(48, 780, 3753, 419); assertEquals(expected3, actual3); inputSets = IoUtils.readTrainTestFile(p); inputSets.getKey().decreaseSamples(0.2); final ExperimentResult actual4 = detection4.trainTest(inputSets.getKey(), inputSets.getValue()); final ExperimentResult expected4 = new ExperimentResult(134, 0, 4533, 333); assertEquals(expected4, actual4); }
From source file:sadl.detectors.ButlaDeterminismTest.java
@Test public void thresholdDeterminismTest() throws IOException, URISyntaxException { double fMeasure = -1; final boolean firstRun = true; for (int i = 1; i <= 10; i++) { final Pair<TimedInput, TimedInput> trainTest = IoUtils .readTrainTestFile(Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI())); Settings.setDebug(false);//from ww w .j a v a2 s. c o m final ButlaPdtaLearner learner = new ButlaPdtaLearner(10000, 0.05, TransitionsType.Incoming, 0.05, 0.05, PTAOrdering.BottomUp, EventsCreationStrategy.SplitEvents, KDEFormelVariant.OriginalKDE, IntervalCreationStrategy.OriginalButla); final SmallFeatureCreator featureCreator = new SmallFeatureCreator(); final ThresholdClassifier classifier = new ThresholdClassifier(Math.exp(-5), Math.exp(-8), 0.01, 0.001); final VectorDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY, featureCreator, classifier); final AnomalyDetection detection = new AnomalyDetection(detector, learner); final ExperimentResult result = detection.trainTest(trainTest.getKey(), trainTest.getValue()); if (firstRun) { fMeasure = result.getFMeasure(); } else { if (!Precision.equals(fMeasure, result.getFMeasure())) { fail("Failed for run " + i + " because in previous runs fMeasure=" + fMeasure + "; now fMeasure=" + result.getFMeasure()); } } } }
From source file:sadl.detectors.ButlaTest.java
@Test public void testAnodaOriginalButla() throws IOException, URISyntaxException { logger.info("Starting Anoda Original BUTLA test..."); final ButlaPdtaLearner learner = new ButlaPdtaLearner(10000, 0.9, TransitionsType.Incoming, 0.000001, 0.3, PTAOrdering.BottomUp, EventsCreationStrategy.NotTimedEvents, KDEFormelVariant.OriginalButlaVariableBandwidth, IntervalCreationStrategy.extendInterval); final AnodaDetector anoda = new AnodaDetector(); final AnomalyDetection detection = new AnomalyDetection(anoda, learner); ExperimentResult expected = new ExperimentResult(464, 4527, 6, 3); Path p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI()); Pair<TimedInput, TimedInput> trainTest = IoUtils.readTrainTestFile(p); TimedInput trainSet = trainTest.getKey(); trainSet.decreaseSamples(0.1);/*from ww w . j ava 2 s .c o m*/ ExperimentResult actual = detection.trainTest(trainSet, trainTest.getValue()); assertEquals(expected, actual); expected = new ExperimentResult(40, 4494, 11, 455); p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type2.txt").toURI()); trainTest = IoUtils.readTrainTestFile(p); trainSet = trainTest.getKey(); trainSet.decreaseSamples(0.1); actual = detection.trainTest(trainSet, trainTest.getValue()); assertEquals(expected, actual); expected = new ExperimentResult(283, 4495, 19, 203); p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type3.txt").toURI()); trainTest = IoUtils.readTrainTestFile(p); trainSet = trainTest.getKey(); trainSet.decreaseSamples(0.1); actual = detection.trainTest(trainSet, trainTest.getValue()); assertEquals(expected, actual); expected = new ExperimentResult(523, 4467, 10, 0); p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type4.txt").toURI()); trainTest = IoUtils.readTrainTestFile(p); trainSet = trainTest.getKey(); trainSet.decreaseSamples(0.1); actual = detection.trainTest(trainSet, trainTest.getValue()); assertEquals(expected, actual); expected = new ExperimentResult(362, 4534, 4, 100); p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type5.txt").toURI()); trainTest = IoUtils.readTrainTestFile(p); trainSet = trainTest.getKey(); trainSet.decreaseSamples(0.1); actual = detection.trainTest(trainSet, trainTest.getValue()); assertEquals(expected, actual); logger.info("Finished Anoda Original BUTLA test."); }
From source file:sadl.detectors.ButlaTest.java
@Test public void testThresholdOriginalKDE() throws IOException, URISyntaxException { logger.info("Starting Threshold Original KDE test..."); final ButlaPdtaLearner learner = new ButlaPdtaLearner(10000, 0.05, TransitionsType.Incoming, 0.01, 0.05, PTAOrdering.TopDown, EventsCreationStrategy.SplitEvents, KDEFormelVariant.OriginalKDE, IntervalCreationStrategy.extendInterval); final AnomalyDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY, new AggregatedSingleFeatureCreator(), new ThresholdClassifier(Math.exp(-1))); final AnomalyDetection detection = new AnomalyDetection(detector, learner); ExperimentResult expected = new ExperimentResult(467, 1382, 3151, 0); Path p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI()); Pair<TimedInput, TimedInput> trainTest = IoUtils.readTrainTestFile(p); TimedInput trainSet = trainTest.getKey(); trainSet.decreaseSamples(0.1);// w w w. j ava2 s.c o m ExperimentResult actual = detection.trainTest(trainSet, trainTest.getValue()); assertEquals(expected, actual); expected = new ExperimentResult(381, 1440, 3065, 114); p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type2.txt").toURI()); trainTest = IoUtils.readTrainTestFile(p); trainSet = trainTest.getKey(); trainSet.decreaseSamples(0.1); actual = detection.trainTest(trainSet, trainTest.getValue()); assertEquals(expected, actual); expected = new ExperimentResult(486, 1640, 2874, 0); p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type3.txt").toURI()); trainTest = IoUtils.readTrainTestFile(p); trainSet = trainTest.getKey(); trainSet.decreaseSamples(0.1); actual = detection.trainTest(trainSet, trainTest.getValue()); assertEquals(expected, actual); expected = new ExperimentResult(523, 1388, 3089, 0); p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type4.txt").toURI()); trainTest = IoUtils.readTrainTestFile(p); trainSet = trainTest.getKey(); trainSet.decreaseSamples(0.1); actual = detection.trainTest(trainSet, trainTest.getValue()); assertEquals(expected, actual); expected = new ExperimentResult(462, 1379, 3159, 0); p = Paths.get(this.getClass().getResource("/pdtta/smac_mix_type5.txt").toURI()); trainTest = IoUtils.readTrainTestFile(p); trainSet = trainTest.getKey(); trainSet.decreaseSamples(0.1); actual = detection.trainTest(trainSet, trainTest.getValue()); assertEquals(expected, actual); logger.info("Finished Threshold Original KDE test."); }
From source file:sadl.detectors.PdttaDeterminismTest.java
@Test public void svmDeterminismTest() throws IOException, URISyntaxException { double fMeasure = -1; final boolean firstRun = true; for (int i = 1; i <= 10; i++) { final Pair<TimedInput, TimedInput> trainTest = IoUtils .readTrainTestFile(Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI())); Settings.setDebug(false);//from ww w .ja va 2 s . c om final PdttaLearner learner = new PdttaLearner(new AlergiaRedBlue(0.05, true)); final AnomalyDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY, new UberFeatureCreator(), new LibSvmClassifier(1, 0.2, 0.1, 1, 0.001, 3, ScalingMethod.NORMALIZE)); final AnomalyDetection detection = new AnomalyDetection(detector, learner); final ExperimentResult result = detection.trainTest(trainTest.getKey(), trainTest.getValue()); if (firstRun) { fMeasure = result.getFMeasure(); } else { if (!Precision.equals(fMeasure, result.getFMeasure())) { fail("Failed for run " + i + " because in previous runs fMeasure=" + fMeasure + "; now fMeasure=" + result.getFMeasure()); } } } }
From source file:sadl.detectors.PdttaDeterminismTest.java
@Test public void thresholdDeterminismTest() throws IOException, URISyntaxException { double fMeasure = -1; final boolean firstRun = true; for (int i = 1; i <= 10; i++) { final Pair<TimedInput, TimedInput> trainTest = IoUtils .readTrainTestFile(Paths.get(this.getClass().getResource("/pdtta/smac_mix_type1.txt").toURI())); Settings.setDebug(false);/*from w ww. j ava 2s . c o m*/ final PdttaLearner learner = new PdttaLearner(new AlergiaRedBlue(0.05, true)); final SmallFeatureCreator featureCreator = new SmallFeatureCreator(); final ThresholdClassifier classifier = new ThresholdClassifier(Math.exp(-5), Math.exp(-8), 0.01, 0.001); final VectorDetector detector = new VectorDetector(ProbabilityAggregationMethod.NORMALIZED_MULTIPLY, featureCreator, classifier); final AnomalyDetection detection = new AnomalyDetection(detector, learner); final ExperimentResult result = detection.trainTest(trainTest.getKey(), trainTest.getValue()); if (firstRun) { fMeasure = result.getFMeasure(); } else { if (!Precision.equals(fMeasure, result.getFMeasure())) { fail("Failed for run " + i + " because in previous runs fMeasure=" + fMeasure + "; now fMeasure=" + result.getFMeasure()); } } } }