List of usage examples for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair
public ImmutablePair(final L left, final R right)
From source file:com.streamsets.pipeline.stage.it.MaliciousPartitionStringsIT.java
@Test public void testType() throws Exception { HiveMetadataProcessor processor = new HiveMetadataProcessorBuilder() .partitions(// www .ja v a 2 s . c om new PartitionConfigBuilder().addPartition("part", HiveType.STRING, partitionValue).build()) .build(); HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().build(); Map<String, Field> map = new LinkedHashMap<>(); map.put("col", Field.create("value")); Record record = RecordCreator.create("s", "s:1"); record.set(Field.create(map)); try { processRecords(processor, hiveTarget, ImmutableList.of(record), OnRecordError.TO_ERROR); } catch (Exception e) { LOG.error("Received Exception with", e); // Currently we don't have characters that we throw StageException. fail(Utils.format("Partition value '{}' failed with {}", partitionValue, e.getMessage())); } if (expected == Result.ERROR_RECORD) { // Check the contents of the error record List<Record> errorRecord = getErrorRecord(Stage.METADATA_PROCESSOR); Assert.assertEquals(1, errorRecord.size()); Assert.assertEquals(Errors.HIVE_METADATA_10.name(), errorRecord.get(0).getHeader().getErrorCode()); } else if (expected == Result.SUCCESS) { assertTableExists("default.tbl"); assertQueryResult("select * from tbl", new QueryValidator() { @Override public void validateResultSet(ResultSet rs) throws Exception { assertResultSetStructure(rs, new ImmutablePair("tbl.col", Types.VARCHAR), new ImmutablePair("tbl.part", Types.VARCHAR)); Assert.assertTrue("Table tbl doesn't contain any rows", rs.next()); Assert.assertEquals("value", rs.getString(1)); Assert.assertEquals(partitionValue, rs.getString(2)); Assert.assertFalse("Table tbl contains more then one row", rs.next()); } }); } }
From source file:com.ottogroup.bi.streaming.operator.json.insert.JsonStaticContentInsertionTest.java
/** * Test case for {@link JsonStaticContentInsertion#map(JSONObject)} being provided null *//*from w w w . j a va 2s .c om*/ @Test public void testMap_withNullInput() throws Exception { List<Pair<JsonContentReference, Serializable>> values = new ArrayList<>(); values.add(new ImmutablePair<JsonContentReference, Serializable>( new JsonContentReference(new String[] { "valid" }, JsonContentType.STRING), "test")); Assert.assertNull(new JsonStaticContentInsertion(values).map(null)); }
From source file:com.galenframework.speclang2.reader.pagespec.PageSectionProcessor.java
private Pair<PageRule, Map<String, String>> findAndProcessRule(String ruleText, StructNode ruleNode) { for (Pair<Rule, PageRule> rulePair : pageSpecHandler.getPageRules()) { Matcher matcher = rulePair.getKey().getPattern().matcher(ruleText); if (matcher.matches()) { int index = 1; Map<String, String> parameters = new HashMap<String, String>(); for (String parameterName : rulePair.getKey().getParameters()) { String value = matcher.group(index); pageSpecHandler.setGlobalVariable(parameterName, value, ruleNode); parameters.put(parameterName, value); index += 1;//from w w w. j ava 2 s. com } return new ImmutablePair<PageRule, Map<String, String>>(rulePair.getValue(), parameters); } } throw new SyntaxException(ruleNode, "Could find rule matching: " + ruleText); }
From source file:lineage2.gameserver.data.xml.parser.RestartPointParser.java
/** * Method readData.// w w w. java2 s . co m * @param rootElement Element * @throws Exception */ @Override protected void readData(Element rootElement) throws Exception { List<Pair<Territory, Map<Race, String>>> restartArea = new ArrayList<>(); Map<String, RestartPoint> restartPoint = new HashMap<>(); for (Iterator<Element> iterator = rootElement.elementIterator(); iterator.hasNext();) { Element listElement = iterator.next(); if ("restart_area".equals(listElement.getName())) { Territory territory = null; Map<Race, String> restarts = new HashMap<>(); for (Iterator<Element> i = listElement.elementIterator(); i.hasNext();) { Element n = i.next(); if ("region".equalsIgnoreCase(n.getName())) { Rectangle shape; Attribute map = n.attribute("map"); String s = map.getValue(); String val[] = s.split("_"); int rx = Integer.parseInt(val[0]); int ry = Integer.parseInt(val[1]); int x1 = World.MAP_MIN_X + ((rx - Config.GEO_X_FIRST) << 15); int y1 = World.MAP_MIN_Y + ((ry - Config.GEO_Y_FIRST) << 15); int x2 = (x1 + (1 << 15)) - 1; int y2 = (y1 + (1 << 15)) - 1; shape = new Rectangle(x1, y1, x2, y2); shape.setZmin(World.MAP_MIN_Z); shape.setZmax(World.MAP_MAX_Z); if (territory == null) { territory = new Territory(); } territory.add(shape); } else if ("polygon".equalsIgnoreCase(n.getName())) { Polygon shape = ZoneParser.parsePolygon(n); if (!shape.validate()) { error("RestartPointParser: invalid territory data : " + shape + "!"); } if (territory == null) { territory = new Territory(); } territory.add(shape); } else if ("restart".equalsIgnoreCase(n.getName())) { Race race = Race.valueOf(n.attributeValue("race")); String locName = n.attributeValue("loc"); restarts.put(race, locName); } } if (territory == null) { throw new RuntimeException("RestartPointParser: empty territory!"); } if (restarts.isEmpty()) { throw new RuntimeException("RestartPointParser: restarts not defined!"); } restartArea.add(new ImmutablePair<>(territory, restarts)); } else if ("restart_loc".equals(listElement.getName())) { String name = listElement.attributeValue("name"); int bbs = Integer.parseInt(listElement.attributeValue("bbs", "0")); int msgId = Integer.parseInt(listElement.attributeValue("msg_id", "0")); List<Location> restartPoints = new ArrayList<>(); List<Location> PKrestartPoints = new ArrayList<>(); for (Iterator<Element> i = listElement.elementIterator(); i.hasNext();) { Element n = i.next(); if ("restart_point".equals(n.getName())) { for (Iterator<Element> ii = n.elementIterator(); ii.hasNext();) { Element d = ii.next(); if ("coords".equalsIgnoreCase(d.getName())) { Location loc = Location.parseLoc(d.attribute("loc").getValue()); restartPoints.add(loc); } } } else if ("PKrestart_point".equals(n.getName())) { for (Iterator<Element> ii = n.elementIterator(); ii.hasNext();) { Element d = ii.next(); if ("coords".equalsIgnoreCase(d.getName())) { Location loc = Location.parseLoc(d.attribute("loc").getValue()); PKrestartPoints.add(loc); } } } } if (restartPoints.isEmpty()) { throw new RuntimeException( "RestartPointParser: restart_points not defined for restart_loc : " + name + "!"); } if (PKrestartPoints.isEmpty()) { PKrestartPoints = restartPoints; } RestartPoint rp = new RestartPoint(name, bbs, msgId, restartPoints, PKrestartPoints); restartPoint.put(name, rp); } } for (Pair<Territory, Map<Race, String>> ra : restartArea) { Map<Race, RestartPoint> restarts = new HashMap<>(); for (Map.Entry<Race, String> e : ra.getValue().entrySet()) { RestartPoint rp = restartPoint.get(e.getValue()); if (rp == null) { throw new RuntimeException("RestartPointParser: restart_loc not found : " + e.getValue() + "!"); } restarts.put(e.getKey(), rp); getHolder().addRegionData(new RestartArea(ra.getKey(), restarts)); } } }
From source file:com.linkedin.pinot.broker.broker.helix.ClusterChangeMediator.java
@Override public void onExternalViewChange(List<ExternalView> externalViewList, NotificationContext changeContext) { // If the deferred update thread is alive, defer the update if (_deferredClusterUpdater != null && _deferredClusterUpdater.isAlive()) { try {/* w ww . j a v a2 s .co m*/ _clusterChangeQueue.put(new ImmutablePair<>(UpdateType.EXTERNAL_VIEW, System.currentTimeMillis())); } catch (InterruptedException e) { LOGGER.warn("Was interrupted while trying to add external view change to queue", e); } } else { LOGGER.warn( "Deferred cluster updater thread is null or stopped, not deferring external view routing table rebuild"); _helixExternalViewBasedRouting.processExternalViewChange(); } }
From source file:com.norconex.importer.handler.transformer.impl.StripBetweenTransformer.java
public void addStripEndpoints(String fromText, String toText) { if (StringUtils.isBlank(fromText) || StringUtils.isBlank(toText)) { return;/*from w w w. ja va 2 s . c om*/ } stripPairs.add(new ImmutablePair<String, String>(fromText, toText)); }
From source file:appeng.block.misc.BlockCharger.java
@SideOnly(Side.CLIENT) private static Pair<ItemStack, Matrix4f> getRenderedItem(TileCharger tile) { Matrix4f transform = new Matrix4f(); transform.translate(new Vector3f(0.5f, 0.4f, 0.5f)); return new ImmutablePair<>(tile.getStackInSlot(0), transform); }
From source file:com.streamsets.pipeline.stage.it.KeywordsInObjectNamesIT.java
@Test public void testKeywordInPartitionColumnName() throws Exception { executeUpdate(Utils.format("CREATE DATABASE IF NOT EXISTS `{}`", keyword)); HiveMetadataProcessor processor = new HiveMetadataProcessorBuilder() .partitions(new PartitionConfigBuilder().addPartition(keyword, HiveType.STRING, "value").build()) .build();// w w w.j ava 2s .c o m HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().build(); Map<String, Field> map = new LinkedHashMap<>(); map.put("col", Field.create("value")); Record record = RecordCreator.create("s", "s:1"); record.set(Field.create(map)); try { processRecords(processor, hiveTarget, ImmutableList.of(record)); } catch (StageException se) { LOG.error("Processing exception", se); Assert.fail("Processing testing record unexpectedly failed: " + se.getMessage()); throw se; } assertTableExists("default.tbl"); assertQueryResult("select * from tbl", new QueryValidator() { @Override public void validateResultSet(ResultSet rs) throws Exception { assertResultSetStructure(rs, new ImmutablePair("tbl.col", Types.VARCHAR), new ImmutablePair(Utils.format("tbl.{}", keyword), Types.VARCHAR)); Assert.assertTrue("Table tbl doesn't contain any rows", rs.next()); Assert.assertEquals("value", rs.getObject(1)); Assert.assertEquals("value", rs.getObject(2)); Assert.assertFalse("Table tbl contains more then one row", rs.next()); } }); }
From source file:com.joyent.manta.config.TestConfigContext.java
/** * Some test cases need a direct reference to a KeyPair along with it's associated config. Manually calling * KeyPairFactory with a half-baked config can get cumbersome, so let's build a ConfigContext which has * everything ready and supplies the relevant KeyPair. * * @return the generated keypair and a config which uses a serialized version of that keypair *//*from www. j a va 2s. c om*/ public static ImmutablePair<KeyPair, BaseChainedConfigContext> generateKeyPairBackedConfig( final String passphrase) { final KeyPair keyPair; try { keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair(); } catch (final NoSuchAlgorithmException impossible) { throw new Error(impossible); // "RSA" is always provided } final Object keySerializer; if (passphrase != null) { try { keySerializer = new JcaMiscPEMGenerator(keyPair.getPrivate(), new JcePEMEncryptorBuilder("AES-128-CBC").build(passphrase.toCharArray())); } catch (IOException e) { throw new RuntimeException(e); } } else { keySerializer = keyPair.getPrivate(); } final String keyContent; try (final StringWriter content = new StringWriter(); final JcaPEMWriter writer = new JcaPEMWriter(content)) { writer.writeObject(keySerializer); writer.flush(); keyContent = content.toString(); } catch (IOException e) { throw new RuntimeException(e); } final BaseChainedConfigContext config = new ChainedConfigContext(DEFAULT_CONFIG) // we need to unset the key path in case one exists at ~/.ssh/id_rsa // see the static initializer in DefaultsConfigContext .setMantaKeyPath(null).setPrivateKeyContent(keyContent) .setMantaKeyId(KeyFingerprinter.md5Fingerprint(keyPair)); if (passphrase != null) { config.setPassword(passphrase); } return new ImmutablePair<>(keyPair, config); }
From source file:com.twosigma.beaker.table.serializer.TableDisplayDeSerializer.java
public static Pair<String, Object> getDeserializeObject(BeakerObjectConverter parent, JsonNode n, ObjectMapper mapper) {//from ww w . java 2 s . co m Object o = null; String subtype = null; try { List<List<?>> values = TableDisplayDeSerializer.getValues(parent, n, mapper); List<String> columns = TableDisplayDeSerializer.getColumns(n, mapper); List<String> classes = TableDisplayDeSerializer.getClasses(n, mapper); if (n.has("subtype")) subtype = mapper.readValue(n.get("subtype").asText(), String.class); if (subtype != null && subtype.equals(TableDisplay.DICTIONARY_SUBTYPE)) { o = getValuesAsDictionary(parent, n, mapper); } else if (subtype != null && subtype.equals(TableDisplay.LIST_OF_MAPS_SUBTYPE) && columns != null && values != null) { o = getValuesAsRows(parent, n, mapper); } else if (subtype != null && subtype.equals(TableDisplay.MATRIX_SUBTYPE)) { o = getValuesAsMatrix(parent, n, mapper); } if (o == null) { if (n.has("hasIndex") && mapper.readValue(n.get("hasIndex").asText(), String.class).equals("true") && columns != null && values != null) { columns.remove(0); classes.remove(0); for (List<?> v : values) { v.remove(0); } o = new TableDisplay(values, columns, classes); } else { o = new TableDisplay(values, columns, classes); } } } catch (Exception e) { logger.error("exception deserializing TableDisplay ", e); } return new ImmutablePair<String, Object>(subtype, o); }