List of usage examples for org.apache.commons.lang3.tuple Pair getValue
@Override
public R getValue()
Gets the value from this pair.
This method implements the Map.Entry interface returning the right element as the value.
From source file:com.act.lcms.db.model.InductionWell.java
public List<InductionWell> insertFromPlateComposition(DB db, PlateCompositionParser parser, Plate p) throws SQLException, IOException { Map<String, String> plateAttributes = parser.getPlateProperties(); Map<Pair<String, String>, String> msids = parser.getCompositionTables().get("msid"); List<Pair<String, String>> sortedCoordinates = new ArrayList<>(msids.keySet()); Collections.sort(sortedCoordinates, new Comparator<Pair<String, String>>() { // TODO: parse the values of these pairs as we read them so we don't need this silly comparator. @Override/* w ww . ja v a2s . c o m*/ public int compare(Pair<String, String> o1, Pair<String, String> o2) { if (o1.getKey().equals(o2.getKey())) { return Integer.valueOf(Integer.parseInt(o1.getValue())) .compareTo(Integer.parseInt(o2.getValue())); } return o1.getKey().compareTo(o2.getKey()); } }); List<InductionWell> results = new ArrayList<>(); for (Pair<String, String> coords : sortedCoordinates) { String msid = msids.get(coords); if (msid == null || msid.isEmpty()) { continue; } String chemicalSource = parser.getCompositionTables().get("chemical_source").get(coords); String composition = parser.getCompositionTables().get("composition").get(coords); String chemical = parser.getCompositionTables().get("chemical").get(coords); String strainSource = parser.getCompositionTables().get("strain_source").get(coords); String note = null; if (parser.getCompositionTables().get("note") != null) { note = parser.getCompositionTables().get("note").get(coords); } // TODO: ditch this when we start using floating point numbers for growth values. Integer growth = null; Map<Pair<String, String>, String> growthTable = parser.getCompositionTables().get("growth"); if (growthTable == null || growthTable.get(coords) == null) { String plateGrowth = plateAttributes.get("growth"); if (plateGrowth != null) { growth = Integer.parseInt(trimAndComplain(plateGrowth)); } } else { String growthStr = growthTable.get(coords); if (PLUS_MINUS_GROWTH_TO_INT.containsKey(growthStr)) { growth = PLUS_MINUS_GROWTH_TO_INT.get(growthStr); } else { growth = Integer.parseInt(growthStr); // If it's not using +/- format, it should be an integer from 1-5. } } Pair<Integer, Integer> index = parser.getCoordinatesToIndices().get(coords); InductionWell s = INSTANCE.insert(db, p.getId(), index.getLeft(), index.getRight(), msid, chemicalSource, composition, chemical, strainSource, note, growth); results.add(s); } return results; }
From source file:com.streamsets.pipeline.stage.processor.hbase.HBaseLookupProcessor.java
private void handleEmptyKey(Record record, Pair<String, HBaseColumn> key) throws StageException { if (conf.ignoreMissingFieldPath) { LOG.debug(Errors.HBASE_41.getMessage(), record, key.getKey(), Bytes.toString(key.getValue().getCf()) + ":" + Bytes.toString(key.getValue().getQualifier()), key.getValue().getTimestamp()); } else {/* w w w . ja va 2 s . c o m*/ LOG.error(Errors.HBASE_41.getMessage(), record, key.getKey(), Bytes.toString(key.getValue().getCf()) + ":" + Bytes.toString(key.getValue().getQualifier()), key.getValue().getTimestamp()); errorRecordHandler.onError(new OnRecordErrorException(record, Errors.HBASE_41, record, key.getKey(), Bytes.toString(key.getValue().getCf()) + ":" + Bytes.toString(key.getValue().getQualifier()), key.getValue().getTimestamp())); } }
From source file:lineage2.gameserver.handler.voicecommands.impl.Wedding.java
/** * Method engage./*from ww w.j av a 2 s. co m*/ * @param activeChar Player * @return boolean */ public boolean engage(final Player activeChar) { if (activeChar.getTarget() == null) { activeChar.sendMessage(new CustomMessage("voicedcommandhandlers.Wedding.NoneTargeted", activeChar)); return false; } if (!activeChar.getTarget().isPlayer()) { activeChar .sendMessage(new CustomMessage("voicedcommandhandlers.Wedding.OnlyAnotherPlayer", activeChar)); return false; } if (activeChar.getPartnerId() != 0) { activeChar.sendMessage(new CustomMessage("voicedcommandhandlers.Wedding.AlreadyEngaged", activeChar)); if (Config.WEDDING_PUNISH_INFIDELITY) { activeChar.startAbnormalEffect(AbnormalEffect.BIG_HEAD); int skillId; int skillLevel = 1; if (activeChar.getLevel() > 40) { skillLevel = 2; } if (activeChar.isMageClass()) { skillId = 4361; } else { skillId = 4362; } Skill skill = SkillTable.getInstance().getInfo(skillId, skillLevel); if (activeChar.getEffectList().getEffectsBySkill(skill) == null) { skill.getEffects(activeChar, activeChar, false, false); activeChar.sendPacket(new SystemMessage(SystemMessage.S1_S2S_EFFECT_CAN_BE_FELT) .addSkillName(skillId, skillLevel)); } } return false; } final Player ptarget = (Player) activeChar.getTarget(); if (ptarget.getObjectId() == activeChar.getObjectId()) { activeChar.sendMessage(new CustomMessage("voicedcommandhandlers.Wedding.EngagingYourself", activeChar)); return false; } if (ptarget.isMaried()) { activeChar.sendMessage( new CustomMessage("voicedcommandhandlers.Wedding.PlayerAlreadyMarried", activeChar)); return false; } if (ptarget.getPartnerId() != 0) { activeChar.sendMessage( new CustomMessage("voicedcommandhandlers.Wedding.PlayerAlreadyEngaged", activeChar)); return false; } Pair<Integer, OnAnswerListener> entry = ptarget.getAskListener(false); if ((entry != null) && (entry.getValue() instanceof CoupleAnswerListener)) { activeChar .sendMessage(new CustomMessage("voicedcommandhandlers.Wedding.PlayerAlreadyAsked", activeChar)); return false; } if (ptarget.getPartnerId() != 0) { activeChar.sendMessage( new CustomMessage("voicedcommandhandlers.Wedding.PlayerAlreadyEngaged", activeChar)); return false; } if ((ptarget.getSex() == activeChar.getSex()) && !Config.WEDDING_SAMESEX) { activeChar.sendMessage(new CustomMessage("voicedcommandhandlers.Wedding.SameSex", activeChar)); return false; } boolean FoundOnFriendList = false; int objectId; Connection con = null; PreparedStatement statement = null; ResultSet rset = null; try { con = DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement("SELECT friend_id FROM character_friends WHERE char_id=?"); statement.setInt(1, ptarget.getObjectId()); rset = statement.executeQuery(); while (rset.next()) { objectId = rset.getInt("friend_id"); if (objectId == activeChar.getObjectId()) { FoundOnFriendList = true; break; } } } catch (Exception e) { _log.error("", e); } finally { DbUtils.closeQuietly(con, statement, rset); } if (!FoundOnFriendList) { activeChar.sendMessage(new CustomMessage("voicedcommandhandlers.Wedding.NotInFriendlist", activeChar)); return false; } ConfirmDlg packet = new ConfirmDlg(SystemMsg.S1, 60000).addString( "Player " + activeChar.getName() + " asking you to engage. Do you want to start new relationship?"); ptarget.ask(packet, new CoupleAnswerListener(activeChar, ptarget)); return true; }
From source file:lineage2.loginserver.serverpackets.ServerList.java
/** * Constructor for ServerList./*from w w w. j a v a2 s. c om*/ * @param account Account */ public ServerList(Account account) { _lastServer = account.getLastServer(); for (GameServer gs : GameServerManager.getInstance().getGameServers()) { InetAddress ip; try { ip = NetUtils.isInternalIP(account.getLastIP()) ? gs.getInternalHost() : gs.getExternalHost(); } catch (UnknownHostException e) { continue; } Pair<Integer, int[]> entry = account.getAccountInfo(gs.getId()); _servers.add(new ServerData(gs.getId(), ip, gs.getPort(), gs.isPvp(), gs.isShowingBrackets(), gs.getServerType(), gs.getOnline(), gs.getMaxPlayers(), gs.isOnline(), entry == null ? 0 : entry.getKey(), gs.getAgeLimit(), entry == null ? ArrayUtils.EMPTY_INT_ARRAY : entry.getValue())); } }
From source file:com.galenframework.speclang2.reader.pagespec.PageSectionProcessor.java
private void processObjectLevelRule(ObjectSpecs objectSpecs, StructNode sourceNode) throws IOException { String ruleText = sourceNode.getName().substring(1).trim(); Pair<PageRule, Map<String, String>> rule = findAndProcessRule(ruleText, sourceNode); pageSpecHandler.setGlobalVariable("objectName", objectSpecs.getObjectName(), sourceNode); List<StructNode> specNodes = rule.getKey().apply(pageSpecHandler, ruleText, objectSpecs.getObjectName(), rule.getValue()); SpecGroup specGroup = new SpecGroup(); specGroup.setName(ruleText);/*from w w w .ja v a 2 s . com*/ objectSpecs.addSpecGroup(specGroup); for (StructNode specNode : specNodes) { specGroup.addSpec( pageSpecHandler.getSpecReader().read(specNode.getName(), pageSpecHandler.getContextPath())); } }
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 .j a v a2 s .c o m*/ 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:com.microsoft.azure.storage.blob.BlobEncryptionPolicy.java
/** * Set up the encryption context required for encrypting blobs. * @param metadata// ww w . java 2 s . c o m * Reference to blob metadata object that is used to set the encryption materials. * @param noPadding * Value indicating if the padding mode should be set or not. * @return The Cipher to use to decrypt the blob. * @throws StorageException * An exception representing any error which occurred during the operation. */ Cipher createAndSetEncryptionContext(Map<String, String> metadata, boolean noPadding) throws StorageException { Utility.assertNotNull("metadata", metadata); // The Key should be set on the policy for encryption. Otherwise, throw an error. if (this.keyWrapper == null) { throw new IllegalArgumentException(SR.KEY_MISSING); } try { KeyGenerator keyGen = KeyGenerator.getInstance("AES"); keyGen.init(256); Cipher myAes; if (noPadding) { myAes = Cipher.getInstance("AES/CBC/NoPadding"); } else { myAes = Cipher.getInstance("AES/CBC/PKCS5Padding"); } SecretKey aesKey = keyGen.generateKey(); myAes.init(Cipher.ENCRYPT_MODE, aesKey); BlobEncryptionData encryptionData = new BlobEncryptionData(); encryptionData.setEncryptionAgent(new EncryptionAgent( Constants.EncryptionConstants.ENCRYPTION_PROTOCOL_V1, EncryptionAlgorithm.AES_CBC_256)); // Wrap key Pair<byte[], String> encryptedKey = this.keyWrapper .wrapKeyAsync(aesKey.getEncoded(), null /* algorithm */).get(); encryptionData.setWrappedContentKey(new WrappedContentKey(this.keyWrapper.getKid(), encryptedKey.getKey(), encryptedKey.getValue())); encryptionData.setContentEncryptionIV(myAes.getIV()); metadata.put(Constants.EncryptionConstants.BLOB_ENCRYPTION_DATA, encryptionData.serialize()); return myAes; } catch (Exception e) { throw StorageException.translateClientException(e); } }
From source file:com.galenframework.speclang2.pagespec.PageSectionProcessor.java
private void processObjectLevelRule(ObjectSpecs objectSpecs, StructNode sourceNode) throws IOException { String ruleText = sourceNode.getName().substring(1).trim(); Pair<PageRule, Map<String, String>> rule = findAndProcessRule(ruleText, sourceNode); try {//from w ww. j ava 2s . co m pageSpecHandler.setGlobalVariable("objectName", objectSpecs.getObjectName(), sourceNode); List<StructNode> specNodes = rule.getKey().apply(pageSpecHandler, ruleText, objectSpecs.getObjectName(), rule.getValue(), sourceNode.getChildNodes()); SpecGroup specGroup = new SpecGroup(); specGroup.setName(ruleText); objectSpecs.addSpecGroup(specGroup); for (StructNode specNode : specNodes) { specGroup.addSpec( pageSpecHandler.getSpecReader().read(specNode.getName(), pageSpecHandler.getContextPath())); } } catch (Exception ex) { throw new SyntaxException(sourceNode, "Error processing rule: " + ruleText, ex); } }
From source file:com.act.lcms.db.model.StandardWell.java
public List<StandardWell> insertFromPlateComposition(DB db, PlateCompositionParser parser, Plate p) throws SQLException, IOException { Map<Pair<String, String>, String> msids = parser.getCompositionTables().get("chemical"); List<Pair<String, String>> sortedCoordinates = new ArrayList<>(msids.keySet()); Collections.sort(sortedCoordinates, new Comparator<Pair<String, String>>() { // TODO: parse the values of these pairs as we read them so we don't need this silly comparator. @Override/*from www .j ava2s . c o m*/ public int compare(Pair<String, String> o1, Pair<String, String> o2) { if (o1.getKey().equals(o2.getKey())) { return Integer.valueOf(Integer.parseInt(o1.getValue())) .compareTo(Integer.parseInt(o2.getValue())); } return o1.getKey().compareTo(o2.getKey()); } }); List<StandardWell> results = new ArrayList<>(); for (Pair<String, String> coords : sortedCoordinates) { String chemical = parser.getCompositionTables().get("chemical").get(coords); if (chemical == null || chemical.isEmpty()) { continue; } Map<Pair<String, String>, String> mediaMap = parser.getCompositionTables().get("media"); if (mediaMap == null) { mediaMap = parser.getCompositionTables().get("solvent"); } String media = mediaMap != null ? mediaMap.get(coords) : null; Map<Pair<String, String>, String> notesMap = parser.getCompositionTables().get("note"); String note = notesMap != null ? notesMap.get(coords) : null; Pair<Integer, Integer> index = parser.getCoordinatesToIndices().get(coords); Map<Pair<String, String>, String> concentrationsMap = parser.getCompositionTables() .get("concentration"); Double concentration = concentrationsMap != null ? Double.parseDouble(concentrationsMap.get(coords)) : null; StandardWell s = INSTANCE.insert(db, p.getId(), index.getLeft(), index.getRight(), chemical, media, note, concentration); results.add(s); } return results; }
From source file:com.epam.dlab.backendapi.core.commands.CommandParserMock.java
/** * Parse command line./* www . j a v a 2 s . c o m*/ * * @param cmd command line. */ public void parse(String cmd, String uuid) { command = null; action = null; resourceType = null; imageType = null; requestId = uuid; responsePath = null; name = null; json = null; envMap.clear(); varMap.clear(); otherArgs.clear(); variables.clear(); List<String> args = extractArgs(cmd); dockerCommand = args.contains("docker"); int i = 0; String s; Pair<String, String> p; while (i < args.size()) { if ((s = getArgValue(args, i, "-v")) != null) { p = getPair("-v", s, ":"); varMap.put(p.getValue(), p.getKey()); } else if ((s = getArgValue(args, i, "-e")) != null) { p = getPair("-e", s, "="); envMap.put(p.getKey(), p.getValue()); } else if ((s = getArgValue(args, i, "docker")) != null || (s = getArgValue(args, i, "python")) != null) { command = s; } else if ((s = getArgValue(args, i, "--action")) != null) { action = s; } else if ((s = getArgValue(args, i, "--name")) != null) { name = s; } else if ((s = getArgValue(args, i, "echo")) != null) { if (s.equals("-e")) { if (i >= args.size()) { throw new DlabException("Argument \"echo -e\" detected but not have value"); } s = args.get(i); args.remove(i); } json = s; } else if ((s = getArgValue(args, i, "--result_path")) != null) { responsePath = s; varMap.put("/response", responsePath); args.remove(i); } else { i++; } } if (args.size() > 0) { otherArgs.addAll(args); } resourceType = envMap.get("conf_resource"); if (isDockerCommand()) { imageType = getImageName(args); imageType = imageType.replace("docker.dlab-", "").replace(":latest", ""); } responsePath = varMap.get("/response"); variables.putAll(envMap); variables.putAll(getJsonVariables(json)); variables.put("request_id", requestId); variables.put("instance_id", "i-" + requestId.replace("-", "").substring(0, 17)); variables.put("cluster_id", "j-" + requestId.replace("-", "").substring(0, 13).toUpperCase()); variables.put("notebook_id", requestId.replace("-", "").substring(17, 22)); }