List of usage examples for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair
public ImmutablePair(final L left, final R right)
From source file:io.cloudslang.lang.compiler.validator.matcher.DescriptionPatternMatcher.java
public Pair<String, String> getDescriptionVariableLineData(String input) { List<String> matches = getData(descriptionVariableLinePattern, input, Regex.DESCRIPTION_VARIABLE_LINE_DECLARATION_GROUP_NR, Regex.DESCRIPTION_VARIABLE_LINE_CONTENT_GROUP_NR); return new ImmutablePair<>(matches.get(0), matches.get(1)); }
From source file:de.flashpixx.rrd_antlr4.generator.CPlugin.java
@Override protected final IGenerator processmessages(final File p_grammar, final File p_outputdirectory, final Collection<String> p_messages) { m_error = !p_messages.isEmpty();//from w ww. j a v a2 s . c o m if (!m_error) m_templates.stream() // generate template to get template data .map(ETemplate::generate) // create grammar file and pair with string name and output directory .forEach(i -> m_files.put(p_grammar, new ImmutablePair<>(i.name(), m_reportdirectory.toURI().relativize(CCommon .outputdirectory(m_baseoutput, i, p_outputdirectory, i.index()).toUri()) .toString()))); return this; }
From source file:de.flashpixx.rrd_antlr4.antlr.CASTVisitorPCRE.java
@Override public final Object visitExpr(final PCREParser.ExprContext p_context) { // iterate over elements final List<Pair<?, String>> l_pairs = p_context.element().stream() // pair with grammar element or string and cardinality .map(i -> (Pair<?, String>) this.visitElement(i)).filter(i -> i != null) .collect(Collectors.toList()); // get pairs and check if a negation "~" is followed by // a grammar symbol so concat this first final List<Pair<?, String>> l_clean = SequenceM .range(0, l_pairs.size()).sliding(2, 2)//www. j a va 2s .co m .flatMap(i -> l_pairs.get(i.get(0)).getLeft().equals("~") ? Stream.of(new ImmutablePair<>( new CGrammarNegation((IGrammarElement) l_pairs.get(i.get(1)).getLeft()), l_pairs.get(i.get(1)).getRight())) : i.get(1) != null ? Stream.of(l_pairs.get(i.get(0)), l_pairs.get(i.get(1))) : Stream.of(l_pairs.get(i.get(0)))) .collect(Collectors.toList()); // build sequences and implode strings return CCommon.sequence(this.implode(l_clean).stream() .map(i -> CCommon.cardinality(i.getRight(), i.getLeft() instanceof String // terminal-value as string ? this.terminalvalue(i.getLeft().toString()) // native grammar element : (IGrammarElement) i.getLeft())) .collect(Collectors.toList())); }
From source file:com.capitati.omtc.core.negotiation.SemanticVersionComparator.java
/** * Lexically compare the components of two string arrays. * * @param one - First string array./*from ww w. j ava 2 s . co m*/ * @param two - The array that is compared to one. * @return If one array is determined to be lexically less than two then * -1 is returned. If one is determined to be lexically greater then two then * 1 is returned. Otherwise, 0 is returned. */ private static ImmutablePair<Integer, Boolean> compareArray(final String[] one, final String[] two) { if ((one == null) && (two == null)) { return new ImmutablePair<Integer, Boolean>(0, true); } if ((one == null) && (two != null)) { return new ImmutablePair<Integer, Boolean>(-1, true); } if ((one != null) && (two == null)) { return new ImmutablePair<Integer, Boolean>(1, true); } @SuppressWarnings("unchecked") final Iterator<String> oneIterator = new ArrayIterator(one); @SuppressWarnings("unchecked") final Iterator<String> twoIterator = new ArrayIterator(two); String oneComp = null; String twoComp = null; int comp = 0; while (true) { try { oneComp = oneIterator.next(); } catch (final NoSuchElementException ex) { oneComp = null; } try { twoComp = twoIterator.next(); } catch (final NoSuchElementException ex) { twoComp = null; } if ((oneComp == null) && (twoComp == null)) { break; } comp = componentCompare(oneComp, twoComp); if (comp != 0) { break; } } return new ImmutablePair<Integer, Boolean>(comp, false); }
From source file:com.wolvereness.overmapped.asm.ByteClass.java
public Pair<ZipEntry, byte[]> call(final Map<Signature, Signature> signatures, final Map<String, String> classMaps, final Map<String, ByteClass> classes, final Map<Signature, Integer> flags, final boolean correctEnums) throws Exception { final ClassWriter writer = new ClassWriter(0); reader.accept(new FlagSetter(new RemappingClassAdapter(correctEnums ? new EnumCorrection(writer) : writer, new SignatureRemapper(classMaps, signatures, classes)), flags), ClassReader.EXPAND_FRAMES); return new ImmutablePair<ZipEntry, byte[]>(new ZipEntry(classMaps.get(token) + FILE_POSTFIX), writer.toByteArray());//from w ww .j av a2 s. co m }
From source file:blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable.java
@Override public void addAvailableEnergy(float amount, Consumer<Float> consume) { long currentTime = world.getTotalWorldTime(); if (lastSourceUpdate != currentTime) { sources.clear();//from w w w. j a v a2 s . c om Pair<Float, Consumer<Float>> own = getOwnEnergy(); if (own != null) sources.add(own); lastSourceUpdate = currentTime; } if (amount > 0 && consume != null) sources.add(new ImmutablePair<>(amount, consume)); }
From source file:models.Document.java
private Pair<URL, String> getContextUrls() throws MalformedURLException { final String path = "public/contexts"; final String file = index.id() + ".json"; URL localContextResourceUrl = Play.application().resource("/" + path + "/" + file); if (localContextResourceUrl == null) // no app running, use plain local file localContextResourceUrl = new File(path, file).toURI().toURL(); final String publicContextUrl = "http://api.lobid.org" + controllers.routes.Assets.at("/" + path, file).url(); return new ImmutablePair<>(localContextResourceUrl, publicContextUrl); }
From source file:com.nextdoor.bender.operation.conditional.ConditionalOperationTest.java
@Test public void testSingleConditionNoMatch() { /*/*from ww w . j av a 2s . c o m*/ * Setup the pipeline of operation processors */ List<Pair<FilterOperation, List<OperationProcessor>>> conditions = new ArrayList<Pair<FilterOperation, List<OperationProcessor>>>(); List<OperationProcessor> case1Ops = new ArrayList<OperationProcessor>(); DummyAppendOperationFactory pos = new DummyAppendOperationFactory(); DummyAppendOperationConfig posConf = new DummyAppendOperationConfig(); posConf.setAppendStr("+"); pos.setConf(posConf); case1Ops.add(new OperationProcessor(pos)); FilterOperation filter = new BasicFilterOperation(false); conditions.add(new ImmutablePair<FilterOperation, List<OperationProcessor>>(filter, case1Ops)); ConditionalOperation op = new ConditionalOperation(conditions, false); /* * Create thread that supplies input events */ Queue<InternalEvent> inputQueue = new Queue<InternalEvent>(); supply(2, inputQueue); /* * Process */ Stream<InternalEvent> input = inputQueue.stream(); Stream<InternalEvent> output = op.getOutputStream(input); List<String> actual = output.map(m -> { return m.getEventObj().getPayload().toString(); }).collect(Collectors.toList()); List<String> expected = Arrays.asList("0", "1"); assertEquals(2, actual.size()); assertTrue(expected.containsAll(actual)); }
From source file:com.quancheng.saluki.registry.consul.ConsulRegistry.java
@Override protected synchronized void doSubscribe(GrpcURL url, NotifyListener.NotifyServiceListener listener) { Pair<GrpcURL, Set<NotifyListener.NotifyServiceListener>> listenersPair = notifyServiceListeners .get(url.getServiceKey());//from ww w .j av a 2s . co m if (listenersPair == null) { Set<NotifyListener.NotifyServiceListener> listeners = Sets.newConcurrentHashSet(); listeners.add(listener); listenersPair = new ImmutablePair<GrpcURL, Set<NotifyListener.NotifyServiceListener>>(url, listeners); } else { listenersPair.getValue().add(listener); } notifyServiceListeners.putIfAbsent(url.getServiceKey(), listenersPair); if (!serviceGroupLookUped.contains(url.getGroup())) { serviceGroupLookUped.add(url.getGroup()); ServiceLookUper serviceLookUper = new ServiceLookUper(url.getGroup()); serviceLookUper.setDaemon(true); serviceLookUper.start(); ConsulEphemralNode ephemralNode = this.buildEphemralNode(url, ThrallRoleType.CONSUMER); client.registerEphemralNode(ephemralNode); } else { notifyListener(url, listener); } }
From source file:com.streamsets.pipeline.stage.it.ColdStartIT.java
@Test public void testColdStart() throws Exception { LOG.info(Utils.format(/*from ww w.j av a 2 s . co m*/ "Starting cold start with database({}), storedAsAvro({}), external({}), and partitioned({})", database, storedAsAvro, external, partitioned)); HiveMetadataProcessor processor = new HiveMetadataProcessorBuilder().database(database).external(external) .tablePathTemplate(external ? getExternalWareHouseDir() : getDefaultWareHouseDir()) .partitionPathTemplate(partitioned ? "dt=super-secret" : null) .partitions(partitioned ? new PartitionConfigBuilder().addPartition("dt", HiveType.STRING, "secret-value").build() : new PartitionConfigBuilder().build()) .build(); HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().storedAsAvro(storedAsAvro).build(); Map<String, Field> map = new LinkedHashMap<>(); map.put("name", Field.create(Field.Type.STRING, "StreamSets")); Record record = RecordCreator.create("s", "s:1"); record.set(Field.create(map)); // Empty string as a database was already configured, so we replace it with // string "default", so that we don't have to do that for every single method // call from now on. if (database.isEmpty()) { database = "default"; } executeUpdate(Utils.format("create database if not exists {}", database)); processRecords(processor, hiveTarget, ImmutableList.of(record)); assertTableExists(Utils.format("{}.tbl", database)); assertQueryResult(Utils.format("select * from {}.tbl", database), new QueryValidator() { @Override public void validateResultSet(ResultSet rs) throws Exception { if (partitioned) { assertResultSetStructure(rs, new ImmutablePair("tbl.name", Types.VARCHAR), new ImmutablePair("tbl.dt", Types.VARCHAR)); } else { assertResultSetStructure(rs, new ImmutablePair("tbl.name", Types.VARCHAR)); } Assert.assertTrue("Table tbl doesn't contain any rows", rs.next()); Assert.assertEquals("StreamSets", rs.getString(1)); Assert.assertFalse("Table tbl contains more then one row", rs.next()); } }); }