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


Java Collection类代码示例

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


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

示例1: testGenericServiceConfig

import java.util.Collection; //导入依赖的package包/类
@Test
public void testGenericServiceConfig() throws Exception {
    ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
    service.setApplication(new ApplicationConfig("test"));
    service.setRegistry(new RegistryConfig("mock://localhost"));
    service.setInterface(DemoService.class.getName());
    service.setGeneric(Constants.GENERIC_SERIALIZATION_BEAN);
    service.setRef(new GenericService(){

        public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
            return null;
        }
    });
    try {
        service.export();
        Collection<Registry> collection = MockRegistryFactory.getCachedRegistry();
        MockRegistry registry = (MockRegistry)collection.iterator().next();
        URL url = registry.getRegistered().get(0);
        Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
    } finally {
        MockRegistryFactory.cleanCachedRegistry();
        service.unexport();
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:25,代码来源:ConfigTest.java

示例2: should_run_renamed_test_as_changed_and_ignore_deleted_one

import java.util.Collection; //导入依赖的package包/类
@Test
public void should_run_renamed_test_as_changed_and_ignore_deleted_one() throws Exception {
    // given
    final Project project = testBed.getProject();
    project.configureSmartTesting().executionOrder(CHANGED).inMode(SELECTING).enable();

    final Collection<TestResult> expectedTestResults =
        project.applyAsCommits("Deletes one test", "Renames unit test");

    // when
    final TestResults actualTestResults =
        project.build("junit/core").options().withSystemProperties("scm.range.head", "HEAD", "scm.range.tail", "HEAD~~").configure().run();

    // then
    assertThat(actualTestResults.accumulatedPerTestClass()).containsAll(expectedTestResults)
        .hasSameSizeAs(expectedTestResults);
}
 
开发者ID:arquillian,项目名称:smart-testing,代码行数:18,代码来源:DeleteAndRenameTestSelectionStrategyFunctionalTest.java

示例3: openScript

import java.util.Collection; //导入依赖的package包/类
/**
 * Opens the given script for reading
 *
 * @param script the script to read (required)
 * @return a non-<code>null</code> input stream
 */
private InputStream openScript(final File script) {
	try {
		return new BufferedInputStream(new FileInputStream(script));
	} catch (final FileNotFoundException fnfe) {
		// Try to find the script via the classloader
		final Collection<URL> urls = findResources(script.getName());

		// Handle search failure
		Assert.notNull(urls, "Unexpected error looking for '" + script.getName() + "'");

		// Handle the search being OK but the file simply not being present
		Assert.notEmpty(urls, "Script '" + script + "' not found on disk or in classpath");
		Assert.isTrue(urls.size() == 1, "More than one '" + script + "' was found in the classpath; unable to continue");
		try {
			return urls.iterator().next().openStream();
		} catch (IOException e) {
			throw new IllegalStateException(e);
		}
	}
}
 
开发者ID:avast,项目名称:hdfs-shell,代码行数:27,代码来源:XScriptCommands.java

示例4: invokeAll

import java.util.Collection; //导入依赖的package包/类
@Override
public <T> List<Future<T>> invokeAll(Collection<Callable<T>> tasks, 
        long timeout, TimeUnit timeoutUnit) {
    if (null == tasks) {
        //todo throw exception
        return null;
    }
    if (timeout < 0) {
        //todo throw exception
        return null;
    }

    try {
        return executorService.invokeAll(tasks, timeout, timeoutUnit);
    } catch (InterruptedException e) {
        logger.info("invoke task list occurs error",e);
    }
    return null;
}
 
开发者ID:ixufeng,项目名称:JavaTools,代码行数:20,代码来源:ThreadPoolImpl.java

示例5: update

import java.util.Collection; //导入依赖的package包/类
public synchronized void update(Collection<Snake> snakes) {
    Location nextLocation = head.getAdjacentLocation(direction);
    if (nextLocation.x >= SnakeWebSocketServlet.PLAYFIELD_WIDTH) {
        nextLocation.x = 0;
    }
    if (nextLocation.y >= SnakeWebSocketServlet.PLAYFIELD_HEIGHT) {
        nextLocation.y = 0;
    }
    if (nextLocation.x < 0) {
        nextLocation.x = SnakeWebSocketServlet.PLAYFIELD_WIDTH;
    }
    if (nextLocation.y < 0) {
        nextLocation.y = SnakeWebSocketServlet.PLAYFIELD_HEIGHT;
    }
    if (direction != Direction.NONE) {
        tail.addFirst(head);
        if (tail.size() > length) {
            tail.removeLast();
        }
        head = nextLocation;
    }

    handleCollisions(snakes);
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:25,代码来源:Snake.java

示例6: isEmpty

import java.util.Collection; //导入依赖的package包/类
/**
 * 检查指定的集合/数组/枚举为空
 * <p>
 * 此方法可以处理如下对象:
 * <ul>
 * <li>Collection
 * <li>Map
 * <li>Array
 * <li>Enumeration
 * </ul>
 * <p>
 *
 * @param object
 * @return true
 * @throws IllegalArgumentException
 * @since 1.0
 */
public static boolean isEmpty(final Object object) {
	if (object == null) {
		return true;
	} else if (object instanceof Collection<?>) {
		return ((Collection<?>) object).isEmpty();
	} else if (object instanceof Map<?, ?>) {
		return ((Map<?, ?>) object).isEmpty();
	} else if (object instanceof Object[]) {
		return ((Object[]) object).length == 0;
	} else if (object instanceof Iterator<?>) {
		return ((Iterator<?>) object).hasNext() == false;
	} else if (object instanceof Enumeration<?>) {
		return ((Enumeration<?>) object).hasMoreElements() == false;
	} else {
		try {
			return Array.getLength(object) == 0;
		} catch (final IllegalArgumentException ex) {
			throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName());
		}
	}
}
 
开发者ID:smxc,项目名称:garlicts,代码行数:39,代码来源:CollectionUtil.java

示例7: removeAll

import java.util.Collection; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * <p>The returned collection is immutable.
 */
@Override
public Collection<V> removeAll(@Nullable Object key) {
  Collection<V> collection = map.remove(key);

  if (collection == null) {
    return createUnmodifiableEmptyCollection();
  }

  Collection<V> output = createCollection();
  output.addAll(collection);
  totalSize -= collection.size();
  collection.clear();

  return unmodifiableCollectionSubclass(output);
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:21,代码来源:AbstractMapBasedMultimap.java

示例8: getLevelOrderedDevices

import java.util.Collection; //导入依赖的package包/类
/**
 * Get the scannables, ordered by level, lowest first
 * @param position
 * @return
 * @throws ScanningException
 */
protected Map<Integer, List<L>> getLevelOrderedDevices() throws ScanningException {
	if (sortedObjects!=null && sortedObjects.get()!=null) return sortedObjects.get();

	final Collection<L> devices = getDevices();

	if (devices == null) return Collections.emptyMap();

	final Map<Integer, List<L>> devicesByLevel = new TreeMap<>();
	for (L object : devices) {
		final int level = object.getLevel();

		if (!devicesByLevel.containsKey(level)) devicesByLevel.put(level, new ArrayList<L>(7));
		devicesByLevel.get(level).add(object);
	}
	if (isLevelCachingAllowed()) sortedObjects = new SoftReference<Map>(devicesByLevel);

	return devicesByLevel;
}
 
开发者ID:eclipse,项目名称:scanning,代码行数:25,代码来源:LevelRunner.java

示例9: connected

import java.util.Collection; //导入依赖的package包/类
/**
 * Test whether a graph is connected.
 * 
 * @param graph to test.
 * @return true if graph is connected, false otherwise.
 */
public static boolean connected(Graph<IVertex, IEdge> graph) {
	DijkstraShortestPath<IVertex, IEdge> sp = new DijkstraShortestPath<>(graph);
	Collection<IVertex> verts = graph.getVertices();

	// forall vertA, vertB in graph exists connecting path <=> graph is connected
	for (IVertex vertA : verts) {
		for (IVertex vertB : verts) {
			if (sp.getDistance(vertA, vertB) == null) {
				return false;
			}
		}
	}

	return true;
}
 
开发者ID:KeepTheBeats,项目名称:alevin-svn2,代码行数:22,代码来源:GraphMetrics.java

示例10: testRemoveMemberReplicaForShard

import java.util.Collection; //导入依赖的package包/类
@Test
public void testRemoveMemberReplicaForShard() {
    configuration.removeMemberReplicaForShard("default", MEMBER_2);
    String shardName = configuration.getShardNameForModule("default");
    assertEquals("ModuleShardName", "default", shardName);
    ShardStrategy shardStrategy = configuration.getStrategyForModule("default");
    assertNull("ModuleStrategy", shardStrategy);
    Collection<MemberName> members = configuration.getMembersFromShardName("default");
    assertEquals("Members", ImmutableSortedSet.of(MEMBER_1, MEMBER_3),
        ImmutableSortedSet.copyOf(members));

    configuration.removeMemberReplicaForShard("non-existent", MEMBER_2);
    Set<String> shardNames = configuration.getAllShardNames();
    assertEquals("ShardNames", ImmutableSortedSet.of("people-1", "cars-1", "test-1", "default"),
        ImmutableSortedSet.copyOf(shardNames));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:ConfigurationImplTest.java

示例11: processCollection

import java.util.Collection; //导入依赖的package包/类
private Object processCollection(Object parent, Property property, Collection<?> col,
	IdentityHashMap<Object, Object> map, Map<Object, Object> evictees, InitialiserCallback callback,
	List<PropertySet> propsToSet)
{
	Collection<Object> newList = getSupportedCollection(col);

	for( Object colObj : col )
	{
		if( colObj != null )
		{
			Object newObj = processObject(parent, property, colObj, null, map, evictees, callback, propsToSet);
			newList.add(newObj);
		}
	}

	map.put(col, newList);
	return newList;
}
 
开发者ID:equella,项目名称:Equella,代码行数:19,代码来源:InitialiserServiceImpl.java

示例12: LinkedBlockingDeque

import java.util.Collection; //导入依赖的package包/类
public LinkedBlockingDeque(Collection<? extends E> c) {
    this(Integer.MAX_VALUE);
    ReentrantLock lock = this.lock;
    lock.lock();
    try {
        for (E e : c) {
            if (e == null) {
                throw new NullPointerException();
            } else if (!linkLast(new Node(e))) {
                throw new IllegalStateException("Deque full");
            }
        }
    } finally {
        lock.unlock();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:17,代码来源:LinkedBlockingDeque.java

示例13: panelActivated

import java.util.Collection; //导入依赖的package包/类
@Override
public void panelActivated(Lookup context) {
    // lookup context and listen to result to get notified about context changes
    currentContext = context.lookup(MY_DATA);
    currentContext.addLookupListener(getContextListener());
    // get actual data and recompute content
    Collection data = currentContext.allInstances();
    currentDataObject = getDataObject(data);
    if (currentDataObject == null) {
        return;
    }
    if (fileChangeListener == null) {
        fileChangeListener = new ImageFileChangeAdapter();
    }
    currentDataObject.getPrimaryFile().addFileChangeListener(fileChangeListener);
    setNewContent(currentDataObject);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ImageNavigatorPanel.java

示例14: getEvents

import java.util.Collection; //导入依赖的package包/类
@Path("events")
@GET
public Collection<Event> getEvents(
        @QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds,
        @QueryParam("type") final List<String> types,
        @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException {
    return Events.getObjects(getUserId(), deviceIds, groupIds, types,
            DateUtil.parseDate(from), DateUtil.parseDate(to));
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:10,代码来源:ReportResource.java

示例15: JSONArray

import java.util.Collection; //导入依赖的package包/类
/**
 * Construct a JSONArray from a collection of beans.
 * The collection should have Java Beans.
 */

public JSONArray(Collection<?> collection, boolean includeSuperClass) {
    this.myArrayList = new ArrayList<Object>();
    if(collection != null) {
        for (Iterator<?> iter = collection.iterator(); iter.hasNext();) {
            this.myArrayList.add(new JSONObject(iter.next(),includeSuperClass));    
        }
    }
}
 
开发者ID:faclc4,项目名称:HTAPBench,代码行数:14,代码来源:JSONArray.java


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