List of usage examples for org.apache.commons.lang3.tuple Pair getRight
public abstract R getRight();
Gets the right element from this pair.
When treated as a key-value pair, this is the value.
From source file:com.shieldsbetter.sbomg.ModelClass.java
public TypeSpec buildTypeSpec() { TypeSpec.Builder result = TypeSpec.classBuilder(myName).addModifiers(Modifier.PUBLIC); if (myStaticFlag) { result.addModifiers(Modifier.STATIC); }//from w w w . jav a 2 s . c om TypeName thisTypeName = ClassName.get("", myName); for (Map.Entry<String, AbstractMethodSet> auxListenerDef : myAuxiliaryListeners.entrySet()) { TypeSpec.Builder auxListener = TypeSpec.interfaceBuilder(auxListenerDef.getKey()) .addModifiers(Modifier.PUBLIC, Modifier.STATIC); AbstractMethodSet methodDefs = auxListenerDef.getValue(); for (String methodName : methodDefs.getNames()) { MethodSpec.Builder method = MethodSpec.methodBuilder(methodName).addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC); method.addParameter(thisTypeName, "source"); for (Pair<String, TypeName> parameter : methodDefs.getParameters(methodName)) { method.addParameter(parameter.getRight(), parameter.getLeft()); } auxListener.addMethod(method.build()); } result.addType(auxListener.build()); } TypeSpec.Builder listener = TypeSpec.interfaceBuilder("Listener").addModifiers(Modifier.PUBLIC, Modifier.STATIC); for (String methodName : myRootListener.getNames()) { MethodSpec.Builder method = MethodSpec.methodBuilder("on" + methodName).addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC); method.addParameter(thisTypeName, "source"); for (Pair<String, TypeName> parameter : myRootListener.getParameters(methodName)) { method.addParameter(parameter.getRight(), parameter.getLeft()); } listener.addMethod(method.build()); } result.addType(listener.build()); TypeSpec.Builder event = TypeSpec.interfaceBuilder("Event").addModifiers(Modifier.PUBLIC, Modifier.STATIC) .addMethod(MethodSpec.methodBuilder("on").addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC) .addParameter(ClassName.get("", "Listener"), "l").build()); result.addType(event.build()); TypeSpec.Builder eventListener = TypeSpec.interfaceBuilder("EventListener") .addModifiers(Modifier.PUBLIC, Modifier.STATIC) .addMethod(MethodSpec.methodBuilder("on").addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC) .addParameter(ClassName.get("", "Event"), "e").build()); result.addType(eventListener.build()); TypeSpec.Builder subscription = TypeSpec.interfaceBuilder("Subscription") .addModifiers(Modifier.PUBLIC, Modifier.STATIC).addMethod(MethodSpec.methodBuilder("unsubscribe") .addModifiers(Modifier.ABSTRACT, Modifier.PUBLIC).build()); result.addType(subscription.build()); CodeBlock.Builder addListenerEventListenerCode = CodeBlock.builder(); if (myRootListener.getMethodCount() > 0) { result.addField(FieldSpec .builder( ParameterizedTypeName.get(ClassName.get("java.util", "List"), ClassName.get("", "EventListener")), "myListeners", Modifier.PRIVATE, Modifier.FINAL) .initializer("new $T<>()", ClassName.get("java.util", "LinkedList")).build()); addListenerEventListenerCode.addStatement("myListeners.add(el)") .beginControlFlow("return new Subscription()") .beginControlFlow("@Override public void unsubscribe()").addStatement("myListeners.remove(el)") .endControlFlow().endControlFlow(""); } else { addListenerEventListenerCode.beginControlFlow("return new Subscription()") .beginControlFlow("@Override public void unsubscribe()").endControlFlow().endControlFlow(""); } result.addMethod(MethodSpec.methodBuilder("addListener").addModifiers(Modifier.PUBLIC) .returns(ClassName.get("", "Subscription")) .addParameter(ClassName.get("", "Listener"), "l", Modifier.FINAL) .addCode(CodeBlock.builder().beginControlFlow("EventListener el = new EventListener()") .beginControlFlow("@Override public void on(Event e)").addStatement("e.on(l)") .endControlFlow().endControlFlow("").addStatement("return addListener(el)").build()) .build()); result.addMethod(MethodSpec.methodBuilder("addListener").addModifiers(Modifier.PUBLIC) .returns(ClassName.get("", "Subscription")) .addParameter(ClassName.get("", "EventListener"), "el", Modifier.FINAL) .addCode(addListenerEventListenerCode.build()).build()); result.addMethod(MethodSpec.methodBuilder("build").addModifiers(Modifier.PUBLIC).returns(TypeName.VOID) .addParameter(ClassName.get("", "Listener"), "l", Modifier.FINAL).addCode(myBuildCode.build()) .build()); for (FieldSpec f : myFields) { result.addField(f); } MethodSpec.Builder constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC); for (Pair<String, TypeName> param : myInitializationParams) { String paramName = param.getLeft(); constructor.addParameter(param.getRight(), paramName); } constructor.addCode(myAdditionalInitializationCode.build()); result.addMethod(constructor.build()); result.addMethods(myRootMethods); for (ModelClass c : mySubModels) { result.addType(c.buildTypeSpec()); } for (TypeSpec type : myRootTypes) { result.addType(type); } for (TypeName type : myImplementsList) { result.addSuperinterface(type); } return result.build(); }
From source file:de.ks.activity.context.ActivityContext.java
@SuppressWarnings("unchecked") @Override//from w w w .j ava 2 s .com public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) { if (contextual instanceof Bean) { Bean bean = (Bean) contextual; Pair<String, Class<?>> key = getKey(bean); lock.writeLock().lock(); try { Object o = bean.create(creationalContext); StoredBean storedBean = new StoredBean(bean, creationalContext, o); activities.get(key.getLeft()).put(key.getRight(), storedBean); return (T) o; } finally { lock.writeLock().unlock(); } } return null; }
From source file:com.yahoo.pulsar.broker.namespace.NamespaceServiceTest.java
@Test public void testSplitAndOwnBundles() throws Exception { OwnershipCache MockOwnershipCache = spy(pulsar.getNamespaceService().getOwnershipCache()); doNothing().when(MockOwnershipCache).disableOwnership(any(NamespaceBundle.class)); Field ownership = NamespaceService.class.getDeclaredField("ownershipCache"); ownership.setAccessible(true);//from ww w .j av a 2 s . c om ownership.set(pulsar.getNamespaceService(), MockOwnershipCache); NamespaceService namespaceService = pulsar.getNamespaceService(); NamespaceName nsname = new NamespaceName("pulsar/global/ns1"); DestinationName dn = DestinationName.get("persistent://pulsar/global/ns1/topic-1"); NamespaceBundles bundles = namespaceService.getNamespaceBundleFactory().getBundles(nsname); NamespaceBundle originalBundle = bundles.findBundle(dn); // Split bundle and take ownership of split bundles CompletableFuture<Void> result = namespaceService.splitAndOwnBundle(originalBundle); try { result.get(); } catch (Exception e) { // make sure: no failure fail("split bundle faild", e); } NamespaceBundleFactory bundleFactory = this.pulsar.getNamespaceService().getNamespaceBundleFactory(); NamespaceBundles updatedNsBundles = bundleFactory.getBundles(nsname); // new updated bundles shouldn't be null assertNotNull(updatedNsBundles); List<NamespaceBundle> bundleList = updatedNsBundles.getBundles(); assertNotNull(bundles); NamespaceBundleFactory utilityFactory = NamespaceBundleFactory.createFactory(Hashing.crc32()); // (1) validate bundleFactory-cache has newly split bundles and removed old parent bundle Pair<NamespaceBundles, List<NamespaceBundle>> splitBundles = splitBundles(utilityFactory, nsname, bundles, originalBundle); assertNotNull(splitBundles); Set<NamespaceBundle> splitBundleSet = new HashSet<>(splitBundles.getRight()); splitBundleSet.removeAll(bundleList); assertTrue(splitBundleSet.isEmpty()); // (2) validate LocalZookeeper policies updated with newly created split // bundles String path = joinPath(LOCAL_POLICIES_ROOT, nsname.toString()); byte[] content = this.pulsar.getLocalZkCache().getZooKeeper().getData(path, null, new Stat()); Policies policies = ObjectMapperFactory.getThreadLocal().readValue(content, Policies.class); NamespaceBundles localZkBundles = bundleFactory.getBundles(nsname, policies.bundles); assertTrue(updatedNsBundles.equals(localZkBundles)); System.out.println(policies); // (3) validate ownership of new split bundles by local owner bundleList.stream().forEach(b -> { try { byte[] data = this.pulsar.getLocalZkCache().getZooKeeper().getData(ServiceUnitZkUtils.path(b), null, new Stat()); NamespaceEphemeralData node = ObjectMapperFactory.getThreadLocal().readValue(data, NamespaceEphemeralData.class); Assert.assertEquals(node.getNativeUrl(), this.pulsar.getBrokerServiceUrl()); } catch (Exception e) { fail("failed to setup ownership", e); } }); }
From source file:de.pixida.logtest.buildserver.RunIntegrationTests.java
private List<Job> createJobs(final Map<File, List<Pair<File, Map<String, String>>>> pairsWithParams) { final List<Job> result = new ArrayList<>(); for (final Entry<File, List<Pair<File, Map<String, String>>>> pair : pairsWithParams.entrySet()) { final List<LogSink> sinks = new ArrayList<>(); for (final Pair<File, Map<String, String>> sinkDef : pair.getValue()) { final LogSink newSink = new LogSink(); newSink.setAutomaton(new JsonAutomatonDefinition(sinkDef.getLeft())); newSink.setParameters(sinkDef.getRight()); sinks.add(newSink);// w w w .j a v a2s. com } final Job newJob = new Job(); newJob.setLogReader(this.createAndConfigureLogReader(pair.getKey())); newJob.setSinks(sinks); result.add(newJob); } return result; }
From source file:com.minlia.cloud.framework.test.common.client.template.AbstractTestRestTemplate.java
@Override public final RequestSpecification givenReadAuthenticated() { final Pair<String, String> credentials = getReadCredentials(); return auth.givenBasicAuthenticated(credentials.getLeft(), credentials.getRight()); }
From source file:com.minlia.cloud.framework.test.common.client.template.AbstractTestRestTemplate.java
final RequestSpecification givenWriteAuthenticated() { final Pair<String, String> credentials = getWriteCredentials(); return auth.givenBasicAuthenticated(credentials.getLeft(), credentials.getRight()); }
From source file:com.minlia.cloud.framework.test.common.client.template.AbstractTestRestTemplate.java
final RequestSpecification givenDeleteAuthenticated() { final Pair<String, String> credentials = getWriteCredentials(); return auth.givenBasicAuthenticated(credentials.getLeft(), credentials.getRight()); }
From source file:com.splicemachine.db.impl.ast.CorrelatedPushDown.java
public boolean pushdownPredWithColumn(ResultSetNode rsn, Predicate pred, ValueNode colRef) throws StandardException { try {//from w w w. j av a 2 s. c om ResultColumn rc = RSUtils.refToRC.apply(colRef); List<Pair<Integer, Integer>> chain = ColumnUtils.rsnChain(rc); Pair<Integer, Integer> lastLink = chain.get(chain.size() - 1); List<ResultSetNode> subTree = RSUtils.getSelfAndDescendants(rsn); Map<Integer, ResultSetNode> nodeMap = zipMap(Iterables.transform(subTree, RSUtils.rsNum), subTree); ResultSetNode targetRSN = nodeMap.get(lastLink.getLeft()); rc.setResultSetNumber(lastLink.getLeft()); rc.setVirtualColumnId(lastLink.getRight()); ((Optimizable) targetRSN).pushOptPredicate(pred); } catch (StandardException e) { LOG.warn("Exception pushing down topmost subquery predicate:", e); return false; } return true; }
From source file:controllers.admin.SystemOwnerController.java
/** * Display the basic information page./*from w w w. j a va 2 s . co m*/ * * <ul> * <li>The sizing of the system</li> * <li>The remaining storage</li> * <li>The number of registered users</li> * <li>The available plugins</li> * </ul> * * @return */ public Result info() { // Find system owners List<String> systemOwners = new ArrayList<String>(); List<Principal> systemOnwerPrincipals = Principal .getPrincipalsWithPermission(IMafConstants.ADMIN_SYSTEM_OWNER_PERMISSION); for (Principal principal : systemOnwerPrincipals) { IUserAccount userAccount; try { userAccount = getAccountManagerPlugin().getUserAccountFromUid(principal.uid); if (userAccount != null) { systemOwners.add(String.format("%s %s (%s)", userAccount.getFirstName(), userAccount.getLastName(), userAccount.getMail())); } } catch (Exception e) { log.error("Unexpected error while looking for system owners", e); } } String authenticationMode = "Slave"; // Check master mode for authentication if (getConfiguration().getBoolean("maf.ic_ldap_master")) { authenticationMode = "Master"; } // Get the number of active users SystemInfo systemInfo = new SystemInfo(Principal.getActivePrincipalCount(), Principal.getRegisteredPrincipalCount(), systemOwners, "1.2", "Bronze", "unknown", authenticationMode); // List of available plugins List<PluginDefinitionTableObject> pluginDescriptions = new ArrayList<PluginDefinitionTableObject>(); for (Pair<Boolean, IPluginDescriptor> pluginDefinitionRecord : getPluginManagerService() .getAllPluginDescriptors().values()) { PluginDefinitionTableObject tableObject = new PluginDefinitionTableObject(); IPluginDescriptor pluginDescriptor = pluginDefinitionRecord.getRight(); tableObject.identifier = pluginDescriptor.getIdentifier(); tableObject.name = Msg.get(pluginDescriptor.getName()); tableObject.version = pluginDescriptor.getVersion(); pluginDescriptions.add(tableObject); } return ok(views.html.admin.systemowner.info.render(systemInfo, pluginDefinitionsTableTemplate.fill(pluginDescriptions))); }
From source file:de.tntinteractive.portalsammler.gui.MainDialog.java
private void poll(final Gui gui) { this.pollButton.setEnabled(false); final Settings settings = this.getStore().getSettings().deepClone(); final ProgressMonitor progress = new ProgressMonitor(this, "Sammle Daten aus den Quell-Portalen...", "...", 0, settings.getSize());//w w w. java2 s. co m progress.setMillisToDecideToPopup(0); progress.setMillisToPopup(0); progress.setProgress(0); final SwingWorker<String, String> task = new SwingWorker<String, String>() { @Override protected String doInBackground() throws Exception { final StringBuilder summary = new StringBuilder(); int cnt = 0; for (final String id : settings.getAllSettingIds()) { if (this.isCancelled()) { break; } cnt++; this.publish(cnt + ": " + id); final Pair<Integer, Integer> counts = MainDialog.this.pollSingleSource(settings, id); summary.append(id).append(": "); if (counts != null) { summary.append(counts.getLeft()).append(" neu, ").append(counts.getRight()) .append(" schon bekannt\n"); } else { summary.append("Fehler!\n"); } this.setProgress(cnt); } MainDialog.this.getStore().writeMetadata(); return summary.toString(); } @Override protected void process(final List<String> ids) { progress.setNote(ids.get(ids.size() - 1)); } @Override public void done() { MainDialog.this.pollButton.setEnabled(true); MainDialog.this.table.refreshContents(); try { final String summary = this.get(); JOptionPane.showMessageDialog(MainDialog.this, summary, "Abruf-Zusammenfassung", JOptionPane.INFORMATION_MESSAGE); } catch (final Exception e) { gui.showError(e); } } }; task.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent evt) { if ("progress".equals(evt.getPropertyName())) { progress.setProgress((Integer) evt.getNewValue()); } if (progress.isCanceled()) { task.cancel(true); } } }); task.execute(); }