java.util.Collection#toArray ( )源码实例Demo

下面列出了java.util.Collection#toArray ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: awex   文件: SingleThreadForEachPromiseTest.java
@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());
}
 
源代码2 项目: awex   文件: SingleThreadFilterPromiseTest.java
@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]);
}
 
源代码3 项目: tracker   文件: TrackDataBuilder.java
@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()]);
		}
	}
}
 
源代码4 项目: streamex   文件: CrossSpliterator.java
@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];
}
 
源代码5 项目: saluki   文件: Pojo2ProtobufHelp.java
/**
 * 集合元素转化为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;
}
 
源代码6 项目: RipplePower   文件: MultiFormatUPCEANReader.java
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();
}
 
源代码8 项目: mars-sim   文件: MainDetailPanel.java
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;
}
 
源代码9 项目: gemfirexd-oss   文件: Table.java
/**
 * 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()]);
}
 
源代码10 项目: FxDock   文件: CKit.java
/** 
 * 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()]);
}
 
源代码11 项目: mybatis.flying   文件: ConditionTest.java
/** 测试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());
}
 
源代码12 项目: neoscada   文件: ViewerLabelProvider.java
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 ) );
                    }
                }

            }
        } );

    }
}
 
源代码13 项目: xds-ide   文件: ModulaOutlinePageContentProvider.java
@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;
}
 
源代码14 项目: depan   文件: RelationSetTableControl.java
public void setSelectedRelations(
    Collection<Relation> relations, boolean reveal) {
  StructuredSelection nextSelection =
      new StructuredSelection(relations.toArray());
  relSetViewer.setSelection(nextSelection, reveal);
}
 
源代码15 项目: openjdk-jdk9   文件: ResponseBuilder.java
public Composite(Collection<? extends ResponseBuilder> builders) {
    this(builders.toArray(new ResponseBuilder[builders.size()]));
}
 
源代码16 项目: mollyim-android   文件: ParcelUtil.java
public static void writeParcelableCollection(@NonNull Parcel dest, @NonNull Collection<? extends Parcelable> collection) {
  Parcelable[] values = collection.toArray(new Parcelable[0]);
  dest.writeParcelableArray(values, 0);
}
 
源代码17 项目: api-gateway-core   文件: StringUtils.java
public static String[] toStringArray(Collection<String> collection) {
    return collection.toArray(new String[0]);
}
 
源代码18 项目: jdk8u_jdk   文件: ConstantPool.java
protected void setMap(Collection<Entry> cpMapList) {
    cpMap = new Entry[cpMapList.size()];
    cpMapList.toArray(cpMap);
    setMap(cpMap);
}
 
源代码19 项目: openjdk-jdk8u   文件: ResponseBuilder.java
public Composite(Collection<? extends ResponseBuilder> builders) {
    this(builders.toArray(new ResponseBuilder[builders.size()]));
}
 
源代码20 项目: finmath-lib   文件: CalibratedCurves.java
/**
 * 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);
}