List of usage examples for java.util Arrays copyOf
public static boolean[] copyOf(boolean[] original, int newLength)
From source file:com.google.testing.coverage.BitField.java
/** * Performs a non-destructive bit-wise merge of this bit field and another one. * * @param other the other bit field//from ww w .j av a 2 s.c o m * @return this bit field */ public BitField or(BitField other) { byte[] largerArray, smallerArray; if (bytes.length < other.bytes.length) { largerArray = other.bytes; smallerArray = bytes; } else { largerArray = bytes; smallerArray = other.bytes; } // Start out with a copy of the larger of the two arrays. byte[] result = Arrays.copyOf(largerArray, largerArray.length); for (int i = 0; i < smallerArray.length; i++) { result[i] |= smallerArray[i]; } return new BitField(result); }
From source file:de.mmichaelis.maven.mojo.MailDevelopersMojoTest.java
private void doTestMailToDevelopers(final int numDevelopers) throws Exception { final MavenProject project = mock(MavenProject.class); when(project.getDevelopers()).thenReturn(Arrays.asList(Arrays.copyOf(developers, numDevelopers))); mojoWrapper.setProject(project);/* w ww . j av a 2 s. com*/ mojoWrapper.execute(); for (int i = 0; i < numDevelopers; i++) { final Developer developer = developers[i]; final Mailbox inbox = Mailbox.get(developer.getEmail()); assertEquals("Should have received one email.", 1, inbox.size()); final Message message = inbox.get(0); final InputStream stream = message.getInputStream(); final int messageSize = message.getSize(); final StringWriter writer; try { writer = new StringWriter(messageSize < 0 ? 512 : messageSize); IOUtils.copy(stream, writer); } finally { stream.close(); } LOG.debug("Mail for one developer:\n" + writer.toString()); } }
From source file:org.springframework.data.gemfire.support.JSONRegionAdvice.java
@Around("execution(* com.gemstone.gemfire.cache.Region.put(..)) || " + "execution(* com.gemstone.gemfire.cache.Region.create(..)) ||" + "execution(* com.gemstone.gemfire.cache.Region.putIfAbsent(..)) ||" + "execution(* com.gemstone.gemfire.cache.Region.replace(..))") public Object put(ProceedingJoinPoint pjp) { boolean JSONRegion = isIncludedSONRegion(pjp.getTarget()); Object returnValue = null;//from www . j ava2s. c o m try { if (JSONRegion) { Object[] newArgs = Arrays.copyOf(pjp.getArgs(), pjp.getArgs().length); Object val = newArgs[1]; newArgs[1] = convertArgumentToPdxInstance(val); returnValue = pjp.proceed(newArgs); log.debug("converting " + returnValue + " to JSON string"); returnValue = convertPdxInstanceToJSONString(returnValue); } else { returnValue = pjp.proceed(); } } catch (Throwable t) { handleThrowable(t); } return returnValue; }
From source file:com.github.mrstampy.gameboot.util.GameBootUtils.java
/** * Prepend array.//from w w w . jav a 2 s. c om * * @param <T> * the generic type * @param pre * the pre * @param post * the post * @return the t[] */ @SuppressWarnings("unchecked") public <T> T[] prependArray(T pre, T... post) { if (pre == null) throw new IllegalArgumentException("Element cannot be null"); if (post == null) throw new IllegalArgumentException("Array cannot be null"); T[] array = Arrays.copyOf(post, post.length + 1); array[0] = pre; if (array.length == 1) return array; System.arraycopy(post, 0, array, 1, post.length); return array; }
From source file:it.scoppelletti.mobilepower.app.FragmentLayoutController.java
/** * Costruttore./*from w ww . j a va 2 s . c o m*/ * * <P>L’attività istanzia un oggetto * {@code FragmentLayoutController} all’interno del proprio metodo * {@code onCreate} dopo aver costruito la propria vista.</P> * * @param activity Attività. * @param frameIds Identificatori dei pannelli a disposizione per i * frammenti di dettaglio. */ public FragmentLayoutController(Activity activity, int... frameIds) { int frameCount; if (activity == null) { throw new NullPointerException("Argument activity is null."); } if (ArrayUtils.isEmpty(frameIds)) { throw new NullPointerException("Argument frameIds is null."); } myActivity = activity; frameCount = 0; myFrameIds = Arrays.copyOf(frameIds, frameIds.length); for (int frameId : myFrameIds) { if (myActivity.findViewById(frameId) != null) { frameCount++; } } if (frameCount == 0) { throw new IllegalStateException("No panel found."); } myFrameCount = frameCount; }
From source file:com.linkedin.pinot.tools.scan.query.Projection.java
public ResultTable run() { ResultTable resultTable = new ResultTable(_columnList, _filteredDocIds.size()); resultTable.setResultType(ResultTable.ResultType.Selection); for (Pair pair : _columnList) { String column = (String) pair.getFirst(); if (!_mvColumns.contains(column)) { BlockSingleValIterator bvIter = (BlockSingleValIterator) _indexSegment.getDataSource(column) .getNextBlock().getBlockValueSet().iterator(); int rowId = 0; for (Integer docId : _filteredDocIds) { bvIter.skipTo(docId);/* ww w .j a v a2 s. c o m*/ resultTable.add(rowId++, bvIter.nextIntVal()); } } else { BlockMultiValIterator bvIter = (BlockMultiValIterator) _indexSegment.getDataSource(column) .getNextBlock().getBlockValueSet().iterator(); int rowId = 0; for (Integer docId : _filteredDocIds) { bvIter.skipTo(docId); int[] dictIds = _mvColumnArrayMap.get(column); int numMVValues = bvIter.nextIntVal(dictIds); dictIds = Arrays.copyOf(dictIds, numMVValues); resultTable.add(rowId++, ArrayUtils.toObject(dictIds)); } } } return transformFromIdToValues(resultTable, _dictionaryMap, _addCountStar); }
From source file:hivemall.model.NewSpaceEfficientDenseModel.java
private void ensureCapacity(final int index) { if (index >= size) { int bits = MathUtils.bitsRequired(index); int newSize = (1 << bits) + 1; int oldSize = size; logger.info("Expands internal array size from " + oldSize + " to " + newSize + " (" + bits + " bits)"); this.size = newSize; this.weights = Arrays.copyOf(weights, newSize); if (covars != null) { this.covars = Arrays.copyOf(covars, newSize); Arrays.fill(covars, oldSize, newSize, HalfFloat.ONE); }/*w ww . ja v a 2 s. c o m*/ if (clocks != null) { this.clocks = Arrays.copyOf(clocks, newSize); this.deltaUpdates = Arrays.copyOf(deltaUpdates, newSize); } } }
From source file:com.wsc.myexample.decisionForest.MyDataset.java
public String[] labels() { return Arrays.copyOf(values[labelId], nblabels()); }
From source file:fitnesse.slim.test.TestSlim.java
public void setStringArray(String[] array) { stringArray = Arrays.copyOf(array, array.length); }
From source file:com.example.marcieltorres.nfcproject_serverapp.cardreader.LoyaltyCardReader.java
/** * Callback when a new tag is discovered by the system. * * <p>Communication with the card should take place here. * * @param tag Discovered tag//from www .j a v a 2s . com */ @Override public void onTagDiscovered(Tag tag) { //Log.i(TAG, "New tag discovered"); // Android's Host-based Card Emulation (HCE) feature implements the ISO-DEP (ISO 14443-4) // protocol. // // In order to communicate with a device using HCE, the discovered tag should be processed // using the IsoDep class. IsoDep isoDep = IsoDep.get(tag); if (isoDep != null) { try { // Connect to the remote NFC device isoDep.connect(); // Build SELECT AID command for our loyalty card service. // This command tells the remote device which service we wish to communicate with. //Log.i(TAG, "Requesting remote AID: " + SAMPLE_LOYALTY_CARD_AID); byte[] command = BuildSelectApdu(SAMPLE_LOYALTY_CARD_AID); // Send command to remote device //Log.i(TAG, "Sending: " + ByteArrayToHexString(command)); byte[] result = isoDep.transceive(command); // If AID is successfully selected, 0x9000 is returned as the status word (last 2 // bytes of the result) by convention. Everything before the status word is // optional payload, which is used here to hold the account number. int resultLength = result.length; byte[] statusWord = { result[resultLength - 2], result[resultLength - 1] }; byte[] payload = Arrays.copyOf(result, resultLength - 2); if (Arrays.equals(SELECT_OK_SW, statusWord)) { // The remote NFC device will immediately respond with its stored account number String accountNumber = new String(payload, "UTF-8"); //Log.i(TAG, "Received: " + accountNumber); // Inform CardReaderFragment of received account number mAccountCallback.get().onAccountReceived(accountNumber); mAccountCallback.get().onAccountReceived(accountNumber); } } catch (IOException e) { //Log.e(TAG, "Error communicating with card: " + e.toString()); } } }