下面列出了java.util.Collection#toArray ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void shouldIterateOverAllItemsOfAResolvedPromise() throws Exception {
setUpAwex();
AwexPromise<Collection<Item>, Float> mCollectionPromise = new AwexPromise<>(mAwex, mTask);
CollectionPromise<Item, Float> mResultPromise = mCollectionPromise.<Item>stream().forEach(new Func<Item>() {
@Override
public void run(Item item) {
item.setValue(item.getValue() + 1);
}
});
mCollectionPromise.resolve(Arrays.asList(new Item(1),
new Item(2),
new Item(3)));
Collection<Item> result = mResultPromise.getResult();
Item[] results = result.toArray(new Item[result.size()]);
assertEquals(2, results[0].getValue());
assertEquals(3, results[1].getValue());
assertEquals(4, results[2].getValue());
}
@Test
public void shouldFilterAResolvedPromiseWithCollection() throws Exception {
setUpAwex();
AwexPromise<Collection<Integer>, Float> mCollectionPromise = new AwexPromise<>(mAwex, mTask);
mFilteredValue = mCollectionPromise.<Integer>stream().filter(new Filter<Integer>() {
@Override
public boolean filter(Integer value) {
return value > 2;
}
});
mCollectionPromise.resolve(Arrays.asList(1, 2, 3, 4, 5));
Collection<Integer> result = mFilteredValue.getResult();
Integer[] results = result.toArray(new Integer[result.size()]);
assertEquals(3, (int) results[0]);
assertEquals(4, (int) results[1]);
assertEquals(5, (int) results[2]);
}
@Override
public void setVisible(boolean vis) {
super.setVisible(vis);
if (!vis) {
// save non-default search paths in Tracker.preferredAutoloadSearchPaths
Collection<String> searchPaths = getSearchPaths();
Collection<String> defaultPaths = Tracker.getDefaultAutoloadSearchPaths();
boolean isDefault = searchPaths.size()==defaultPaths.size();
for (String next: searchPaths) {
isDefault = isDefault && defaultPaths.contains(next);
}
if (isDefault) {
Tracker.preferredAutoloadSearchPaths = null;
}
else {
Tracker.preferredAutoloadSearchPaths = searchPaths.toArray(new String[searchPaths.size()]);
}
}
}
@SuppressWarnings("unchecked")
CrossSpliterator(Collection<? extends Collection<T>> source) {
this.splitPos = 0;
long est = 1;
try {
for (Collection<T> c : source) {
long size = c.size();
est = StrictMath.multiplyExact(est, size);
}
} catch (ArithmeticException e) {
est = Long.MAX_VALUE;
}
this.est = est;
this.collections = source.toArray(new Collection[0]);
this.spliterators = new Spliterator[collections.length];
}
/**
* 集合元素转化为Protobuf
*/
public static final Object convertCollectionToProtobufs(
Collection<Object> collectionOfNonProtobufs) throws JException {
if (collectionOfNonProtobufs.isEmpty()) {
return collectionOfNonProtobufs;
}
final Object first = collectionOfNonProtobufs.toArray()[0];
if (!ProtobufSerializerUtils.isProtbufEntity(first)) {
return collectionOfNonProtobufs;
}
final Collection<Object> newCollectionValues;
if (collectionOfNonProtobufs instanceof Set) {
newCollectionValues = new HashSet<>();
} else {
newCollectionValues = new ArrayList<>();
}
for (Object iProtobufGenObj : collectionOfNonProtobufs) {
newCollectionValues.add(Pojo2ProtobufHelp.serializeToProtobufEntity(iProtobufGenObj));
}
return newCollectionValues;
}
public MultiFormatUPCEANReader(Map<DecodeHintType, ?> hints) {
@SuppressWarnings("unchecked")
Collection<BarcodeFormat> possibleFormats = hints == null ? null
: (Collection<BarcodeFormat>) hints.get(DecodeHintType.POSSIBLE_FORMATS);
Collection<UPCEANReader> readers = new ArrayList<>();
if (possibleFormats != null) {
if (possibleFormats.contains(BarcodeFormat.EAN_13)) {
readers.add(new EAN13Reader());
} else if (possibleFormats.contains(BarcodeFormat.UPC_A)) {
readers.add(new UPCAReader());
}
if (possibleFormats.contains(BarcodeFormat.EAN_8)) {
readers.add(new EAN8Reader());
}
if (possibleFormats.contains(BarcodeFormat.UPC_E)) {
readers.add(new UPCEReader());
}
}
if (readers.isEmpty()) {
readers.add(new EAN13Reader());
// UPC-A is covered by EAN-13
readers.add(new EAN8Reader());
readers.add(new UPCEReader());
}
this.readers = readers.toArray(new UPCEANReader[readers.size()]);
}
@Override // ITreeContentProvider
public Object[] getChildren(Object parentElement) {
if (parentElement == input) {
parentElement = getRoot();
}
if (!(parentElement instanceof IXdsContainer)) {
return EMPTY_ARRAY;
}
Collection<IXdsElement> children = ((IXdsContainer)parentElement).getChildren();
children = filter(children);
return parentElement == null ? EMPTY_ARRAY : children.toArray();
}
private int getIndex(Collection<?> col, Object obj) {
int result = -1;
Object array[] = col.toArray();
int size = array.length;
for (int i = 0; i < size; i++) {
if (array[i].equals(obj)) {
result = i;
break;
}
}
return result;
}
/**
* Returns the required (not-nullable) columns in this table. If none are found,
* then an empty array will be returned.
*
* @return The required columns
*/
public Column[] getRequiredColumns()
{
Collection requiredColumns = CollectionUtils.select(_columns, new Predicate() {
public boolean evaluate(Object input) {
return ((Column)input).isRequired();
}
});
return (Column[])requiredColumns.toArray(new Column[requiredColumns.size()]);
}
/**
* utility method converts a String Collection to a String[].
* returns null if input is null
*/
public static String[] toArray(Collection<String> coll)
{
if(coll == null)
{
return null;
}
return coll.toArray(new String[coll.size()]);
}
/** 测试condition:like功能 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/conditionTest/testConditionLike.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/conditionTest/testConditionLike.xml")
public void testConditionLike() {
Account_Condition ac = new Account_Condition();
ac.setEmailLike("%%");
Collection<Account_> c = accountService.selectAll(ac);
Account_[] accounts = c.toArray(new Account_[c.size()]);
Assert.assertEquals(1, accounts.length);
Assert.assertEquals("an%%[email protected]", accounts[0].getEmail());
}
protected final void fireChangeEvent ( final Collection<?> changes )
{
final LabelProviderChangedEvent event = new LabelProviderChangedEvent ( ViewerLabelProvider.this, changes.toArray () );
final ILabelProviderListener[] listenerArray = ViewerLabelProvider.this.listeners.toArray ( new ILabelProviderListener[ViewerLabelProvider.this.listeners.size ()] );
final Display display = getDisplay ();
if ( !display.isDisposed () )
{
display.asyncExec ( new Runnable () {
public void run ()
{
for ( final ILabelProviderListener listener : listenerArray )
{
try
{
listener.labelProviderChanged ( event );
}
catch ( final Exception e )
{
Policy.getLog ().log ( new Status ( IStatus.ERROR, Policy.JFACE_DATABINDING, e.getLocalizedMessage (), e ) );
}
}
}
} );
}
}
@Override // ITreeContentProvider
public Object[] getElements(Object inputElement) {
if (getRoot() != null) {
Collection<IXdsElement> children = getRoot().getChildren();
children = filter(children);
if (children != null) {
return children.toArray();
}
}
return EMPTY_ARRAY;
}
public void setSelectedRelations(
Collection<Relation> relations, boolean reveal) {
StructuredSelection nextSelection =
new StructuredSelection(relations.toArray());
relSetViewer.setSelection(nextSelection, reveal);
}
public Composite(Collection<? extends ResponseBuilder> builders) {
this(builders.toArray(new ResponseBuilder[builders.size()]));
}
public static void writeParcelableCollection(@NonNull Parcel dest, @NonNull Collection<? extends Parcelable> collection) {
Parcelable[] values = collection.toArray(new Parcelable[0]);
dest.writeParcelableArray(values, 0);
}
public static String[] toStringArray(Collection<String> collection) {
return collection.toArray(new String[0]);
}
protected void setMap(Collection<Entry> cpMapList) {
cpMap = new Entry[cpMapList.size()];
cpMapList.toArray(cpMap);
setMap(cpMap);
}
public Composite(Collection<? extends ResponseBuilder> builders) {
this(builders.toArray(new ResponseBuilder[builders.size()]));
}
/**
* Generate a collection of calibrated curves (discount curves, forward curves)
* from a vector of calibration products.
*
* @param calibrationSpecs Array of calibration specs.
* @throws net.finmath.optimizer.SolverException May be thrown if the solver does not cannot find a solution of the calibration problem.
* @throws CloneNotSupportedException Thrown, when a curve could not be cloned.
*/
public CalibratedCurves(final Collection<CalibrationSpec> calibrationSpecs) throws SolverException, CloneNotSupportedException {
this(calibrationSpecs.toArray(new CalibrationSpec[calibrationSpecs.size()]), null);
}