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:hu.ppke.itk.nlpg.purepos.common.AnalysisQueue.java
public static Pair<String, List<String>> parse(String token) { int wordRB = token.indexOf("{{"); int analRB = token.indexOf("}}"); String word = token.substring(0, wordRB); String analsStrings = token.substring(wordRB + 2, analRB); List<String> analsList = Arrays.asList(analsStrings.split(analSplitRe)); return ImmutablePair.of(word, analsList); }
From source file:com.yahoo.bullet.storm.drpc.DRPCQuerySubscriber.java
@Override public void commit(String id, int sequence) { super.commit(id, sequence); emittedIDs.remove(ImmutablePair.of(id, sequence)); }
From source file:cc.kave.commons.pointsto.evaluation.TimeEvaluation.java
private void updateTimesRegistry(Map<Pair<String, ITypeName>, AnalysisTimeEntry> registry) { if (registry.isEmpty()) { for (AnalysisTimeEntry timeEntry : analysisTimes) { registry.put(ImmutablePair.of(timeEntry.analysisName, timeEntry.contextType), timeEntry); }/*www . jav a2 s. com*/ } else { for (AnalysisTimeEntry timeEntry : analysisTimes) { Pair<String, ITypeName> key = ImmutablePair.of(timeEntry.analysisName, timeEntry.contextType); AnalysisTimeEntry currentEntry = registry.get(key); registry.put(key, new AnalysisTimeEntry(timeEntry.analysisName, timeEntry.contextType, timeEntry.numStmts, timeEntry.time + currentEntry.time)); } } analysisTimes.clear(); }
From source file:me.tfeng.play.mongodb.MongoDbTypeConverter.java
public static <S, T> S convertToMongoDbType(Class<S> mongoClass, T data) { if (data == null) { return null; } else if (mongoClass.isInstance(data)) { return mongoClass.cast(data); } else {// w w w. ja v a 2s . co m @SuppressWarnings("unchecked") Converter<S, T> converter = (Converter<S, T>) CONVERTER_MAP .get(ImmutablePair.of(mongoClass, data.getClass())); if (converter != null) { return converter.convertToMongoDbType(data); } else if (DBObject.class.isAssignableFrom(mongoClass) && data instanceof String) { return mongoClass.cast(JSON.parse((String) data)); } else { return null; } } }
From source file:io.github.carlomicieli.footballdb.starter.pages.PageTests.java
@Test public void shouldGetValuesFromTablesWithEmptyRows() { String html = "<table id=\"my-table\">" + "<tr><td>1</td><td>one</td><td>1</td></tr>" + "<tr><td colspan=\"3\"></td></tr>" + "<tr><td>2</td><td>two</td><td>1</td></tr>" + "</table>"; Page page = page(fromHtml(html));/*from www. j ava 2s.com*/ Table table = page.getTableById("my-table").orElse(null); assertThat(table).isNotNull(); assertThat(table.size()).isEqualTo(ImmutablePair.of(3, 3)); assertThat(table.rowValues(2)).contains(Arrays.asList("", "", "")); }
From source file:com.github.jakubkolar.autobuilder.impl.NamedResolver.java
public NamedResolver add(String name, @Nullable Object value, Collection<Annotation> requiredAnnotations) { if (value == null) { // TODO: this may be a problem since for null there is no Class, so how to look it up? return new NamedResolver(namedValues, ImmutablePair.of(name, null), new RegisteredValue(null, requiredAnnotations)); } else {//from w w w .ja v a 2 s.c o m return contributeValue(name, value.getClass(), value, requiredAnnotations); } }
From source file:candr.yoclip.DefaultParserHelpFactory.java
@Override public Pair<String, String> getOptionDescription(String prefix, String separator, ParserOption<T> parserOption) { if (null == parserOption) { throw new IllegalArgumentException("ParserOption cannot be null."); }//from w w w . j a v a 2 s .c om String usage = parserOption.getUsage(); if (StringUtils.isEmpty(usage)) { usage = createParserParameterUsage(prefix, separator, parserOption); } String description = parserOption.getDescription(); if (StringUtils.isEmpty(description)) { description = createParserParameterDescription(parserOption); } return ImmutablePair.of(usage, description); }
From source file:io.lavagna.service.ProjectService.java
/** * Bulk creation of projects. Will skip the project that already exists. * * @param projects// w ww.j a v a 2 s .com */ @Transactional(readOnly = false) public ImmutablePair<List<Project>, List<Project>> createMissing(List<Project> projects) { List<Project> created = new ArrayList<>(); List<Project> skipped = new ArrayList<>(); Set<String> usedShortNames = new HashSet<>(); for (Project pi : findAll()) { usedShortNames.add(pi.getShortName()); } for (Project p : projects) { if (!usedShortNames.contains(p.getShortName())) { Project createdProject = create(p.getName(), p.getShortName(), p.getDescription()); updateProject(createdProject.getId(), createdProject.getName(), createdProject.getDescription(), p.isArchived()); created.add(createdProject); } else { skipped.add(p); } } return ImmutablePair.of(Collections.unmodifiableList(created), Collections.unmodifiableList(skipped)); }
From source file:forge.quest.QuestUtilUnlockSets.java
private static List<CardEdition> getUnlockableEditions(final QuestController qData) { if (qData.getFormat() == null || !qData.getFormat().canUnlockSets()) { return emptyEditions; }//from w w w .j a va 2 s.c o m if (qData.getUnlocksTokens() < 1) { // Should never happen if we made it this far but better safe than sorry... throw new RuntimeException("BUG? Could not find unlockable sets even though we should."); } List<CardEdition> options = new ArrayList<CardEdition>(); // Sort current sets by date List<CardEdition> allowedSets = Lists.newArrayList(Iterables.transform( qData.getFormat().getAllowedSetCodes(), FModel.getMagicDb().getEditions().FN_EDITION_BY_CODE)); Collections.sort(allowedSets); // Sort unlockable sets by date List<CardEdition> excludedSets = Lists.newArrayList(Iterables.transform(qData.getFormat().getLockedSets(), FModel.getMagicDb().getEditions().FN_EDITION_BY_CODE)); Collections.sort(excludedSets); // get a number of sets between an excluded and any included set List<ImmutablePair<CardEdition, Long>> excludedWithDistances = new ArrayList<ImmutablePair<CardEdition, Long>>(); for (CardEdition ex : excludedSets) { if (!unlockableSetTypes.contains(ex.getType())) // don't add non-traditional sets continue; long distance = Long.MAX_VALUE; for (CardEdition in : allowedSets) { long d = (Math.abs(ex.getDate().getTime() - in.getDate().getTime())); if (d < distance) { distance = d; } } excludedWithDistances.add(ImmutablePair.of(ex, distance)); } // sort by distance, then by code desc Collections.sort(excludedWithDistances, new Comparator<ImmutablePair<CardEdition, Long>>() { @Override public int compare(ImmutablePair<CardEdition, Long> o1, ImmutablePair<CardEdition, Long> o2) { long delta = o2.right - o1.right; return delta < 0 ? -1 : delta == 0 ? 0 : 1; } }); for (ImmutablePair<CardEdition, Long> set : excludedWithDistances) { options.add(set.left); // System.out.println("Padded with: " + fillers.get(i).getName()); } Collections.reverse(options); return options.subList(0, Math.min(options.size(), Math.min(8, 2 + ((qData.getAchievements().getWin()) / 50)))); }
From source file:com.github.jakubkolar.autobuilder.impl.NamedResolver.java
private NamedResolver contributeValue(String name, @Nullable Class<?> type, Object value, Collection<Annotation> requiredAnnotations) { if (type == null || namedValues.containsKey(ImmutablePair.of(name, (Class) type))) { return this; }/* w w w . java 2s .co m*/ NamedResolver result = new NamedResolver(namedValues, ImmutablePair.of(name, type), new RegisteredValue(value, requiredAnnotations)); result = result.contributeValue(name, type.getSuperclass(), value, requiredAnnotations); for (Class<?> iface : type.getInterfaces()) { result = result.contributeValue(name, iface, value, requiredAnnotations); } return result; }