Java Code Examples for gnu.trove.TIntArrayList#size()
The following examples show how to use
gnu.trove.TIntArrayList#size() .
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: 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 2
Source File: MyDeviceChooser.java From ADBWIFI with Apache License 2.0 | 6 votes |
private void refreshTable() { IDevice[] devices = myDetectedDevicesRef.get(); myDisplayedDevices = devices; final IDevice[] selectedDevices = getSelectedDevices(); final TIntArrayList selectedRows = new TIntArrayList(); for (int i = 0; i < devices.length; i++) { if (ArrayUtil.indexOf(selectedDevices, devices[i]) >= 0) { selectedRows.add(i); } } myProcessSelectionFlag = false; myDeviceTable.setModel(new MyDeviceTableModel(devices)); if (selectedRows.size() == 0 && devices.length > 0) { myDeviceTable.getSelectionModel().setSelectionInterval(0, 0); } for (int selectedRow : selectedRows.toNativeArray()) { if (selectedRow < devices.length) { myDeviceTable.getSelectionModel().addSelectionInterval(selectedRow, selectedRow); } } fireSelectedDevicesChanged(); myProcessSelectionFlag = true; updatePreviouslySelectedSerials(); }
Example 3
Source File: Reindexer.java From consulo with Apache License 2.0 | 6 votes |
private int[] discard(int[] needed, int[] toDiscard, int arrayIndex) { myOriginalLengths[arrayIndex] = toDiscard.length; int[] sorted1 = createSorted(needed); TIntArrayList discarded = new TIntArrayList(toDiscard.length); TIntArrayList oldIndecies = new TIntArrayList(toDiscard.length); for (int i = 0; i < toDiscard.length; i++) { int index = toDiscard[i]; if (Arrays.binarySearch(sorted1, index) >= 0) { discarded.add(index); oldIndecies.add(i); } } myOldIndecies[arrayIndex] = oldIndecies.toNativeArray(); myDiscardedLengths[arrayIndex] = discarded.size(); return discarded.toNativeArray(); }
Example 4
Source File: MyDeviceChooser.java From ADB-Duang with MIT License | 6 votes |
private void refreshTable() { IDevice[] devices = myDetectedDevicesRef.get(); myDisplayedDevices = devices; final IDevice[] selectedDevices = getSelectedDevices(); final TIntArrayList selectedRows = new TIntArrayList(); for (int i = 0; i < devices.length; i++) { if (ArrayUtil.indexOf(selectedDevices, devices[i]) >= 0) { selectedRows.add(i); } } myProcessSelectionFlag = false; myDeviceTable.setModel(new MyDeviceTableModel(devices)); if (selectedRows.size() == 0 && devices.length > 0) { myDeviceTable.getSelectionModel().setSelectionInterval(0, 0); } for (int selectedRow : selectedRows.toNativeArray()) { if (selectedRow < devices.length) { myDeviceTable.getSelectionModel().addSelectionInterval(selectedRow, selectedRow); } } fireSelectedDevicesChanged(); myProcessSelectionFlag = true; updatePreviouslySelectedSerials(); }
Example 5
Source File: URLUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static String unescapePercentSequences(@Nonnull String s) { if (s.indexOf('%') == -1) { return s; } StringBuilder decoded = new StringBuilder(); final int len = s.length(); int i = 0; while (i < len) { char c = s.charAt(i); if (c == '%') { TIntArrayList bytes = new TIntArrayList(); while (i + 2 < len && s.charAt(i) == '%') { final int d1 = decode(s.charAt(i + 1)); final int d2 = decode(s.charAt(i + 2)); if (d1 != -1 && d2 != -1) { bytes.add(((d1 & 0xf) << 4 | d2 & 0xf)); i += 3; } else { break; } } if (!bytes.isEmpty()) { final byte[] bytesArray = new byte[bytes.size()]; for (int j = 0; j < bytes.size(); j++) { bytesArray[j] = (byte)bytes.getQuick(j); } decoded.append(new String(bytesArray, CharsetToolkit.UTF8_CHARSET)); continue; } } decoded.append(c); i++; } return decoded.toString(); }
Example 6
Source File: FewExamplesSiblingNegativesChooser.java From jatecs with GNU General Public License v3.0 | 5 votes |
public TIntArrayListIterator selectNegatives(String category) { TIntArrayList negatives = new TIntArrayList(); short id = _globalIndex.getCategoryDB().getCategory(category); selectNegativesFromParent(id, negatives, id); if (negatives.size() < _minNumNegatives) { IShortIterator it = _globalIndex.getCategoryDB() .getParentCategories(id); short nextParent = -1; if (it.hasNext()) nextParent = it.next(); boolean done = false; while (!done && nextParent != -1) { selectNegativesFromParent(nextParent, negatives, id); if (negatives.size() >= _minNumNegatives) { done = true; break; } it = _globalIndex.getCategoryDB().getParentCategories( nextParent); if (it.hasNext()) nextParent = it.next(); else nextParent = -1; } } return new TIntArrayListIterator(negatives); }
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: TroveContentFullDB.java From jatecs with GNU General Public License v3.0 | 5 votes |
public int getDocumentLength(int document) { if (_documentLenghts.containsKey(document)) return _documentLenghts.get(document); else { if (document < _documentsFrequencies.size()) { TIntArrayList frequencies = _documentsFrequencies.get(document); int length = 0; for (int i = 0; i < frequencies.size(); ++i) length += frequencies.getQuick(i); _documentLenghts.put(document, length); return length; } else return 0; } }
Example 9
Source File: TroveDomainDB.java From jatecs with GNU General Public License v3.0 | 5 votes |
public void removeCategoryFeatures(short category, IIntIterator removedFeatures) { TIntArrayList feats = _categoriesFeatures.get(category); while (removedFeatures.hasNext()) { int feature = removedFeatures.next(); if (feats.binarySearch(feature) < 0) feats.add(feature); } feats.sort(); _hasLocalRepresentation = _hasLocalRepresentation || feats.size() > 0; }
Example 10
Source File: TroveContentDB.java From jatecs with GNU General Public License v3.0 | 5 votes |
public int getDocumentLength(int document) { if (_documentLenghts.containsKey(document)) return _documentLenghts.get(document); else { if (document < _documentsFrequencies.size()) { TIntArrayList frequencies = _documentsFrequencies.get(document); int length = 0; for (int i = 0; i < frequencies.size(); ++i) length += frequencies.getQuick(i); _documentLenghts.put(document, length); return length; } else return 0; } }
Example 11
Source File: TroveContentILDB.java From jatecs with GNU General Public License v3.0 | 4 votes |
public void removeDocuments(IIntIterator removedDocuments) { for (int i = 0; i < _featuresDocuments.size(); ++i) { TIntArrayList docs = _featuresDocuments.get(i); TIntArrayList freqs = _featuresFrequencies.get(i); int j = 0; int shift = 0; int doc; int rem; if (j < docs.size() && removedDocuments.hasNext()) { doc = docs.getQuick(j); rem = removedDocuments.next(); while (true) { if (doc == rem) { docs.remove(j); freqs.remove(j); if (j < docs.size() && removedDocuments.hasNext()) { doc = docs.getQuick(j); rem = removedDocuments.next(); ++shift; } else break; } else if (doc > rem) { if (removedDocuments.hasNext()) { rem = removedDocuments.next(); ++shift; } else break; } else { docs.setQuick(j, doc - shift); ++j; if (j < docs.size()) doc = docs.getQuick(j); else break; } } ++shift; } while (j < docs.size()) { docs.setQuick(j, docs.getQuick(j) - shift); ++j; } removedDocuments.begin(); } removedDocuments.begin(); while (removedDocuments.hasNext()) { int document = removedDocuments.next(); _documentFeaturesCount.remove(document); _documentLenghts.remove(document); } }
Example 12
Source File: TroveContentFullDB.java From jatecs with GNU General Public License v3.0 | 4 votes |
public void removeFeatures(IIntIterator removedFeatures) { int shift = 0; while (removedFeatures.hasNext()) { int feature = removedFeatures.next() - shift; _featuresDocuments.remove(feature); _featuresFrequencies.remove(feature); ++shift; } removedFeatures.begin(); for (int i = 0; i < _documentsFeatures.size(); ++i) { TIntArrayList feats = _documentsFeatures.get(i); TIntArrayList freqs = _documentsFrequencies.get(i); int j = 0; shift = 0; int feat; int rem; if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); while (true) { if (feat == rem) { feats.remove(j); freqs.remove(j); if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); ++shift; } else break; } else if (feat > rem) { if (removedFeatures.hasNext()) { rem = removedFeatures.next(); ++shift; } else break; } else { feats.setQuick(j, feat - shift); ++j; if (j < feats.size()) feat = feats.getQuick(j); else break; } } ++shift; } while (j < feats.size()) { feats.setQuick(j, feats.getQuick(j) - shift); ++j; } removedFeatures.begin(); } _documentLenghts.clear(); }
Example 13
Source File: IndexStatistics.java From jatecs with GNU General Public License v3.0 | 4 votes |
/** * Print statistics about document and classification. * * @param docsDB The documents DB. * @param classificationDB The classification DB. * @param wantDetails True if must print more details about the statistics, false * otherwise. */ public static void printDocumentsClassificationStatistics( IDocumentDB docsDB, IClassificationDB classificationDB, boolean wantDetails) { if (docsDB == null) throw new NullPointerException( "The specified documents DB is 'null'"); if (classificationDB == null) throw new NullPointerException( "The specified classification DB is 'null'"); int docsCount = docsDB.getDocumentsCount(); double avgCatsPerDoc = 0.0; int minCatsPerDoc = Integer.MAX_VALUE; TIntArrayList minCatsPerDocDocs = new TIntArrayList(); int maxCatsPerDoc = Integer.MIN_VALUE; TIntArrayList maxCatsPerDocDocs = new TIntArrayList(); IIntIterator docIt = docsDB.getDocuments(); docIt.begin(); while (docIt.hasNext()) { int doc = docIt.next(); int docCats = classificationDB.getDocumentCategoriesCount(doc); if (docCats == minCatsPerDoc) minCatsPerDocDocs.add(doc); if (docCats < minCatsPerDoc) { minCatsPerDoc = docCats; minCatsPerDocDocs.clear(); minCatsPerDocDocs.add(doc); } if (docCats == maxCatsPerDoc) maxCatsPerDocDocs.add(doc); if (docCats > maxCatsPerDoc) { maxCatsPerDoc = docCats; maxCatsPerDocDocs.clear(); maxCatsPerDocDocs.add(doc); } avgCatsPerDoc += docCats; } avgCatsPerDoc /= docsCount; JatecsLogger.status().println(""); JatecsLogger.status().println( "Average categories per documents: " + Os.generateDouble(avgCatsPerDoc, 3)); JatecsLogger.status().print( "Maximum categories per documents: [" + maxCatsPerDocDocs.size() + "] " + maxCatsPerDoc + " ("); if (wantDetails) { for (int i = 0; i < maxCatsPerDocDocs.size(); ++i) { JatecsLogger.status().print( docsDB.getDocumentName(maxCatsPerDocDocs.get(i)) + " "); } } JatecsLogger.status().println(")"); JatecsLogger.status().print( "Minimum categories per documents: [" + minCatsPerDocDocs.size() + "] " + minCatsPerDoc + " ("); if (wantDetails) { for (int i = 0; i < minCatsPerDocDocs.size(); ++i) { JatecsLogger.status().print( docsDB.getDocumentName(minCatsPerDocDocs.get(i)) + " "); } } }
Example 14
Source File: TroveDomainDB.java From jatecs with GNU General Public License v3.0 | 4 votes |
public void removeFeatures(IIntIterator removedFeatures) { for (int i = 0; i < _categoriesFeatures.size(); ++i) { TIntArrayList feats = _categoriesFeatures.get(i); int j = 0; int shift = 0; int feat; int rem; if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); while (true) { if (feat == rem) { feats.remove(j); if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); ++shift; } else break; } else if (feat > rem) { if (removedFeatures.hasNext()) { rem = removedFeatures.next(); ++shift; } else break; } else { feats.setQuick(j, feat - shift); ++j; if (j < feats.size()) feat = feats.getQuick(j); else break; } } } while (j < feats.size()) { feats.setQuick(j, feats.getQuick(j) - shift); ++j; } removedFeatures.begin(); } }
Example 15
Source File: DuplicatesInspectionBase.java From consulo with Apache License 2.0 | 4 votes |
@Override public boolean process(@Nonnull VirtualFile file, TIntArrayList list) { for(int i = 0, len = list.size(); i < len; i+=2) { ProgressManager.checkCanceled(); if (list.getQuick(i + 1) != myHash2) continue; int offset = list.getQuick(i); if (myFileIndex.isInSourceContent(virtualFile)) { if (!myFileIndex.isInSourceContent(file)) return true; if (!TestSourcesFilter.isTestSources(virtualFile, project) && TestSourcesFilter.isTestSources(file, project)) return true; if (mySkipGeneratedCode) { if (!myFileWithinGeneratedCode && GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(file, project)) return true; } } else if (myFileIndex.isInSourceContent(file)) { return true; } final int startOffset = getStartOffset(myNode); final int endOffset = getEndOffset(myNode); if (file.equals(virtualFile) && offset >= startOffset && offset < endOffset) continue; PsiElement target = getPsi(myNode); TextRange rangeInElement = getRangeInElement(myNode); Integer fragmentStartOffsetInteger = startOffset; SortedMap<Integer,TextRange> map = reportedRanges.subMap(fragmentStartOffsetInteger, endOffset); int newFragmentSize = !map.isEmpty() ? 0:1; Iterator<Integer> iterator = map.keySet().iterator(); while(iterator.hasNext()) { Integer next = iterator.next(); iterator.remove(); reportedFiles.remove(next); reportedOffsetInOtherFiles.remove(next); reportedPsi.remove(next); newFragmentSize += fragmentSize.remove(next); } reportedRanges.put(fragmentStartOffsetInteger, rangeInElement); reportedFiles.put(fragmentStartOffsetInteger, file); reportedOffsetInOtherFiles.put(fragmentStartOffsetInteger, offset); reportedPsi.put(fragmentStartOffsetInteger, target); fragmentSize.put(fragmentStartOffsetInteger, newFragmentSize); if (newFragmentSize >= MIN_FRAGMENT_SIZE || isLightProfile()) { fragmentHash.put(fragmentStartOffsetInteger, (myHash & 0xFFFFFFFFL) | ((long)myHash2 << 32)); } return false; } return true; }
Example 16
Source File: FileBasedJrcAcquisCorpusReader.java From jatecs with GNU General Public License v3.0 | 4 votes |
protected TIntArrayList getValidParagraphs(String doc, boolean firstlanguage) { TIntArrayList valids = new TIntArrayList(); TIntArrayList others = new TIntArrayList(); String pattern = "xtargets=\""; int from = 0; boolean done = false; while (!done) { int startIdx = doc.indexOf(pattern, from); if (startIdx == -1) { done = true; continue; } if (from == 0) { from = startIdx + 1; continue; } startIdx += pattern.length(); int endIdx = doc.indexOf("\"", startIdx); assert (endIdx != -1); String val = doc.substring(startIdx, endIdx); String[] values = null; if (val.startsWith(";")) { values = val.split("[;]"); values = new String[]{" ", values[0]}; } else if (val.endsWith(";")) { values = val.split("[;]"); values = new String[]{values[0], " "}; } else values = val.split("[;]"); String[] intLangVals = null; String[] intForeignVals = null; if (!(values.length == 2)) System.out.println("Val: " + val); if (firstlanguage) { intLangVals = values[0].split("[ ]"); intForeignVals = values[1].split("[ ]"); } else { intLangVals = values[1].split("[ ]"); intForeignVals = values[0].split("[ ]"); } if (intForeignVals.length != 0 && intLangVals.length != 0) { for (int i = 0; i < intLangVals.length; i++) { if (intLangVals[i].equals("")) continue; valids.add(Integer.parseInt(intLangVals[i])); } for (int i = 0; i < intForeignVals.length; i++) { if (intForeignVals[i].equals("")) continue; others.add(Integer.parseInt(intForeignVals[i])); } } from = endIdx; } if (others.size() == 0) return new TIntArrayList(); return valids; }
Example 17
Source File: JrcAcquisCorpusReader.java From jatecs with GNU General Public License v3.0 | 4 votes |
protected TIntArrayList getValidParagraphs(String doc, boolean firstlanguage) { TIntArrayList valids = new TIntArrayList(); TIntArrayList others = new TIntArrayList(); String pattern = "xtargets=\""; int from = 0; boolean done = false; while (!done) { int startIdx = doc.indexOf(pattern, from); if (startIdx == -1) { done = true; continue; } if (from == 0) { from = startIdx + 1; continue; } startIdx += pattern.length(); int endIdx = doc.indexOf("\"", startIdx); assert (endIdx != -1); String val = doc.substring(startIdx, endIdx); String[] values = null; if (val.startsWith(";")) { values = val.split("[;]"); values = new String[]{" ", values[0]}; } else if (val.endsWith(";")) { values = val.split("[;]"); values = new String[]{values[0], " "}; } else values = val.split("[;]"); String[] intLangVals = null; String[] intForeignVals = null; if (!(values.length == 2)) System.out.println("Val: " + val); if (firstlanguage) { intLangVals = values[0].split("[ ]"); intForeignVals = values[1].split("[ ]"); } else { intLangVals = values[1].split("[ ]"); intForeignVals = values[0].split("[ ]"); } if (intForeignVals.length != 0 && intLangVals.length != 0) { for (int i = 0; i < intLangVals.length; i++) { if (intLangVals[i].equals("")) continue; valids.add(Integer.parseInt(intLangVals[i])); } for (int i = 0; i < intForeignVals.length; i++) { if (intForeignVals[i].equals("")) continue; others.add(Integer.parseInt(intForeignVals[i])); } } from = endIdx; } if (others.size() == 0) return new TIntArrayList(); return valids; }
Example 18
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 19
Source File: TroveWeightingDB.java From jatecs with GNU General Public License v3.0 | 4 votes |
public void removeFeatures(IIntIterator removedFeatures) { for (int i = 0; i < _documentsWeights.size(); ++i) { TIntDoubleHashMap weigs = _documentsWeights.get(i); TIntArrayList feats = new TIntArrayList(weigs.size()); TDoubleArrayList weigths = new TDoubleArrayList(weigs.size()); TIntDoubleIterator wit = weigs.iterator(); while (wit.hasNext()) { wit.advance(); feats.add(wit.key()); weigths.add(wit.value()); } int j = 0; int shift = 0; int feat; int rem; if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); while (true) { if (feat == rem) { feats.remove(j); weigths.remove(j); if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); ++shift; } else break; } else if (feat > rem) { if (removedFeatures.hasNext()) { rem = removedFeatures.next(); ++shift; } else break; } else { feats.setQuick(j, feat - shift); ++j; if (j < feats.size()) feat = feats.getQuick(j); else break; } } ++shift; } while (j < feats.size()) { feats.setQuick(j, feats.getQuick(j) - shift); ++j; } weigs.clear(); for (j = 0; j < feats.size(); ++j) weigs.put(feats.getQuick(j), weigths.getQuick(j)); removedFeatures.begin(); } }
Example 20
Source File: TroveContentDB.java From jatecs with GNU General Public License v3.0 | 4 votes |
public void removeFeatures(IIntIterator removedFeatures) { for (int i = 0; i < _documentsFeatures.size(); ++i) { TIntArrayList feats = _documentsFeatures.get(i); TIntArrayList freqs = _documentsFrequencies.get(i); int j = 0; int shift = 0; int feat; int rem; if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); while (true) { if (feat == rem) { feats.remove(j); freqs.remove(j); if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); ++shift; } else break; } else if (feat > rem) { if (removedFeatures.hasNext()) { rem = removedFeatures.next(); ++shift; } else break; } else { feats.setQuick(j, feat - shift); ++j; if (j < feats.size()) feat = feats.getQuick(j); else break; } } ++shift; } while (j < feats.size()) { feats.setQuick(j, feats.getQuick(j) - shift); ++j; } removedFeatures.begin(); } _documentLenghts.clear(); _featureDocumentsCount.clear(); }