public boolean equals(Pair one, Pair two) { if ((one.getFirst() == two.getFirst()) && (one.getSecond() == two.getSecond())) { return true; } else { return false; } }
public void swap(int i1, int i2, int j1, int j2) { int ilength = i2 - i1 + 1; int jlength = j2 - j1 + 1; int diff = jlength - ilength; Set<Pair<Integer, Integer>> newAlignments = new HashSet<Pair<Integer, Integer>>(); for (Pair<Integer, Integer> alignment : sureAlignments) { int pos = alignment.getFirst(); if (pos < i1 || pos > j2) { newAlignments.add(alignment); } else if (pos >= i1 && pos <= i2) { newAlignments.add(new Pair<Integer, Integer>(pos + j2 - i2, alignment.getSecond())); } else if (pos > i2 && pos < j1) { newAlignments.add(new Pair<Integer, Integer>(pos + diff, alignment.getSecond())); } else if (pos >= j1 && pos <= j2) { newAlignments.add(new Pair<Integer, Integer>(pos - j1 + i1, alignment.getSecond())); } else { System.err.println("Error in Alignment.swap()"); System.exit(1); } } sureAlignments = newAlignments; }
public static void main(String[] args) { Pair<String> mm = new Pair<String>("1st", "2nd"); System.out.println(mm.getFirst() + "," + mm.getSecond()); Pair<Integer> i = new Pair<Integer>(3, 3); System.out.println(i.getFirst() + "," + i.getSecond()); System.out.println(i.toString()); System.out.println(mm.toString()); }
public static int comparePoolName(String s1, String s2) { Pair<String, Integer> p1 = CobarStringUtil.splitIndex(s1, '[', ']'); Pair<String, Integer> p2 = CobarStringUtil.splitIndex(s2, '[', ']'); if (p1.getFirst().compareTo(p2.getFirst()) == 0) { return p1.getSecond() - p2.getSecond(); } else { return p1.getFirst().compareTo(p2.getFirst()); } }
private boolean tryToReloadApplication() { try { final Application app = ApplicationManager.getApplication(); if (app.isDisposed()) return false; final HashSet<Pair<VirtualFile, StateStorage>> causes = new HashSet<Pair<VirtualFile, StateStorage>>(myChangedApplicationFiles); if (causes.isEmpty()) return true; final boolean[] reloadOk = {false}; final LinkedHashSet<String> components = new LinkedHashSet<String>(); ApplicationManager.getApplication() .runWriteAction( new Runnable() { @Override public void run() { try { reloadOk[0] = ((ApplicationImpl) app).getStateStore().reload(causes, components); } catch (StateStorageException e) { Messages.showWarningDialog( ProjectBundle.message("project.reload.failed", e.getMessage()), ProjectBundle.message("project.reload.failed.title")); } catch (IOException e) { Messages.showWarningDialog( ProjectBundle.message("project.reload.failed", e.getMessage()), ProjectBundle.message("project.reload.failed.title")); } } }); if (!reloadOk[0] && !components.isEmpty()) { String message = "Application components were changed externally and cannot be reloaded:\n"; for (String component : components) { message += component + "\n"; } final boolean canRestart = ApplicationManager.getApplication().isRestartCapable(); message += "Would you like to " + (canRestart ? "restart " : "shutdown "); message += ApplicationNamesInfo.getInstance().getProductName() + "?"; if (Messages.showYesNoDialog( message, "Application Configuration Reload", Messages.getQuestionIcon()) == Messages.YES) { for (Pair<VirtualFile, StateStorage> cause : causes) { StateStorage stateStorage = cause.getSecond(); if (stateStorage instanceof XmlElementStorage) { ((XmlElementStorage) stateStorage).disableSaving(); } } ApplicationManagerEx.getApplicationEx().restart(true); } } return reloadOk[0]; } finally { myChangedApplicationFiles.clear(); } }
// Gestiona la reacción de la colisión de los dos shoots pasados por parámetro public static void manageCollisionWithShoot(Pair<Shoot, Shoot> shootToShoot) { Shoot shoot1 = shootToShoot.getFirst(); Shoot shoot2 = shootToShoot.getSecond(); shoot1.collideWithShoot(shoot2); shoot2.collideWithShoot(shoot1); }
/** * Get Result String * * @return result string */ public String printComparableResults(boolean newline) { if (!(resultVector != null)) log.error("Attempted to access null vector."); String outString = ""; int i = 0; for (TypeQ question : sortedQuestions) { Double tempResult = resultVector.get(i); // if(tempResult.intValue() == 0) // continue; if (groundTruthVector != null) { Double evalInd = groundTruthVector.getSecond().get(i); if (evalInd.intValue() == 0) { ++i; continue; } } ++i; if (!newline) outString += "\n"; outString += question + " " + tempResult.intValue(); newline = false; } if (log.isDebugEnabled()) { log.debug(outString); } return outString; }
public void run() { _isDone = false; _results = new FindResults(_searchText.length()); switch (_requestCode) { case ProgressSource.FIND: _results.foundOffset = FINDER.wrappedFind(_src, _searchText, _start, _isCaseSensitive, _isWholeWord); notifyComplete(_results); break; case ProgressSource.FIND_BACKWARDS: _results.foundOffset = FINDER.wrappedFindBackwards(_src, _searchText, _start, _isCaseSensitive, _isWholeWord); notifyComplete(_results); break; case ProgressSource.REPLACE_ALL: Pair replaceResult = FINDER.replaceAll( _src, _searchText, _replacementText, _start, _isCaseSensitive, _isWholeWord); _results.replacementCount = replaceResult.getFirst(); _results.newStartPosition = replaceResult.getSecond(); notifyComplete(_results); break; default: TextWarriorException.assertVerbose(false, "Invalid request code for FindThread"); break; } }
@Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof Pair<?, ?>)) { return false; } Pair<?, ?> otherPair = (Pair<?, ?>) obj; return otherPair.getFirst().equals(e1) && otherPair.getSecond().equals(e2); }
public Set<Integer> getAlignedSources(int targetPosition) { Set<Integer> sources = new HashSet<Integer>(); for (Pair<Integer, Integer> alignment : sureAlignments) { if (alignment.getFirst() == targetPosition) { sources.add(alignment.getSecond()); } } return sources; }
public int getAlignedTarget(int sourcePosition) { for (Pair<Integer, Integer> alignment : sureAlignments) { if (alignment.getSecond() == sourcePosition) { return alignment.getFirst(); } } System.err.println("nothing aligned with " + sourcePosition); return -999; }
/** * Returns both the total and the GC elapsed times since the counter was created. * * @param id Id generated by getNewTimeId. * @return Total and GC elapsed times, in milliseconds. The GC time is always smaller or equal * than the total time. */ public static Pair<Long, Long> elapsedAndGcTime(long id) { // first take times long milliTime = milliTime(); long milliGcTime = milliGcTime(); // now do the calculations Pair<Long, Long> startTimes = times.get(id); long startTime = startTimes.getFirst(); long startGcTime = startTimes.getSecond(); return new Pair<Long, Long>(milliTime - startTime, milliGcTime - startGcTime); }
public static void main(String[] args) { GregorianCalendar[] birthdays = { new GregorianCalendar(1906, Calendar.DECEMBER, 9), // G.Hopper new GregorianCalendar(1815, Calendar.DECEMBER, 10), // A.Lovelace new GregorianCalendar(1903, Calendar.DECEMBER, 3), // J.von Neumann new GregorianCalendar(1910, Calendar.JUNE, 22), // K.Zuse }; Pair<GregorianCalendar> mm = ArrayAlg.minmax(birthdays); System.out.println("min = " + mm.getFirst().getTime()); System.out.println("max = " + mm.getSecond().getTime()); }
private void shiftAlignments(int targetPosition, boolean up, int changeto) { Set<Pair<Integer, Integer>> newAlignments = new HashSet<Pair<Integer, Integer>>(); for (Pair<Integer, Integer> alignment : sureAlignments) { int pos = alignment.getFirst(); // System.out.println("shift: "+pos); if (pos < targetPosition) { newAlignments.add(alignment); } else if (pos == targetPosition) { newAlignments.add( new Pair<Integer, Integer>((up ? pos + 1 : changeto), alignment.getSecond())); } else if (pos > targetPosition) { newAlignments.add( new Pair<Integer, Integer>((up ? pos + 1 : pos - 1), alignment.getSecond())); } } sureAlignments = newAlignments; }
private void highlightTodo(boolean left, List<Pair<TextRange, TextAttributes>> todoRanges) { FragmentedDiffPanelState panelState = (FragmentedDiffPanelState) ((DiffPanelImpl) myHorizontal).getDiffPanelState(); FragmentedDiffPanelState panelState2 = (FragmentedDiffPanelState) ((DiffPanelImpl) myVertical).getDiffPanelState(); for (Pair<TextRange, TextAttributes> range : todoRanges) { TextAttributes second = range.getSecond().clone(); panelState.addRangeHighlighter( left, range.getFirst().getStartOffset(), range.getFirst().getEndOffset(), second); panelState2.addRangeHighlighter( left, range.getFirst().getStartOffset(), range.getFirst().getEndOffset(), second); } }
/** * Returns the index for the specified edge. Calculates the indices for <code>e</code> and for all * edges parallel to <code>e</code>. */ public int getIndex(Graph<V, E> graph, E e) { Integer index = edge_index.get(e); if (index == null) { Pair<V> endpoints = graph.getEndpoints(e); V u = endpoints.getFirst(); V v = endpoints.getSecond(); if (u.equals(v)) { index = getIndex(graph, e, v); } else { index = getIndex(graph, e, u, v); } } return index.intValue(); }
/** * Adds a list of Pairs (x and y points) to this term. Updates the min and max values of this term * if needed. * * @param pairs list of points to add to this set */ private void addValue(Pair... pairs) { for (Pair pair : pairs) { values.add(pair); // Update the minimum value that this term covers if (pair.getFirst() < minValue) minValue = pair.getFirst(); // Update the maximum value that this term covers. if (pair.getFirst() > maxValue) maxValue = pair.getFirst(); // If this point is 1 then its point value is this if (pair.getSecond() == 1) pointValue = pair.getFirst(); } // Sort the points in increasing order with respect to the X value, // for them membership algorithm to work. sortValues(); }
public double getWeightedStandardDeviation() { if (values.size() == 0) { return Double.NaN; } else { double mean = sum / (double) values.size(); double variance = 0; for (Pair<T, Double> entry : values) { variance += entry.getSecond() * Math.pow(entry.getFirst().doubleValue() - mean, 2); } variance /= weightedSum; double std = Math.sqrt(variance); return std; } }
private void doReplaceString(int startOffset, int endOffset, CharSequence s) { assert intersectWithEditable(new TextRange(startOffset, startOffset)) != null; assert intersectWithEditable(new TextRange(endOffset, endOffset)) != null; List<Pair<TextRange, CharSequence>> hostRangesToModify; synchronized (myLock) { hostRangesToModify = new ArrayList<Pair<TextRange, CharSequence>>(myShreds.size()); int offset = startOffset; int curRangeStart = 0; for (int i = 0; i < myShreds.size(); i++) { PsiLanguageInjectionHost.Shred shred = myShreds.get(i); curRangeStart += shred.getPrefix().length(); if (offset < curRangeStart) offset = curRangeStart; Segment hostRange = shred.getHostRangeMarker(); if (hostRange == null) continue; int hostRangeLength = hostRange.getEndOffset() - hostRange.getStartOffset(); TextRange range = TextRange.from(curRangeStart, hostRangeLength); if (range.contains(offset) || range.getEndOffset() == offset /* in case of inserting at the end*/) { TextRange rangeToModify = new TextRange(offset, Math.min(range.getEndOffset(), endOffset)); TextRange hostRangeToModify = rangeToModify.shiftRight(hostRange.getStartOffset() - curRangeStart); CharSequence toReplace = i == myShreds.size() - 1 || range.getEndOffset() + shred.getSuffix().length() >= endOffset ? s : s.subSequence(0, Math.min(hostRangeToModify.getLength(), s.length())); s = toReplace == s ? "" : s.subSequence(toReplace.length(), s.length()); hostRangesToModify.add(Pair.create(hostRangeToModify, toReplace)); offset = rangeToModify.getEndOffset(); } curRangeStart += hostRangeLength; curRangeStart += shred.getSuffix().length(); if (curRangeStart > endOffset) break; } } int delta = 0; for (Pair<TextRange, CharSequence> pair : hostRangesToModify) { TextRange hostRange = pair.getFirst(); CharSequence replace = pair.getSecond(); myDelegate.replaceString( hostRange.getStartOffset() + delta, hostRange.getEndOffset() + delta, replace); delta -= hostRange.getLength() - replace.length(); } }
private boolean handleBackspace(String filter) { boolean clicked = false; final Iterator<Pair<String, JCheckBox>> iterator = myTriggeredCheckboxes.iterator(); while (iterator.hasNext()) { final Pair<String, JCheckBox> next = iterator.next(); if (next.getFirst().length() < filter.length()) break; if (next.getFirst().length() >= filter.length()) { iterator.remove(); next.getSecond().doClick(); clicked = true; } } return clicked; }
public static Properties getProperties(PropertyFilter filter) { if (null == filter) { return System.getProperties(); } Properties ret = new Properties(); Properties props = System.getProperties(); for (String pName : props.stringPropertyNames()) { String pValue = props.getProperty(pName); Pair<String, String> p = Pair.of(pName, pValue); if (filter.accept(p)) { ret.put(p.getFirst(), p.getSecond()); } } return ret; }
public static void main(String[] args) throws RuntimeException { Pair<String, Integer> result = LongestString.findLongestString(args); // as you see we have not used cast here, because compiler knows that // getFirst method returns String. because first type in a parameterized type is String. String longestArg = result.getFirst(); // **as comapred to prevoius version we did not use unboxing, // **because Java has impicit auto-boxing and auto-unboxing. // **rather than "getSecongd().intValue()" we use "getSecongd()" // **it automatically unbox Integer object to an int. int longestIndex = result.getSecond(); System.out.println("A longest argument was '" + longestArg + "'"); System.out.println("Of length " + longestArg.length()); System.out.println("found at position " + (longestIndex + 1)); } // main
/** * Resolves the default text color for notifications. * * <p>Based on * http://stackoverflow.com/questions/4867338/custom-notification-layouts-and-text-colors/7320604#7320604 */ private static Pair<Integer, Integer> getNotificationTextColors(Context context) { if (NOTIFICATION_TEXT_COLORS.getFirst() == null && NOTIFICATION_TEXT_COLORS.getSecond() == null) { try { Notification notification = new Notification(); String title = "title"; String content = "content"; notification.setLatestEventInfo(context, title, content, null); LinearLayout group = new LinearLayout(context); ViewGroup event = (ViewGroup) notification.contentView.apply(context, group); findNotificationTextColors(event, title, content); group.removeAllViews(); } catch (Exception x) { Log.w(TAG, "Failed to resolve notification text colors.", x); } } return NOTIFICATION_TEXT_COLORS; }
public void printToHistory(@NotNull final List<Pair<String, TextAttributes>> attributedText) { ApplicationManager.getApplication().assertIsDispatchThread(); if (LOG.isDebugEnabled()) { LOG.debug("printToHistory(): " + attributedText.size()); } final boolean scrollToEnd = shouldScrollHistoryToEnd(); final int[] offsets = new int[attributedText.size() + 1]; int i = 0; offsets[i] = 0; final StringBuilder sb = new StringBuilder(); for (final Pair<String, TextAttributes> pair : attributedText) { sb.append(StringUtil.convertLineSeparators(pair.getFirst())); offsets[++i] = sb.length(); } final DocumentEx history = myHistoryViewer.getDocument(); final int oldHistoryLength = history.getTextLength(); appendToHistoryDocument(history, sb.toString()); assert oldHistoryLength + offsets[i] == history.getTextLength() : "unexpected history length " + oldHistoryLength + " " + offsets[i] + " " + history.getTextLength(); LOG.debug("printToHistory(): text processed"); final MarkupModel markupModel = DocumentMarkupModel.forDocument(history, myProject, true); i = 0; for (final Pair<String, TextAttributes> pair : attributedText) { markupModel.addRangeHighlighter( oldHistoryLength + offsets[i], oldHistoryLength + offsets[i + 1], HighlighterLayer.SYNTAX, pair.getSecond(), HighlighterTargetArea.EXACT_RANGE); ++i; } LOG.debug("printToHistory(): markup added"); if (scrollToEnd) { scrollHistoryToEnd(); } queueUiUpdate(scrollToEnd); LOG.debug("printToHistory(): completed"); }
@Override public boolean process(Pair<HighlightInfo, ProgressIndicator> pair) { ApplicationManager.getApplication().assertIsDispatchThread(); ProgressIndicator indicator = pair.getSecond(); if (indicator.isCanceled()) { return false; } HighlightInfo info = pair.getFirst(); final EditorColorsScheme colorsScheme = getColorsScheme(); UpdateHighlightersUtil.addHighlighterToEditorIncrementally( myProject, myDocument, myFile, myStartOffset, myEndOffset, info, colorsScheme, Pass.UPDATE_ALL, ranges2markersCache); return true; }
/** * Find the optimal next play to perform from the given game state, using the alpha-beta * algorithm. * * @param <Play> class capable of representing a game play * @param state current game state * @return the optimal next play */ public static <Play> Play alphaBetaSearch(final GameState<Play> state) { final Pair<Float, Play> m = maxValue(state, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY); return m.getSecond(); }
/** * Find the optimal next play to perform from the given game state, using the minimax algorithm. * * @param <Play> class capable of representing a game play * @param state current game state * @return the optimal next play */ public static <Play> Play minimaxSearch(final GameState<Play> state) { final Pair<Float, Play> m = maxValue(state); return m.getSecond(); }
VoltXMLElement voltGetXMLSpecification(QuerySpecification select, Session session) throws HSQLParseException { // select VoltXMLElement query = new VoltXMLElement("select"); if (select.isDistinctSelect) query.attributes.put("distinct", "true"); // limit if ((select.sortAndSlice != null) && (select.sortAndSlice.limitCondition != null)) { Expression limitCondition = select.sortAndSlice.limitCondition; if (limitCondition.nodes.length != 2) { throw new HSQLParseException( "Parser did not create limit and offset expression for LIMIT."); } try { // read offset. it may be a parameter token. if (limitCondition.nodes[0].isParam() == false) { Integer offset = (Integer) limitCondition.nodes[0].getValue(session); if (offset > 0) { query.attributes.put("offset", offset.toString()); } } else { query.attributes.put("offset_paramid", limitCondition.nodes[0].getUniqueId(session)); } // read limit. it may be a parameter token. if (limitCondition.nodes[1].isParam() == false) { Integer limit = (Integer) limitCondition.nodes[1].getValue(session); query.attributes.put("limit", limit.toString()); } else { query.attributes.put("limit_paramid", limitCondition.nodes[1].getUniqueId(session)); } } catch (HsqlException ex) { // XXX really? ex.printStackTrace(); } } // columns that need to be output by the scans VoltXMLElement scanCols = new VoltXMLElement("scan_columns"); query.children.add(scanCols); assert (scanCols != null); // Just gather a mish-mash of every possible relevant expression // and uniq them later HsqlList col_list = new HsqlArrayList(); select.collectAllExpressions( col_list, Expression.columnExpressionSet, Expression.emptyExpressionSet); if (select.queryCondition != null) { Expression.collectAllExpressions( col_list, select.queryCondition, Expression.columnExpressionSet, Expression.emptyExpressionSet); } for (int i = 0; i < select.exprColumns.length; i++) { Expression.collectAllExpressions( col_list, select.exprColumns[i], Expression.columnExpressionSet, Expression.emptyExpressionSet); } for (RangeVariable rv : select.rangeVariables) { if (rv.indexCondition != null) { Expression.collectAllExpressions( col_list, rv.indexCondition, Expression.columnExpressionSet, Expression.emptyExpressionSet); } if (rv.indexEndCondition != null) { Expression.collectAllExpressions( col_list, rv.indexEndCondition, Expression.columnExpressionSet, Expression.emptyExpressionSet); } if (rv.nonIndexJoinCondition != null) { Expression.collectAllExpressions( col_list, rv.nonIndexJoinCondition, Expression.columnExpressionSet, Expression.emptyExpressionSet); } } HsqlList uniq_col_list = new HsqlArrayList(); for (int i = 0; i < col_list.size(); i++) { Expression orig = (Expression) col_list.get(i); if (!uniq_col_list.contains(orig)) { uniq_col_list.add(orig); } } for (int i = 0; i < uniq_col_list.size(); i++) { VoltXMLElement xml = ((Expression) uniq_col_list.get(i)).voltGetXML(session); scanCols.children.add(xml); assert (xml != null); } // columns VoltXMLElement cols = new VoltXMLElement("columns"); query.children.add(cols); ArrayList<Expression> orderByCols = new ArrayList<Expression>(); ArrayList<Expression> groupByCols = new ArrayList<Expression>(); ArrayList<Expression> displayCols = new ArrayList<Expression>(); ArrayList<Pair<Integer, SimpleName>> aliases = new ArrayList<Pair<Integer, SimpleName>>(); /* * select.exprColumn stores all of the columns needed by HSQL to * calculate the query's result set. It contains more than just the * columns in the output; for example, it contains columns representing * aliases, columns for groups, etc. * * Volt uses multiple collections to organize these columns. * * Observing this loop in a debugger, the following seems true: * * 1. Columns in exprColumns that appear in the output schema, appear in * exprColumns in the same order that they occur in the output schema. * * 2. expr.columnIndex is an index back in to the select.exprColumns * array. This allows multiple exprColumn entries to refer to each * other; for example, an OpType.SIMPLE_COLUMN type storing an alias * will have its columnIndex set to the offset of the expr it aliases. */ for (int i = 0; i < select.exprColumns.length; i++) { final Expression expr = select.exprColumns[i]; if (expr.alias != null) { /* * Remember how aliases relate to columns. Will iterate again later * and mutate the exprColumn entries setting the alias string on the aliased * column entry. */ if (expr instanceof ExpressionColumn) { ExpressionColumn exprColumn = (ExpressionColumn) expr; if (exprColumn.alias != null && exprColumn.columnName == null) { aliases.add(Pair.of(expr.columnIndex, expr.alias)); } } else if (expr.columnIndex > -1) { /* * Only add it to the list of aliases that need to be * propagated to columns if the column index is valid. * ExpressionArithmetic will have an alias but not * necessarily a column index. */ aliases.add(Pair.of(expr.columnIndex, expr.alias)); } } // If the column doesn't refer to another exprColumn entry, set its // column index to itself. If all columns have a valid column index, // it's easier to patch up display column ordering later. if (expr.columnIndex == -1) { expr.columnIndex = i; } if (isGroupByColumn(select, i)) { groupByCols.add(expr); } else if (expr.opType == OpTypes.ORDER_BY) { orderByCols.add(expr); } else if (expr.opType != OpTypes.SIMPLE_COLUMN || (expr.isAggregate && expr.alias != null)) { // Add aggregate aliases to the display columns to maintain // the output schema column ordering. displayCols.add(expr); } // else, other simple columns are ignored. If others exist, maybe // volt infers a display column from another column collection? } for (Pair<Integer, SimpleName> alias : aliases) { // set the alias data into the expression being aliased. select.exprColumns[alias.getFirst()].alias = alias.getSecond(); } /* * The columns chosen above as display columns aren't always the same * expr objects HSQL would use as display columns - some data were * unified (namely, SIMPLE_COLUMN aliases were pushed into COLUMNS). * * However, the correct output schema ordering was correct in exprColumns. * This order was maintained by adding SIMPLE_COLUMNs to displayCols. * * Now need to serialize the displayCols, serializing the non-simple-columns * corresponding to simple_columns for any simple_columns that woodchucks * could chuck. * * Serialize the display columns in the exprColumn order. */ for (int jj = 0; jj < displayCols.size(); ++jj) { Expression expr = displayCols.get(jj); if (expr == null) { continue; } else if (expr.opType == OpTypes.SIMPLE_COLUMN) { // simple columns are not serialized as display columns // but they are place holders for another column // in the output schema. Go find that corresponding column // and serialize it in this place. for (int ii = jj; ii < displayCols.size(); ++ii) { Expression otherCol = displayCols.get(ii); if (otherCol == null) { continue; } else if ((otherCol.opType != OpTypes.SIMPLE_COLUMN) && (otherCol.columnIndex == expr.columnIndex)) { // serialize the column this simple column stands-in for VoltXMLElement xml = otherCol.voltGetXML(session); cols.children.add(xml); assert (xml != null); // null-out otherCol to not serialize it twice displayCols.set(ii, null); // quit seeking simple_column's replacement break; } } } else { VoltXMLElement xml = expr.voltGetXML(session); cols.children.add(xml); assert (xml != null); } } // parameters voltAppendParameters(session, query); // scans VoltXMLElement scans = new VoltXMLElement("tablescans"); query.children.add(scans); assert (scans != null); for (RangeVariable rangeVariable : select.rangeVariables) { scans.children.add(rangeVariable.voltGetRangeVariableXML(session)); } // Columns from USING expression in join are not qualified. // if join is INNER then the column from USING expression can be from any table // participating in join. In case of OUTER join, it must be the outer column resolveUsingColumns(cols, select.rangeVariables); // having if (select.havingCondition != null) { throw new HSQLParseException("VoltDB does not support the HAVING clause"); } // groupby if (select.isGrouped) { VoltXMLElement groupCols = new VoltXMLElement("groupcolumns"); query.children.add(groupCols); for (Expression groupByCol : groupByCols) { groupCols.children.add(groupByCol.voltGetXML(session)); } } // orderby if (orderByCols.size() > 0) { VoltXMLElement orderCols = new VoltXMLElement("ordercolumns"); query.children.add(orderCols); for (Expression orderByCol : orderByCols) { orderCols.children.add(orderByCol.voltGetXML(session)); } } // query condition should be covered by table scans, but can un-comment // this to see if anything is missed /*if (select.queryCondition != null) { VoltXMLElement queryCond = new VoltXMLElement("querycondition"); query.children.add(queryCond); queryCond.children.add(select.queryCondition.voltGetXML(session)); }*/ return query; }
private static void addPatchedInfos( @NotNull HighlightInfo info, @NotNull PsiFile injectedPsi, @NotNull DocumentWindow documentWindow, @NotNull InjectedLanguageManager injectedLanguageManager, @Nullable TextRange fixedTextRange, @NotNull Collection<HighlightInfo> out) { ProperTextRange textRange = new ProperTextRange(info.startOffset, info.endOffset); List<TextRange> editables = injectedLanguageManager.intersectWithAllEditableFragments(injectedPsi, textRange); for (TextRange editable : editables) { TextRange hostRange = fixedTextRange == null ? documentWindow.injectedToHost(editable) : fixedTextRange; boolean isAfterEndOfLine = info.isAfterEndOfLine(); if (isAfterEndOfLine) { // convert injected afterEndOfLine to either host' afterEndOfLine or not-afterEndOfLine // highlight of the injected fragment boundary int hostEndOffset = hostRange.getEndOffset(); int lineNumber = documentWindow.getDelegate().getLineNumber(hostEndOffset); int hostLineEndOffset = documentWindow.getDelegate().getLineEndOffset(lineNumber); if (hostEndOffset < hostLineEndOffset) { // convert to non-afterEndOfLine isAfterEndOfLine = false; hostRange = new ProperTextRange(hostRange.getStartOffset(), hostEndOffset + 1); } } HighlightInfo patched = new HighlightInfo( info.forcedTextAttributes, info.forcedTextAttributesKey, info.type, hostRange.getStartOffset(), hostRange.getEndOffset(), info.getDescription(), info.getToolTip(), info.type.getSeverity(null), isAfterEndOfLine, null, false, 0, info.getProblemGroup(), info.getGutterIconRenderer()); patched.setHint(info.hasHint()); if (info.quickFixActionRanges != null) { for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : info.quickFixActionRanges) { TextRange quickfixTextRange = pair.getSecond(); List<TextRange> editableQF = injectedLanguageManager.intersectWithAllEditableFragments( injectedPsi, quickfixTextRange); for (TextRange editableRange : editableQF) { HighlightInfo.IntentionActionDescriptor descriptor = pair.getFirst(); if (patched.quickFixActionRanges == null) patched.quickFixActionRanges = new ArrayList<Pair<HighlightInfo.IntentionActionDescriptor, TextRange>>(); TextRange hostEditableRange = documentWindow.injectedToHost(editableRange); patched.quickFixActionRanges.add(Pair.create(descriptor, hostEditableRange)); } } } patched.setFromInjection(true); out.add(patched); } }
public boolean equals(Object o) { Pair<K, V> other = (Pair<K, V>) o; return this.getFirst().equals(other.getFirst()) && this.getSecond().equals(other.getSecond()); }