List of usage examples for org.apache.commons.lang3.tuple ImmutablePair of
public static <L, R> ImmutablePair<L, R> of(final L left, final R right)
Obtains an immutable pair of from two objects inferring the generic types.
This factory allows the pair to be created using inference to obtain the generic types.
From source file:me.tfeng.play.mongodb.MongoDbTypeConverter.java
public static <S, T> T convertFromMongoDbType(Class<T> dataClass, S object) { if (object == null) { return null; } else if (dataClass.isInstance(object)) { return dataClass.cast(object); } else {// www .j a v a 2 s. c o m @SuppressWarnings("unchecked") Converter<S, T> converter = (Converter<S, T>) CONVERTER_MAP .get(ImmutablePair.of(object.getClass(), dataClass)); if (converter != null) { return converter.convertFromMongoDbType(object); } else if (String.class.isAssignableFrom(dataClass) && object instanceof DBObject) { return dataClass.cast(JSON.serialize(object)); } else { return null; } } }
From source file:com.addthis.hydra.job.store.CachedSpawnDataStore.java
@Override public String getChild(String parent, String childId) throws Exception { return cache.get(ImmutablePair.of(parent, childId)); }
From source file:candr.yoclip.Parser.java
/** * Constructs a parser instances./*from www .j a v a2s . c o m*/ * * @param parserOptions The parse parameters manager. * @param parserHelpFactory The parser help factory that will be used. * @throws java.lang.IllegalArgumentException if parser parameters or parser help factory is null. */ public Parser(final ParserOptions<T> parserOptions, final ParserHelpFactory<T> parserHelpFactory) { if (null == parserOptions) { throw new IllegalArgumentException("OptionParameters cannot be null."); } if (null == parserHelpFactory) { throw new IllegalArgumentException("OptionHelpFormatter cannot be null."); } this.parserOptions = parserOptions; this.parserHelpFactory = parserHelpFactory; final List<Pair<Matcher, String>> matchers = new LinkedList<Pair<Matcher, String>>(); for (final ParserOption optionParameter : parserOptions.get()) { if (optionParameter.isProperties()) { final String propertyName = optionParameter.getNames()[0]; final String regex = getPropertyPattern(propertyName); final Matcher matcher = Pattern.compile(regex).matcher(""); matchers.add(ImmutablePair.of(matcher, propertyName)); } } this.propertyMatchers = Collections.unmodifiableList(matchers); }
From source file:com.github.rwhogg.git_vcr.VelocityReport.java
/** * extract the changes between two reviews * @return A map of (old) files to changes in results *//* w w w .ja v a 2 s . com*/ @SuppressWarnings("rawtypes") private Map<String, Changes> extractChanges() { Map<String, Changes> changeMap = new HashMap<>(); List<ImmutablePair<String, String>> changedFiles = Util.getFilesChanged(patch); // FIXME: for now, we'll just assume no files were added or deleted for (ImmutablePair<String, String> filePair : changedFiles) { String oldFileName = filePair.getLeft(); String newFileName = filePair.getRight(); Changes changesForThisFile = new Changes(); Map<Class, List<String>> resultsForOldFile = oldResults.getResultsFor(oldFileName); Map<Class, List<String>> resultsForNewFile = newResults.getResultsFor(newFileName); Set<Class> toolsUsed = resultsForOldFile.keySet(); assert toolsUsed.equals(resultsForNewFile.keySet()); // for each tool, go through and detect changes for (Class toolUsed : toolsUsed) { List<String> oldResultListFromThisTool = resultsForOldFile.get(toolUsed); List<String> newResultListFromThisTool = resultsForNewFile.get(toolUsed); Set<String> oldResultsFromThisTool = new HashSet<>(oldResultListFromThisTool); Set<String> newResultsFromThisTool = new HashSet<>(newResultListFromThisTool); Set<String> additions = Sets.difference(newResultsFromThisTool, oldResultsFromThisTool); Set<String> subtractions = Sets.difference(oldResultsFromThisTool, newResultsFromThisTool); // construct the change List<String> additionList = Arrays.asList(additions.toArray(new String[additions.size()])); List<String> subtractionList = Arrays.asList(subtractions.toArray(new String[subtractions.size()])); ImmutablePair<List<String>, List<String>> changeListPair = ImmutablePair.of(additionList, subtractionList); changesForThisFile.put(toolUsed, changeListPair); } changeMap.put(oldFileName, changesForThisFile); } return changeMap; }
From source file:com.addthis.hydra.job.store.CachedSpawnDataStore.java
@Override public void deleteChild(String parent, String childId) { dataStore.deleteChild(parent, childId); cache.invalidate(ImmutablePair.of(parent, childId)); }
From source file:candr.yoclip.DefaultParserHelpFactory.java
@Override public List<Pair<String, String>> getOptionPropertyDescriptions(ParserOption<T> parserOption) { if (null == parserOption) { throw new IllegalArgumentException("ParserOption cannot be null."); }// w w w. ja v a 2 s . c om List<Pair<String, String>> propertyDescriptions = parserOption.getPropertyDescriptions(); if (propertyDescriptions.isEmpty()) { return Collections.emptyList(); } List<Pair<String, String>> optionPropertiesHelp = new LinkedList<Pair<String, String>>(); for (final Pair<String, String> propertyDescription : propertyDescriptions) { String synopsis = propertyDescription.getKey(); if (StringUtils.isEmpty(synopsis)) { synopsis = "key"; } String details = propertyDescription.getValue(); if (StringUtils.isEmpty(details)) { details = String.format("An option property value for %s.", parserOption); } optionPropertiesHelp.add(ImmutablePair.of(synopsis, details)); } return optionPropertiesHelp; }
From source file:io.github.carlomicieli.footballdb.starter.pages.PageTests.java
@Test public void shouldGetValuesFromTablesWithMoreHeaders() { String html = "<table id=\"my-table\">" + "<thead>" + "<tr><td>cat1</td><td colspan=\"2\">cat2</td></tr>" + "<tr><td>col1</td><td>col2</td><td>col3</td></tr>" + "</thead>" + "<tr><td>1</td><td>one</td><td>1</td></tr>" + "<tr><td>2</td><td>two</td><td>1</td></tr>" + "</table>"; Page page = page(fromHtml(html));/* w ww .j a va 2 s .c o m*/ Table table = page.getTableById("my-table").orElse(null); assertThat(table).isNotNull(); assertThat(table.header()).contains("cat1.col1", "cat2.col2", "cat2.col3"); assertThat(table.size()).isEqualTo(ImmutablePair.of(2, 3)); }
From source file:eu.scape_project.tool.toolwrapper.core.ToolWrapperCommandline.java
/** * Method that assesses if the minimum command-line parameters were * provided, as well as if the {@link Tool} object can be created * /*w w w.j a v a 2s . c om*/ * @param args * command line arguments array * @return an {@link ImmutablePair} object containing both the * {@link CommandLine} object and the associated {@link Tool} object */ public ImmutablePair<CommandLine, Tool> processToolWrapperGenerationRequest(String[] args) throws SpecParsingException, ErrorParsingCmdArgsException { ImmutablePair<CommandLine, Tool> pair = null; Tool tool = null; CommandLine cmd = parseArguments(args); try { if (isCommandLineParamentersValid(cmd)) { tool = Utils.createTool(cmd.getOptionValue("t")); pair = ImmutablePair.of(cmd, tool); } else { throw new SpecParsingException( "Unable to process the toolspec provided! Please check it and also if all mandatory parameters were provided properly!"); } } catch (JAXBException e) { throw new SpecParsingException( "Unable to process the toolspec provided! Please check it and also if all mandatory parameters were provided properly!", e); } catch (SAXException e) { throw new SpecParsingException("The XML Schema is not valid!", e); } catch (IOException e) { throw new SpecParsingException( "An error occured while copying the XML Schema from the resources to a temporary location!", e); } return pair; }
From source file:com.yahoo.bullet.storm.drpc.DRPCQuerySubscriber.java
@Override public List<PubSubMessage> getMessages() throws PubSubException { // Try and read from DRPC. The DRPCSpout does a sleep for 1 ms if there are no tuples, so we don't have to do it. spout.nextTuple();/*from www .j av a2s. c o m*/ if (!collector.haveOutput()) { return null; } // The DRPCSpout only should have emitted one tuple List<List<Object>> tuples = collector.reset(); log.debug("Have a message through DRPC {}", tuples); List<Object> tupleAndID = tuples.get(0); // The first object is the actual DRPCSpout tuple and the second is the DRPC messageID. List<Object> tuple = (List<Object>) tupleAndID.get(0); Object drpcID = tupleAndID.get(1); // The first object in the tuple is our PubSubMessage as JSON String pubSubMessageJSON = (String) tuple.get(0); // The second object in the tuple is the serialized returnInfo added by the DRPCSpout String returnInfo = (String) tuple.get(1); log.debug("Read message\n{}\nfrom DRPC with return information {}", pubSubMessageJSON, returnInfo); PubSubMessage pubSubMessage = PubSubMessage.fromJSON(pubSubMessageJSON); // Add returnInfo as metadata. Cannot add it to pubSubMessage String id = pubSubMessage.getId(); String content = pubSubMessage.getContent(); int sequence = pubSubMessage.getSequence(); PubSubMessage message = new PubSubMessage(id, content, new Metadata(null, returnInfo), sequence); emittedIDs.put(ImmutablePair.of(id, sequence), drpcID); return Collections.singletonList(message); }
From source file:io.cloudslang.content.vmware.services.DeployOvfTemplateServiceTest.java
@Before public void setUp() { pair = ImmutablePair.of(httpNfcLeaseMock, ovfCreateImportSpecResultMock); }