/** This method is called by Swing to delete text from this document. */
 @Override
 public void remove(int offset, int length) throws BadLocationException {
   if (length == 0) return;
   if (undone > 0) {
     now = now - undone;
     undone = 0;
   } // clear the REDO entries
   String string = toString().substring(offset, offset + length);
   super.remove(offset, length);
   if (now > 0 && !insert[now - 1]) { // merge with last edit if possible
     if (where[now - 1] == offset) {
       text[now - 1] += string;
       return;
     }
     if (where[now - 1] == offset + length) {
       where[now - 1] = offset;
       text[now - 1] = string + text[now - 1];
       return;
     }
   }
   if (now >= MAXUNDO) {
     arraycopy(insert, 1, insert, 0, MAXUNDO - 1);
     arraycopy(text, 1, text, 0, MAXUNDO - 1);
     arraycopy(where, 1, where, 0, MAXUNDO - 1);
     now--;
   }
   insert[now] = false;
   text[now] = string;
   where[now] = offset;
   now++;
 }
 /** This method is called by Swing to insert a String into this document. */
 @Override
 public void insertString(int offset, String string, AttributeSet attr)
     throws BadLocationException {
   if (string.length() == 0) return;
   else if (string.indexOf('\r') >= 0)
     string = Util.convertLineBreak(string); // we don't want '\r'
   if (undone > 0) {
     now = now - undone;
     undone = 0;
   } // clear the REDO entries
   super.insertString(offset, string, attr);
   if (now > 0 && insert[now - 1]) { // merge with last edit if possible
     if (where[now - 1] == offset - text[now - 1].length()) {
       text[now - 1] += string;
       return;
     }
   }
   if (now >= MAXUNDO) {
     arraycopy(insert, 1, insert, 0, MAXUNDO - 1);
     arraycopy(text, 1, text, 0, MAXUNDO - 1);
     arraycopy(where, 1, where, 0, MAXUNDO - 1);
     now--;
   }
   insert[now] = true;
   text[now] = string;
   where[now] = offset;
   now++;
 }
 private int enumerate(ThreadGroup list[], int n, boolean recurse) {
   int ngroupsSnapshot = 0;
   ThreadGroup[] groupsSnapshot = null;
   synchronized (this) {
     if (destroyed) {
       return 0;
     }
     int ng = ngroups;
     if (ng > list.length - n) {
       ng = list.length - n;
     }
     if (ng > 0) {
       System.arraycopy(groups, 0, list, n, ng);
       n += ng;
     }
     if (recurse) {
       ngroupsSnapshot = ngroups;
       if (groups != null) {
         groupsSnapshot = new ThreadGroup[ngroupsSnapshot];
         System.arraycopy(groups, 0, groupsSnapshot, 0, ngroupsSnapshot);
       } else {
         groupsSnapshot = null;
       }
     }
   }
   if (recurse) {
     for (int i = 0; i < ngroupsSnapshot; i++) {
       n = groupsSnapshot[i].enumerate(list, n, true);
     }
   }
   return n;
 }
Пример #4
0
  /**
   * Adds post advices to the pointcut.
   *
   * @param advicesToAdd the advices to add
   */
  public void addPostAdvices(final String[] advicesToAdd) {
    for (int i = 0; i < advicesToAdd.length; i++) {
      if (advicesToAdd[i] == null || advicesToAdd[i].trim().length() == 0)
        throw new IllegalArgumentException(
            "name of advice to add can not be null or an empty string");
    }
    synchronized (m_postNames) {
      synchronized (m_postIndexes) {
        final String[] clone = new String[advicesToAdd.length];
        java.lang.System.arraycopy(advicesToAdd, 0, clone, 0, advicesToAdd.length);

        final String[] tmp = new String[m_postNames.length + advicesToAdd.length];
        java.lang.System.arraycopy(m_postNames, 0, tmp, 0, m_postNames.length);
        java.lang.System.arraycopy(clone, 0, tmp, m_postNames.length, tmp.length);

        m_postNames = new String[tmp.length];
        java.lang.System.arraycopy(tmp, 0, m_postNames, 0, tmp.length);

        m_postIndexes = new IndexTuple[m_postNames.length];
        for (int j = 0; j < m_postNames.length; j++) {
          m_postIndexes[j] = SystemLoader.getSystem(m_uuid).getAdviceIndexFor(m_postNames[j]);
        }
      }
    }
  }
Пример #5
0
 /**
  * Removes a StmtLine (0..*).
  *
  * @param index The index of the StmtLine to get.
  */
 public void removeStmtLine(int index) {
   if (this.stmtLine == null) throw new java.lang.ArrayIndexOutOfBoundsException();
   biz.c24.io.training.statements.StatementLine[] temp = this.stmtLine;
   this.stmtLine = new biz.c24.io.training.statements.StatementLine[temp.length - 1];
   java.lang.System.arraycopy(temp, 0, this.stmtLine, 0, index);
   java.lang.System.arraycopy(temp, index + 1, this.stmtLine, index, temp.length - index - 1);
   if (this.stmtLine.length == 0) this.stmtLine = null;
 }
 static final AttributeDefinition[] concat(
     AttributeDefinition[] common, AttributeDefinition... specific) {
   int size = common.length + specific.length;
   AttributeDefinition[] result = new AttributeDefinition[size];
   arraycopy(common, 0, result, 0, common.length);
   arraycopy(specific, 0, result, common.length, specific.length);
   return result;
 }
Пример #7
0
  /**
   * Appends the given array to this array.
   *
   * @param aas The array to append to this one.
   * @return A new array that has appended the given array.
   */
  public Array<A> append(final Array<A> aas) {
    final Object[] x = new Object[a.length + aas.a.length];

    arraycopy(a, 0, x, 0, a.length);
    arraycopy(aas.a, 0, x, a.length, aas.a.length);

    return new Array<A>(x);
  }
Пример #8
0
 public void write(byte[] buffer, int offset, int length) {
   if (count + length >= bytes.length) {
     byte[] newBytes = new byte[(count + length) * 2];
     System.arraycopy(bytes, 0, newBytes, 0, count);
     bytes = newBytes;
   }
   System.arraycopy(buffer, offset, bytes, count, length);
   count += length;
 }
Пример #9
0
 /**
  * Insert a subarray of the <code>char[]</code> argument into this <code>StringBuffer</code>.
  *
  * @param offset the place to insert in this buffer
  * @param str the <code>char[]</code> to insert
  * @param str_offset the index in <code>str</code> to start inserting from
  * @param len the number of characters to insert
  * @return this <code>StringBuffer</code>
  * @throws NullPointerException if <code>str</code> is <code>null</code>
  * @throws StringIndexOutOfBoundsException if any index is out of bounds
  * @since 1.2
  */
 public synchronized StringBuffer insert(int offset, char[] str, int str_offset, int len) {
   if (offset < 0 || offset > count || len < 0 || str_offset < 0 || str_offset > str.length - len)
     throw new StringIndexOutOfBoundsException();
   ensureCapacity_unsynchronized(count + len);
   System.arraycopy(value, offset, value, offset + len, count - offset);
   System.arraycopy(str, str_offset, value, offset, len);
   count += len;
   return this;
 }
  public Object decode(InputStream inStream) throws IOException {
    LinkedList<byte[]> blocks = new LinkedList<byte[]>();
    byte[] curr = new byte[BLOCK_SIZE];
    blocks.add(curr);

    int totalRead = 0;
    int read;

    for (int i = 0; i < curr.length; i++) {
      totalRead += (read = inStream.read(curr));
      if (read < curr.length) break;
      blocks.add(curr = new byte[BLOCK_SIZE]);
    }

    byte[] newByte = new byte[totalRead];
    int offset = 0;
    int copySize;
    for (byte[] block : blocks) {
      if ((totalRead - (block.length + offset)) < 0) {
        copySize = totalRead % block.length;
      } else {
        copySize = block.length;
      }
      arraycopy(block, 0, newByte, offset, copySize);
      offset += block.length;
    }

    return decode(newByte);
  }
Пример #11
0
 private static HardDisk[] getHardDisks(Properties props, String propPrefix) {
   HardDisk[] rv = null;
   if (props != null) {
     for (int i = 0; i < 2; i++) {
       HardDisk disk = null;
       String prefix = String.format("%sharddisk.%d.", propPrefix, i + 1);
       String diskModel = EmuUtil.getProperty(props, prefix + "model");
       String fileName = EmuUtil.getProperty(props, prefix + "file");
       if (!diskModel.isEmpty() && !fileName.isEmpty()) {
         int c = EmuUtil.getIntProperty(props, prefix + "cylinders", 0);
         int h = EmuUtil.getIntProperty(props, prefix + "heads", 0);
         int n = EmuUtil.getIntProperty(props, prefix + "sectors_per_track", 0);
         if ((c > 0) && (h > 0) && (n > 0)) {
           disk = new HardDisk(diskModel, c, h, n, fileName);
         }
       }
       if (disk != null) {
         if (rv != null) {
           HardDisk[] a = new HardDisk[rv.length + 1];
           System.arraycopy(rv, 0, a, 0, rv.length);
           rv = a;
         } else {
           rv = new HardDisk[1];
         }
         rv[rv.length - 1] = disk;
       }
     }
   }
   return rv;
 }
Пример #12
0
 char[] toCharArray() {
   // Arrays.copyOfRange() requires Java 6
   int size = size();
   char[] result = new char[size];
   arraycopy(array, start, result, 0, size);
   return result;
 }
 void list(PrintStream out, int indent) {
   int ngroupsSnapshot;
   ThreadGroup[] groupsSnapshot;
   synchronized (this) {
     for (int j = 0; j < indent; j++) {
       out.print(" ");
     }
     out.println(this);
     indent += 4;
     for (int i = 0; i < nthreads; i++) {
       for (int j = 0; j < indent; j++) {
         out.print(" ");
       }
       out.println(threads[i]);
     }
     ngroupsSnapshot = ngroups;
     if (groups != null) {
       groupsSnapshot = new ThreadGroup[ngroupsSnapshot];
       System.arraycopy(groups, 0, groupsSnapshot, 0, ngroupsSnapshot);
     } else {
       groupsSnapshot = null;
     }
   }
   for (int i = 0; i < ngroupsSnapshot; i++) {
     groupsSnapshot[i].list(out, indent);
   }
 }
 private int enumerate(Thread list[], int n, boolean recurse) {
   int ngroupsSnapshot = 0;
   ThreadGroup[] groupsSnapshot = null;
   synchronized (this) {
     if (destroyed) {
       return 0;
     }
     int nt = nthreads;
     if (nt > list.length - n) {
       nt = list.length - n;
     }
     for (int i = 0; i < nt; i++) {
       if (threads[i].isAlive()) {
         list[n++] = threads[i];
       }
     }
     if (recurse) {
       ngroupsSnapshot = ngroups;
       if (groups != null) {
         groupsSnapshot = new ThreadGroup[ngroupsSnapshot];
         System.arraycopy(groups, 0, groupsSnapshot, 0, ngroupsSnapshot);
       } else {
         groupsSnapshot = null;
       }
     }
   }
   if (recurse) {
     for (int i = 0; i < ngroupsSnapshot; i++) {
       n = groupsSnapshot[i].enumerate(list, n, true);
     }
   }
   return n;
 }
Пример #15
0
 public static char[] copyOfRange(final char[] a, final int from, final int to) {
   final int len = to - from;
   if (len < 0) throw new IllegalArgumentException(from + " > " + to);
   final char[] copy = new char[len];
   System.arraycopy(a, from, copy, 0, Math.min(a.length - from, len));
   return copy;
 }
    /**
     * Create the element from this builder.
     *
     * @return Element
     */
    public Element create() {
      mRS.validate();
      Element[] ein = new Element[mCount];
      String[] sin = new String[mCount];
      int[] asin = new int[mCount];
      java.lang.System.arraycopy(mElements, 0, ein, 0, mCount);
      java.lang.System.arraycopy(mElementNames, 0, sin, 0, mCount);
      java.lang.System.arraycopy(mArraySizes, 0, asin, 0, mCount);

      long[] ids = new long[ein.length];
      for (int ct = 0; ct < ein.length; ct++) {
        ids[ct] = ein[ct].getID(mRS);
      }
      long id = mRS.nElementCreate2(ids, sin, asin);
      return new Element(id, mRS, ein, sin, asin);
    }
 /**
  * Destroys this thread group and all of its subgroups. This thread group must be empty,
  * indicating that all threads that had been in this thread group have since stopped.
  *
  * <p>First, the <code>checkAccess</code> method of this thread group is called with no arguments;
  * this may result in a security exception.
  *
  * @exception IllegalThreadStateException if the thread group is not empty or if the thread group
  *     has already been destroyed.
  * @exception SecurityException if the current thread cannot modify this thread group.
  * @see java.lang.ThreadGroup#checkAccess()
  * @since JDK1.0
  */
 public final void destroy() {
   int ngroupsSnapshot;
   ThreadGroup[] groupsSnapshot;
   synchronized (this) {
     checkAccess();
     if (destroyed || (nthreads > 0)) {
       throw new IllegalThreadStateException();
     }
     ngroupsSnapshot = ngroups;
     if (groups != null) {
       groupsSnapshot = new ThreadGroup[ngroupsSnapshot];
       System.arraycopy(groups, 0, groupsSnapshot, 0, ngroupsSnapshot);
     } else {
       groupsSnapshot = null;
     }
     if (parent != null) {
       destroyed = true;
       ngroups = 0;
       groups = null;
       nthreads = 0;
       threads = null;
     }
   }
   for (int i = 0; i < ngroupsSnapshot; i += 1) {
     groupsSnapshot[i].destroy();
   }
   if (parent != null) {
     parent.remove(this);
   }
 }
Пример #18
0
 long[] toLongArray() {
   // Arrays.copyOfRange() requires Java 6
   int size = size();
   long[] result = new long[size];
   arraycopy(array, start, result, 0, size);
   return result;
 }
Пример #19
0
 private PASSTHRU_MSG passThruMessage(byte... data) {
   PASSTHRU_MSG msg = passThruMessage();
   msg.dataSize = new NativeLong(data.length);
   arraycopy(data, 0, msg.data, 0, data.length);
   msg.write();
   return msg;
 }
        @Override
        public void onPreviewFrame(byte[] data, Camera camera) {
          if (!mMoSyncPreviewFrameEventEnabled) {
            if (!mMoSyncPreviewAutoFocusEventEnabled) {
              // Return the buffer if in use
              if (mIsUsingPreviewCallbackBuffer) camera.addCallbackBuffer(data);

              return;
            }

            if (!mMoSyncPreviewHasFocus) {
              // Return the buffer if in use
              if (mIsUsingPreviewCallbackBuffer) camera.addCallbackBuffer(data);

              return;
            }

            // Restore the flag for the next auto focus event
            mMoSyncPreviewHasFocus = false;
          }

          if (!mSendEvent) {
            // Return the buffer if in use
            if (mIsUsingPreviewCallbackBuffer) camera.addCallbackBuffer(data);

            return;
          }

          lock.lock();

          try {
            if (data != null) {
              mSendEvent = false;

              System.arraycopy(data, 0, mImageBuffer, 0, data.length);

              // To the time consuming task in a new thread
              new Thread(
                      new Runnable() {
                        public void run() {
                          YUV420toRGB8888();

                          int[] event = new int[1];
                          event[0] = MAAPI_consts.EVENT_TYPE_CAMERA_PREVIEW;
                          mMoSyncThread.postEvent(event);
                        }
                      })
                  .start();
            }

          } catch (Exception e) {
            Log.i("Camera API", "Got exception:" + e.toString());
          } finally {
            lock.unlock();

            // Return the buffer if in use
            if (mIsUsingPreviewCallbackBuffer) camera.addCallbackBuffer(data);
          }
        }
Пример #21
0
 public void write(int b) {
   if (count == bytes.length) {
     byte[] newBytes = new byte[count * 2];
     System.arraycopy(bytes, 0, newBytes, 0, count);
     bytes = newBytes;
   }
   bytes[count++] = (byte) b;
 }
Пример #22
0
 /**
  * Insert the <code>char</code> argument into this <code>StringBuffer</code>.
  *
  * @param offset the place to insert in this buffer
  * @param ch the <code>char</code> to insert
  * @return this <code>StringBuffer</code>
  * @throws StringIndexOutOfBoundsException if offset is out of bounds
  */
 public synchronized StringBuffer insert(int offset, char ch) {
   if (offset < 0 || offset > count) throw new StringIndexOutOfBoundsException(offset);
   ensureCapacity_unsynchronized(count + 1);
   System.arraycopy(value, offset, value, offset + 1, count - offset);
   value[offset] = ch;
   count++;
   return this;
 }
Пример #23
0
 public byte[] toByteArray() {
   if (count == bytes.length) {
     return bytes;
   }
   byte[] result = new byte[count];
   System.arraycopy(bytes, 0, result, 0, count);
   return result;
 }
Пример #24
0
 /**
  * Append part of the <code>char</code> array to this <code>StringBuffer</code>. This is similar
  * (but more efficient) than <code>append(new String(data, offset, count))</code>, except in the
  * case of null.
  *
  * @param data the <code>char[]</code> to append
  * @param offset the start location in <code>str</code>
  * @param count the number of characters to get from <code>str</code>
  * @return this <code>StringBuffer</code>
  * @throws NullPointerException if <code>str</code> is <code>null</code>
  * @throws IndexOutOfBoundsException if offset or count is out of range (while unspecified, this
  *     is a StringIndexOutOfBoundsException)
  */
 public synchronized StringBuffer append(char[] data, int offset, int count) {
   if (offset < 0 || count < 0 || offset > data.length - count)
     throw new StringIndexOutOfBoundsException();
   ensureCapacity_unsynchronized(this.count + count);
   System.arraycopy(data, offset, value, this.count, count);
   this.count += count;
   return this;
 }
Пример #25
0
 /**
  * Adds a StmtLine (0..*).
  *
  * @param value The new StmtLine.
  */
 public void addStmtLine(biz.c24.io.training.statements.StatementLine value) {
   biz.c24.io.training.statements.StatementLine[] temp = this.stmtLine;
   this.stmtLine =
       new biz.c24.io.training.statements.StatementLine[temp == null ? 1 : (temp.length + 1)];
   if (temp != null) java.lang.System.arraycopy(temp, 0, this.stmtLine, 0, temp.length);
   this.stmtLine[this.stmtLine.length - 1] = value;
   ((biz.c24.io.api.data.ComplexDataObject) value).setParent(this, "StmtLine");
 }
Пример #26
0
 @SuppressWarnings({"SuspiciousSystemArraycopy", "unchecked", "ObjectEquality", "RedundantCast"})
 public static <T, U> T[] copyOf(final U[] a, final int len, final Class<? extends T[]> newType) {
   final T[] copy =
       (Object) newType == Object[].class
           ? (T[]) new Object[len]
           : (T[]) java.lang.reflect.Array.newInstance(newType.getComponentType(), len);
   System.arraycopy(a, 0, copy, 0, Math.min(a.length, len));
   return copy;
 }
Пример #27
0
 private static final int[] createRankArray(final int[] input) {
   final int[] sorted = new int[input.length], ranks = new int[input.length];
   arraycopy(input, 0, sorted, 0, input.length);
   sort(sorted); // tuned quicksort, O(n log n)
   for (int i = 0; i < input.length; i++) {
     ranks[i] = indexOf(sorted, input[i]);
   }
   return ranks;
 }
Пример #28
0
 float[] flatten2DimArray(float[][] twoDimArray) {
   // Converts an array of two dimensions into a single dimension array row by row.
   float[] flatArray = new float[twoDimArray.length * twoDimArray[0].length];
   for (int row = 0; row < twoDimArray.length; row++) {
     int offset = row * twoDimArray[row].length;
     arraycopy(twoDimArray[row], 0, flatArray, offset, twoDimArray[row].length);
   }
   return flatArray;
 }
Пример #29
0
 /**
  * Delete characters from this <code>StringBuffer</code>. <code>delete(10, 12)</code> will delete
  * 10 and 11, but not 12. It is harmless for end to be larger than length().
  *
  * @param start the first character to delete
  * @param end the index after the last character to delete
  * @return this <code>StringBuffer</code>
  * @throws StringIndexOutOfBoundsException if start or end are out of bounds
  * @since 1.2
  */
 public synchronized StringBuffer delete(int start, int end) {
   if (start < 0 || start > count || start > end) throw new StringIndexOutOfBoundsException(start);
   if (end > count) end = count;
   // This will unshare if required.
   ensureCapacity_unsynchronized(count);
   if (count - end != 0) System.arraycopy(value, end, value, start, count - end);
   count -= end - start;
   return this;
 }
Пример #30
0
  public synchronized void readBandData(
      Band destBand,
      int sourceOffsetX,
      int sourceOffsetY,
      int sourceWidth,
      int sourceHeight,
      int sourceStepX,
      int sourceStepY,
      ProductData destBuffer,
      ProgressMonitor pm)
      throws IOException, InvalidRangeException {

    if (mustFlipY) {
      sourceOffsetY = destBand.getSceneRasterHeight() - (sourceOffsetY + sourceHeight);
    }
    if (mustFlipX) {
      sourceOffsetX = destBand.getSceneRasterWidth() - (sourceOffsetX + sourceWidth);
    }
    sourceOffsetY += leadLineSkip;
    start[0] = sourceOffsetY;
    start[1] = sourceOffsetX;
    stride[0] = sourceStepY;
    stride[1] = sourceStepX;
    count[0] = sourceHeight;
    count[1] = sourceWidth;
    Object buffer = destBuffer.getElems();
    Variable variable = variableMap.get(destBand);

    pm.beginTask("Reading band '" + variable.getShortName() + "'...", sourceHeight);
    try {
      Section section = new Section(start, count, stride);

      Array array;
      int[] newshape = {sourceHeight, sourceWidth};

      array = variable.read(section);
      if (array.getRank() == 3) {
        array = array.reshapeNoCopy(newshape);
      }
      Object storage;

      if (mustFlipX && !mustFlipY) {
        storage = array.flip(1).copyTo1DJavaArray();
      } else if (!mustFlipX && mustFlipY) {
        storage = array.flip(0).copyTo1DJavaArray();
      } else if (mustFlipX && mustFlipY) {
        storage = array.flip(0).flip(1).copyTo1DJavaArray();
      } else {
        storage = array.copyTo1DJavaArray();
      }

      arraycopy(storage, 0, buffer, 0, destBuffer.getNumElems());
    } finally {
      pm.done();
    }
  }