List of usage examples for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair
public ImmutablePair(final L left, final R right)
From source file:com.jaspersoft.jasperserver.jrsh.operation.grammar.parser.PlainGrammarParser.java
/** * Parses operation grammar using Search Graph algorithm for * building all possible grammar paths./*from w w w .j a v a 2s . c o m*/ * * @param operation operation instance * @return operation grammar * @throws OperationParseException */ public Grammar parseGrammar(Operation operation) throws OperationParseException { graph = new DefaultDirectedGraph<>(new TokenEdgeFactory()); dependencies = new HashMap<>(); groups = new HashMap<String, RuleGroup>(); Grammar grammar = new DefaultGrammar(); Set<Rule> rules = new HashSet<>(); Class<?> clazz = operation.getClass(); Master master = clazz.getAnnotation(Master.class); if (master != null) { root = instantiateToken(master.tokenClass(), master.name(), master.name(), true, true); if (master.tail()) { rules.add(new PlainRule(root)); } dependencies.put(root.getName(), new ImmutablePair<>(root, new String[] {})); graph.addVertex(root); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { Prefix prefix = field.getAnnotation(Prefix.class); Parameter param = field.getAnnotation(Parameter.class); if (param != null) { OperationParameter param1 = new OperationParameter(); param1.getTokens().add(root); for (String key : groups.keySet()) { groups.get(key).getParameters().add(param1); } boolean isMandatory = param.mandatory(); Value[] values = param.values(); OperationParameter param2 = new OperationParameter(); for (Value v : values) { Token token = instantiateToken(v.tokenClass(), v.tokenAlias(), v.tokenValue(), isMandatory, v.tail()); graph.addVertex(token); if (prefix != null) { Token prefixTkn = instantiateToken(prefix.tokenClass(), prefix.value(), prefix.value(), isMandatory, false); dependencies.put(prefixTkn.getName(), new ImmutablePair<>(prefixTkn, param.dependsOn())); dependencies.put(token.getName(), new ImmutablePair<>(token, new String[] { prefix.value() })); param2.getTokens().add(prefixTkn); graph.addVertex(prefixTkn); } else { dependencies.put(token.getName(), new ImmutablePair<>(token, param.dependsOn())); } param2.getTokens().add(token); String[] ruleGroupKey = param.ruleGroups(); for (String groupKey : ruleGroupKey) { RuleGroup ruleGroup = groups.get(groupKey); if (ruleGroup != null) { ruleGroup.getParameters().add(param2); } else { groups.put(groupKey, new RuleGroup(param1, param2)); } } } } } } buildGraphEdges(); if (!(graph.vertexSet().size() == 1 && graph.vertexSet().contains(root))) { rules.addAll(buildRules()); } if (!rules.isEmpty()) { grammar.addRules(rules); } else throw new WrongOperationFormatException(); return grammar; }
From source file:com.kantenkugel.discordbot.modules.AutoRespond.java
@Override public void fromJson(JSONObject cfg) { if (!cfg.has("channels")) { cfg.put("channels", new JSONArray()); }/*from www . java 2 s.c o m*/ if (!cfg.has("responses")) { cfg.put("responses", new JSONArray()); } channels.clear(); JSONArray arr = cfg.getJSONArray("channels"); for (int i = 0; i < arr.length(); i++) { channels.add(arr.getString(i)); } responses.clear(); arr = cfg.getJSONArray("responses"); for (int i = 0; i < arr.length(); i++) { JSONObject obj = arr.getJSONObject(i); Set<String> keys = new HashSet<>(); JSONArray keyarr = obj.getJSONArray("keys"); for (int j = 0; j < keyarr.length(); j++) { keys.add(keyarr.getString(j)); } responses.put(obj.getString("name"), new ImmutablePair<>(keys, obj.getString("response"))); } }
From source file:com.datatorrent.benchmark.util.serde.GenericSerdePerformanceTest.java
protected ImmutablePair generatePair(long now) { return new ImmutablePair(new Window.TimeWindow(now + random.nextInt(100), random.nextInt(100)), "" + random.nextInt(1000)); }
From source file:au.gov.ga.earthsci.bookmark.properties.layer.LayersPropertyPersister.java
@Override public IBookmarkProperty createFromXML(String type, Element propertyElement) { Validate.isTrue(LayersProperty.TYPE.equals(type), INVALID_TYPE_MSG); Validate.notNull(propertyElement, "A property element is required"); //$NON-NLS-1$ LayersProperty result = new LayersProperty(); for (Element state : XmlUtil.getElements(propertyElement, LAYER_XPATH, null)) { // state.getAttributes() String id = XMLUtil.getText(state, ID_ATTRIBUTE_XPATH); Double opacity = XMLUtil.getDouble(state, OPACITY_ATTRIBUTE_XPATH, 1.0d); NamedNodeMap attrs = state.getAttributes(); if (id != null) { List<Pair<String, String>> pairs = new ArrayList<Pair<String, String>>(); for (int i = 0; i < attrs.getLength(); i++) { String key = attrs.item(i).getNodeName(); String value = attrs.item(i).getNodeValue(); if (!key.equals(ID_ATTRIBUTE_NAME)) { pairs.add(new ImmutablePair<String, String>(key, value)); }//from w w w . j a va2 s .com } result.addLayer(id, pairs.toArray(new Pair[0])); } } return result; }
From source file:de.fuberlin.agcsw.svont.changedetection.smartcex.PartitionEL.java
/** * Splits the given ontology into two partitions: The set of OWL EL * compliant axioms and the set of axioms which are not compliant with the * OWL EL profile. The EL compliant partition is stored in the left part of * resulting pair, and the EL non-compliant partition is stored in the right * part.// www .ja v a 2s .c o m * * @param sourceOnto * The source ontology to be partitioned. * @param compatibilityMode * Specifies the reasoner with which the resulting partition * should be compatible (e.g. Pellet has a different notion of EL * than other reasoners). * @return A pair containing two ontologies. The left part is the partition * of the source ontology with all EL-compliant axioms. The right * part is the partition of the source ontology with all * non-EL-compliant axioms. If the source ontology already conforms * to the OWL-EL profile, then the left part of the result contains * the source ontology, and the right part is null. * @throws OWLOntologyCreationException * If there is an error loading the source ontology. * @throws IllegalAccessException * @throws InstantiationException */ public static Pair<OWLOntology, OWLOntology> partition(OWLOntology sourceOnto, ReasonerCompatibilityMode compatibilityMode) throws OWLOntologyCreationException, InstantiationException, IllegalAccessException { OWLProfile elProfile = compatibilityMode.getProfileClass().newInstance(); OWLProfileReport report = elProfile.checkOntology(sourceOnto); if (report.isInProfile()) { return new ImmutablePair<OWLOntology, OWLOntology>(sourceOnto, null); } HashSet<OWLAxiom> nonELAxioms = new HashSet<OWLAxiom>(); Set<OWLProfileViolation> violations = report.getViolations(); for (OWLProfileViolation violation : violations) { nonELAxioms.add(violation.getAxiom()); } OWLOntologyID ontologyID = sourceOnto.getOntologyID(); IRI ontologyIRI = ontologyID.getOntologyIRI(); IRI targetELOntologyIRI = IRI.create(ontologyIRI.toString() + "/ELpart"); IRI targetNonELOntologyIRI = IRI.create(ontologyIRI.toString() + "/nonELpart"); OWLOntologyManager targetELOntoManager = OWLManager.createOWLOntologyManager(); targetELOntoManager.addIRIMapper(new NonMappingOntologyIRIMapper()); OWLOntology targetELOnto = targetELOntoManager.createOntology(new OWLOntologyID(targetELOntologyIRI)); OWLOntologyManager targetNonELOntoManager = OWLManager.createOWLOntologyManager(); targetNonELOntoManager.addIRIMapper(new NonMappingOntologyIRIMapper()); OWLOntology targetNonELOnto = targetNonELOntoManager .createOntology(new OWLOntologyID(targetNonELOntologyIRI)); Set<OWLAxiom> allAxioms = sourceOnto.getAxioms(); for (OWLAxiom axiom : allAxioms) { if (nonELAxioms.contains(axiom)) { targetNonELOntoManager.addAxiom(targetNonELOnto, axiom); System.out.println("- " + axiom); } else { targetELOntoManager.addAxiom(targetELOnto, axiom); System.out.println("+ " + axiom); } } return new ImmutablePair<OWLOntology, OWLOntology>(targetELOnto, targetNonELOnto); }
From source file:ch.mlutz.plugins.t4e.tapestry.element.TapestryHtmlElement.java
public List<Pair<IFile, Object>> getRelations() { List<Pair<IFile, Object>> result = new ArrayList<Pair<IFile, Object>>(); /*/*from w w w . j a v a 2 s . c o m*/ IFile javaFile= null; if (javaCompilationUnit != null) { try { IResource javaResource = javaCompilationUnit.getCorrespondingResource(); if (javaResource != null) { javaFile= (IFile) javaResource.getAdapter(IFile.class); } } catch (JavaModelException e) { log.warn("Can't get correspondingResource for " + javaCompilationUnit.getElementName()); } } if (javaFile != null) { */ result.add(new ImmutablePair<IFile, Object>(htmlFile, javaCompilationUnit)); if (specification != null) { result.add(new ImmutablePair<IFile, Object>(specification, javaCompilationUnit)); } /* } */ return result; }
From source file:com.offbynull.portmapper.common.UdpCommunicator.java
/** * Add a packet to the send queue of this UDP communicator. * @param channel channel to send on// ww w .j a v a2 s. com * @param dst destination to send to * @param data packet to send * @throws NullPointerException if any argument is {@code null}, or if {@code channel} doesn't belong to this communicator * @throws IllegalStateException if this communicator isn't running */ public void send(DatagramChannel channel, InetSocketAddress dst, ByteBuffer data) { Validate.notNull(channel); Validate.notNull(dst); Validate.notNull(data); Validate.validState(isRunning()); LinkedBlockingQueue<ImmutablePair<InetSocketAddress, ByteBuffer>> queue = sendQueue.get(channel); Validate.isTrue(channel != null); queue.add(new ImmutablePair<>(dst, ByteBufferUtils.copyContents(data))); selector.wakeup(); }
From source file:code.elix_x.excore.utils.net.packets.SmartNetworkWrapper.java
public <REQ extends IMessage> void registerMessage1( final Function<Pair<REQ, MessageContext>, Runnable> onReceive, Class<REQ> requestMessageType, Side side) {//from w ww. j ava2 s . co m registerMessage(new Function<Pair<REQ, MessageContext>, Pair<Runnable, IMessage>>() { @Override public Pair<Runnable, IMessage> apply(Pair<REQ, MessageContext> t) { return new ImmutablePair<Runnable, IMessage>(onReceive.apply(t), null); } }, requestMessageType, side); }
From source file:eu.bittrade.libs.steemj.BaseTransactionalIT.java
/** * Setup the test environment for transaction related tests. *///from w w w . jav a 2 s . c om protected static void setupIntegrationTestEnvironmentForTransactionalTests(String mode, String endpoint) { setupIntegrationTestEnvironment(); if (TEST_ENDPOINT == null) { TEST_ENDPOINT = endpoint; } if (TEST_MODE == null) { TEST_MODE = mode; } // The expiration date used for tests is way to old in general - // Therefore the validation needs to be disabled. config.setValidationLevel(ValidationType.SKIP_VALIDATION); try { if (TEST_ENDPOINT.equals(TESTNET_ENDPOINT_IDENTIFIER)) { // Configure SteemJ to work against the TestNet. config.setChainId("79276aea5d4877d9a25892eaa01b0adf019d3e5cb12a97478df3298ccdd01673"); config.setAddressPrefix(AddressPrefixType.STX); try { if (TEST_MODE.equals(HTTP_MODE_IDENTIFIER)) { configureTestNetHttpEndpoint(); } else if (TEST_MODE.equals(WEBSOCKET_MODE_IDENTIFIER)) { configureTestNetWebsocketEndpoint(); } else { LOGGER.error("Unknown Test Mode {}. - Test execution stopped.", TEST_MODE); } } catch (URISyntaxException e) { throw new RuntimeException("Unable to start test due to a wrong endpoint URI."); } try { createTestNetAccount(STEEMJ_ACCOUNT_NAME.getName(), STEEMJ_PASSWORD); createTestNetAccount(DEZ_ACCOUNT_NAME.getName(), DEZ_PASSWORD); // Fille the private key storage. List<ImmutablePair<PrivateKeyType, String>> privateKeys = new ArrayList<>(); privateKeys.add(new ImmutablePair<>(PrivateKeyType.POSTING, SteemJ .getPrivateKeyFromPassword(STEEMJ_ACCOUNT_NAME, PrivateKeyType.POSTING, STEEMJ_PASSWORD) .getRight())); privateKeys.add(new ImmutablePair<>(PrivateKeyType.ACTIVE, SteemJ .getPrivateKeyFromPassword(STEEMJ_ACCOUNT_NAME, PrivateKeyType.ACTIVE, STEEMJ_PASSWORD) .getRight())); privateKeys.add(new ImmutablePair<>(PrivateKeyType.OWNER, SteemJ .getPrivateKeyFromPassword(STEEMJ_ACCOUNT_NAME, PrivateKeyType.OWNER, STEEMJ_PASSWORD) .getRight())); config.getPrivateKeyStorage().addAccount(STEEMJ_ACCOUNT_NAME, privateKeys); privateKeys = new ArrayList<>(); privateKeys.add(new ImmutablePair<>(PrivateKeyType.POSTING, SteemJ.getPrivateKeyFromPassword(DEZ_ACCOUNT_NAME, PrivateKeyType.POSTING, DEZ_PASSWORD) .getRight())); privateKeys.add(new ImmutablePair<>(PrivateKeyType.ACTIVE, SteemJ.getPrivateKeyFromPassword(DEZ_ACCOUNT_NAME, PrivateKeyType.ACTIVE, DEZ_PASSWORD) .getRight())); privateKeys.add(new ImmutablePair<>(PrivateKeyType.OWNER, SteemJ.getPrivateKeyFromPassword(DEZ_ACCOUNT_NAME, PrivateKeyType.OWNER, DEZ_PASSWORD) .getRight())); config.getPrivateKeyStorage().addAccount(DEZ_ACCOUNT_NAME, privateKeys); } catch (IOException | GeneralSecurityException e) { throw new RuntimeException("Could not create TestNet accounts. - Test execution stopped.", e); } } else if (TEST_ENDPOINT.equals(STEEMNET_ENDPOINT_IDENTIFIER)) { /* * If running against the real Steem Blockchain an existing * account with real private keys is required. This mode can * currently only be used by @dez1337 as most of the integration * tests are written for his account. */ try { if (TEST_MODE.equals(HTTP_MODE_IDENTIFIER)) { // Do nothing as this is the default. } else if (TEST_MODE.equals(WEBSOCKET_MODE_IDENTIFIER)) { configureSteemWebSocketEndpoint(); } else { LOGGER.error("Unknown Test Mode {}. - Test execution stopped.", TEST_MODE); } } catch (URISyntaxException e) { throw new RuntimeException("Unable to start test due to a wrong endpoint URI."); } } else { LOGGER.error("Unknown Test Endpoint {}. - Test execution stopped.", TEST_ENDPOINT); } // Create a new instance to respect the settings made above. steemJ = new SteemJ(); } catch (SteemCommunicationException | SteemResponseException e) { throw new RuntimeException("Could not create a SteemJ instance. - Test execution stopped.", e); } }
From source file:com.microsoft.tooling.msservices.serviceexplorer.azure.storagearm.StorageModule.java
@Override protected void refresh(@NotNull EventStateHandle eventState) throws AzureCmdException { removeAllChildNodes();//w w w . j a v a2 s . co m AzureManager azureManager = AzureManagerImpl.getManager(getProject()); // load all Storage Accounts List<Subscription> subscriptionList = azureManager.getSubscriptionList(); List<Pair<String, String>> failedSubscriptions = new ArrayList<>(); for (Subscription subscription : subscriptionList) { try { List<ArmStorageAccount> storageAccounts = AzureArmManagerImpl.getManager(getProject()) .getStorageAccounts(subscription.getId()); if (eventState.isEventTriggered()) { return; } for (StorageAccount sm : storageAccounts) { String type = sm.getType(); if (type.equals(StorageAccountTypes.STANDARD_GRS) || type.equals(StorageAccountTypes.STANDARD_LRS) || type.equals(StorageAccountTypes.STANDARD_RAGRS) || type.equals(StorageAccountTypes.STANDARD_ZRS)) { addChildNode(new StorageNode(this, subscription.getId(), sm)); } } } catch (Exception ex) { failedSubscriptions.add(new ImmutablePair<>(subscription.getName(), ex.getMessage())); continue; } } // load External Accounts for (ClientStorageAccount clientStorageAccount : ExternalStorageHelper.getList(getProject())) { ClientStorageAccount storageAccount = StorageClientSDKManagerImpl.getManager() .getStorageAccount(clientStorageAccount.getConnectionString()); if (eventState.isEventTriggered()) { return; } // addChildNode(new ExternalStorageNode(this, storageAccount)); } if (!failedSubscriptions.isEmpty()) { StringBuilder errorMessage = new StringBuilder( "An error occurred when trying to load Storage Accounts for the subscriptions:\n\n"); for (Pair error : failedSubscriptions) { errorMessage.append(error.getKey()).append(": ").append(error.getValue()).append("\n"); } DefaultLoader.getUIHelper().logError( "An error occurred when trying to load Storage Accounts\n\n" + errorMessage.toString(), null); } }