List of usage examples for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair
public ImmutablePair(final L left, final R right)
From source file:io.swagger.api.impl.ToolsApiServiceImpl.java
/** * Convert our Tool object to a standard Tool format * * @param container our data object/*from w w w . j av a2s . com*/ * @return standardised data object */ private static Pair<io.swagger.model.Tool, Table<String, SourceFile.FileType, Object>> convertContainer2Tool( Entry container) { Table<String, SourceFile.FileType, Object> fileTable = HashBasedTable.create(); String globalId; // TODO: properly pass this information String newID; try { // construct escaped ID if (container instanceof Tool) { newID = ((Tool) container).getToolPath(); } else if (container instanceof Workflow) { newID = "#workflow/" + ((Workflow) container).getPath(); } else { LOG.error("Could not construct URL for our container with id: " + container.getId()); return null; } String escapedID = URLEncoder.encode(newID, StandardCharsets.UTF_8.displayName()); URI uri = new URI(config.getScheme(), null, config.getHostname(), Integer.parseInt(config.getPort()), "/api/ga4gh/v1/tools/", null, null); globalId = uri.toString() + escapedID; } catch (URISyntaxException | UnsupportedEncodingException e) { LOG.error("Could not construct URL for our container with id: " + container.getId()); return null; } // TODO: hook this up to a type field in our DB? ToolClass type = container instanceof Tool ? ToolClassesApiServiceImpl.getCommandLineToolClass() : ToolClassesApiServiceImpl.getWorkflowClass(); io.swagger.model.Tool tool = new io.swagger.model.Tool(); if (container.getAuthor() == null) { tool.setAuthor("Unknown author"); } else { tool.setAuthor(container.getAuthor()); } tool.setDescription(container.getDescription()); tool.setMetaVersion(container.getLastUpdated() != null ? container.getLastUpdated().toString() : null); tool.setToolclass(type); tool.setId(newID); tool.setUrl(globalId); tool.setVerified(false); tool.setVerifiedSource(""); // tool specific if (container instanceof Tool) { Tool inputTool = (Tool) container; tool.setToolname(inputTool.getToolname()); tool.setOrganization(inputTool.getNamespace()); tool.setToolname(inputTool.getName()); } // workflow specific if (container instanceof Workflow) { Workflow inputTool = (Workflow) container; tool.setToolname(inputTool.getPath()); tool.setOrganization(inputTool.getOrganization()); tool.setToolname(inputTool.getWorkflowName()); } // TODO: contains has no counterpart in our DB // setup versions as well Set inputVersions; if (container instanceof Tool) { inputVersions = ((Tool) container).getTags(); } else { inputVersions = ((Workflow) container).getWorkflowVersions(); } for (Version inputVersion : (Set<Version>) inputVersions) { // tags with no names make no sense here // also hide hidden tags if (inputVersion.getName() == null || inputVersion.isHidden()) { continue; } if (inputVersion instanceof Tag && ((Tag) inputVersion).getImageId() == null) { continue; } ToolVersion version = new ToolVersion(); // version id String globalVersionId; try { globalVersionId = globalId + "/versions/" + URLEncoder.encode(inputVersion.getName(), StandardCharsets.UTF_8.displayName()); } catch (UnsupportedEncodingException e) { LOG.error("Could not construct URL for our container with id: " + container.getId()); return null; } version.setUrl(globalVersionId); version.setId(tool.getId() + ":" + inputVersion.getName()); version.setName(inputVersion.getName()); version.setVerified(false); version.setVerifiedSource(""); version.setDockerfile(false); String urlBuilt; final String githubPrefix = "git@github.com:"; final String bitbucketPrefix = "git@bitbucket.org:"; if (container.getGitUrl().startsWith(githubPrefix)) { urlBuilt = extractHTTPPrefix(container.getGitUrl(), inputVersion.getReference(), githubPrefix, "https://raw.githubusercontent.com/"); } else if (container.getGitUrl().startsWith(bitbucketPrefix)) { urlBuilt = extractHTTPPrefix(container.getGitUrl(), inputVersion.getReference(), bitbucketPrefix, "https://bitbucket.org/"); } else { LOG.error("Found a git url neither from bitbucket or github " + container.getGitUrl()); urlBuilt = null; } final Set<SourceFile> sourceFiles = inputVersion.getSourceFiles(); for (SourceFile file : sourceFiles) { if (inputVersion instanceof Tag) { switch (file.getType()) { case DOCKERFILE: ToolDockerfile dockerfile = new ToolDockerfile(); dockerfile.setDockerfile(file.getContent()); dockerfile.setUrl(urlBuilt + ((Tag) inputVersion).getDockerfilePath()); version.setDockerfile(true); fileTable.put(inputVersion.getName(), DOCKERFILE, dockerfile); break; case DOCKSTORE_CWL: version.addDescriptorTypeItem(ToolVersion.DescriptorTypeEnum.CWL); fileTable.put(inputVersion.getName(), DOCKSTORE_CWL, buildSourceFile(urlBuilt + ((Tag) inputVersion).getCwlPath(), file)); break; case DOCKSTORE_WDL: version.addDescriptorTypeItem(ToolVersion.DescriptorTypeEnum.CWL); fileTable.put(inputVersion.getName(), DOCKSTORE_WDL, buildSourceFile(urlBuilt + ((Tag) inputVersion).getWdlPath(), file)); break; } } else if (inputVersion instanceof WorkflowVersion) { switch (file.getType()) { case DOCKSTORE_CWL: version.addDescriptorTypeItem(ToolVersion.DescriptorTypeEnum.CWL); fileTable.put(inputVersion.getName(), DOCKSTORE_CWL, buildSourceFile( urlBuilt + ((WorkflowVersion) inputVersion).getWorkflowPath(), file)); break; case DOCKSTORE_WDL: version.addDescriptorTypeItem(ToolVersion.DescriptorTypeEnum.CWL); fileTable.put(inputVersion.getName(), DOCKSTORE_WDL, buildSourceFile( urlBuilt + ((WorkflowVersion) inputVersion).getWorkflowPath(), file)); break; } } } if (container instanceof Tool) { version.setImage(((Tool) container).getPath() + ":" + inputVersion.getName()); } if (!version.getDescriptorType().isEmpty()) { // ensure that descriptor is non-null before adding to list tool.getVersions().add(version); version.setMetaVersion( inputVersion.getLastModified() != null ? String.valueOf(inputVersion.getLastModified()) : null); } } return new ImmutablePair<>(tool, fileTable); }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.KubernetesDistributedService.java
default List<ConfigSource> stageProfiles(AccountDeploymentDetails<KubernetesAccount> details, GenerateService.ResolvedConfiguration resolvedConfiguration) { SpinnakerService thisService = getService(); ServiceSettings thisServiceSettings = resolvedConfiguration.getServiceSettings(thisService); SpinnakerRuntimeSettings runtimeSettings = resolvedConfiguration.getRuntimeSettings(); Integer version = getRunningServiceDetails(details, runtimeSettings).getLatestEnabledVersion(); if (version == null) { version = 0;//from ww w . ja v a2s. com } else { version++; } String namespace = getNamespace(thisServiceSettings); KubernetesProviderUtils.createNamespace(details, namespace); String name = getServiceName(); Map<String, String> env = new HashMap<>(); List<ConfigSource> configSources = new ArrayList<>(); Map<String, Profile> serviceProfiles = resolvedConfiguration.getProfilesForService(thisService.getType()); Set<String> requiredFiles = new HashSet<>(); for (SidecarService sidecarService : getSidecars(runtimeSettings)) { for (Profile profile : sidecarService.getSidecarProfiles(resolvedConfiguration, thisService)) { if (profile == null) { throw new HalException(Problem.Severity.FATAL, "Service " + sidecarService.getService().getCanonicalName() + " is required but was not supplied for deployment."); } serviceProfiles.put(profile.getName(), profile); requiredFiles.addAll(profile.getRequiredFiles()); } } Map<String, Set<Profile>> collapseByDirectory = new HashMap<>(); for (Map.Entry<String, Profile> entry : serviceProfiles.entrySet()) { Profile profile = entry.getValue(); String mountPoint = Paths.get(profile.getOutputFile()).getParent().toString(); Set<Profile> profiles = collapseByDirectory.getOrDefault(mountPoint, new HashSet<>()); profiles.add(profile); requiredFiles.addAll(profile.getRequiredFiles()); collapseByDirectory.put(mountPoint, profiles); } String stagingPath = getSpinnakerStagingPath(details.getDeploymentName()); if (!requiredFiles.isEmpty()) { String secretName = KubernetesProviderUtils.componentDependencies(name, version); String mountPoint = null; for (String file : requiredFiles) { String nextMountPoint = Paths.get(file).getParent().toString(); if (mountPoint == null) { mountPoint = nextMountPoint; } assert (mountPoint.equals(nextMountPoint)); } Set<Pair<File, String>> pairs = requiredFiles.stream().map(f -> { return new ImmutablePair<>(new File(f), new File(f).getName()); }).collect(Collectors.toSet()); KubernetesProviderUtils.upsertSecret(details, pairs, secretName, namespace); configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint)); } int ind = 0; for (Map.Entry<String, Set<Profile>> entry : collapseByDirectory.entrySet()) { env.clear(); String mountPoint = entry.getKey(); Set<Profile> profiles = entry.getValue(); env.putAll(profiles.stream().reduce(new HashMap<>(), (acc, profile) -> { acc.putAll(profile.getEnv()); return acc; }, (a, b) -> { a.putAll(b); return a; })); String secretName = KubernetesProviderUtils.componentSecret(name + ind, version); ind += 1; Set<Pair<File, String>> pairs = profiles.stream().map(p -> { return new ImmutablePair<>(new File(stagingPath, p.getName()), new File(p.getOutputFile()).getName()); }).collect(Collectors.toSet()); KubernetesProviderUtils.upsertSecret(details, pairs, secretName, namespace); configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint).setEnv(env)); } return configSources; }
From source file:com.nextdoor.bender.operation.conditional.ConditionalOperationTest.java
public void testFilterNonMatch() { List<Pair<FilterOperation, List<OperationProcessor>>> conditions = new ArrayList<Pair<FilterOperation, List<OperationProcessor>>>(); /*/* ww w .jav a2s . c om*/ * Case 1 */ List<OperationProcessor> case1Ops = new ArrayList<OperationProcessor>(); FilterOperation case1Filter = new BasicFilterOperation(false); conditions.add(new ImmutablePair<FilterOperation, List<OperationProcessor>>(case1Filter, case1Ops)); ConditionalOperation op = new ConditionalOperation(conditions, true); /* * 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()); assertEquals(0, actual.size()); }
From source file:hu.ppke.itk.nlpg.purepos.decoder.AbstractDecoder.java
private Map<NGram<Integer>, Map<Integer, Pair<Double, Double>>> getNextForGuessedVocToken( final Set<NGram<Integer>> prevTagsSet, String lWord, Collection<Integer> anals, ISuffixGuesser<String, Integer> guesser) { Map<NGram<Integer>, Map<Integer, Pair<Double, Double>>> ret = new HashMap<NGram<Integer>, Map<Integer, Pair<Double, Double>>>(); Map<Integer, Pair<Double, Double>> tagProbs; Collection<Integer> possibleTags; possibleTags = anals;/*from w w w . ja v a 2s.c om*/ tagProbs = new HashMap<Integer, Pair<Double, Double>>(); for (Integer tag : possibleTags) { Double emissionProb = 0.0; Double transitionProb; Integer newTag = guesser.getMapper().map(tag); if (newTag > model.getTagVocabulary().getMaximalIndex()) { emissionProb = UNKNOWN_TAG_WEIGHT; // TODO: RESEARCH: new tags should handled better transitionProb = UNKOWN_TAG_TRANSITION; tagProbs.put(tag, new ImmutablePair<Double, Double>(transitionProb, emissionProb)); for (NGram<Integer> prevTags : prevTagsSet) { ret.put(prevTags, tagProbs); } } else { Double aprioriProb = model.getAprioriTagProbs().get(newTag); Double logAprioriPorb = Math.log(aprioriProb); double tagLogProbability = guesser.getTagLogProbability(lWord, tag); if (tagLogProbability == Double.NEGATIVE_INFINITY) emissionProb = UNKNOWN_TAG_WEIGHT; else emissionProb = tagLogProbability - logAprioriPorb; for (NGram<Integer> prevTags : prevTagsSet) { transitionProb = model.getTagTransitionModel().getLogProb(prevTags.toList(), tag); tagProbs.put(tag, new ImmutablePair<Double, Double>(transitionProb, emissionProb)); ret.put(prevTags, tagProbs); } } } return ret; }
From source file:cgeo.geocaching.AboutActivity.java
@Override protected final Pair<List<? extends Page>, Integer> getOrderedPages() { final List<Page> pages = Arrays.asList(Page.values()); return new ImmutablePair<List<? extends Page>, Integer>(pages, 0); }
From source file:io.lavagna.web.api.CardControllerTest.java
@Test public void createWithMilestone() { CardData cardData = new CardData(); cardData.setName("name"); BulkOperation milestone = new BulkOperation(1, new CardLabelValue.LabelValue(1), Collections.<Integer>emptyList()); cardData.setMilestone(milestone);/* w w w .ja v a 2s . c o m*/ ImmutablePair<List<Integer>, List<Integer>> result = new ImmutablePair<>(cardIds, cardIds); when(cardService.createCard(eq("name"), eq(columnId), any(Date.class), eq(user))).thenReturn(card); when(bulkOperationService.setMilestone(eq(projectShortName), eq(cardIds), any(CardLabelValue.LabelValue.class), eq(user))).thenReturn(result); cardController.create(columnId, cardData, user); verify(cardService).createCard(eq("name"), eq(columnId), any(Date.class), eq(user)); verify(eventEmitter).emitCreateCard(project.getShortName(), board.getShortName(), boardColumn.getId(), card, user); verify(bulkOperationService).setMilestone(eq(projectShortName), eq(cardIds), any(CardLabelValue.LabelValue.class), eq(user)); verify(cardDataService, never()).updateDescription(eq(cardId), anyString(), any(Date.class), eq(userId)); verify(bulkOperationService, never()).addUserLabel(eq(projectShortName), anyInt(), any(CardLabelValue.LabelValue.class), ArgumentMatchers.<Integer>anyList(), eq(user)); verify(bulkOperationService, never()).setDueDate(eq(projectShortName), ArgumentMatchers.<Integer>anyList(), any(CardLabelValue.LabelValue.class), eq(user)); verify(bulkOperationService, never()).assign(eq(projectShortName), ArgumentMatchers.<Integer>anyList(), any(CardLabelValue.LabelValue.class), eq(user)); verify(cardDataService, never()).assignFileToCard(anyString(), anyString(), anyInt(), eq(user), any(Date.class)); }
From source file:com.linkedin.pinot.core.query.aggregation.groupby.AggregationGroupByOperatorService.java
/** * Translate the reducedGroupByResults (output of broker's reduce) to AggregationResult object * to be used to build the BrokerResponse. * * @param reducedGroupByResults//from w w w. jav a 2s . c o m * @return */ public List<AggregationResult> renderAggregationGroupByResult( List<Map<String, Serializable>> reducedGroupByResults) { if (reducedGroupByResults == null || reducedGroupByResults.size() != _aggregationFunctionList.size()) { return null; } List<AggregationResult> aggregationResults = new ArrayList<AggregationResult>(); for (int i = 0; i < _aggregationFunctionList.size(); ++i) { int groupSize = _groupByColumns.size(); Map<String, Serializable> reducedGroupByResult = reducedGroupByResults.get(i); AggregationFunction aggregationFunction = _aggregationFunctionList.get(i); String functionName = aggregationFunction.getFunctionName(); List<GroupByResult> groupByResults = new ArrayList<GroupByResult>(); if (!reducedGroupByResult.isEmpty()) { /* Reverse sort order for min functions. */ boolean reverseOrder = aggregationFunction.getFunctionName().startsWith(MIN_PREFIX); // The MinMaxPriorityQueue will only add TOP N MinMaxPriorityQueue<ImmutablePair<Serializable, String>> minMaxPriorityQueue = getMinMaxPriorityQueue( reducedGroupByResult.values().iterator().next(), _groupByTopN, reverseOrder); if (minMaxPriorityQueue != null) { for (String groupedKey : reducedGroupByResult.keySet()) { minMaxPriorityQueue .add(new ImmutablePair(reducedGroupByResult.get(groupedKey), groupedKey)); } ImmutablePair res; while ((res = (ImmutablePair) minMaxPriorityQueue.pollFirst()) != null) { String groupByColumnsString = (String) res.getRight(); List<String> groupByColumns = Arrays.asList(groupByColumnsString.split( GroupByConstants.GroupByDelimiter.groupByMultiDelimeter.toString(), groupSize)); Serializable value = (Serializable) res.getLeft(); GroupByResult groupValue = new GroupByResult(); groupValue.setGroup(groupByColumns); groupValue.setValue(formatValue(value)); groupByResults.add(groupValue); } } } AggregationResult aggregationResult = new AggregationResult(groupByResults, _groupByColumns, functionName); aggregationResults.add(aggregationResult); } return aggregationResults; }
From source file:fr.fastconnect.factory.tibco.bw.maven.deployment.StartEARMojo.java
@Override public void postAction() throws MojoExecutionException { try {// w w w.j a v a 2s . c o m if (waitForRunningInstances) { if (!initHawk(false)) { return; } List<ImmutablePair<String, String>> instances = new ArrayList<ImmutablePair<String, String>>(); ApplicationManagement application = new ApplicationManagement(deploymentDescriptorFinal); String applicationName = application.getName(); List<String> servicesNames = application.getInstancesNames(true); for (String serviceName : servicesNames) { instances.add(new ImmutablePair<String, String>(applicationName, serviceName)); } if (doWaitForRunningInstances(instances)) { getLog().info(""); getLog().info(ALL_INSTANCES_STARTED); } else { getLog().info(""); if (failWhenTimeoutReached) { throw new MojoExecutionException(SOME_INSTANCES_NOT_STARTED); } else { getLog().info(SOME_INSTANCES_NOT_STARTED); } } } } catch (JAXBException e) { throw new MojoExecutionException(SOME_INSTANCES_NOT_STARTED); } catch (ConsoleInitializationException e) { throw new MojoExecutionException(SOME_INSTANCES_NOT_STARTED); } catch (MicroAgentException e) { throw new MojoExecutionException(SOME_INSTANCES_NOT_STARTED); } }
From source file:android.databinding.tool.util.XmlEditor.java
private static int recurseReplace(XMLParser.ElementContext node, ArrayList<String> lines, ArrayList<Pair<String, XMLParser.ElementContext>> noTag, String newTag, int bindingIndex) { int nextBindingIndex = bindingIndex; boolean isMerge = "merge".equals(nodeName(node)); final boolean containsInclude = filterNodesByName("include", elements(node)).size() > 0; if (!isMerge && (hasExpressionAttributes(node) || newTag != null || containsInclude)) { String tag = ""; if (newTag != null) { tag = "android:tag=\"" + newTag + "_" + bindingIndex + "\""; nextBindingIndex++;//from w ww. j a v a 2 s . c o m } else if (!"include".equals(nodeName(node))) { tag = "android:tag=\"binding_" + bindingIndex + "\""; nextBindingIndex++; } for (AttributeContext it : expressionAttributes(node)) { Position start = toPosition(it.getStart()); Position end = toEndPosition(it.getStop()); String defaultVal = defaultReplacement(it); if (defaultVal != null) { replace(lines, start, end, it.attrName.getText() + "=\"" + defaultVal + "\""); } else if (replace(lines, start, end, tag)) { tag = ""; } } if (tag.length() != 0) { noTag.add(new ImmutablePair<>(tag, node)); } } String nextTag; if (bindingIndex == 0 && isMerge) { nextTag = newTag; } else { nextTag = null; } for (XMLParser.ElementContext it : elements(node)) { nextBindingIndex = recurseReplace(it, lines, noTag, nextTag, nextBindingIndex); } return nextBindingIndex; }
From source file:com.sk89q.craftbook.sponge.mechanics.variable.Variables.java
public static Set<Pair<String, String>> getPossibleVariables(String line) { Set<Pair<String, String>> variables = new HashSet<>(); if (!line.contains("%")) return variables; Matcher matcher = VARIABLE_PATTERN.matcher(line); while (matcher.find()) { String namespace = matcher.group(1); String key = matcher.group(2); variables.add(new ImmutablePair<>(namespace, key)); }/*from ww w .ja v a2 s. c o m*/ return variables; }