本文整理汇总了Java中java.util.Collections类的典型用法代码示例。如果您正苦于以下问题:Java Collections类的具体用法?Java Collections怎么用?Java Collections使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Collections类属于java.util包,在下文中一共展示了Collections类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadArtists
import java.util.Collections; //导入依赖的package包/类
@Override
public List<String> loadArtists(Context context) {
try (Cursor cursor = context.getContentResolver().query(
URI, PROJECTION, null, null, null)) {
if (cursor == null) {
throw new IllegalStateException("No cursor was obtained");
}
Set<String> artistsSet = new HashSet<>();
while (cursor.moveToNext()) {
int columnIndex = cursor.getColumnIndex(MediaStore.Audio.AudioColumns.ARTIST);
String artist = cursor.getString(columnIndex);
if (!artist.isEmpty()) {
artistsSet.add(artist);
}
}
List<String> artists = Arrays.asList(artistsSet.toArray(new String[artistsSet.size()]));
Collections.sort(artists);
return artists;
}
}
示例2: upToDate
import java.util.Collections; //导入依赖的package包/类
/** True if this TypePanel object does not need to be rebuilt. */
private boolean upToDate(final AlloyType type, List<AlloyAtom> atoms) {
if (!this.type.equals(type)) {
return false;
}
atoms = new ArrayList<AlloyAtom>(atoms);
Collections.sort(atoms);
if (!this.atoms.equals(atoms)) {
return false;
}
for (int i = 0; i < this.atoms.size(); i++) {
final String n = this.atoms.get(i).getVizName(VizGraphPanel.this.vizState, true);
if (!this.atomnames[i].equals(n)) {
return false;
}
}
return true;
}
示例3: onSongSelected
import java.util.Collections; //导入依赖的package包/类
private void onSongSelected(MusicDirectory.Entry song, boolean save, boolean append, boolean autoplay, boolean playNext)
{
DownloadService downloadService = getDownloadService();
if (downloadService != null)
{
if (!append && !playNext)
{
downloadService.clear();
}
downloadService.download(Collections.singletonList(song), save, false, playNext, false, false);
if (autoplay)
{
downloadService.play(downloadService.size() - 1);
}
Util.toast(SearchActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_added, 1, 1));
}
}
示例4: shouldBeFlaggedAsIdempotentWhenIdempotentRecords
import java.util.Collections; //导入依赖的package包/类
@Test
public void shouldBeFlaggedAsIdempotentWhenIdempotentRecords() throws Exception {
final MemoryRecords memoryRecords = MemoryRecords.withIdempotentRecords(1,
CompressionType.NONE,
1L,
(short) 1,
1,
1,
simpleRecord);
final ProduceRequest request = new ProduceRequest.Builder(RecordBatch.CURRENT_MAGIC_VALUE,
(short) -1,
10,
Collections.singletonMap(
new TopicPartition("topic", 1), memoryRecords)).build();
assertTrue(request.isIdempotent());
}
示例5: draw
import java.util.Collections; //导入依赖的package包/类
@Override
public void draw(WeaponsCapability weaponsCapability, ItemStack stack, final EntityLivingBase living, World world) {
super.draw(weaponsCapability, stack, living, world);
if (!world.isRemote) {
weaponsCapability.controlledSentry = null;
List<EntitySentry> list = world.getEntitiesWithinAABB(EntitySentry.class,
living.getEntityBoundingBox().grow(128, 128, 128), new Predicate<EntitySentry>() {
@Override
public boolean apply(EntitySentry input) {
// TODO Auto-generated method stub
return input.getOwner() == living && !input.isDisabled();
}
});
Collections.sort(list, new EntityAINearestAttackableTarget.Sorter(living));
if (!list.isEmpty()) {
list.get(0).setControlled(true);
weaponsCapability.controlledSentry = list.get(0);
}
}
}
示例6: makeDescriptor
import java.util.Collections; //导入依赖的package包/类
static <T> Descriptor makeDescriptor(OpenType<T> openType,
T defaultValue,
T[] legalValues,
Comparable<T> minValue,
Comparable<T> maxValue) {
Map<String, Object> map = new HashMap<String, Object>();
if (defaultValue != null)
map.put("defaultValue", defaultValue);
if (legalValues != null) {
Set<T> set = new HashSet<T>();
for (T v : legalValues)
set.add(v);
set = Collections.unmodifiableSet(set);
map.put("legalValues", set);
}
if (minValue != null)
map.put("minValue", minValue);
if (maxValue != null)
map.put("maxValue", maxValue);
if (map.isEmpty()) {
return openType.getDescriptor();
} else {
map.put("openType", openType);
return new ImmutableDescriptor(map);
}
}
示例7: testRemoveUntrackedFile
import java.util.Collections; //导入依赖的package包/类
public void testRemoveUntrackedFile () throws Exception {
File file = new File(workDir, "toRemove");
file.createNewFile();
assertTrue(file.exists());
GitClient client = getClient(workDir);
Map<File, GitStatus> statuses = client.getStatus(new File[] { file }, NULL_PROGRESS_MONITOR);
assertEquals(1, statuses.size());
assertStatus(statuses, workDir, file, false, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_ADDED, false);
Monitor m = new Monitor();
client.addNotificationListener(m);
client.remove(new File[] { file }, false, m);
assertFalse(file.exists());
assertEquals(Collections.singleton(file), m.notifiedFiles);
statuses = client.getStatus(new File[] { file }, NULL_PROGRESS_MONITOR);
assertEquals(0, statuses.size());
}
示例8: addLibraryRecordList
import java.util.Collections; //导入依赖的package包/类
public void addLibraryRecordList(List<OfflineHistoryRecord> offlineRecords) {
if (offlineRecords == null || offlineRecords == Collections.EMPTY_LIST)
return;
//checkLibraryRecord(offlineRecords);
int startPos = 0;
if (mItems != null) {
startPos = this.mItems.size();
this.mItems.addAll(offlineRecords);
} else {
this.mItems = offlineRecords;
}
mResults = (List<OfflineHistoryRecord>) ((ArrayList<OfflineHistoryRecord>) mItems).clone();
if (offlineRecords.size() > 1)
this.notifyItemRangeInserted(startPos, offlineRecords.size() - 1);
else
this.notifyItemRangeInserted(startPos, 1);
}
示例9: testIpv4RouteDelete
import java.util.Collections; //导入依赖的package包/类
/**
* Tests deleting a IPv4 route entry.
*/
@Test
public void testIpv4RouteDelete() {
// Firstly add a route
testIpv4RouteAdd();
RouteEntry deleteRouteEntry = new RouteEntry(
Ip4Prefix.valueOf("1.1.1.0/24"),
Ip4Address.valueOf("192.168.10.1"));
FibEntry deleteFibEntry = new FibEntry(
Ip4Prefix.valueOf("1.1.1.0/24"), null, null);
reset(fibListener);
fibListener.update(Collections.emptyList(), Collections.singletonList(
new FibUpdate(FibUpdate.Type.DELETE, deleteFibEntry)));
replay(fibListener);
router.processRouteUpdates(Collections.singletonList(
new RouteUpdate(RouteUpdate.Type.DELETE, deleteRouteEntry)));
verify(fibListener);
}
示例10: extractCashtagsWithIndices
import java.util.Collections; //导入依赖的package包/类
/**
* Extract $cashtag references from Tweet text.
*
* @param text of the tweet from which to extract cashtags
* @return List of cashtags referenced (without the leading $ sign)
*/
public List<Entity> extractCashtagsWithIndices(String text) {
if (text == null || text.length() == 0) {
return Collections.emptyList();
}
// Performance optimization.
// If text doesn't contain $, text doesn't contain
// cashtag, so we can simply return an empty list.
if (text.indexOf('$') == -1) {
return Collections.emptyList();
}
List<Entity> extracted = new ArrayList<Entity>();
Matcher matcher = Regex.VALID_CASHTAG.matcher(text);
while (matcher.find()) {
extracted.add(new Entity(matcher, Type.CASHTAG, Regex.VALID_CASHTAG_GROUP_CASHTAG));
}
return extracted;
}
示例11: getRemoteAddresses
import java.util.Collections; //导入依赖的package包/类
@Override
public Set<SocketAddress> getRemoteAddresses()
throws IOException {
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
if (!isConnected() || isShutdown)
return Collections.emptySet();
try {
return SctpNet.getRemoteAddresses(fdVal, 0/*unused*/);
} catch (SocketException unused) {
/* an open connected channel should always have remote addresses */
return remoteAddresses;
}
}
}
示例12: lit16NotSupported
import java.util.Collections; //导入依赖的package包/类
@Test
public void lit16NotSupported() {
String[] lit8OnlyBinops = new String[]{
"shl", "shr", "ushr",
};
for (String binop : lit8OnlyBinops) {
for (int lit16Value : lit16Values) {
DexEncodedMethod method = oneMethodApplication(
"int", Collections.singletonList("int"),
1,
" const/16 v0, " + lit16Value,
" " + binop + "-int/2addr p0, v0 ",
" return p0"
);
DexCode code = method.getCode().asDexCode();
assertEquals(3, code.instructions.length);
assertTrue(code.instructions[0] instanceof Const16);
assertEquals(lit16Value, ((Const16) code.instructions[0]).BBBB);
assertTrue(code.instructions[2] instanceof Return);
}
}
}
示例13: doFilter
import java.util.Collections; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpServletRequest = ((HttpServletRequest) request);
HttpServletMapping mapping = ((HttpServletRequest) request).getHttpServletMapping();
String resourceURI = mapping.getMatchValue();
if (mapping.getServletName().equals("jsp")) {
// Push resources
resourceCache.keySet().stream()
.filter(resourceURI::contains)
.findFirst()
.ifPresent(s -> resourceCache.get(s)
.forEach(path -> httpServletRequest.newPushBuilder().path(path).push()));
// create empty resource list if absent
resourceCache.putIfAbsent(resourceURI, Collections.newSetFromMap(new ConcurrentHashMap<>()));
} else {
// Add resource
resourceCache.keySet().stream()
.filter(httpServletRequest.getHeader("Referer")::contains)
.forEach(page -> resourceCache.get(page).add(resourceURI));
}
chain.doFilter(request, response);
}
示例14: testReadIdRef
import java.util.Collections; //导入依赖的package包/类
@Test
public void testReadIdRef() throws Exception {
final Map<String, Map<Date, IdentityMapping>> identityMapping = Maps.newHashMap();
final IdentityMapping value = new IdentityMapping();
final Date rev = new Date();
identityMapping.put("namespace", Collections.singletonMap(rev, value));
identityMapping.put("inner", Collections.singletonMap(rev, value));
final SimpleIdentityRefAttributeReadingStrategy key = new SimpleIdentityRefAttributeReadingStrategy(null, "key",
identityMapping);
String read = key.readElementContent(XmlElement.fromString("<el xmlns=\"namespace\">local</el>"));
assertEquals(
org.opendaylight.yangtools.yang.common.QName.create(URI.create("namespace"), rev, "local").toString(),
read);
read = key.readElementContent(XmlElement.fromString("<el xmlns:a=\"inner\" xmlns=\"namespace\">a:local</el>"));
assertEquals(org.opendaylight.yangtools.yang.common.QName.create(URI.create("inner"), rev, "local").toString(),
read);
read = key.readElementContent(
XmlElement.fromString("<top xmlns=\"namespace\"><el>local</el></top>").getOnlyChildElement());
assertEquals(
org.opendaylight.yangtools.yang.common.QName.create(URI.create("namespace"), rev, "local").toString(),
read);
}
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:26,代码来源:SimpleIdentityRefAttributeReadingStrategyTest.java
示例15: resolveShardAdditions
import java.util.Collections; //导入依赖的package包/类
void resolveShardAdditions(final Set<DOMDataTreeIdentifier> additions) {
LOG.debug("{}: Resolving additions : {}", memberName, additions);
final ArrayList<DOMDataTreeIdentifier> list = new ArrayList<>(additions);
// we need to register the shards from top to bottom, so we need to atleast make sure the ordering reflects that
Collections.sort(list, (o1, o2) -> {
if (o1.getRootIdentifier().getPathArguments().size() < o2.getRootIdentifier().getPathArguments().size()) {
return -1;
} else if (o1.getRootIdentifier().getPathArguments().size()
== o2.getRootIdentifier().getPathArguments().size()) {
return 0;
} else {
return 1;
}
});
list.forEach(this::createShardFrontend);
}