Java Code Examples for gnu.trove.TIntArrayList#get()
The following examples show how to use
gnu.trove.TIntArrayList#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KMeansDocumentClusterizer.java From jatecs with GNU General Public License v3.0 | 6 votes |
protected void computeInitialCentroids(DocumentCentroid[] centroids, IIntIterator documents, IIndex index) { TIntArrayList initial = new TIntArrayList(); documents.begin(); while (documents.hasNext()) { initial.add(documents.next()); } Random r = new Random(); for (int i = 0; i < centroids.length; i++) { // Choose random document. int nextDoc = initial.get(r.nextInt(initial.size())); TIntArrayList ar = new TIntArrayList(); ar.add(nextDoc); centroids[i].features = Clustering.computeDocumentCentroid( new TIntArrayListIterator(ar), index); } }
Example 2
Source File: KMeansDocumentClusterizer.java From jatecs with GNU General Public License v3.0 | 6 votes |
protected void computeInitialCentroidsNormal(DocumentCentroid[] centroids, IIntIterator documents, IIndex index) { TIntArrayList initial = new TIntArrayList(); documents.begin(); while (documents.hasNext()) { initial.add(documents.next()); } Random r = new Random(); for (int i = 0; i < centroids.length; i++) { // Choose random document. int nextDoc = initial.get(r.nextInt(initial.size())); TIntArrayList ar = new TIntArrayList(); ar.add(nextDoc); centroids[i].features = Clustering.computeDocumentCentroid( new TIntArrayListIterator(ar), index); } }
Example 3
Source File: MoveArrangementMatchingRuleUpAction.java From consulo with Apache License 2.0 | 6 votes |
@Override protected void fillMappings(@Nonnull ArrangementMatchingRulesControl control, @Nonnull List<int[]> mappings) { TIntArrayList rows = control.getSelectedModelRows(); rows.reverse(); int top = -1; for (int i = 0; i < rows.size(); i++) { int row = rows.get(i); if (row == top + 1) { mappings.add(new int[] { row, row }); top++; } else { mappings.add(new int[]{ row, row - 1 }); } } }
Example 4
Source File: AddArrangementRuleAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(AnActionEvent e) { ArrangementMatchingRulesControl control = getRulesControl(e); if (control == null) { return; } control.hideEditor(); TIntArrayList rows = control.getSelectedModelRows(); ArrangementMatchingRulesModel model = control.getModel(); int rowToEdit; if (rows.size() == 1) { rowToEdit = rows.get(0) + 1; model.insertRow(rowToEdit, new Object[] {createNewRule(control)}); } else { rowToEdit = model.getSize(); model.add(createNewRule(control)); } showEditor(control, rowToEdit); control.getSelectionModel().setSelectionInterval(rowToEdit, rowToEdit); scrollRowToVisible(control, rowToEdit); }
Example 5
Source File: FileBasedIndexImpl.java From consulo with Apache License 2.0 | 6 votes |
private ProjectIndexableFilesFilter(@Nonnull TIntArrayList set, int modificationCount) { myModificationCount = modificationCount; final int[] minMax = new int[2]; if (!set.isEmpty()) { minMax[0] = minMax[1] = set.get(0); } set.forEach(value -> { minMax[0] = Math.min(minMax[0], value); minMax[1] = Math.max(minMax[1], value); return true; }); myMaxId = minMax[1]; myMinId = minMax[0]; myBitMask = new long[((myMaxId - myMinId) >> SHIFT) + 1]; set.forEach(value -> { value -= myMinId; myBitMask[value >> SHIFT] |= (1L << (value & MASK)); return true; }); }
Example 6
Source File: MergeModelBase.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @RequiredUIAccess private TIntArrayList collectAffectedChanges(@Nonnull TIntArrayList directChanges) { TIntArrayList result = new TIntArrayList(directChanges.size()); int directArrayIndex = 0; int otherIndex = 0; while (directArrayIndex < directChanges.size() && otherIndex < getChangesCount()) { int directIndex = directChanges.get(directArrayIndex); if (directIndex == otherIndex) { result.add(directIndex); otherIndex++; continue; } int directStart = getLineStart(directIndex); int directEnd = getLineEnd(directIndex); int otherStart = getLineStart(otherIndex); int otherEnd = getLineEnd(otherIndex); if (otherEnd < directStart) { otherIndex++; continue; } if (otherStart > directEnd) { directArrayIndex++; continue; } result.add(otherIndex); otherIndex++; } LOG.assertTrue(directChanges.size() <= result.size()); return result; }
Example 7
Source File: ArrangementMatchingRulesControl.java From consulo with Apache License 2.0 | 5 votes |
private void onMouseClicked(@Nonnull MouseEvent e) { final int count = e.getClickCount(); if (count != 2) { return; } final TIntArrayList rows = getSelectedModelRows(); if (rows.size() != 1) { return; } final int row = rows.get(0); showEditor(row); scrollRowToVisible(row); }
Example 8
Source File: MoveArrangementMatchingRuleDownAction.java From consulo with Apache License 2.0 | 5 votes |
@Override protected void fillMappings(@Nonnull ArrangementMatchingRulesControl control, @Nonnull List<int[]> mappings) { TIntArrayList rows = control.getSelectedModelRows(); int bottom = control.getModel().getSize(); for (int i = 0; i < rows.size(); i++) { int row = rows.get(i); if (row == bottom - 1) { mappings.add(new int[] { row, row }); bottom--; } else { mappings.add(new int[]{ row, row + 1 }); } } }
Example 9
Source File: EditArrangementRuleAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(AnActionEvent e) { ArrangementMatchingRulesControl control = getRulesControl(e); if (control == null) { return; } TIntArrayList rows = control.getSelectedModelRows(); if (rows.size() != 1) { return; } final int row = rows.get(0); control.showEditor(row); scrollRowToVisible(control, row); }
Example 10
Source File: KFoldEvaluator.java From jatecs with GNU General Public License v3.0 | 4 votes |
protected void integrateTestIndex(int step, IIndex idx, IIndex originalIndex, TIntArrayList docs, int numTotalSteps) { if (docs.size() == 0) return; String catName = idx.getCategoryDB().getCategoryName((short) 0); int positive = idx.getClassificationDB().getCategoryDocumentsCount((short) 0); if (positive <= numTotalSteps) numTotalSteps = positive; if (numTotalSteps == 0) numTotalSteps = 1; int numDocs = docs.size(); int perStep = numDocs / numTotalSteps; if (numDocs % numTotalSteps != 0) perStep++; TroveMainIndexBuilder builder = new TroveMainIndexBuilder(idx); int startVal = perStep * step; int endVal = (startVal + perStep) <= docs.size() ? startVal + perStep : docs.size(); for (int i = startVal; i < endVal; i++) { int docID = docs.get(i); String docName = originalIndex.getDocumentDB().getDocumentName(docID); docName += "_" + System.currentTimeMillis(); // Prepare categories. ArrayList<String> catsToInsert = new ArrayList<String>(); IShortIterator cats = originalIndex.getClassificationDB().getDocumentCategories(docID); while (cats.hasNext()) { short curCatID = cats.next(); String curCatName = originalIndex.getCategoryDB().getCategoryName(curCatID); if (curCatName.equals(catName)) catsToInsert.add(curCatName); } // Prepare features. ArrayList<String> featsToInsert = new ArrayList<String>(); IIntIterator feats = originalIndex.getContentDB().getDocumentFeatures(docID); while (feats.hasNext()) { int featID = feats.next(); featsToInsert.add(originalIndex.getFeatureDB().getFeatureName(featID)); } builder.addDocument(docName, featsToInsert.toArray(new String[0]), catsToInsert.toArray(new String[0])); } JatecsLogger.status().println("After integration the validation contain " + idx.getDocumentDB().getDocumentsCount() + " document(s)"); }
Example 11
Source File: ArrangementEngine.java From consulo with Apache License 2.0 | 4 votes |
@SuppressWarnings("AssignmentToForLoopParameter") @Override public void replace(@Nonnull ArrangementEntryWrapper<E> newWrapper, @Nonnull ArrangementEntryWrapper<E> oldWrapper, @Nullable ArrangementEntryWrapper<E> previous, @Nullable ArrangementEntryWrapper<E> next, @Nonnull Context<E> context) { // Calculate blank lines before the arrangement. int blankLinesBefore = 0; TIntArrayList lineFeedOffsets = new TIntArrayList(); int oldStartLine = context.document.getLineNumber(oldWrapper.getStartOffset()); if (oldStartLine > 0) { int lastLineFeed = context.document.getLineStartOffset(oldStartLine) - 1; lineFeedOffsets.add(lastLineFeed); for (int i = lastLineFeed - 1 - myParentShift; i >= 0; i--) { i = CharArrayUtil.shiftBackward(myParentText, i, " \t"); if (myParentText.charAt(i) == '\n') { blankLinesBefore++; lineFeedOffsets.add(i + myParentShift); } else { break; } } } ArrangementEntryWrapper<E> parentWrapper = oldWrapper.getParent(); int desiredBlankLinesNumber = getBlankLines(context, parentWrapper, newWrapper, previous, next); if (desiredBlankLinesNumber == blankLinesBefore && newWrapper.equals(oldWrapper)) { return; } String newEntryText = myParentText.substring(newWrapper.getStartOffset() - myParentShift, newWrapper.getEndOffset() - myParentShift); int lineFeedsDiff = desiredBlankLinesNumber - blankLinesBefore; if (lineFeedsDiff == 0 || desiredBlankLinesNumber < 0) { context.addMoveInfo(newWrapper.getStartOffset() - myParentShift, newWrapper.getEndOffset() - myParentShift, oldWrapper.getStartOffset()); context.document.replaceString(oldWrapper.getStartOffset(), oldWrapper.getEndOffset(), newEntryText); return; } if (lineFeedsDiff > 0) { // Insert necessary number of blank lines. StringBuilder buffer = new StringBuilder(StringUtil.repeat("\n", lineFeedsDiff)); buffer.append(newEntryText); context.document.replaceString(oldWrapper.getStartOffset(), oldWrapper.getEndOffset(), buffer); } else { // Cut exceeding blank lines. int replacementStartOffset = lineFeedOffsets.get(-lineFeedsDiff) + 1; context.document.replaceString(replacementStartOffset, oldWrapper.getEndOffset(), newEntryText); } // Update wrapper ranges. ArrangementEntryWrapper<E> parent = oldWrapper.getParent(); if (parent == null) { return; } Deque<ArrangementEntryWrapper<E>> parents = new ArrayDeque<ArrangementEntryWrapper<E>>(); do { parents.add(parent); parent.setEndOffset(parent.getEndOffset() + lineFeedsDiff); parent = parent.getParent(); } while (parent != null); while (!parents.isEmpty()) { for (ArrangementEntryWrapper<E> wrapper = parents.removeLast().getNext(); wrapper != null; wrapper = wrapper.getNext()) { wrapper.applyShift(lineFeedsDiff); } } }