/** push bytes back, to be read again later. */ private void pushback(byte[] bytes, int len) { if (pushbackBufferLen == 0) { pushbackBuffer = bytes; // TODO: copy? pushbackBufferLen = len; pushbackBufferOffset = 0; } else { final byte[] newPushbackBuffer = new byte[pushbackBufferLen + len]; System.arraycopy(pushbackBuffer, 0, newPushbackBuffer, 0, pushbackBufferLen); System.arraycopy(bytes, 0, newPushbackBuffer, pushbackBufferLen, len); pushbackBuffer = newPushbackBuffer; pushbackBufferLen = pushbackBufferLen + len; pushbackBufferOffset = 0; } }
public TestType1CFont(InputStream is) throws IOException { super(); setPreferredSize(new Dimension(800, 800)); addKeyListener(this); BufferedInputStream bis = new BufferedInputStream(is); int count = 0; ArrayList<byte[]> al = new ArrayList<byte[]>(); byte b[] = new byte[32000]; int len; while ((len = bis.read(b, 0, b.length)) >= 0) { byte[] c = new byte[len]; System.arraycopy(b, 0, c, 0, len); al.add(c); count += len; b = new byte[32000]; } data = new byte[count]; len = 0; for (int i = 0; i < al.size(); i++) { byte from[] = al.get(i); System.arraycopy(from, 0, data, len, from.length); len += from.length; } pos = 0; // printData(); parse(); // TODO: free up (set to null) unused structures (data, subrs, stack) }
public MenuElement[] getPath() { MenuSelectionManager menuselectionmanager = MenuSelectionManager.defaultManager(); MenuElement amenuelement[] = menuselectionmanager.getSelectedPath(); int i1 = amenuelement.length; if (i1 == 0) { return new MenuElement[0]; } Container container = menuItem.getParent(); MenuElement amenuelement1[]; if (amenuelement[i1 - 1].getComponent() == container) { amenuelement1 = new MenuElement[i1 + 1]; System.arraycopy(amenuelement, 0, amenuelement1, 0, i1); amenuelement1[i1] = menuItem; } else { int j1; for (j1 = amenuelement.length - 1; j1 >= 0; j1--) { if (amenuelement[j1].getComponent() == container) { break; } } amenuelement1 = new MenuElement[j1 + 2]; System.arraycopy(amenuelement, 0, amenuelement1, 0, j1 + 1); amenuelement1[j1 + 1] = menuItem; } return amenuelement1; }
/** Creates a copy of <code>from</code>. */ public Obj3d(Obj3d from, boolean register) { this(from.modelViewer, from.polygons.length, register); // make our storage same size as from's maxpoints = from.maxpoints; npoints = from.npoints; polynext = from.polynext; ps = new float[maxpoints * 3]; ps_ = new float[maxpoints * 3]; visibles = new boolean[maxpoints]; // copy co-ords data System.arraycopy(from.ps, 0, ps, 0, npoints * 3); // copy polygons for (int i = 0; i < from.polygons.length; i++) { Polygon fromPoly = from.polygons[i]; polygons[i] = new Polygon(fromPoly.n, fromPoly.c, fromPoly.doubleSided); System.arraycopy(fromPoly.points, 0, polygons[i].points, 0, fromPoly.points.length); } // copy shadows numShadows = from.numShadows; System.arraycopy(from.shadowCasters, 0, shadowCasters, 0, MAX_SHADOWS); for (int i = 0; i < numShadows; i++) { Polygon fromPoly = from.shadows[i]; shadows[i] = new Polygon(fromPoly.n, fromPoly.c, fromPoly.doubleSided); System.arraycopy(fromPoly.points, 0, shadows[i].points, 0, fromPoly.points.length); } }
/** * first and second elements of the array are x and y Mario coordinates correspondingly * * @return an array of size 2*(number of creatures on screen) including mario */ public float[] getCreaturesFloatPos() { float[] enemies = this.getEnemiesFloatPos(); float ret[] = new float[enemies.length + 2]; System.arraycopy(this.getMarioFloatPos(), 0, ret, 0, 2); System.arraycopy(enemies, 0, ret, 2, enemies.length); return ret; }
/** Trims all steps after endFrame. */ protected void trimSteps() { // return if trimming not needed VideoClip clip = trackerPanel.getPlayer().getVideoClip(); int n = clip.getFrameCount() - 1; int end = getEndFrame() == Integer.MAX_VALUE ? n : getEndFrame(); while (end > getStartFrame() && !clip.includesFrame(end)) { end--; } if (end >= lastValidFrame) return; int trimCount = (tracePtsPerStep * (lastValidFrame - end)) / clip.getStepSize(); ParticleModel[] models = getModels(); for (ParticleModel next : models) { // create smaller trace arrays and copy existing points into them next.locked = false; int traceLength = next.traceX.length - trimCount; if (traceLength < 0) return; // trap for error during closing next.prevX = next.traceX; next.prevY = next.traceY; next.traceX = new double[traceLength]; next.traceY = new double[traceLength]; System.arraycopy(next.prevX, 0, next.traceX, 0, traceLength); System.arraycopy(next.prevY, 0, next.traceY, 0, traceLength); // reduce number of steps next.steps.setLength(end + 1); // refresh derivatives next.updateDerivatives(end - 2, lastValidFrame - end + 2); // restore state restoreState(end); next.support.firePropertyChange("steps", null, null); // $NON-NLS-1$ next.locked = true; } lastValidFrame = end; repaint(); // trackerPanel.repaint(); }
public void run(String arg) { ImageWindow iw = WindowManager.getCurrentWindow(); pw = jutils.getPW4SelCopy(iw); String title = pw.getTitle(); float[][] yvals = pw.getYValues(); float[][] xvals = pw.getXValues(); int length = yvals[0].length; if (pw.getShowErrors()) errs = pw.getErrors(0, false); int[] colors = pw.getColors(); colors[0] = 0; ScriptEngineManager manager = new ScriptEngineManager(); engine = manager.getEngineByName("js"); ce = (Compilable) engine; // hitcounter=0; c2 = 0.0f; iterations = 0; checkc2 = false; double[] stats = new double[3]; tempx = new float[length]; tempdata = new float[length]; System.arraycopy(xvals[0], 0, tempx, 0, length); System.arraycopy(yvals[0], 0, tempdata, 0, length); pw.addPoints(tempx, new float[tempx.length], false); series = pw.getNpts().length - 1; double[] params = new double[10]; int[] fixes = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1}; init_options(params, fixes); if (!init_functions()) { return; } while (showoptions(params, fixes)) { NLLSfit_v2 fitclass; if (checkc2) { fitclass = new NLLSfit_v2(this, 0); } else { fitclass = new NLLSfit_v2(this, 0.0001, 50, 0.1); } float[] fit = fitclass.fitdata(params, fixes, constraints, yvals[0], weights, stats, true); pw.updateSeries(fit, series, false); c2 = (float) stats[1]; iterations = (int) stats[0]; } IJ.log("Chi Squared = " + (float) stats[1]); IJ.log("Iterations = " + (int) stats[0]); for (int i = 0; i < 10; i++) { IJ.log("P" + (i + 1) + " = " + (float) params[i] + " fixed = " + fixes[i]); } IJ.log("AIC = " + (float) stats[2]); // IJ.log("hits = "+hitcounter); set_options(params, fixes); }
// add a point x,y to the outline polygon private void addPoint(int x, int y) { if (npoints == maxPoints) { int[] xtemp = new int[maxPoints * 2]; int[] ytemp = new int[maxPoints * 2]; System.arraycopy(xpoints, 0, xtemp, 0, maxPoints); System.arraycopy(ypoints, 0, ytemp, 0, maxPoints); xpoints = xtemp; ypoints = ytemp; maxPoints *= 2; } xpoints[npoints] = x; ypoints[npoints] = y; npoints++; if (xmin > x) xmin = x; }
@Override public void insertRow(int row) { int[][][] oldSpan = span; int numRows = oldSpan.length; int numColumns = oldSpan[0].length; span = new int[numRows + 1][numColumns][2]; if (0 < row) { System.arraycopy(oldSpan, 0, span, 0, row - 1); } System.arraycopy(oldSpan, 0, span, row, numRows - row); for (int i = 0; i < numColumns; i++) { span[row][i][COLUMN] = 1; span[row][i][ROW] = 1; } }
private void copyStx(RasterDataNode sourceRaster, RasterDataNode targetRaster) { final Stx sourceStx = sourceRaster.getStx(); final Histogram sourceHistogram = sourceStx.getHistogram(); final Histogram targetHistogram = new Histogram( sourceStx.getHistogramBinCount(), sourceHistogram.getLowValue(0), sourceHistogram.getHighValue(0), 1); System.arraycopy( sourceHistogram.getBins(0), 0, targetHistogram.getBins(0), 0, sourceStx.getHistogramBinCount()); final Stx targetStx = new Stx( sourceStx.getMinimum(), sourceStx.getMaximum(), sourceStx.getMean(), sourceStx.getStandardDeviation(), sourceStx.getCoefficientOfVariation(), sourceStx.getEquivalentNumberOfLooks(), sourceStx.isLogHistogram(), sourceStx.isIntHistogram(), targetHistogram, sourceStx.getResolutionLevel()); targetRaster.setStx(targetStx); }
/*------------------------------------------------------------------*/ void getHessian(double[] c) { double h[] = {-2.0, 1.0}; double s[] = new double[c.length]; symmetricFirMirrorOnBounds(h, c, s); System.arraycopy(s, 0, c, 0, s.length); } /* end getHessian */
/*------------------------------------------------------------------*/ void getGradient(double[] c) { double h[] = {0.0, -1.0 / 2.0}; double s[] = new double[c.length]; antiSymmetricFirMirrorOnBounds(h, c, s); System.arraycopy(s, 0, c, 0, s.length); } /* end getGradient */
/** * Adds a point to the list. First scan through the list to see if we already have a point with * identical coords. If so, return index of that point. */ int addPoint(float x, float y, float z) { int index = -1; for (int i = 0; i < npoints * 3; i += 3) { if (ps[i] == x && ps[i + 1] == y && ps[i + 2] == z) { index = i; break; } } if (index != -1) { // we already have this point - just return its index return index; } else { // add point if (npoints >= maxpoints) { // double array size maxpoints *= 2; float[] qs = new float[maxpoints * 3]; System.arraycopy(ps, 0, qs, 0, ps.length); ps = qs; ps_ = new float[maxpoints * 3]; visibles = new boolean[maxpoints]; } int i = npoints * 3; ps[i] = x; ps[i + 1] = y; ps[i + 2] = z; npoints++; return i; } }
/** Opens the SubMenu */ public void menuKeyTyped(MenuKeyEvent e) { if (!crossMenuMnemonic) { JPopupMenu pm = getActivePopupMenu(); if (pm != null && pm != menuItem.getParent()) { return; } } int key = menuItem.getMnemonic(); if (key == 0) return; MenuElement path[] = e.getPath(); if (lower((char) key) == lower(e.getKeyChar())) { JPopupMenu popupMenu = ((JMenu) menuItem).getPopupMenu(); MenuElement sub[] = popupMenu.getSubElements(); if (sub.length > 0) { MenuSelectionManager manager = e.getMenuSelectionManager(); MenuElement newPath[] = new MenuElement[path.length + 2]; System.arraycopy(path, 0, newPath, 0, path.length); newPath[path.length] = popupMenu; newPath[path.length + 1] = sub[0]; manager.setSelectedPath(newPath); } e.consume(); } }
/** @see java.awt.im.spi.InputMethodDescriptor#getAvailableLocales */ public Locale[] getAvailableLocales() { // returns a copy of internal list for public API Object[] locales = getAvailableLocalesInternal(); Locale[] tmp = new Locale[locales.length]; System.arraycopy(locales, 0, tmp, 0, locales.length); return tmp; }
/** * Return pixel value at coordinates (<code>x</code>, <code>y</code>). Use {@code dest} to store * the value. * * @param x x is the width * @param y y is the height * @param dest array to store pixel value, can be {@code null}. If null it wll be instantiated * @return pixel value. */ public float[] get(final int x, final int y, float[] dest) { /* If the values of x and y are not legal */ if (x < 0 || x >= width || y < 0 || y >= height) { throw new IllegalArgumentException( "Value of coordinates (x,y)=(" + x + "," + y + ") is out of range [" + width + "," + height + "]."); } /* If dest is null, instantiate it */ if (dest == null) { dest = new float[numberOfValues]; } else { if (dest.length != numberOfValues) { throw new IllegalArgumentException("Invalid length of array dest."); } } /* Computing the row position in pixels and copying the array into dest */ final int offset = x + y * width; final float[] v = pixels[offset]; System.arraycopy(v, 0, dest, 0, v.length); return dest; }
/** * Adds new reading list URL. * * @param aNewListURL new reading list. */ public void addList(URL aNewListURL) { ReadingList[] newList = new ReadingList[lists.length + 1]; System.arraycopy(lists, 0, newList, 0, lists.length); newList[lists.length] = new ReadingList(aNewListURL); setLists(newList); }
/** * Returns an array of the values for the selected cells. The returned values are sorted in * increasing index order. * * @return the selected values or an empty list if nothing is selected * @see #isSelectedIndex * @see #getModel * @see #addListSelectionListener */ public Object[] getCheckBoxListSelectedValues() { CheckBoxListSelectionModel listSelectionModel = getCheckBoxListSelectionModel(); ListModel model = getModel(); int iMin = listSelectionModel.getMinSelectionIndex(); int iMax = listSelectionModel.getMaxSelectionIndex(); if ((iMin < 0) || (iMax < 0)) { return new Object[0]; } Object[] temp = new Object[1 + (iMax - iMin)]; int n = 0; for (int i = iMin; i <= iMax; i++) { if (listSelectionModel.isAllEntryConsidered() && i == listSelectionModel.getAllEntryIndex()) { continue; } if (listSelectionModel.isSelectedIndex(i)) { temp[n] = model.getElementAt(i); n++; } } Object[] indices = new Object[n]; System.arraycopy(temp, 0, indices, 0, n); return indices; }
void ToIndexedColor(byte r[][], byte g[][], byte b[][]) throws AWTException { pixels_ = new byte[width_ * height_]; colors_ = new byte[256 * 3]; int colornum = 0; for (int x = 0; x < width_; ++x) { for (int y = 0; y < height_; ++y) { int search; for (search = 0; search < colornum; ++search) if (colors_[search * 3] == r[x][y] && colors_[search * 3 + 1] == g[x][y] && colors_[search * 3 + 2] == b[x][y]) break; if (search > 255) throw new AWTException("Too many colors."); pixels_[y * width_ + x] = (byte) search; if (search == colornum) { colors_[search * 3] = r[x][y]; colors_[search * 3 + 1] = g[x][y]; colors_[search * 3 + 2] = b[x][y]; ++colornum; } } } numColors_ = 1 << BitUtils.BitsNeeded(colornum); byte copy[] = new byte[numColors_ * 3]; System.arraycopy(colors_, 0, copy, 0, numColors_ * 3); colors_ = copy; }
/** * Creates an image containing pixels read from the screen. * * @param bounds the rect to capture in screen coordinates * @return the array of pixels */ @Override public int[] getRGBPixels(final Rectangle bounds) { Rectangle screenBounds = fDevice.getDefaultConfiguration().getBounds(); // screenBounds is in the coordinates of the primary device // but bounds is in the coordinates of fDevice // so we fix screenbounds at 0,0 origin screenBounds.x = screenBounds.y = 0; Rectangle intersection = screenBounds.intersection(bounds); int c[] = new int[intersection.width * intersection.height]; getScreenPixels(intersection, c); if (!intersection.equals(bounds)) { // Since we are returning a smaller array than the code expects, // we have to copy our existing array into an array of the // "correct" size int c2[] = new int[bounds.width * bounds.height]; for (int h = 0; h < bounds.height; h++) { int boundsRow = h + bounds.y; if (boundsRow >= intersection.y && boundsRow < intersection.height) { int srcPos = (boundsRow - intersection.y) * intersection.width; int destPos = (h * bounds.width) + (intersection.x - bounds.x); System.arraycopy(c, srcPos, c2, destPos, intersection.width); } } c = c2; } return c; }
private static void copyData( ProductData sourceBuffer, int sourcePos, ProductData destBuffer, int destPos, int destLength) { System.arraycopy( sourceBuffer.getElems(), sourcePos, destBuffer.getElems(), destPos, destLength); }
private void refresh() { int maxIndex = mySeverityRegistrar.getSeverityMaxIndex(); if (errorCount != null && maxIndex == errorCount.length) return; int[] newErrors = new int[maxIndex]; if (errorCount != null) { System.arraycopy(errorCount, 0, newErrors, 0, Math.min(errorCount.length, newErrors.length)); } errorCount = newErrors; }
public void addPopulation2History(Population pop) { InterfaceOptimizationObjective[] tmpObj = null; if (this.show == null) { this.use = new boolean[1]; this.use[0] = true; this.show = new boolean[1]; this.show[0] = true; this.colors = new Color[1]; this.colors[0] = this.getColor4Index(0); } else { boolean[] newUse = new boolean[this.show.length + 1]; boolean[] newShow = new boolean[this.show.length + 1]; Color[] newColor = new Color[this.show.length + 1]; for (int i = 0; i < this.show.length; i++) { newUse[i] = this.use[i]; newShow[i] = this.show[i]; newColor[i] = this.colors[i]; } newUse[show.length] = true; newShow[show.length] = true; newColor[show.length] = this.getColor4Index(this.populationHistory.length); this.use = newUse; this.show = newShow; this.colors = newColor; } Population[] newPop = new Population[this.populationHistory.length + 1]; System.arraycopy(this.populationHistory, 0, newPop, 0, this.populationHistory.length); newPop[newPop.length - 1] = (Population) pop.clone(); newPop[newPop.length - 1].addPopulation(newPop[newPop.length - 1].getArchive()); newPop[newPop.length - 1].SetArchive(null); this.populationHistory = newPop; ArrayList fitness = new ArrayList(); ArrayList objectives = new ArrayList(); ArrayList constraint = new ArrayList(); if (this.currentProblem instanceof InterfaceMultiObjectiveDeNovoProblem) { tmpObj = ((InterfaceMultiObjectiveDeNovoProblem) this.currentProblem).getProblemObjectives(); } for (int j = 0; j < newPop[newPop.length - 1].size(); j++) { if (tmpObj != null) { double[] tmoF = new double[tmpObj.length]; for (int k = 0; k < tmpObj.length; k++) { tmoF[k] = (Double) newPop[newPop.length - 1].get(j).getData(tmpObj[k].getIdentName()); } objectives.add(tmoF); } fitness.add(newPop[newPop.length - 1].get(j).getFitness()); constraint.add(newPop[newPop.length - 1].get(j).getConstraintViolation()); } if (this.objectiveCache != null) { this.objectiveCache.add(objectives); } this.fitnessCache.add(fitness); this.constraintCache.add(constraint); }
/** supports pushback. */ private int read(byte[] buffer, int offset, int length) throws IOException { if (pushbackBufferLen > 0) { // read from pushback buffer final int lenToCopy = length < pushbackBufferLen ? length : pushbackBufferLen; System.arraycopy(pushbackBuffer, pushbackBufferOffset, buffer, offset, lenToCopy); pushbackBufferLen -= lenToCopy; pushbackBufferOffset += lenToCopy; return lenToCopy; } else { return stream.read(buffer, offset, length); } }
/** * Sets the output text. * * @param out cached output */ public void setText(final ArrayOutput out) { final byte[] buf = out.buffer(); final int size = (int) out.size(); final byte[] chop = token(DOTS); if (out.finished() && size >= chop.length) { System.arraycopy(chop, 0, buf, size - chop.length, chop.length); } text.setText(buf, size); header.setText((out.finished() ? CHOPPED : "") + RESULT); home.setEnabled(gui.context.data() != null); }
public Polygon2D(double[] x, double[] y) { if (x.length != y.length) { throw new RuntimeException("Unbalanced arrays"); } if (x[0] != x[x.length - 1] && y[0] != y[y.length - 1]) { double[] newX = new double[x.length + 1]; double[] newY = new double[y.length + 1]; System.arraycopy(x, 0, newX, 0, x.length); System.arraycopy(y, 0, newY, 0, y.length); newX[x.length] = x[0]; newY[y.length] = y[0]; this.x = newX; this.y = newY; } else { this.x = x; this.y = y; } length = this.x.length - 1; }
/** * Replaces child views. If there are no views to remove this acts as an insert. If there are no * views to add this acts as a remove. Views being removed will have the parent set to <code>null * </code>, and the internal reference to them removed so that they may be garbage collected. * * @param offset the starting index into the child views to insert the new views; >= 0 and * <= getViewCount * @param length the number of existing child views to remove; this should be a value >= 0 and * <= (getViewCount() - offset) * @param views the child views to add; this value can be <code>null</code> to indicate no * children are being added (useful to remove) */ public void replace(int offset, int length, View[] views) { // make sure an array exists if (views == null) { views = ZERO; } // update parent reference on removed views for (int i = offset; i < offset + length; i++) { if (children[i].getParent() == this) { // in FlowView.java view might be referenced // from two super-views as a child. see logicalView children[i].setParent(null); } children[i] = null; } // update the array int delta = views.length - length; int src = offset + length; int nmove = nchildren - src; int dest = src + delta; if ((nchildren + delta) >= children.length) { // need to grow the array int newLength = Math.max(2 * children.length, nchildren + delta); View[] newChildren = new View[newLength]; System.arraycopy(children, 0, newChildren, 0, offset); System.arraycopy(views, 0, newChildren, offset, views.length); System.arraycopy(children, src, newChildren, dest, nmove); children = newChildren; } else { // patch the existing array System.arraycopy(children, src, children, dest, nmove); System.arraycopy(views, 0, children, offset, views.length); } nchildren = nchildren + delta; // update parent reference on added views for (int i = 0; i < views.length; i++) { views[i].setParent(this); } }
@Override public void addColumn() { int[][][] oldSpan = span; int numRows = oldSpan.length; int numColumns = oldSpan[0].length; span = new int[numRows][numColumns + 1][2]; System.arraycopy(oldSpan, 0, span, 0, numRows); for (int i = 0; i < numRows; i++) { span[i][numColumns][COLUMN] = 1; span[i][numColumns][ROW] = 1; } }
public void method345() { int ai[] = new int[anInt1444 * anInt1445]; for (int j = 0; j < myHeight; j++) { System.arraycopy(myPixels, j * myWidth, ai, j + anInt1443 * anInt1444 + anInt1442, myWidth); } myPixels = ai; myWidth = anInt1444; myHeight = anInt1445; anInt1442 = 0; anInt1443 = 0; }
void enlargeArrays() { if (xp != null) { int[] xptemp = new int[maxPoints * 2]; int[] yptemp = new int[maxPoints * 2]; System.arraycopy(xp, 0, xptemp, 0, maxPoints); System.arraycopy(yp, 0, yptemp, 0, maxPoints); xp = xptemp; yp = yptemp; } if (xpf != null) { float[] xpftemp = new float[maxPoints * 2]; float[] ypftemp = new float[maxPoints * 2]; System.arraycopy(xpf, 0, xpftemp, 0, maxPoints); System.arraycopy(ypf, 0, ypftemp, 0, maxPoints); xpf = xpftemp; ypf = ypftemp; } int[] xp2temp = new int[maxPoints * 2]; int[] yp2temp = new int[maxPoints * 2]; System.arraycopy(xp2, 0, xp2temp, 0, maxPoints); System.arraycopy(yp2, 0, yp2temp, 0, maxPoints); xp2 = xp2temp; yp2 = yp2temp; if (IJ.debugMode) IJ.log("PolygonRoi: " + maxPoints + " points"); maxPoints *= 2; }