public synchronized byte[] getExtendedRAM(int size) { byte[] rv = null; if (size > 0) { if (this.ramExtended != null) { if (size > this.ramExtended.length) { rv = new byte[size]; Arrays.fill(rv, (byte) 0); System.arraycopy(this.ramExtended, 0, rv, 0, this.ramExtended.length); this.ramExtended = rv; } else { rv = this.ramExtended; } } else { rv = new byte[size]; Arrays.fill(rv, (byte) 0); this.ramExtended = rv; } } return rv; }
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) }
/** 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 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; }
// extend the class path in order to search the path(s) designated with the parameter path also public void extendClassPath(String path) { // if path is already in the extension's loader class path do not reinsert it for (int k = 0; k < dirs.length; k++) { if (dirs[k].equals(path)) return; } String[] exDirs = path.split(System.getProperty("path.separator")); // vector with the paths to be added String[] newDirs = new String[dirs.length + exDirs.length + 1]; newDirs[0] = GlobalValues.jarFilePath; System.arraycopy(dirs, 0, newDirs, 1, dirs.length); // copy current path System.arraycopy(exDirs, 0, newDirs, dirs.length + 1, exDirs.length); // append new paths dirs = newDirs; }
/** * Robustly make a curve to a front * * @param curve the curve * @param flip true to flip the pips * @return the resulting front as a FieldImpl * @throws RemoteException On badness */ public FieldImpl robustCurveToFront(float[][] curve, boolean flip) throws RemoteException { // resample curve uniformly along length float increment = rsegment_length / (rprofile_length * zoom); float[][] oldCurve = null; try { oldCurve = resample_curve(curve, increment); } catch (VisADError ve) { // bad curve return null; } int fw = filter_window; fw = 1; FieldImpl front = null; float[][] originalCurve = curve; debug = true; for (int tries = 0; tries < 12; tries++) { // lowpass filter curve curve = smooth_curve(oldCurve, fw); // resample smoothed curve curve = resample_curve(curve, increment); try { front = curveToFront(curve, flip); break; } catch (VisADException e) { oldCurve = curve; if (tries > 4) { int n = oldCurve[0].length; if (n > 2) { float[][] no = new float[2][n - 2]; System.arraycopy(oldCurve[0], 1, no[0], 0, n - 2); System.arraycopy(oldCurve[1], 1, no[1], 0, n - 2); oldCurve = no; } } if (tries > 8) { fw = 2 * fw; } // if (debug) System.out.println("retry filter window = " + fw + " " + e); if (tries == 9) { // System.out.println("cannot smooth curve"); front = null; } } } return front; }
@NotNull private static PsiClass[] resolveClassReferenceList( @NotNull PsiClassType[] listOfTypes, @NotNull PsiManager manager, @NotNull GlobalSearchScope resolveScope, boolean includeObject) { PsiClass objectClass = JavaPsiFacade.getInstance(manager.getProject()) .findClass(CommonClassNames.JAVA_LANG_OBJECT, resolveScope); if (objectClass == null) includeObject = false; if (listOfTypes.length == 0) { if (includeObject) return new PsiClass[] {objectClass}; return PsiClass.EMPTY_ARRAY; } int referenceCount = listOfTypes.length; if (includeObject) referenceCount++; PsiClass[] resolved = new PsiClass[referenceCount]; int resolvedCount = 0; if (includeObject) resolved[resolvedCount++] = objectClass; for (PsiClassType reference : listOfTypes) { PsiClass refResolved = reference.resolve(); if (refResolved != null) resolved[resolvedCount++] = refResolved; } if (resolvedCount < referenceCount) { PsiClass[] shorter = new PsiClass[resolvedCount]; System.arraycopy(resolved, 0, shorter, 0, resolvedCount); resolved = shorter; } return resolved; }
/** 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(); } }
/** * 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); }
/** * Add the given filename to the list of plugins to be deleted on the next JabRef startup. * * @param filename The path to the file to delete. */ public static void schedulePluginForDeletion(String filename) { String[] oldValues = Globals.prefs.getStringArray("deletePlugins"); String[] newValues = oldValues == null ? new String[1] : new String[oldValues.length + 1]; if (oldValues != null) System.arraycopy(oldValues, 0, newValues, 0, oldValues.length); newValues[newValues.length - 1] = filename; Globals.prefs.putStringArray("deletePlugins", newValues); }
/** * 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; }
// -------------------------------------------------- public void recvUpdate(RouterPacket pkt) { System.arraycopy(pkt.mincost, 0, neighbourVectors[pkt.sourceid], 0, RouterSimulator.NUM_NODES); boolean dirty = recalculateCost(); if (dirty) { sendVectors(); } }
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 DataFlavor[] getTransferDataFlavors() { DataFlavor[] richerFlavors = getRicherFlavors(); int nRicher = (richerFlavors != null) ? richerFlavors.length : 0; int nHtml = (isHtmlSupported()) ? htmlFlavors.length : 0; int nPlain = (isPlainSupported()) ? plainFlavors.length : 0; int nString = (isPlainSupported()) ? stringFlavors.length : 0; int nImage = (isImageSupported()) ? stringFlavors.length : 0; int nFlavors = nRicher + nHtml + nPlain + nString + nImage; DataFlavor[] flavors = new DataFlavor[nFlavors]; // fill in the array int nDone = 0; if (nRicher > 0) { System.arraycopy(richerFlavors, 0, flavors, nDone, nRicher); nDone += nRicher; } if (nHtml > 0) { System.arraycopy(htmlFlavors, 0, flavors, nDone, nHtml); nDone += nHtml; } if (nPlain > 0) { System.arraycopy(plainFlavors, 0, flavors, nDone, nPlain); nDone += nPlain; } if (nString > 0) { System.arraycopy(stringFlavors, 0, flavors, nDone, nString); nDone += nString; } if (nImage > 0) { System.arraycopy(imageFlavors, 0, flavors, nDone, nImage); nDone += nImage; } return flavors; }
/** * Returns an array of DataFlavor objects indicating the flavors the data can be provided in. * The array should be ordered according to preference for providing the data (from most richly * descriptive to least descriptive). * * @return an array of data flavors in which this data can be transferred */ public DataFlavor[] getTransferDataFlavors() { int plainCount = (isPlainSupported()) ? plainFlavors.length : 0; int stringCount = (isPlainSupported()) ? stringFlavors.length : 0; int totalCount = plainCount + stringCount; DataFlavor[] flavors = new DataFlavor[totalCount]; // fill in the array int pos = 0; if (plainCount > 0) { System.arraycopy(plainFlavors, 0, flavors, pos, plainCount); pos += plainCount; } if (stringCount > 0) { System.arraycopy(stringFlavors, 0, flavors, pos, stringCount); // pos += stringCount; } return flavors; }
@NotNull private static PsiClass[] getSupersInner(@NotNull PsiClass psiClass) { PsiClassType[] extendsListTypes = psiClass.getExtendsListTypes(); PsiClassType[] implementsListTypes = psiClass.getImplementsListTypes(); if (psiClass.isInterface()) { return resolveClassReferenceList( extendsListTypes, psiClass.getManager(), psiClass.getResolveScope(), true); } if (psiClass instanceof PsiAnonymousClass) { PsiAnonymousClass psiAnonymousClass = (PsiAnonymousClass) psiClass; PsiClassType baseClassReference = psiAnonymousClass.getBaseClassType(); PsiClass baseClass = baseClassReference.resolve(); if (baseClass != null) { if (baseClass.isInterface()) { PsiClass objectClass = JavaPsiFacade.getInstance(psiClass.getProject()) .findClass(CommonClassNames.JAVA_LANG_OBJECT, psiClass.getResolveScope()); return objectClass != null ? new PsiClass[] {objectClass, baseClass} : new PsiClass[] {baseClass}; } return new PsiClass[] {baseClass}; } PsiClass objectClass = JavaPsiFacade.getInstance(psiClass.getProject()) .findClass(CommonClassNames.JAVA_LANG_OBJECT, psiClass.getResolveScope()); return objectClass != null ? new PsiClass[] {objectClass} : PsiClass.EMPTY_ARRAY; } if (psiClass instanceof PsiTypeParameter) { if (extendsListTypes.length == 0) { final PsiClass objectClass = JavaPsiFacade.getInstance(psiClass.getProject()) .findClass(CommonClassNames.JAVA_LANG_OBJECT, psiClass.getResolveScope()); return objectClass != null ? new PsiClass[] {objectClass} : PsiClass.EMPTY_ARRAY; } return resolveClassReferenceList( extendsListTypes, psiClass.getManager(), psiClass.getResolveScope(), false); } PsiClass[] interfaces = resolveClassReferenceList( implementsListTypes, psiClass.getManager(), psiClass.getResolveScope(), false); PsiClass superClass = getSuperClass(psiClass); if (superClass == null) return interfaces; PsiClass[] types = new PsiClass[interfaces.length + 1]; types[0] = superClass; System.arraycopy(interfaces, 0, types, 1, interfaces.length); return types; }
/** * 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 static void main(String[] args) { initData(); calculateXorsGrid(); printResultGrid(possibleLetters); for (int i = 0; i < possibleLetters.length; i++) System.arraycopy(possibleLetters[i], 0, resultLetters[i], 0, resultLetters[0].length); printResultGrid(resultLetters); calculateMostPossibleValues(); printResultGrid(resultLetters); manualDecryption(); }
private static byte[] getFileAsBytes(String path) throws IOException { int len = 0; int totalLen = 0; Object streamOrError = FileManager.getInputStream(path, false, null, null); if (streamOrError instanceof String) { LogPanel.log((String) streamOrError); return null; } byte[] buf = new byte[1024]; byte[] bytes = new byte[4096]; BufferedInputStream bis = new BufferedInputStream((InputStream) streamOrError); while ((len = bis.read(buf)) > 0) { totalLen += len; if (totalLen >= bytes.length) bytes = ArrayUtil.ensureLength(bytes, totalLen * 2); System.arraycopy(buf, 0, bytes, totalLen - len, len); } bis.close(); buf = new byte[totalLen]; System.arraycopy(bytes, 0, buf, 0, totalLen); return buf; }
public void userAsBlack() { ChessEngine.flipBoard(); for (int i = 0; i < 8; i++) { System.arraycopy(ChessEngine.chessboard[i], 0, chessboard[i], 0, 8); } ChessEngine.flipBoard(); System.out.println(ChessEngine.sortMoves2(ChessEngine.possibleMoves())); ChessEngine.makeMove(ChessEngine.printMove()); ChessEngine.flipBoard(); if (ChessEngine.possibleMoves().length() == 0) { System.out.println("Defeat"); } }
@NotNull private String[] getRecentFiles() { final String[] recent = PropertiesComponent.getInstance().getValues(RECENT_FILES_KEY); if (recent != null) { if (recent.length > 0 && myPathTextField.getField().getText().replace('\\', '/').equals(recent[0])) { final String[] pathes = new String[recent.length - 1]; System.arraycopy(recent, 1, pathes, 0, recent.length - 1); return pathes; } return recent; } return ArrayUtil.EMPTY_STRING_ARRAY; }
/** * Remove the first line from the passed byte array. * * @param inputArray The byte array to process * @return The processed byte array */ private static byte[] removeFirstLine(byte[] inputArray) { int offset = 0; while (offset < inputArray.length && (inputArray[offset] == 10 || inputArray[offset] == 13)) offset++; while (offset < inputArray.length && inputArray[offset] != 10 && inputArray[offset] != 13) offset++; while (offset < inputArray.length && (inputArray[offset] == 10 || inputArray[offset] == 13)) offset++; byte[] newArray = new byte[inputArray.length - offset]; System.arraycopy(inputArray, offset, newArray, 0, newArray.length); return newArray; }
@NotNull public static PsiClassType[] getSuperTypes(@NotNull PsiClass psiClass) { if (psiClass instanceof PsiAnonymousClass) { PsiClassType baseClassType = ((PsiAnonymousClass) psiClass).getBaseClassType(); PsiClass baseClass = baseClassType.resolve(); if (baseClass == null || !baseClass.isInterface()) { return new PsiClassType[] {baseClassType}; } else { PsiClassType objectType = PsiType.getJavaLangObject(psiClass.getManager(), psiClass.getResolveScope()); return new PsiClassType[] {objectType, baseClassType}; } } PsiClassType[] extendsTypes = psiClass.getExtendsListTypes(); PsiClassType[] implementsTypes = psiClass.getImplementsListTypes(); boolean hasExtends = extendsTypes.length != 0; int extendsListLength = extendsTypes.length + (hasExtends ? 0 : 1); PsiClassType[] result = new PsiClassType[extendsListLength + implementsTypes.length]; System.arraycopy(extendsTypes, 0, result, 0, extendsTypes.length); if (!hasExtends) { if (CommonClassNames.JAVA_LANG_OBJECT.equals(psiClass.getQualifiedName())) { return PsiClassType.EMPTY_ARRAY; } PsiManager manager = psiClass.getManager(); PsiClassType objectType = PsiType.getJavaLangObject(manager, psiClass.getResolveScope()); result[0] = objectType; } System.arraycopy(implementsTypes, 0, result, extendsListLength, implementsTypes.length); for (int i = 0; i < result.length; i++) { PsiClassType type = result[i]; result[i] = (PsiClassType) PsiUtil.captureToplevelWildcards(type, psiClass); } return result; }
/** Updates the matrix with current board and current pentomino */ public void updateMatrix() { int[][] tmpBoard = new int[gameBoard.getBoard().length][gameBoard.getBoard()[0].length]; // Copy the old board to the tmp for (int i = 0; i < gameBoard.getBoard().length; i++) { System.arraycopy(gameBoard.getBoard()[i], 0, tmpBoard[i], 0, gameBoard.getBoard()[i].length); } // Add the pentomino to the tmpBoard for (Point p : activePentomino.getLocation()) { int newX = (int) (pentominoLocation.getX() + p.getX()); int newY = (int) (pentominoLocation.getY() + p.getY()); if (newY >= 0) tmpBoard[newX][newY] = activePentomino.getID(); } matrix = tmpBoard; }
/** Adds the necessary number of elements to the Component array. */ private Component[] fillOut(Component[] c) { // warn the user System.err.println("Warning: spreadsheet cell layout is corrupted"); // add blank components to the layout Component[] nc = new Component[NumCols * NumRows]; System.arraycopy(c, 0, nc, 0, c.length); for (int i = c.length; i < nc.length; i++) { nc[i] = new JComponent() { public void paint(Graphics g) {} }; } return nc; }
// -------------------------------------------------- public RouterNode(int ID, RouterSimulator sim, int[] costs) { myID = ID; this.sim = sim; myGUI = new GuiTextArea(" Output window for Router #" + ID + " "); System.arraycopy(costs, 0, this.costs, 0, RouterSimulator.NUM_NODES); for (int i = 0; i < RouterSimulator.NUM_NODES; i++) { routes[i] = i; for (int j = 0; j < RouterSimulator.NUM_NODES; j++) { if (i == myID) neighbourVectors[i][j] = costs[j]; else neighbourVectors[i][j] = RouterSimulator.INFINITY; } } sendVectors(); }
public boolean play() { try { if (playState != STOPPED) playStop(); if (audioBytes == null) return false; DataLine.Info info = new DataLine.Info(Clip.class, format); clip = (Clip) AudioSystem.getLine(info); clip.addLineListener(new ClipListener()); long clipStart = (long) (audioBytes.length * getStartTime() / (getDuration() * 1000.0)); long clipEnd = (long) (audioBytes.length * getEndTime() / (getDuration() * 1000.0)); if ((clipEnd - clipStart) > MAX_CLIP_LENGTH) clipEnd = clipStart + MAX_CLIP_LENGTH; byte[] clipBytes = new byte[(int) (clipEnd - clipStart)]; System.arraycopy(audioBytes, (int) clipStart, clipBytes, 0, clipBytes.length); clip.open(format, clipBytes, 0, clipBytes.length); FloatControl panControl = (FloatControl) clip.getControl(FloatControl.Type.PAN); panControl.setValue((float) panSetting / 100.0f); double value = (double) gainSetting; FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); float dB = (float) (Math.log(value == 0.0 ? 0.0001 : value) / Math.log(10.0) * 20.0); gainControl.setValue(dB); double playStartTime = (player.getSeekTime() / 100) * (playGetLength()); clip.setMicrosecondPosition((long) playStartTime); clip.start(); playState = PLAYING; return true; } catch (Exception ex) { ex.printStackTrace(); playState = STOPPED; clip = null; return false; } }
protected void checkEDTRule(Component component) { if (violatesEDTRule(component)) { EDTRuleViolation violation = new EDTRuleViolation(component); StackTraceElement[] stackTrace = violation.getStackTrace(); try { for (int e = stackTrace.length - 1; e >= 0; e--) { if (isLiableToEDTRule(stackTrace[e])) { StackTraceElement[] subStackTrace = new StackTraceElement[stackTrace.length - e]; indicate(violation); System.arraycopy(stackTrace, e, subStackTrace, 0, subStackTrace.length); violation.setStackTrace(subStackTrace); } } } catch (Exception ex) { // keep stackTrace } indicate(violation); } }
// -------------------------------------------------- private void sendVectors() { for (int i = 0; i < RouterSimulator.NUM_NODES; i++) { if (i != myID) { if (costs[i] != RouterSimulator.INFINITY) { int[] c = new int[RouterSimulator.NUM_NODES]; System.arraycopy(costs, 0, c, 0, RouterSimulator.NUM_NODES); if (usePoisonedReverse) { // check if we are using the active node in some route for (int r = 0; r < RouterSimulator.NUM_NODES; r++) { if (routes[r] == i) { c[r] = RouterSimulator.INFINITY; } } } RouterPacket pkt = new RouterPacket(myID, i, c); sendUpdate(pkt); } } } }
/** * Returns an array of all of the selected indices in increasing order. * * @return all of the selected indices, in increasing order * @see #removeSelectionInterval * @see #addListSelectionListener */ public int[] getCheckBoxListSelectedIndices() { ListSelectionModel listSelectionModel = getCheckBoxListSelectionModel(); int iMin = listSelectionModel.getMinSelectionIndex(); int iMax = listSelectionModel.getMaxSelectionIndex(); if ((iMin < 0) || (iMax < 0)) { return new int[0]; } int[] temp = new int[1 + (iMax - iMin)]; int n = 0; for (int i = iMin; i <= iMax; i++) { if (listSelectionModel.isSelectedIndex(i)) { temp[n] = i; n++; } } int[] indices = new int[n]; System.arraycopy(temp, 0, indices, 0, n); return indices; }