当前位置: 首页>>代码示例>>Java>>正文


Java Collection.toArray方法代码示例

本文整理汇总了Java中java.util.Collection.toArray方法的典型用法代码示例。如果您正苦于以下问题:Java Collection.toArray方法的具体用法?Java Collection.toArray怎么用?Java Collection.toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Collection的用法示例。


在下文中一共展示了Collection.toArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRandomObject

import java.util.Collection; //导入方法依赖的package包/类
@Nullable
public V getRandomObject(Random random)
{
    if (this.values == null)
    {
        Collection<?> collection = this.registryObjects.values();

        if (collection.isEmpty())
        {
            return (V)null;
        }

        this.values = collection.toArray(new Object[collection.size()]);
    }

    return (V)this.values[random.nextInt(this.values.length)];
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:18,代码来源:RegistrySimple.java

示例2: OlympiadGameManager

import java.util.Collection; //导入方法依赖的package包/类
protected OlympiadGameManager()
{
	final Collection<L2OlympiadStadiumZone> zones = ZoneManager.getInstance().getAllZones(L2OlympiadStadiumZone.class);
	if ((zones == null) || zones.isEmpty())
	{
		throw new Error("No olympiad stadium zones defined !");
	}
	
	final L2OlympiadStadiumZone[] array = zones.toArray(new L2OlympiadStadiumZone[zones.size()]);
	_tasks = new ArrayList<>(STADIUM_COUNT);
	
	final int zonesCount = array.length;
	for (int i = 0; i < STADIUM_COUNT; i++)
	{
		final OlympiadStadium stadium = new OlympiadStadium(array[i % zonesCount], i);
		stadium.registerTask(new OlympiadGameTask(stadium));
		_tasks.add(stadium);
	}
	
	_log.info("Olympiad System: Loaded " + _tasks.size() + " stadiums.");
}
 
开发者ID:rubenswagner,项目名称:L2J-Global,代码行数:22,代码来源:OlympiadGameManager.java

示例3: readFromXML_parseAttrValues

import java.util.Collection; //导入方法依赖的package包/类
private static String[] readFromXML_parseAttrValues(Element typeNode){
    Collection<String> result = new ArrayList<String>();
    NodeList typeLst = typeNode.getElementsByTagName("val"); //NOI18N

    for (int i = 0; i < typeLst.getLength(); i++) {
        Node valNode = typeLst.item(i);

        if (valNode.getNodeType() == Node.ELEMENT_NODE){
            Element elem = (Element) valNode;

            String val = elem.getTextContent();

            if (val != null){
                result.add(val);
            }
        }
    }

    return result.toArray(new String[result.size()]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:LibraryMetadata.java

示例4: load

import java.util.Collection; //导入方法依赖的package包/类
public void load () throws Exception
{
    final Collection<X509Certificate> certificates = loadCert ( this.certificateUrl );
    final Collection<X509CRL> crls = loadCrl ( this.crlUrls );

    this.certificates = certificates.toArray ( new X509Certificate[certificates.size ()] );
    this.crls = crls.toArray ( new X509CRL[crls.size ()] );

}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:10,代码来源:X509CA.java

示例5: getOpposites

import java.util.Collection; //导入方法依赖的package包/类
/**
 * Returns all distincts visible opposite cells for the specified terminal on the given edges.
 *
 * @param edges Edges whose opposite terminals should be returned.
 * @param terminal Terminal that specifies the end whose opposite should be returned.
 * @param sources Specifies if source terminals should be included in the result.
 * @param targets Specifies if target terminals should be included in the result.
 * @return Returns the cells at the opposite ends of the given edges.
 */
public Object[] getOpposites(final Object[] edges, final Object terminal, final boolean sources,
    final boolean targets) {
  final Collection<Object> terminals = new LinkedHashSet<Object>();

  if (edges != null) {
    for (int i = 0; i < edges.length; i++) {
      final mxCellState state = this.view.getState(edges[i]);
      final Object source = state != null ? state.getVisibleTerminal(true)
          : this.view.getVisibleTerminal(edges[i], true);
      final Object target = state != null ? state.getVisibleTerminal(false)
          : this.view.getVisibleTerminal(edges[i], false);

      // Checks if the terminal is the source of
      // the edge and if the target should be
      // stored in the result
      if (targets && source == terminal && target != null && target != terminal) {
        terminals.add(target);
      }

      // Checks if the terminal is the taget of
      // the edge and if the source should be
      // stored in the result
      else if (sources && target == terminal && source != null && source != terminal) {
        terminals.add(source);
      }
    }
  }

  return terminals.toArray();
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:40,代码来源:mxGraph.java

示例6: toArray

import java.util.Collection; //导入方法依赖的package包/类
/**
 * Returns an array containing each value of {@code collection}, converted to a {@code byte} value
 * in the manner of {@link Number#byteValue}.
 *
 * <p>Elements are copied from the argument collection as if by {@code
 * collection.toArray()}. Calling this method is as thread-safe as calling that method.
 *
 * @param collection a collection of {@code Number} instances
 * @return an array containing the same values as {@code collection}, in the same order, converted
 *     to primitives
 * @throws NullPointerException if {@code collection} or any of its elements is null
 * @since 1.0 (parameter was {@code Collection<Byte>} before 12.0)
 */
public static byte[] toArray(Collection<? extends Number> collection) {
  if (collection instanceof ByteArrayAsList) {
    return ((ByteArrayAsList) collection).toByteArray();
  }

  Object[] boxedArray = collection.toArray();
  int len = boxedArray.length;
  byte[] array = new byte[len];
  for (int i = 0; i < len; i++) {
    // checkNotNull for GWT (do not optimize)
    array[i] = ((Number) checkNotNull(boxedArray[i])).byteValue();
  }
  return array;
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:28,代码来源:Bytes.java

示例7: testDescendingValuesToArray

import java.util.Collection; //导入方法依赖的package包/类
/**
 * Values.toArray contains all values
 */
public void testDescendingValuesToArray() {
    ConcurrentNavigableMap map = dmap5();
    Collection v = map.values();
    Object[] ar = v.toArray();
    ArrayList s = new ArrayList(Arrays.asList(ar));
    assertEquals(5, ar.length);
    assertTrue(s.contains("A"));
    assertTrue(s.contains("B"));
    assertTrue(s.contains("C"));
    assertTrue(s.contains("D"));
    assertTrue(s.contains("E"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ConcurrentSkipListSubMapTest.java

示例8: compose

import java.util.Collection; //导入方法依赖的package包/类
/**
 * Returns the composition of the given expressions using the given operator. 
 * @requires exprs.size() = 2 => op.binary(), exprs.size() > 2 => op.nary()
 * @return exprs.size()=1 => exprs.iterator().next() else {e: Expression | e.children = exprs.toArray() and e.op = this }
 */
public static Expression compose(ExprOperator op, Collection<? extends Expression> exprs) { 
	switch(exprs.size()) { 
	case 0 : 	throw new IllegalArgumentException("Expected at least one argument: " + exprs);
	case 1 : 	return exprs.iterator().next();
	case 2 :
		final Iterator<? extends Expression> itr = exprs.iterator();
		return new BinaryExpression(itr.next(), op, itr.next());
	default : 			
		return new NaryExpression(op, exprs.toArray(new Expression[exprs.size()]));
	}
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:17,代码来源:Expression.java

示例9: toArray

import java.util.Collection; //导入方法依赖的package包/类
/**
 * Adapted from {@code com.google.common.base.Strings#emptyToNull}.
 */
@SuppressWarnings("unchecked")
public static <T> T[] toArray(Iterable<? extends T> iterable, Class<T> type) {
  Collection<T> collection;
  if (iterable instanceof Collection) {
    collection = (Collection<T>) iterable;
  } else {
    collection = new ArrayList<T>();
    for (T element : iterable) {
      collection.add(element);
    }
  }
  T[] array = (T[]) Array.newInstance(type, collection.size());
  return collection.toArray(array);
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:18,代码来源:Util.java

示例10: getInlineType

import java.util.Collection; //导入方法依赖的package包/类
public LocalSimpleType getInlineType() {
    Collection<LocalSimpleType> types = getChildren(LocalSimpleType.class);
    if (types.size() > 1 || types.size() < 0) {
        throw new IllegalArgumentException("'" + SchemaElements.LIST + "' can only local simpleType child");
    }
    LocalSimpleType[] typesA = types.toArray(new LocalSimpleType[1]);
    if (typesA.length == 0) {
        return null;
    } else {
        return typesA[0];
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:ListImpl.java

示例11: getHtmlTagNames

import java.util.Collection; //导入方法依赖的package包/类
private String[] getHtmlTagNames() {
    HtmlModel model = HtmlModelFactory.getModel(HtmlVersion.HTML5);
    Collection<HtmlTag> tags = model.getAllTags();
    Collection<String> tagNames = new ArrayList<String>();
    for(HtmlTag tag : tags) {
        tagNames.add(tag.getName());
    }
    return tagNames.toArray(new String[]{});
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:SelectorsGroupEditor.java

示例12: processTaskUpdate

import java.util.Collection; //导入方法依赖的package包/类
protected void processTaskUpdate(final String taskId, final Collection<TaskStatusChange<?>> changes)
{
	synchronized( stateMutex )
	{
		final TaskStatusImpl taskStatus = taskStatuses.get(taskId);
		if( taskStatus == null )
		{
			throw new RuntimeException("Unknown taskId:" + taskId);
		}
		ClusteredTask clusteredTask = activeTasks.get(taskId);
		synchronized( taskStatus )
		{
			for( TaskStatusChange<?> taskStatusChange : changes )
			{
				taskStatusChange.modifyStatus(taskStatus);
			}
		}
		Collection<TaskStatusListener> listeners = taskListeners.get(taskId);
		if( !listeners.isEmpty() )
		{
			final TaskStatusListener[] listenerArray = listeners.toArray(new TaskStatusListener[listeners.size()]);
			listenerThread.execute(new Runnable()
			{
				@Override
				public void run()
				{
					for( TaskStatusListener taskStatusListener : listenerArray )
					{
						taskStatusListener.taskStatusChanged(taskId, taskStatus);
					}
				}
			});
		}
		if( taskStatus.isFinished() )
		{
			activeTasks.remove(taskId);
			if( clusteredTask.getGlobalId() != null )
			{
				globalTasks.remove(clusteredTask.getGlobalId());
			}
			taskStatuses.remove(taskId);
			finishedStatuses.put(taskId, taskStatus);
			taskListeners.removeAll(taskId);
		}
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:47,代码来源:LocalTaskServiceImpl.java

示例13: VisitableURLClassLoader

import java.util.Collection; //导入方法依赖的package包/类
public VisitableURLClassLoader(ClassLoader parent, Collection<URL> urls) {
    super(urls.toArray(new URL[0]), parent);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:4,代码来源:VisitableURLClassLoader.java

示例14: register

import java.util.Collection; //导入方法依赖的package包/类
/**
 * Register a new class to add injection to it
 *
 * @param classes list of the classes
 *
 * @throws IOException                rethrown from {@link org.objectweb.asm.ClassReader} constructor
 * @throws UnmodifiableClassException if any of the given class is unmodifiable
 */
public void register(final Class<?>... classes) throws IOException, UnmodifiableClassException
{
    if (!InstrumentationHolder.isInstrumentationAvailable())
    {
        throw new RuntimeException("Instrumentation not available", InstrumentationHolder.getUnavailabilityCause());
    }
    if (!InternalContainer.isContainerPresent(this.containerId))
    {
        InternalContainer.registerInjector(this);
    }

    final Collection<ClassDefinition> definitions = new ArrayList<>(classes.length);

    for (final Class<?> clazz : classes)
    {
        if (this.registered.contains(clazz))
        {
            continue;
        }

        final ReflectAnnotatedClass reflectClass = this.gasketAnnotationProcessor.getJavaReflectClass(clazz);
        final List<String> fields = new ArrayList<>(reflectClass.getFields().length);

        for (final AnnotatedField field : reflectClass.getFields())
        {
            if (field.isAnnotationPresent(Inject.class))
            {
                fields.add(field.getName());
            }
        }

        if (!fields.isEmpty())
        {
            final String javaClassPath = AsmUtils.getJavaClassPath(clazz.getName());
            final byte[] bytes = IOUtils.toByteArray(clazz.getClassLoader().getResourceAsStream(javaClassPath));
            definitions.add(new ClassDefinition(clazz, new InjectionClassModifier(bytes, fields, this.getContainerId()).modify()));
        }

        for (final InjectionProvider injectionProvider : this.injectionProviders)
        {
            injectionProvider.register(this, clazz);
        }

        this.registered.add(clazz);
    }

    if (!definitions.isEmpty())
    {
        try
        {
            final ClassDefinition[] definitionsArray = new ClassDefinition[definitions.size()];
            definitions.toArray(definitionsArray);
            InstrumentationHolder.getInstrumentation().redefineClasses(definitionsArray);
        }
        catch (final ClassNotFoundException e)
        {
            throw new Error("According to the documentation this can't happen, but it did, not my problem", e);
        }
    }
}
 
开发者ID:MrGregorix,项目名称:Gasket,代码行数:69,代码来源:GasketInjector.java

示例15: ThreadsSample

import java.util.Collection; //导入方法依赖的package包/类
ThreadsSample(long t, Collection<ThreadInfo> tis) {
    time = t;
    tinfos = tis.toArray(new ThreadInfo[0]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:5,代码来源:LoadedSnapshot.java


注:本文中的java.util.Collection.toArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。