Java Code Examples for gnu.trove.TIntArrayList#toNativeArray()

The following examples show how to use gnu.trove.TIntArrayList#toNativeArray() . 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: MyDeviceChooser.java    From ADB-Duang with MIT License 6 votes vote down vote up
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 2
Source File: MyDeviceChooser.java    From ADBWIFI with Apache License 2.0 6 votes vote down vote up
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 vote down vote up
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: ByChar.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static CharOffsets getNonSpaceChars(@Nonnull CharSequence text) {
  TIntArrayList chars = new TIntArrayList(text.length());
  TIntArrayList offsets = new TIntArrayList(text.length());

  for (int i = 0; i < text.length(); i++) {
    char c = text.charAt(i);
    if (!isWhiteSpace(c)) {
      chars.add(c);
      offsets.add(i);
    }
  }

  return new CharOffsets(chars.toNativeArray(), offsets.toNativeArray());
}
 
Example 5
Source File: ByChar.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static CharOffsets getPunctuationChars(@Nonnull CharSequence text) {
  TIntArrayList chars = new TIntArrayList(text.length());
  TIntArrayList offsets = new TIntArrayList(text.length());

  for (int i = 0; i < text.length(); i++) {
    char c = text.charAt(i);
    if (isPunctuation(c)) {
      chars.add(c);
      offsets.add(i);
    }
  }

  return new CharOffsets(chars.toNativeArray(), offsets.toNativeArray());
}
 
Example 6
Source File: FoldingTransformation.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FoldingTransformation(Editor editor) {
  myEditor = editor;
  FoldRegion[] foldRegions = myEditor.getFoldingModel().getAllFoldRegions();
  Arrays.sort(foldRegions, RangeMarker.BY_START_OFFSET);
  TIntArrayList foldBeginings = new TIntArrayList();
  for (FoldRegion foldRegion : foldRegions) {
    if (!foldRegion.isValid() || foldRegion.isExpanded()) continue;
    foldBeginings.add(getStartLine(foldRegion));
    myCollapsed.add(foldRegion);
  }
  myFoldBeginings = foldBeginings.toNativeArray();
}
 
Example 7
Source File: StringSearcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public int[] findAllOccurrences(@Nonnull CharSequence text) {
  int end = text.length();
  TIntArrayList result = new TIntArrayList();
  for (int index = 0; index < end; index++) {
    //noinspection AssignmentToForLoopParameter
    index = scan(text, index, end);
    if (index < 0) break;
    result.add(index);
  }
  return result.toNativeArray();
}
 
Example 8
Source File: DFSTBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
public Frame(int nodeI) {
  this.nodeI = nodeI;
  Iterator<Node> outNodes = myGraph.getOut(myAllNodes[nodeI]);
  TIntArrayList list = new TIntArrayList();

  while (outNodes.hasNext()) {
    Node node = outNodes.next();
    list.add(nodeIndex.get(node));
  }
  out = list.toNativeArray();
}
 
Example 9
Source File: LineSet.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static LineSet createLineSet(@Nonnull CharSequence text, boolean markModified) {
  TIntArrayList starts = new TIntArrayList();
  TByteArrayList flags = new TByteArrayList();

  LineTokenizer lineTokenizer = new LineTokenizer(text);
  while (!lineTokenizer.atEnd()) {
    starts.add(lineTokenizer.getOffset());
    flags.add((byte)(lineTokenizer.getLineSeparatorLength() | (markModified ? MODIFIED_MASK : 0)));
    lineTokenizer.advance();
  }
  return new LineSet(starts.toNativeArray(), flags.toNativeArray(), text.length());
}
 
Example 10
Source File: LowLevelSearchUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static int[] getTextOccurrences(@Nonnull CharSequence text,
                                        int startOffset,
                                        int endOffset,
                                        @Nonnull StringSearcher searcher,
                                        @Nullable ProgressIndicator progress) {
  if (endOffset > text.length()) {
    throw new IllegalArgumentException("end: " + endOffset + " > length: " + text.length());
  }
  Map<StringSearcher, int[]> cachedMap = cache.get(text);
  int[] cachedOccurrences = cachedMap == null ? null : cachedMap.get(searcher);
  boolean hasCachedOccurrences = cachedOccurrences != null && cachedOccurrences[0] <= startOffset && cachedOccurrences[1] >= endOffset;
  if (!hasCachedOccurrences) {
    TIntArrayList occurrences = new TIntArrayList();
    int newStart = Math.min(startOffset, cachedOccurrences == null ? startOffset : cachedOccurrences[0]);
    int newEnd = Math.max(endOffset, cachedOccurrences == null ? endOffset : cachedOccurrences[1]);
    occurrences.add(newStart);
    occurrences.add(newEnd);
    for (int index = newStart; index < newEnd; index++) {
      if (progress != null) progress.checkCanceled();
      //noinspection AssignmentToForLoopParameter
      index = searcher.scan(text, index, newEnd);
      if (index < 0) break;
      if (checkJavaIdentifier(text, 0, text.length(), searcher, index)) {
        occurrences.add(index);
      }
    }
    cachedOccurrences = occurrences.toNativeArray();
    if (cachedMap == null) {
      cachedMap = ConcurrencyUtil.cacheOrGet(cache, text, Maps.newConcurrentSoftHashMap());
    }
    cachedMap.put(searcher, cachedOccurrences);
  }
  TIntArrayList offsets = new TIntArrayList(cachedOccurrences.length - 2);
  for (int i = 2; i < cachedOccurrences.length; i++) {
    int occurrence = cachedOccurrences[i];
    if (occurrence > endOffset - searcher.getPatternLength()) break;
    if (occurrence >= startOffset) {
      offsets.add(occurrence);
    }
  }
  return offsets.toNativeArray();
}