/** * Sets the output text. * * @param t output text * @param s text size */ public final void setText(final byte[] t, final int s) { // remove invalid characters and compare old with new string int ns = 0; final int ts = text.size(); final byte[] tt = text.text(); boolean eq = true; for (int r = 0; r < s; ++r) { final byte b = t[r]; // support characters, highlighting codes, tabs and newlines if (b >= ' ' || b <= TokenBuilder.MARK || b == 0x09 || b == 0x0A) { t[ns++] = t[r]; } eq &= ns < ts && ns < s && t[ns] == tt[ns]; } eq &= ns == ts; // new text is different... if (!eq) { text = new BaseXTextTokens(Arrays.copyOf(t, ns)); rend.setText(text); scroll.pos(0); } if (undo != null) undo.store(t.length != ns ? Arrays.copyOf(t, ns) : t, 0); SwingUtilities.invokeLater(calc); }
public static ClusterData makeCd( final int lane, final int tile, final int xCoord, final int yCoord, final boolean pf, final byte[] bases, final byte[] qualities, final String matchedBarcode) { final ReadData rd = new ReadData(); rd.setBases(Arrays.copyOf(bases, bases.length)); rd.setQualities(Arrays.copyOf(qualities, bases.length)); rd.setReadType( ReadType.T); // This will be ignored, as the cluster will be chopped up by ReadStructure final ClusterData cd = new ClusterData(rd); cd.setLane(lane); cd.setTile(tile); cd.setX(xCoord); cd.setY(yCoord); cd.setPf(pf); cd.setMatchedBarcode(matchedBarcode); return cd; }
/** * Adds a record to the table and the ID index. * * @param i index in the table where the record should be inserted * @param pre pre value * @param fid first ID value * @param nid last ID value * @param inc increment value * @param oid original ID value */ private void add( final int i, final int pre, final int fid, final int nid, final int inc, final int oid) { if (rows == pres.length) { final int s = Array.newSize(rows); pres = Arrays.copyOf(pres, s); fids = Arrays.copyOf(fids, s); nids = Arrays.copyOf(nids, s); incs = Arrays.copyOf(incs, s); oids = Arrays.copyOf(oids, s); } if (i < rows) { final int destPos = i + 1; final int length = rows - i; System.arraycopy(pres, i, pres, destPos, length); System.arraycopy(fids, i, fids, destPos, length); System.arraycopy(nids, i, nids, destPos, length); System.arraycopy(incs, i, incs, destPos, length); System.arraycopy(oids, i, oids, destPos, length); } pres[i] = pre; fids[i] = fid; nids[i] = nid; incs[i] = inc; oids[i] = oid; ++rows; }
boolean checkSameChar(char[] s1, char[] s2) { s1 = Arrays.copyOf(s1, s1.length); s2 = Arrays.copyOf(s2, s2.length); Arrays.sort(s1); Arrays.sort(s2); return Arrays.equals(s1, s2); }
/** Appends a named column, keeping the last Vec as the response */ public void add(String name, Vec vec) { assert _vecs.length == 0 || anyVec().group().equals(vec.group()); final int len = _names.length; _names = Arrays.copyOf(_names, len + 1); _vecs = Arrays.copyOf(_vecs, len + 1); _keys = Arrays.copyOf(_keys, len + 1); _names[len] = name; _vecs[len] = vec; _keys[len] = vec._key; }
/** Appends an entire Frame */ public Frame add(Frame fr) { assert anyVec().group().equals(fr.anyVec().group()); final int len0 = _names.length; final int len1 = fr._names.length; final int len = len0 + len1; _names = Arrays.copyOf(_names, len); _vecs = Arrays.copyOf(_vecs, len); _keys = Arrays.copyOf(_keys, len); System.arraycopy(fr._names, 0, _names, len0, len1); System.arraycopy(fr._vecs, 0, _vecs, len0, len1); System.arraycopy(fr._keys, 0, _keys, len0, len1); return this; }
/** Removes a numbered column. */ public Vec remove(int idx) { int len = _names.length; if (idx < 0 || idx >= len) return null; Vec v = _vecs[idx]; System.arraycopy(_names, idx + 1, _names, idx, len - idx - 1); System.arraycopy(_vecs, idx + 1, _vecs, idx, len - idx - 1); System.arraycopy(_keys, idx + 1, _keys, idx, len - idx - 1); _names = Arrays.copyOf(_names, len - 1); _vecs = Arrays.copyOf(_vecs, len - 1); _keys = Arrays.copyOf(_keys, len - 1); if (v == _col0) _col0 = null; return v; }
@Override public byte[] getChunkData(int cidx) { if (cidx == _cidx0) return _bits0; if (cidx == _cidx1) return _bits1; assert cidx == _cidx0 + 1 || cidx == _cidx1 + 1; byte[] bits = _cidx0 < _cidx1 ? _bits0 : _bits1; if (_cidx0 < _cidx1) { _cidx0 = cidx; _coff0 = -1; } else { _cidx1 = cidx; _coff1 = -1; } // Read as much as the buffer will hold int off = 0; try { while (off < bits.length) { int len = _is.read(bits, off, bits.length - off); if (len == -1) break; off += len; } assert off == bits.length || _is.available() <= 0; } catch (IOException ioe) { throw new RuntimeException(ioe); } if (off == bits.length) return bits; // Final read is short; cache the short-read byte[] bits2 = (off == 0) ? null : Arrays.copyOf(bits, off); if (_cidx0 == cidx) _bits0 = bits2; else _bits1 = bits2; return bits2; }
/** * Trims the capacity of this vector to be the vector's current size. If the capacity of this * vector is larger than its current size, then the capacity is changed to equal the size by * replacing its internal data array, kept in the field {@code elementData}, with a smaller one. * An application can use this operation to minimize the storage of a vector. */ public synchronized void trimToSize() { modCount++; int oldCapacity = elementData.length; if (elementCount < oldCapacity) { elementData = Arrays.copyOf(elementData, elementCount); } }
/** * Constructs a vector containing the elements of the specified collection, in the order they are * returned by the collection's iterator. * * @param c the collection whose elements are to be placed into this vector * @throws NullPointerException if the specified collection is null * @since 1.2 */ public Vector(Collection<? extends E> c) { elementData = c.toArray(); elementCount = elementData.length; // c.toArray might (incorrectly) not return Object[] (see 6260652) if (elementData.getClass() != Object[].class) elementData = Arrays.copyOf(elementData, elementCount, Object[].class); }
/** Resize the heap array. Call only when holding lock. */ private void grow() { int oldCapacity = queue.length; int newCapacity = oldCapacity + (oldCapacity >> 1); // grow 50% if (newCapacity < 0) // overflow newCapacity = Integer.MAX_VALUE; queue = Arrays.copyOf(queue, newCapacity); }
/** * Converts a token to a sequence of codepoints. * * @param token token * @return codepoints */ public static int[] cps(final byte[] token) { int pos = 0; final int len = token.length; final int[] cp = new int[len]; for (int i = 0; i < len; i += cl(token, i)) cp[pos++] = cp(token, i); return pos < len ? Arrays.copyOf(cp, pos) : cp; }
@Override public void rehash() { super.rehash(); final int s = size << 1; ids = Array.copyOf(ids, s); len = Arrays.copyOf(len, s); }
/** * Ecrit la piece donnée dans le fichier temporaire sur le disque * * @param piece : pièce à écrire * @param num : numéros de la pièce */ private synchronized void writePieceTmpFile(byte[] piece, int num) { if (num < 0 || num >= this.nbPieces()) { throw new IllegalArgumentException(); } if (piece.length > _piecesize) { throw new IllegalArgumentException(); } try { RandomAccessFile writer_tmp = new RandomAccessFile(this, "rw"); FileChannel writer = writer_tmp.getChannel(); int index_piece = ((int) this.length() - this.headerSize()) / _piecesize; if (piece.length < _piecesize) { piece = Arrays.copyOf(piece, _piecesize); } Tools.write(writer, 4 + _key.length() + 4 + 4 + 4 * num, index_piece); Tools.write(writer, this.headerSize() + _piecesize * index_piece, piece); writer.force(true); writer_tmp.close(); } catch (Exception e) { System.out.println("Unable to write tmp file piece"); e.printStackTrace(); } }
@Override public double[] distributionForInstance(Instance xy) throws Exception { int L = xy.classIndex(); double y[] = new double[L]; double w = 0.0; /* * e.g. K = [3,3,5] * we push y_[] from [0,0,0] to [2,2,4] over all necessary iterations. */ int K[] = getKs(xy.dataset()); if (getDebug()) System.out.println("K[] = " + Arrays.toString(K)); double y_[] = new double[L]; for (int i = 0; i < 1000000; i++) { // limit to 1m // System.out.println(""+i+" "+Arrays.toString(y_)); double w_ = A.product(super.probabilityForInstance(xy, y_)); if (w_ > w) { if (getDebug()) System.out.println("y' = " + Arrays.toString(y_) + ", :" + w_); y = Arrays.copyOf(y_, y_.length); w = w_; } if (push(y_, K, 0)) { // Done ! if (getDebug()) System.out.println("Tried all " + (i + 1) + " combinations."); break; } } return y; }
/** * Update a ExtModClassRef to encode a different namespace, the existing entry is re-used but any * parent components of the namespace result in new ExtModClassRef being added to the table to * avoid disrupting other entries which may depend on the parent ExtModClassRef/TermName entries * of the existing entry for purposes we don't understand. * * @param ref the entry to update * @param with array of namespace components to use instead */ private void updateClassRef(ExtModClassRefEntry ref, String[] with) { entries.add(new TermNameEntry(with[with.length - 1])); int termRef = entries.size() - 1; int symbolRef = -1; if (with.length > 1) symbolRef = addClassRef(Arrays.copyOf(with, with.length - 1)); ref.update(termRef, symbolRef); }
public Typing(Type[] inputs, List<Entry> stmts, int numSlots) { this.stmts = new ArrayList<Entry>(stmts); this.cache = new HashMap<String, Type[]>(); this.environments = new Type[stmts.size()][]; this.environments[0] = Arrays.copyOf(inputs, numSlots); this.numSlots = numSlots; }
private void add(PooledFatPipe child) { long start = System.currentTimeMillis(); while (true) { int fails = 0; for (int i = 0; i < inUse.length(); i++) { if (!inUse.compareAndSet(i, 0, 2)) { if (inUse.get(i) != 2) fails++; } } if (fails == 0) break; if (start + 100 < System.currentTimeMillis()) { logger.warn("unable to add cleanly " + toString()); break; } } final AtomicIntegerArray updated = new AtomicIntegerArray(inUse.length() + 1); final List<Integer> needsReset = new ArrayList<>(); for (int i = 0; i < inUse.length(); i++) { int value = inUse.get(i); if (value == 1) { updated.set(i, value); needsReset.add(i); } } final AtomicIntegerArray oldUse = inUse; inUse = updated; signals = new ChildSignalImpl[signals.length + poolSize]; for (int i = 0; i < signals.length; i++) { signals[i] = new ChildSignalImpl(inUse, 0); } children = Arrays.copyOf(children, children.length + 1); children[children.length - 1] = child; scheduleReset(needsReset, oldUse, updated); }
/** * @param type * @return a map whose keys are the values corresponding to nodes of type 'type' and the values * are the number of them */ private Map<String, Integer> extractNodes(NodeType type) { Map<String, Integer> resultNodes = new HashMap<String, Integer>(); List<ISANode> node = graph.getNodes(type); for (ISANode nodeOfInterest : node) { // extract the values! for (int rowIndex = 1; rowIndex < assayTable.length; rowIndex++) { if (nodeOfInterest.getIndex() < assayTable[rowIndex].length) { String[] row = Arrays.copyOf(assayTable[rowIndex], assayTable[rowIndex].length, String[].class); String value = row[nodeOfInterest.getIndex()]; if (value != null && !value.equals("")) { if (!resultNodes.containsKey(value)) { resultNodes.put(value, 1); } else { int newCount = resultNodes.get(value) + 1; resultNodes.put(value, newCount); } } } } } return resultNodes; }
public ClanPosition addPosition() { Authority[] pows = new Authority[Function.values().length]; for (int i = 0; i < pows.length; i++) pows[i] = Authority.CAN_NOT_DO; Set<Integer> roles = new HashSet<Integer>(); int highestRank = 0; for (ClanPosition pos : positions) { roles.add(Integer.valueOf(pos.getRoleID())); if (highestRank < pos.getRank()) highestRank = pos.getRank(); } if (positions.length > 0) for (int i = 0; i < pows.length; i++) pows[i] = positions[0].getFunctionChart()[i]; positions = Arrays.copyOf(positions, positions.length + 1); ClanPosition P = (ClanPosition) CMClass.getCommon("DefaultClanPosition"); P.setID(positions.length + "" + Math.random()); P.setRoleID(0); P.setRank(highestRank); P.setName("Unnamed"); P.setPluralName("Unnameds"); P.setMax(Integer.MAX_VALUE); P.setInnerMaskStr(""); P.setFunctionChart(pows); P.setPublic(true); positions[positions.length - 1] = P; for (int i = 0; i < positions.length; i++) if (!roles.contains(Integer.valueOf(i))) { P.setRoleID(i); break; } return P; }
public InputStreamWrapper(InputStream is, byte[] boundary) { _wrapped = is; _boundary = Arrays.copyOf(BOUNDARY_PREFIX, BOUNDARY_PREFIX.length + boundary.length); System.arraycopy(boundary, 0, _boundary, BOUNDARY_PREFIX.length, boundary.length); _lookAheadBuf = new byte[_boundary.length]; _lookAheadLen = 0; }
public MetaData getMetaData(int index) { if (indexMap == null || indexMap.length < index + 1) { int startFrom = 0; int lastIndex = index; if (indexMap != null) { startFrom = indexMap.length; indexMap = Arrays.copyOf(indexMap, index + 1); } else { String[] headers = context.headers(); if (headers != null && lastIndex < headers.length) { lastIndex = headers.length; } int[] indexes = context.extractedFieldIndexes(); if (indexes != null) { for (int i = 0; i < indexes.length; i++) { if (lastIndex < indexes[i]) { lastIndex = indexes[i]; } } } indexMap = new MetaData[lastIndex + 1]; } for (int i = startFrom; i < lastIndex + 1; i++) { indexMap[i] = new MetaData(i); } } return indexMap[index]; }
/** {@inheritDoc} */ @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) { if (cpy) return (T) Arrays.copyOf(val, val.length); return (T) val; }
/** * Initialises the Ciphers for both encryption and decryption using the generated or supplied * secret key. * * @param algorithm * @param secret * @throws Exception */ private void initSymCiphers(String algorithm, SecretKey secret) throws Exception { log.debug("initializing symmetric ciphers (pool size=%d)", cipher_pool_size); for (int i = 0; i < cipher_pool_size; i++) { encoding_ciphers[i] = symProvider != null && !symProvider.trim().isEmpty() ? Cipher.getInstance(algorithm, symProvider) : Cipher.getInstance(algorithm); encoding_ciphers[i].init(Cipher.ENCRYPT_MODE, secret); decoding_ciphers[i] = symProvider != null && !symProvider.trim().isEmpty() ? Cipher.getInstance(algorithm, symProvider) : Cipher.getInstance(algorithm); decoding_ciphers[i].init(Cipher.DECRYPT_MODE, secret); encoding_locks[i] = new ReentrantLock(); decoding_locks[i] = new ReentrantLock(); } // set the version MessageDigest digest = MessageDigest.getInstance("MD5"); digest.reset(); digest.update(secret.getEncoded()); byte[] tmp = digest.digest(); symVersion = Arrays.copyOf(tmp, tmp.length); // symVersion = byteArrayToHexString(digest.digest()); log.debug("initialized symmetric ciphers with secret key (" + symVersion.length + " bytes)"); }
public int[][] simulate(int[][] board, int direction) { // Scanner sc = new Scanner(System.in); // print(board); // System.out.println(direction); // fml.println(10); int[][] out = new int[4][]; for (int i = 0; i < 4; i++) { out[i] = Arrays.copyOf(board[i], 4); } if (direction % 2 == 1) transpose(out); // everything is left or right if (direction / 2 == 1) flip(out); // everything is left /*for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { if (out[i][j] == 0) { int index = j; for (int k = j + 1; k < 4; k++) { if (out[i][k] > 0) { out[i][index] = out[i][k]; //out[i][k] = 0; index++; } } for (int k = index; k < 4; k++) { out[i][k] = 0; } } if (out[i][j] == out[i][j + 1]) { out[i][j] *= 2; out[i][j + 1] = 0; } } }*/ for (int i = 0; i < 4; i++) { int index = 0; for (int j = 1; j < 4; j++) { if (out[i][j] == 0) continue; if (out[i][index] == 0) { out[i][index] = out[i][j]; out[i][j] = 0; } else if (out[i][index] == out[i][j]) { out[i][index] *= 2; out[i][j] = 0; index++; } else { index++; if (index == j) continue; out[i][index] = out[i][j]; out[i][j] = 0; } } } if (direction / 2 == 1) flip(out); // undo! if (direction % 2 == 1) transpose(out); // undo! // print(out); // sc.nextLine(); // fml.println(11); return out; }
@Override public JMSProducer setJMSCorrelationIDAsBytes(byte[] correlationID) { if (correlationID == null || correlationID.length == 0) { throw new JMSRuntimeException("Please specify a non-zero length byte[]"); } jmsHeaderCorrelationIDAsBytes = Arrays.copyOf(correlationID, correlationID.length); return this; }
/** * Creates a new InstanceSet with the header and Instances from the passed object It performs a * deep (new allocated) copy. * * @param is Original InstanceSet */ public InstanceSet(InstanceSet is) { this.instanceSet = Arrays.copyOf(is.instanceSet, is.instanceSet.length); // this.header = new String(is.header); // this.attHeader = new String(is.attHeader); // this.attributes = new InstanceAttributes(is.attributes); // this.storeAttributesAsNonStatic = is.storeAttributesAsNonStatic; }
private void ensureSize(int index) { if (values == null) { values = new long[index + 1]; } if (values.length <= index) { values = Arrays.copyOf(values, index + 1); } }
static public int[] difference(int a[], int b[]) { int[] r = new int[a.length]; int cnt = 0; for (int i=0; i<a.length; i++) { if (!contains(b, a[i])) r[cnt++] = a[i]; } return Arrays.copyOf(r, cnt); }
/** * Chops a token to the specified length and adds dots. * * @param token token to be chopped * @param max maximum length * @return chopped token */ public static byte[] chop(final byte[] token, final int max) { if (token.length <= max) return token; final byte[] tt = Arrays.copyOf(token, max); if (max > 2) tt[max - 3] = '.'; if (max > 1) tt[max - 2] = '.'; if (max > 0) tt[max - 1] = '.'; return tt; }