List of usage examples for org.apache.commons.lang3.tuple Pair getLeft
public abstract L getLeft();
Gets the left element from this pair.
When treated as a key-value pair, this is the key.
From source file:edu.umd.umiacs.clip.tools.classifier.LibSVMUtils.java
public static Pair<List<String>, List<String>> scale(Pair<List<String>, List<String>> pair) { Map<Integer, Pair<Float, Float>> model = learnScalingModel(pair.getLeft()); return Pair.of(applyScalingModel(model, pair.getLeft()), applyScalingModel(model, pair.getRight())); }
From source file:forge.properties.ForgeProfileProperties.java
public static void load() { final Properties props = new Properties(); final File propFile = new File(ForgeConstants.PROFILE_FILE); try {/*from www. j a v a 2s .c o m*/ if (propFile.canRead()) { props.load(new FileInputStream(propFile)); } } catch (final IOException e) { System.err.println("error while reading from profile properties file"); } final Pair<String, String> defaults = getDefaultDirs(); userDir = getDir(props, USER_DIR_KEY, defaults.getLeft()); cacheDir = getDir(props, CACHE_DIR_KEY, defaults.getRight()); cardPicsDir = getDir(props, CARD_PICS_DIR_KEY, cacheDir + "pics" + File.separator + "cards" + File.separator); cardPicsSubDirs = getMap(props, CARD_PICS_SUB_DIRS_KEY); serverPort = getInt(props, SERVER_PORT_KEY, 36743); // "Forge" using phone keypad //ensure directories exist FileUtil.ensureDirectoryExists(userDir); FileUtil.ensureDirectoryExists(cacheDir); FileUtil.ensureDirectoryExists(cardPicsDir); }
From source file:forge.properties.ForgeProfileProperties.java
private static void save() { final Pair<String, String> defaults = getDefaultDirs(); final String defaultUserDir = defaults.getLeft() + File.separator; final String defaultCacheDir = defaults.getRight() + File.separator; final String defaultCardPicsDir = defaultCacheDir + "pics" + File.separator + "cards" + File.separator; //only append values that aren't equal to defaults final StringBuilder sb = new StringBuilder(); if (!userDir.equals(defaultUserDir)) { //ensure backslashes are escaped sb.append(USER_DIR_KEY + "=" + userDir.replace("\\", "\\\\") + "\n"); }/*from ww w. j a v a2 s.c o m*/ if (!cacheDir.equals(defaultCacheDir)) { sb.append(CACHE_DIR_KEY + "=" + cacheDir.replace("\\", "\\\\") + "\n"); } if (!cardPicsDir.equals(defaultCardPicsDir)) { sb.append(CARD_PICS_DIR_KEY + "=" + cardPicsDir.replace("\\", "\\\\") + "\n"); } if (cardPicsSubDirs.size() > 0) { sb.append(CARD_PICS_SUB_DIRS_KEY + "="); final boolean needDelim = false; for (final Map.Entry<String, String> entry : cardPicsSubDirs.entrySet()) { if (needDelim) { sb.append("|"); } sb.append(entry.getKey() + "->" + entry.getValue()); } sb.append("\n"); } if (serverPort != 0) { sb.append(SERVER_PORT_KEY + "=" + serverPort); } if (sb.length() > 0) { FileUtil.writeFile(ForgeConstants.PROFILE_FILE, sb.toString()); } else { //delete file if empty try { final File file = new File(ForgeConstants.PROFILE_FILE); if (file.exists()) { file.delete(); } } catch (final Exception e) { e.printStackTrace(); } } }
From source file:com.silverpeas.gallery.dao.OrderDAO.java
/** * Finds orders from the specified criteria. * @param con/*from w ww. jav a2s. c om*/ * @param criteria * @return a list of orders, empty if no order found. */ public static List<Order> findByCriteria(final Connection con, MediaOrderCriteria criteria) throws SQLException { MediaOrderSQLQueryBuilder queryBuilder = new MediaOrderSQLQueryBuilder(); criteria.processWith(queryBuilder); Pair<String, List<Object>> queryBuild = queryBuilder.result(); return queryBuilder.orderingResult( select(con, queryBuild.getLeft(), queryBuild.getRight(), new SelectResultRowProcessor<Order>() { @Override protected Order currentRow(final int rowIndex, final ResultSet rs) throws SQLException { Order order = new Order(rs.getString(1)); order.setUserId(rs.getString(2)); order.setInstanceId(rs.getString(3)); order.setCreationDate(rs.getTimestamp(4)); order.setProcessDate(rs.getTimestamp(5)); order.setProcessUserId(rs.getString(6)); order.setRows(getAllOrderDetails(con, order.getOrderId())); return order; } })); }
From source file:com.streamsets.pipeline.stage.origin.jdbc.table.ReferentialConstraintOrderingIT.java
@BeforeClass public static void setupTables() throws SQLException { populateRecords();// w w w . j a v a 2 s . co m try (Statement statement = connection.createStatement()) { //USER_TABLE TABLE statement.addBatch( "CREATE TABLE TEST.USER_TABLE (u_id INT PRIMARY KEY, name varchar(100), address varchar(1000))"); //PRODUCT TABLE statement.addBatch("CREATE TABLE TEST.PRODUCT" + " (p_id INT PRIMARY KEY, name varchar(100), manufacturer varchar(1000))"); statement.addBatch("CREATE TABLE TEST.ORDER_TBL" + " (o_id INT PRIMARY KEY, u_id INT, FOREIGN KEY (u_id) REFERENCES TEST.USER_TABLE(u_id))"); //ITEMS TABLE //We do not support composite keys so for now the primary key here is a timestamp. statement.addBatch("CREATE TABLE TEST.ITEMS (" + "time_id BIGINT PRIMARY KEY, o_id INT," + " p_id INT, quantity int," + " FOREIGN KEY (o_id) REFERENCES TEST.ORDER_TBL(o_id), FOREIGN KEY (p_id) REFERENCES TEST.PRODUCT(p_id))"); statement.executeBatch(); } for (Pair<String, ArrayList<Record>> value : TABLE_TO_TEMPLATE_AND_RECORDS_MAP.values()) { insertRows(value.getLeft(), value.getRight()); } }
From source file:forge.download.GuiDownloadService.java
protected static void addMissingItems(Map<String, String> list, String nameUrlFile, String dir) { for (Pair<String, String> nameUrlPair : FileUtil.readNameUrlFile(nameUrlFile)) { File f = new File(dir, nameUrlPair.getLeft()); //System.out.println(f.getAbsolutePath()); if (!f.exists()) { list.put(f.getAbsolutePath(), nameUrlPair.getRight()); }/*ww w .j av a2 s . c o m*/ } }
From source file:com.addthis.hydra.kafka.consumer.ConsumerUtils.java
public static Pair<ConsumerConnector, KafkaStream<Bundle, Bundle>> newBundleConsumer(String zookeeper, String topic, HashMap<String, String> overrides) { Map<String, Integer> topicStreams = new HashMap<>(); topicStreams.put(topic, 1);/*from w w w . ja v a 2 s.co m*/ Pair<ConsumerConnector, Map<String, List<KafkaStream<Bundle, Bundle>>>> connectorAndStreams = newBundleStreams( zookeeper, topicStreams, overrides); return new ImmutablePair<>(connectorAndStreams.getLeft(), connectorAndStreams.getRight().get(topic).get(0)); }
From source file:com.deepoove.poi.resolver.TemplateResolver.java
private static void calcRunPosInParagraph(List<XWPFRun> runs, List<Pair<RunEdge, RunEdge>> pairs) { int size = runs.size(), pos = 0, calc = 0; Pair<RunEdge, RunEdge> pair = pairs.get(pos); RunEdge leftEdge = pair.getLeft(); RunEdge rightEdge = pair.getRight(); int leftInAll = leftEdge.getAllPos(); int rightInAll = rightEdge.getAllPos(); for (int i = 0; i < size; i++) { XWPFRun run = runs.get(i);//ww w . j a v a 2 s .com String str = run.getText(0); if (null == str) { logger.warn("found the empty text run,may be produce bug:" + run); calc += run.toString().length(); continue; } logger.debug(str); if (str.length() + calc < leftInAll) { calc += str.length(); continue; } for (int j = 0; j < str.length(); j++) { if (calc + j == leftInAll) { leftEdge.setRunPos(i); leftEdge.setRunEdge(j); leftEdge.setText(str); } if (calc + j == rightInAll - 1) { rightEdge.setRunPos(i); rightEdge.setRunEdge(j); rightEdge.setText(str); if (pos == pairs.size() - 1) break; pair = pairs.get(++pos); leftEdge = pair.getLeft(); rightEdge = pair.getRight(); leftInAll = leftEdge.getAllPos(); rightInAll = rightEdge.getAllPos(); } } calc += str.length(); } }
From source file:com.act.lcms.db.model.ChemicalAssociatedWithPathway.java
public static List<Pair<Integer, DB.OPERATION_PERFORMED>> insertOrUpdateChemicalsAssociatedWithPathwayFromParser( DB db, ConstructAnalysisFileParser parser) throws SQLException, IOException, ClassNotFoundException { List<Pair<Integer, DB.OPERATION_PERFORMED>> operationsPerformed = new ArrayList<>(); List<Pair<String, List<ConstructAnalysisFileParser.ConstructAssociatedChemical>>> stepPairs = parser .getConstructProducts();//from www . j av a 2s . c o m for (Pair<String, List<ConstructAnalysisFileParser.ConstructAssociatedChemical>> stepPair : stepPairs) { String constructId = stepPair.getLeft(); for (ConstructAnalysisFileParser.ConstructAssociatedChemical step : stepPair.getRight()) { System.out.format("Processing entry %s %s %s %d\n", constructId, step.getChemical(), step.getKind(), step.getIndex()); ChemicalAssociatedWithPathway cp = INSTANCE .getChemicalAssociatedWithPathwayByConstructIdAndIndex(db, constructId, step.getIndex()); DB.OPERATION_PERFORMED op = null; if (cp == null) { cp = INSTANCE.insert(db, new ChemicalAssociatedWithPathway(null, constructId, step.getChemical(), step.getKind(), step.getIndex())); op = DB.OPERATION_PERFORMED.CREATE; } else { cp.setConstructId(constructId); cp.setChemical(step.getChemical()); cp.setKind(step.getKind()); cp.setIndex(step.getIndex()); INSTANCE.update(db, cp); op = DB.OPERATION_PERFORMED.UPDATE; } // Chem should only be null if we couldn't insert the row into the DB. if (cp == null) { operationsPerformed.add(Pair.of((Integer) null, DB.OPERATION_PERFORMED.ERROR)); } else { operationsPerformed.add(Pair.of(cp.getId(), op)); } } } return operationsPerformed; }
From source file:com.deepoove.poi.resolver.TemplateResolver.java
/** * running string Algorithm/*from w w w. j a v a 2 s .co m*/ * * @param paragraph * @return */ public static List<RunTemplate> parseRun(XWPFParagraph paragraph) { List<XWPFRun> runs = paragraph.getRuns(); if (null == runs || runs.isEmpty()) return null; String text = paragraph.getText(); logger.debug("Paragrah's text is:" + text); List<Pair<RunEdge, RunEdge>> pairs = new ArrayList<Pair<RunEdge, RunEdge>>(); List<String> tags = new ArrayList<String>(); calcTagPosInParagraph(text, pairs, tags); List<RunTemplate> rts = new ArrayList<RunTemplate>(); if (pairs.isEmpty()) return rts; RunTemplate runTemplate; calcRunPosInParagraph(runs, pairs); for (Pair<RunEdge, RunEdge> pai : pairs) { logger.debug(pai.getLeft().toString()); logger.debug(pai.getRight().toString()); } // split and merge Pair<RunEdge, RunEdge> pair2 = pairs.get(0); int length = pairs.size(); int tagIndex = length; for (int n = length - 1; n >= 0; n--) { pair2 = pairs.get(n); RunEdge left2 = pair2.getLeft(); RunEdge right2 = pair2.getRight(); int left_r = left2.getRunPos(); int right_r = right2.getRunPos(); int runEdge = left2.getRunEdge(); int runEdge2 = right2.getRunEdge(); String text1 = runs.get(left_r).getText(0); String text2 = runs.get(right_r).getText(0); if (runEdge2 + 1 >= text2.length()) { if (left_r != right_r) paragraph.removeRun(right_r); } else { String substring = text2.substring(runEdge2 + 1, text2.length()); if (left_r == right_r) { XWPFRun insertNewRun = paragraph.insertNewRun(right_r + 1); styleRun(insertNewRun, runs.get(right_r)); insertNewRun.setText(substring, 0); } else runs.get(right_r).setText(substring, 0); } for (int m = right_r - 1; m > left_r; m--) { paragraph.removeRun(m); } if (runEdge <= 0) { runs.get(left_r).setText(tags.get(--tagIndex), 0); runTemplate = parseRun(runs.get(left_r)); } else { String substring = text1.substring(0, runEdge); XWPFRun xwpfRun = runs.get(left_r); runs.get(left_r).setText(substring, 0); XWPFRun insertNewRun = paragraph.insertNewRun(left_r + 1); styleRun(insertNewRun, xwpfRun); insertNewRun.setText(tags.get(--tagIndex), 0); runTemplate = parseRun(runs.get(left_r + 1)); } if (null != runTemplate) { rts.add(runTemplate); } } return rts; }