List of usage examples for org.apache.commons.lang3.tuple Pair getKey
@Override public final L getKey()
Gets the key from this pair.
This method implements the Map.Entry interface returning the left element as the key.
From source file:py.una.pol.karaku.replication.client.ReplicationHandler.java
/** * @param ri/*from ww w . j a va 2 s . com*/ * @param response */ @SuppressWarnings({ "rawtypes", "unchecked" }) private String handleResponse(ReplicationInfo ri, Object response) { Pair<String, Collection<?>> pair = responseHandlers.getChanges(response); Collection items = pair.getValue(); String newLastId = pair.getKey(); Converter converter = converterProvider.getConverter(ri.getEntityClazz(), ri.getDaoClazz()); handleCacheAll(converter); int i = 0; for (Object obj : items) { DTO dto = (DTO) obj; i++; try { log.info("Process {}: {}/{} ({}%)", new Object[] { ri.getEntityClassName(), i, items.size(), i * 100 / items.size() }); Shareable entity = converter.toEntity(dto); merge(ri, entity); } catch (EntityNotFoundException enf) { log.warn("Can't get entity from uri, entity with uri {}", dto.getUri()); throw new KarakuRuntimeException( "Can't replicate entity " + obj.getClass().getSimpleName() + " uri = " + dto.getUri(), enf); } catch (Exception e) { log.warn("Can't replicate entity with name {} and uri {}", obj.getClass().getSimpleName(), dto.getUri()); throw new KarakuRuntimeException( "Can't replicate entity " + obj.getClass().getSimpleName() + " uri = " + dto.getUri(), e); } } return newLastId; }
From source file:py.una.pol.karaku.test.test.replication.ReplicationResponseHandlerTest.java
@Test public void testHandleResponse() throws Exception { ReplicationResponseTest1 t1 = new ReplicationResponseTest1(); List<Object> td1 = new ArrayList<Object>(); t1.data = td1;//www . j av a 2 s . c o m t1.id = ZERO; Pair<String, Collection<?>> changes = handler.getChanges(t1); assertEquals(changes.getKey(), ZERO); assertEquals(changes.getValue(), td1); ReplicationResponseTest2 t2 = new ReplicationResponseTest2(); Set<Object> td2 = new HashSet<Object>(); t2.entitiess = td2; t2.lastId = ZERO; Pair<String, Collection<?>> changes2 = handler.getChanges(t1); assertEquals(changes2.getKey(), ZERO); assertEquals(changes2.getValue(), td1); }
From source file:richtercloud.document.scanner.gui.MainPanel.java
/** * Handles both switching documents (if {@code old} and {@code aNew} are not * {@code null} and adding the first document (if {@code old} is * {@code null}.//from w w w .j av a 2 s . co m * @param old * @param aNew */ /* internal implementation notes: - handling both switching and adding the first document maximizes code reusage */ private void switchDocument(OCRSelectComponent old, final OCRSelectComponent aNew) { synchronized (aNew.getTreeLock()) { Pair<OCRPanel, EntityPanel> newPair = documentSwitchingMap.get(aNew); assert newPair != null; OCRPanel oCRPanelNew = newPair.getKey(); EntityPanel entityPanelNew = newPair.getValue(); assert oCRPanelNew != null; assert entityPanelNew != null; //check if dockables already exist in order to avoid failure of //CControl.replace if dockable is recreated MultipleCDockable oCRPanelNewDockable = dockableMap.get(oCRPanelNew); if (oCRPanelNewDockable == null) { oCRPanelNewDockable = new DefaultMultipleCDockable(null, "OCR result", oCRPanelNew); dockableMap.put(oCRPanelNew, oCRPanelNewDockable); } MultipleCDockable entityPanelNewDockable = dockableMap.get(entityPanelNew); if (entityPanelNewDockable == null) { entityPanelNewDockable = new DefaultMultipleCDockable(null, "Entities", entityPanelNew); dockableMap.put(entityPanelNew, entityPanelNewDockable); } if (old != null) { Pair<OCRPanel, EntityPanel> oldPair = documentSwitchingMap.get(old); assert oldPair != null; //order doesn't matter OCRPanel oCRPanelOld = oldPair.getKey(); EntityPanel entityPanelOld = oldPair.getValue(); assert oCRPanelOld != null; assert entityPanelOld != null; MultipleCDockable oCRPanelOldDockable = dockableMap.get(oCRPanelOld); MultipleCDockable entityPanelOldDockable = dockableMap.get(entityPanelOld); control.replace(oCRPanelOldDockable, oCRPanelNewDockable); //CControl.replace fails if new dockable is already //registered at CControl //CControl.replace fails if old dockable has already been //removed from CControl //CDockable.setVisible(false) unregisters dockable at //CControl oCRPanelNewDockable.setVisible(true); control.replace(entityPanelOldDockable, entityPanelNewDockable); //MultipleCDockable.setVisible(true) fails if it's not //registered at a CControl (which has to be done with //CControl.replace (see above)) entityPanelNewDockable.setVisible(true); } else { //order matters control.addDockable(oCRPanelNewDockable); control.addDockable(entityPanelNewDockable); oCRPanelNewDockable.setLocation(CLocation.base().normalEast(0.4)); oCRPanelNewDockable.setVisible(true); entityPanelNewDockable.setLocation(CLocation.base().normalSouth(0.4)); entityPanelNewDockable.setVisible(true); } this.oCRSelectComponentScrollPane = aNew; validate(); } }
From source file:richtercloud.reflection.form.builder.fieldhandler.AbstractListFieldHandler.java
@Override public JComponent handle(Field field, Object instance, FieldUpdateListener<E> updateListener, R reflectionFormBuilder) throws IllegalArgumentException, IllegalAccessException, FieldHandlingException, InstantiationException, InvocationTargetException { Type fieldGenericType = field.getGenericType(); Pair<JComponent, ComponentHandler<?>> retValue = this.typeHandler.handle(fieldGenericType, (T) field.get(instance), //fieldValue field.getName(), field.getDeclaringClass(), //declaringClass updateListener, reflectionFormBuilder); return retValue.getKey(); }
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 ww w .ja v a2s . co m*/ 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"); }//from w ww . j a va 2 s . 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 ava2 s .co 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));//from ww w . j a va 2s . 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);// www . j av a 2 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);/* w w w . j a v a 2 s .co 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."); }