List of usage examples for org.apache.commons.lang3.tuple ImmutablePair ImmutablePair
public ImmutablePair(final L left, final R right)
From source file:com.acmutv.ontoqa.core.parser.ParserState.java
/** * Adds a waiting adjunction, found immediately after {@code prevLexicalEntry}. * @param candidate the SLTAG to adjunct. * @param prevIdx the previous lexical entry index. *///w w w .ja v a2 s . c o m public void addAdjunction(Sltag candidate, Integer prevIdx) { this.adjunctions.add(new ImmutablePair<>(candidate, prevIdx)); }
From source file:com.streamsets.pipeline.stage.destination.hive.EventCreationIT.java
public List<Record> runNewTableRecord() throws Exception { HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().build(); TargetRunner runner = new TargetRunner.Builder(HiveMetastoreTarget.class, hiveTarget) .setOnRecordError(OnRecordError.STOP_PIPELINE).build(); runner.runInit();/*www. j a va 2 s . com*/ LinkedHashMap<String, HiveTypeInfo> columns = new LinkedHashMap<>(); columns.put("name", HiveType.STRING.getSupport().generateHiveTypeInfoFromResultSet("STRING")); columns.put("surname", HiveType.STRING.getSupport().generateHiveTypeInfoFromResultSet("STRING")); LinkedHashMap<String, HiveTypeInfo> partitions = new LinkedHashMap<>(); partitions.put("dt", HiveType.STRING.getSupport().generateHiveTypeInfoFromResultSet("STRING")); Field newTableField = HiveMetastoreUtil.newSchemaMetadataFieldBuilder("default", "tbl", columns, partitions, true, BaseHiveIT.getDefaultWareHouseDir(), HiveMetastoreUtil.generateAvroSchema(columns, "tbl")); Record record = RecordCreator.create(); record.set(newTableField); Assert.assertTrue(HiveMetastoreUtil.isSchemaChangeRecord(record)); runner.runWrite(ImmutableList.of(record)); assertTableStructure("default.tbl", new ImmutablePair("tbl.name", Types.VARCHAR), new ImmutablePair("tbl.surname", Types.VARCHAR), new ImmutablePair("tbl.dt", Types.VARCHAR)); try { return runner.getEventRecords(); } finally { runner.runDestroy(); } }
From source file:com.streamsets.pipeline.stage.executor.jdbc.TestJdbcQueryExecutor.java
@Test public void testExecuteSimpleQuery() throws Exception { JdbcQueryExecutor queryExecutor = createExecutor("CREATE TABLE copy AS SELECT * FROM origin"); ExecutorRunner runner = new ExecutorRunner.Builder(JdbcQueryDExecutor.class, queryExecutor) .setOnRecordError(OnRecordError.STOP_PIPELINE).build(); runner.runInit();//ww w . j a va 2 s. c om Record record = RecordCreator.create(); record.set(Field.create("blank line")); runner.runWrite(ImmutableList.of(record)); runner.runDestroy(); assertTableStructure("copy", new ImmutablePair("ID", Types.INTEGER), new ImmutablePair("NAME", Types.VARCHAR)); }
From source file:com.telefonica.iot.cygnus.utils.NGSIUtils.java
/** * Gets a geometry value, ready for insertion in CartoDB, given a NGSI attribute value and its metadata. * If the attribute is not geo-related, it is returned as it is. * @param attrValue/*from w ww .java2 s. c o m*/ * @param attrType * @param metadata * @param swapCoordinates * @return The geometry value, ready for insertion in CartoDB/PostGIS, or the value as it is */ public static ImmutablePair<String, Boolean> getGeometry(String attrValue, String attrType, String metadata, boolean swapCoordinates) { // First, check the attribute type if (attrType.equals("geo:point")) { String[] split = attrValue.split(","); if (swapCoordinates) { return new ImmutablePair( "ST_SetSRID(ST_MakePoint(" + split[1].trim() + "," + split[0].trim() + "), 4326)", true); } else { return new ImmutablePair( "ST_SetSRID(ST_MakePoint(" + split[0].trim() + "," + split[1].trim() + "), 4326)", true); } // if else } // if if (attrType.equals("geo:json")) { return new ImmutablePair("ST_GeomFromGeoJSON(" + attrValue + ")", true); } // if // TBD: What about: ? // 'geo:line' // 'geo:box' // 'geo:polygon' // 'geo:multipoint' // 'geo:multiline' // 'geo:multipolygon' // The type was not 'geo:point' nor 'geo:json', thus try the metadata JSONParser parser = new JSONParser(); JSONArray mds; try { mds = (JSONArray) parser.parse(metadata); } catch (ParseException e) { LOGGER.error("Error while parsing the metadata. Details: " + e.getMessage()); return new ImmutablePair(attrValue, false); } // try catch for (Object mdObject : mds) { JSONObject md = (JSONObject) mdObject; String mdName = (String) md.get("name"); String mdType = (String) md.get("type"); String mdValue = (String) md.get("value"); if (mdName.equals("location") && mdType.equals("string") && mdValue.equals("WGS84")) { String[] split = attrValue.split(","); if (swapCoordinates) { return new ImmutablePair( "ST_SetSRID(ST_MakePoint(" + split[1].trim() + "," + split[0].trim() + "), 4326)", true); } else { return new ImmutablePair( "ST_SetSRID(ST_MakePoint(" + split[0].trim() + "," + split[1].trim() + "), 4326)", true); } // if else } // if } // for // The attribute was not related to a geolocation return new ImmutablePair(attrValue, false); }
From source file:fr.cvlaminck.merging.impl.DefaultValueMergers.java
@Override public void registerValueMerger(ValueMerger valueMerger) { //If the fieldMerger is already registered, we ignore if (mergers.containsValue(valueMerger)) return;//from w w w . j av a2 s.c o m //Otherwise, we register it registeredMergerTypes.add(valueMerger.getType()); Pair<Class<?>, String> key = new ImmutablePair<Class<?>, String>(valueMerger.getType(), valueMerger.getMergingStrategy()); mergers.put(key, valueMerger); }
From source file:com.romeikat.datamessie.core.base.util.CollectionUtil.java
public <T, U> Collection<Pair<T, U>> getPairs(final Collection<T> elements1, final Collection<U> elements2) { final List<Pair<T, U>> pairs = new LinkedList<Pair<T, U>>(); for (final T element1 : elements1) { for (final U element2 : elements2) { pairs.add(new ImmutablePair<T, U>(element1, element2)); }/* w w w .j a v a 2 s . c o m*/ } return pairs; }
From source file:com.microsoft.tooling.msservices.helpers.ServiceCodeReferenceHelper.java
public void fillNotificationHubResource(String activityName, String senderId, String connStr, String hubName, Object module) {/*from w ww. jav a 2 s. c o m*/ DefaultLoader.getIdeHelper().replaceInFile(module, new ImmutablePair<String, String>(">$SENDERID_" + activityName + "<", ">" + senderId + "<"), new ImmutablePair<String, String>(">$CONNSTR_" + activityName + "<", ">" + connStr + "<"), new ImmutablePair<String, String>(">$HUBNAME_" + activityName + "<", ">" + hubName + "<")); }
From source file:com.linkedin.pinot.broker.routing.builder.GeneratorBasedRoutingTableBuilder.java
/** * Generates a routing table, decorated with a metric. * * @param routingTableGenerator The routing table generator to use to generate routing tables. * @return A pair of a routing table and its associated metric. *//*from w w w . j a va2 s . c o m*/ private Pair<Map<String, List<String>>, Float> generateRoutingTableWithMetric( RoutingTableGenerator routingTableGenerator) { Map<String, List<String>> routingTable = routingTableGenerator.generateRoutingTable(); int segmentCount = 0; int serverCount = 0; // Compute the number of segments and servers (for the average part of the variance) for (List<String> segmentsForServer : routingTable.values()) { int segmentCountForServer = segmentsForServer.size(); segmentCount += segmentCountForServer; serverCount++; } // Compute the variance of the number of segments allocated per server float averageSegmentCount = ((float) segmentCount) / serverCount; float variance = 0.0f; for (List<String> segmentsForServer : routingTable.values()) { int segmentCountForServer = segmentsForServer.size(); float difference = segmentCountForServer - averageSegmentCount; variance += difference * difference; } return new ImmutablePair<>(routingTable, variance); }
From source file:com.github.aptd.simulation.elements.common.CMath.java
/** * returns the angel/* ww w .jav a 2 s . c o m*/ * * @param p_first first vector * @param p_second second vector * @return pair of angel in radians and boolean for calulation correctness */ public static Pair<Double, Boolean> angle(final DoubleMatrix1D p_first, final DoubleMatrix1D p_second) { final double l_first = ALGEBRA.norm2(p_first); final double l_second = ALGEBRA.norm2(p_second); return (l_first == 0) || (l_second == 0) ? new ImmutablePair<>(0.0, false) : new ImmutablePair<>( Math.acos(ALGEBRA.mult(p_first, p_second) / (Math.sqrt(l_first) * Math.sqrt(l_second))), true); }
From source file:com.streamsets.pipeline.stage.destination.hive.queryexecutor.HiveQueryExecutorIT.java
@Test public void testEL() throws Exception { HiveQueryExecutor queryExecutor = createExecutor( "CREATE TABLE ${record:value('/table')} AS SELECT * FROM origin"); TargetRunner runner = new TargetRunner.Builder(HiveQueryDExecutor.class, queryExecutor) .setOnRecordError(OnRecordError.STOP_PIPELINE).build(); runner.runInit();/*w w w. j av a2 s. c om*/ Map<String, Field> map = new HashMap<>(); map.put("table", Field.create("el")); Record record = RecordCreator.create(); record.set(Field.create(map)); runner.runWrite(ImmutableList.of(record)); runner.runDestroy(); assertTableStructure("default.el", new ImmutablePair("el.id", Types.INTEGER), new ImmutablePair("el.name", Types.VARCHAR)); }