Java Code Examples for java.util.Collection#toArray()

The following examples show how to use java.util.Collection#toArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiFormatUPCEANReader.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
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()]);
}
 
Example 2
Source File: Pojo2ProtobufHelp.java    From saluki with Apache License 2.0 6 votes vote down vote up
/**
 * 集合元素转化为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;
}
 
Example 3
Source File: CrossSpliterator.java    From streamex with Apache License 2.0 6 votes vote down vote up
@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];
}
 
Example 4
Source File: SingleThreadForEachPromiseTest.java    From awex with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 5
Source File: TrackDataBuilder.java    From tracker with GNU General Public License v3.0 6 votes vote down vote up
@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()]);
		}
	}
}
 
Example 6
Source File: SingleThreadFilterPromiseTest.java    From awex with Apache License 2.0 6 votes vote down vote up
@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]);
}
 
Example 7
Source File: MainDetailPanel.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: ModulaOutlinePageContentProvider.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example 9
Source File: ViewerLabelProvider.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
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 ) );
                    }
                }

            }
        } );

    }
}
 
Example 10
Source File: ConditionTest.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
/** 测试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());
}
 
Example 11
Source File: CKit.java    From FxDock with Apache License 2.0 5 votes vote down vote up
/** 
 * 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()]);
}
 
Example 12
Source File: Table.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * 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()]);
}
 
Example 13
Source File: ModulaOutlinePageContentProvider.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@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();
}
 
Example 14
Source File: StringUtils.java    From api-gateway-core with Apache License 2.0 4 votes vote down vote up
public static String[] toStringArray(Collection<String> collection) {
    return collection.toArray(new String[0]);
}
 
Example 15
Source File: ParcelUtil.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public static void writeParcelableCollection(@NonNull Parcel dest, @NonNull Collection<? extends Parcelable> collection) {
  Parcelable[] values = collection.toArray(new Parcelable[0]);
  dest.writeParcelableArray(values, 0);
}
 
Example 16
Source File: ResponseBuilder.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public Composite(Collection<? extends ResponseBuilder> builders) {
    this(builders.toArray(new ResponseBuilder[builders.size()]));
}
 
Example 17
Source File: ConstantPool.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected void setMap(Collection<Entry> cpMapList) {
    cpMap = new Entry[cpMapList.size()];
    cpMapList.toArray(cpMap);
    setMap(cpMap);
}
 
Example 18
Source File: RelationSetTableControl.java    From depan with Apache License 2.0 4 votes vote down vote up
public void setSelectedRelations(
    Collection<Relation> relations, boolean reveal) {
  StructuredSelection nextSelection =
      new StructuredSelection(relations.toArray());
  relSetViewer.setSelection(nextSelection, reveal);
}
 
Example 19
Source File: ResponseBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public Composite(Collection<? extends ResponseBuilder> builders) {
    this(builders.toArray(new ResponseBuilder[builders.size()]));
}
 
Example 20
Source File: CalibratedCurves.java    From finmath-lib with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}