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


Java Collectors类代码示例

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


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

示例1: testOps

import java8.util.stream.Collectors; //导入依赖的package包/类
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
public void testOps(String name, TestData.OfRef<Integer> data) {
    // @@@ More things to test here:
    //     - Every value in data is present in right bucket
    //     - Total number of values equals size of data

    for (MapperData<Integer, ?> md : getMapperData(data)) {
        Collector<Integer, ?, Map<Object, List<Integer>>> tab = Collectors.groupingBy(md.m);
        Map<Object, List<Integer>> result =
                withData(data)
                .terminal((Stream<Integer> s) -> s, s -> s.collect(tab))
                .resultAsserter((act, exp, ord, par) -> {
                    if (par & !ord) {
                        GroupByOpTest.assertMultiMapEquals(act, exp);
                    }
                    else {
                        GroupByOpTest.assertObjectEquals(act, exp);
                    }
                })
                .exercise();
        assertEquals(result.keySet().size(), md.expectedSize);
    }
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:24,代码来源:GroupByOpTest.java

示例2: testShouldImplementMostRandomMethods

import java8.util.stream.Collectors; //导入依赖的package包/类
/**
 * SplittableRandom should implement most of Random's public methods
 */
public void testShouldImplementMostRandomMethods() throws Throwable {
    Predicate<Method> wasForgotten = method -> {
        String name = method.getName();
        // some methods deliberately not implemented
        if (name.equals("setSeed")) return false;
        if (name.equals("nextFloat")) return false;
        if (name.equals("nextGaussian")) return false;
        try {
            SplittableRandom.class.getMethod(
                method.getName(), method.getParameterTypes());
        } catch (Exception ex) {
            return true;
        }
        return false;
    };
    List<Method> forgotten =
        J8Arrays.stream(java.util.Random.class.getMethods())
        .filter(wasForgotten)
        .collect(Collectors.toList());
    if (!forgotten.isEmpty())
        throw new AssertionError("Please implement: " + forgotten);
}
 
开发者ID:streamsupport,项目名称:streamsupport,代码行数:26,代码来源:SplittableRandomTest.java

示例3: fill

import java8.util.stream.Collectors; //导入依赖的package包/类
public void fill(ITaskScheduler taskScheduler, AiStatistics aiStatistics, byte playerId, int maxNewPioneersCount) {
	if (isFull()) {
		return;
	}

	MovableGrid movableGrid = aiStatistics.getMainGrid().getMovableGrid();
	List<ShortPoint2D> joblessBearers = aiStatistics.getPositionsOfJoblessBearersForPlayer(playerId);

	int newPioneers = Math.min(getMissingPioneers(), maxNewPioneersCount);

	List<Integer> newPioneerIds = stream(joblessBearers)
			.limit(newPioneers)
			.map(position -> movableGrid.getMovableAt(position.x, position.y))
			.map(ILogicMovable::getID)
			.collect(Collectors.toList());

	if (newPioneerIds.size() > 0) {
		taskScheduler.scheduleTask(new ConvertGuiTask(playerId, newPioneerIds, EMovableType.PIONEER));
		pioneerIds.addAll(newPioneerIds);
	}
}
 
开发者ID:jsettlers,项目名称:settlers-remake,代码行数:22,代码来源:PioneerGroup.java

示例4: AiStatistics

import java8.util.stream.Collectors; //导入依赖的package包/类
public AiStatistics(MainGrid mainGrid) {
	this.mainGrid = mainGrid;
	buildings = Building.getAllBuildings();
	landscapeGrid = mainGrid.getLandscapeGrid();
	objectsGrid = mainGrid.getObjectsGrid();
	partitionsGrid = mainGrid.getPartitionsGrid();
	movableGrid = mainGrid.getMovableGrid();
	flagsGrid = mainGrid.getFlagsGrid();
	constructionMarksGrid = mainGrid.getConstructionMarksGrid();
	playerStatistics = new PlayerStatistic[mainGrid.getGuiInputGrid().getNumberOfPlayers()];
	aiMapInformation = new AiMapInformation(partitionsGrid, landscapeGrid);
	for (byte i = 0; i < mainGrid.getGuiInputGrid().getNumberOfPlayers(); i++) {
		this.playerStatistics[i] = new PlayerStatistic();
	}
	sortedRiversInDefaultPartition = new AiPositions();
	sortedCuttableObjectsInDefaultPartition = new HashMap<>();
	sortedResourceTypes = new AiPositions[EResourceType.VALUES.length];
	for (int i = 0; i < sortedResourceTypes.length; i++) {
		sortedResourceTypes[i] = new AiPositions();
	}
	resourceCountInDefaultPartition = new long[EResourceType.VALUES.length];
	players = J8Arrays.stream(partitionsGrid.getPlayers()).filter(Objects::nonNull).collect(Collectors.toList());
}
 
开发者ID:jsettlers,项目名称:settlers-remake,代码行数:24,代码来源:AiStatistics.java

示例5: toAppSpeakers

import java8.util.stream.Collectors; //导入依赖的package包/类
public List<com.nilhcem.droidconde.data.app.model.Speaker> toAppSpeakers(@Nullable List<Speaker> from) {
    if (from == null) {
        return null;
    }

    return stream(from).map(speaker -> new com.nilhcem.droidconde.data.app.model.Speaker(
            speaker.getId(), speaker.getName(), speaker.getTitle(),
            speaker.getBio(), speaker.getWebsite(), speaker.getTwitter(),
            speaker.getGithub(), speaker.getPhoto())
    ).collect(Collectors.toList());
}
 
开发者ID:Nilhcem,项目名称:droidconde-2016,代码行数:12,代码来源:NetworkMapper.java

示例6: toAppSessions

import java8.util.stream.Collectors; //导入依赖的package包/类
public List<com.nilhcem.droidconde.data.app.model.Session> toAppSessions(@Nullable List<Session> from, @NonNull Map<Integer, com.nilhcem.droidconde.data.app.model.Speaker> speakersMap) {
    if (from == null) {
        return null;
    }

    return stream(from).map(session -> new com.nilhcem.droidconde.data.app.model.Session(session.getId(),
            Room.getFromId(session.getRoomId()).label,
            appMapper.toSpeakersList(session.getSpeakersId(), speakersMap),
            session.getTitle(), session.getDescription(),
            session.getStartAt(), session.getStartAt().plusMinutes(session.getDuration()))
    ).collect(Collectors.toList());
}
 
开发者ID:Nilhcem,项目名称:droidconde-2016,代码行数:13,代码来源:NetworkMapper.java

示例7: toAppSessions

import java8.util.stream.Collectors; //导入依赖的package包/类
public List<com.nilhcem.droidconde.data.app.model.Session> toAppSessions(@NonNull List<Session> from, @NonNull Map<Integer, com.nilhcem.droidconde.data.app.model.Speaker> speakersMap) {
    return stream(from).map(session -> {
        LocalDateTime fromTime = localDateTimeAdapter.fromText(session.startAt);
        return new com.nilhcem.droidconde.data.app.model.Session(session.id, Room.getFromId(session.roomId).label,
                appMapper.toSpeakersList(deserialize(session.speakersIds), speakersMap),
                session.title, session.description, fromTime, fromTime.plusMinutes(session.duration));
    }).collect(Collectors.toList());
}
 
开发者ID:Nilhcem,项目名称:droidconde-2016,代码行数:9,代码来源:DbMapper.java

示例8: toAppSpeakers

import java8.util.stream.Collectors; //导入依赖的package包/类
public List<com.nilhcem.droidconde.data.app.model.Speaker> toAppSpeakers(@Nullable List<Speaker> from) {
    if (from == null) {
        return null;
    }

    return stream(from).map(speaker -> new com.nilhcem.droidconde.data.app.model.Speaker(speaker.id,
            speaker.name, speaker.title, speaker.bio, speaker.website, speaker.twitter,
            speaker.github, speaker.photo)
    ).collect(Collectors.toList());
}
 
开发者ID:Nilhcem,项目名称:droidconde-2016,代码行数:11,代码来源:DbMapper.java

示例9: toAppSpeakers

import java8.util.stream.Collectors; //导入依赖的package包/类
public List<com.nilhcem.devfestnantes.data.app.model.Speaker> toAppSpeakers(@Nullable List<Speaker> from) {
    if (from == null) {
        return null;
    }

    return stream(from).map(speaker -> new com.nilhcem.devfestnantes.data.app.model.Speaker(
            speaker.getId(), speaker.getName(), speaker.getTitle(),
            speaker.getBio(), speaker.getWebsite(), speaker.getTwitter(),
            speaker.getGithub(), speaker.getPhoto())
    ).collect(Collectors.toList());
}
 
开发者ID:Nilhcem,项目名称:devfestnantes-2016,代码行数:12,代码来源:NetworkMapper.java

示例10: toAppSessions

import java8.util.stream.Collectors; //导入依赖的package包/类
public List<com.nilhcem.devfestnantes.data.app.model.Session> toAppSessions(@Nullable List<Session> from, @NonNull Map<Integer, com.nilhcem.devfestnantes.data.app.model.Speaker> speakersMap) {
    if (from == null) {
        return null;
    }

    return stream(from).map(session -> new com.nilhcem.devfestnantes.data.app.model.Session(session.getId(),
            Room.getFromId(session.getRoomId()).label,
            appMapper.toSpeakersList(session.getSpeakersId(), speakersMap),
            session.getTitle(), session.getDescription(),
            session.getStartAt(), session.getStartAt().plusMinutes(session.getDuration()))
    ).collect(Collectors.toList());
}
 
开发者ID:Nilhcem,项目名称:devfestnantes-2016,代码行数:13,代码来源:NetworkMapper.java

示例11: toAppSessions

import java8.util.stream.Collectors; //导入依赖的package包/类
public List<com.nilhcem.devfestnantes.data.app.model.Session> toAppSessions(@NonNull List<Session> from, @NonNull Map<Integer, com.nilhcem.devfestnantes.data.app.model.Speaker> speakersMap) {
    return stream(from).map(session -> {
        LocalDateTime fromTime = localDateTimeAdapter.fromText(session.startAt);
        return new com.nilhcem.devfestnantes.data.app.model.Session(session.id, Room.getFromId(session.roomId).label,
                appMapper.toSpeakersList(deserialize(session.speakersIds), speakersMap),
                session.title, session.description, fromTime, fromTime.plusMinutes(session.duration));
    }).collect(Collectors.toList());
}
 
开发者ID:Nilhcem,项目名称:devfestnantes-2016,代码行数:9,代码来源:DbMapper.java

示例12: toAppSpeakers

import java8.util.stream.Collectors; //导入依赖的package包/类
public List<com.nilhcem.devfestnantes.data.app.model.Speaker> toAppSpeakers(@Nullable List<Speaker> from) {
    if (from == null) {
        return null;
    }

    return stream(from).map(speaker -> new com.nilhcem.devfestnantes.data.app.model.Speaker(speaker.id,
            speaker.name, speaker.title, speaker.bio, speaker.website, speaker.twitter,
            speaker.github, speaker.photo)
    ).collect(Collectors.toList());
}
 
开发者ID:Nilhcem,项目名称:devfestnantes-2016,代码行数:11,代码来源:DbMapper.java

示例13: toAppSpeakers

import java8.util.stream.Collectors; //导入依赖的package包/类
public List<com.nilhcem.mobilization.data.app.model.Speaker> toAppSpeakers(@Nullable List<Speaker> from) {
    if (from == null) {
        return null;
    }

    return stream(from).map(speaker -> new com.nilhcem.mobilization.data.app.model.Speaker(
            speaker.getId(), speaker.getName(), speaker.getTitle(),
            speaker.getBio(), speaker.getWebsite(), speaker.getTwitter(),
            speaker.getGithub(), speaker.getPhoto())
    ).collect(Collectors.toList());
}
 
开发者ID:Nilhcem,项目名称:mobilization-2016,代码行数:12,代码来源:NetworkMapper.java

示例14: toAppSessions

import java8.util.stream.Collectors; //导入依赖的package包/类
public List<com.nilhcem.mobilization.data.app.model.Session> toAppSessions(@Nullable List<Session> from, @NonNull Map<Integer, com.nilhcem.mobilization.data.app.model.Speaker> speakersMap) {
    if (from == null) {
        return null;
    }

    return stream(from).map(session -> new com.nilhcem.mobilization.data.app.model.Session(session.getId(),
            Room.getFromId(session.getRoomId()).label,
            appMapper.toSpeakersList(session.getSpeakersId(), speakersMap),
            session.getTitle(), session.getDescription(),
            session.getStartAt(), session.getStartAt().plusMinutes(session.getDuration()))
    ).collect(Collectors.toList());
}
 
开发者ID:Nilhcem,项目名称:mobilization-2016,代码行数:13,代码来源:NetworkMapper.java

示例15: toAppSessions

import java8.util.stream.Collectors; //导入依赖的package包/类
public List<com.nilhcem.mobilization.data.app.model.Session> toAppSessions(@NonNull List<Session> from, @NonNull Map<Integer, com.nilhcem.mobilization.data.app.model.Speaker> speakersMap) {
    return stream(from).map(session -> {
        LocalDateTime fromTime = localDateTimeAdapter.fromText(session.startAt);
        return new com.nilhcem.mobilization.data.app.model.Session(session.id, Room.getFromId(session.roomId).label,
                appMapper.toSpeakersList(deserialize(session.speakersIds), speakersMap),
                session.title, session.description, fromTime, fromTime.plusMinutes(session.duration));
    }).collect(Collectors.toList());
}
 
开发者ID:Nilhcem,项目名称:mobilization-2016,代码行数:9,代码来源:DbMapper.java


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