本文整理汇总了Java中java.util.ArrayList.forEach方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayList.forEach方法的具体用法?Java ArrayList.forEach怎么用?Java ArrayList.forEach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.ArrayList
的用法示例。
在下文中一共展示了ArrayList.forEach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveShardAdditions
import java.util.ArrayList; //导入方法依赖的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);
}
示例2: testGetNewUniqueName
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* Test of getNewUniqueName method, of class FileLoader.
*/
@Test
public void testGetNewUniqueName() {
System.out.println("getNewUniqueName");
String pathToDir = "/src/test/testfiles/";
ArrayList<String> usedNames = new ArrayList<>();
File folder = new File(pathToDir);
File[] listOfFiles = folder.listFiles();
if (listOfFiles != null) {
for (File file : listOfFiles) {
if (file.isFile()) {
usedNames.add(file.getName());
}
}
}
String result = FileLoader.getNewUniqueName(pathToDir);
assert (result != null);
usedNames.forEach((filename) -> {
assert (!(filename.equals(result)));
});
}
示例3: sendDownloadRequestsOpenSub
import java.util.ArrayList; //导入方法依赖的package包/类
public void sendDownloadRequestsOpenSub(ArrayList<VideoInfo> videoInfoArray, String lang) {
videoInfoArray.forEach((videoInfo) -> {
try {
if (!videoInfo.getChecksumHash().equals("") && !videoInfo.isDownloaded()) {
String subtitle = sendGetSubtitleOpenSub(videoInfo.getChecksumHash(), videoInfo.getFileByteLength(), lang);
if (subtitle != null && !subtitle.equals("")) {
videoInfo.setSubtitle(subtitle);
videoInfo.setDownloaded(true);
}
System.out.println("subtitlemanager.HTTPRequest.sendDownloadRequestsOpenSub() subtile == null = " + (videoInfo.getSubtitle() == null) + " hash = " + videoInfo.getChecksumHash() + " fileName = " + videoInfo.getFullFilePath());;
} else {
if (!videoInfo.isDownloaded()) {
System.out.println("subtitlemanager.HTTPRequest.sendDownloadRequestsOpenSub() Hash for file = " + videoInfo.getFullFilePath() + " is " + videoInfo.getChecksumHash());
}
}
} catch (Exception ex) {
Logger.getLogger(HTTPRequest.class.getName()).log(Level.SEVERE, null, ex);
}
});
}
示例4: Colar
import java.util.ArrayList; //导入方法依赖的package包/类
public void Colar(FormaElementar var) {
if (copiado == null) {
return;
}
if (var instanceof Forma) {
if (((Forma) var).editFonte) {
var.setFont(fonteCopiada);
}
}
ArrayList<InspectorProperty> dest = Resuma(var.GenerateFullProperty());
ArrayList<InspectorProperty> aColar = new ArrayList<>();
ArrayList<String> tmp = new ArrayList<>();
dest.forEach(it -> {
tmp.add(it.property);
});
copiado.stream().filter(c -> tmp.indexOf(c.property) > -1).forEach(ac -> {
aColar.add(ac);
});
aColar.forEach(ac -> {
var.getMaster().ColeFormatacao(var, ac, ac.valor_string);
});
}
示例5: main
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* Tester method
*/
public static void main(String... args) {
// Example 1 : sorting an ArrayList of integers
InsertionSort<Integer> sortIntegers = new InsertionSort<>();
ArrayList<Integer> elements = new ArrayList<>(
Arrays.asList(98, 56, 42, 78, 36, 4, 12, 2)
);
sortIntegers.sort(elements);
elements.forEach(element -> System.out.print(element + " "));
// Example 2 : sorting an array of strings
InsertionSort<String> sortStrings = new InsertionSort<>();
String[] data = {"echo", "foxtrot", "charlie", "alpha", "bravo", "delta"};
sortStrings.sort(data);
System.out.println("\n" + Arrays.toString(data));
// Example 3 : sorting an empty array
InsertionSort<Character> sortChars = new InsertionSort<>();
Character[] chars = new Character[0];
sortChars.sort(chars);
System.out.println(Arrays.toString(chars));
// Example 4 : sorting an already sorted ArrayList of Integers
ArrayList<Integer> sorted = new ArrayList<>(
Arrays.asList(2, 4, 12, 36, 42, 56, 78, 98)
);
sortIntegers.sort(sorted);
elements.forEach(element -> System.out.print(element + " "));
System.out.println();
// Example 5 : sorting a list that is sorted in reverse order
final List<String> words = Arrays.asList(
"foxtrot", "echo", "delta", "charlie", "bravo", "alpha");
List<String> result = sortStrings.sort(words);
result.forEach(element -> System.out.print(element + " "));
System.out.println();
}
示例6: addArrayList
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* adds an ArrayList with the indenting
*
* @param arrayList the added ArrayList
*/
public void addArrayList(ArrayList<String> arrayList) {
if (arrayList != null) {
arrayList.forEach((singleItem) -> {
this.add(singleItem);
});
}
}
示例7: unloadAll
import java.util.ArrayList; //导入方法依赖的package包/类
private Consumer<CommandSource> unloadAll(Player player) {
return src -> {
ArrayList<LoadedRegion> loadedRegions = Lists
.newArrayList(dataStore.getPlayerRegions(player.getUniqueId()));
loadedRegions.forEach(loadedRegion ->
dataStore.deletePlayerRegion(loadedRegion.getOwner(), loadedRegion.getUniqueId())
);
};
}
示例8: runOnLoop
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* Process all loops in the entire function.
* @param loop
* @return
*/
@Override
public boolean runOnLoop(Loop loop, LPPassManager ppm)
{
predCache.clear();
li = (LoopInfo) getAnalysisToUpDate(LoopInfo.class);
dt = (DomTree) getAnalysisToUpDate(DomTree.class);
loopBlocks = new ArrayList<>(loop.getBlocks());
ArrayList<BasicBlock> exitBlocks = loop.getExitingBlocks();
ArrayList<Instruction> affectedValues = new ArrayList<>();
getLoopValueUsedOutsideLoop(loop, affectedValues, exitBlocks);
// If no values are affected, we can save a lot of work, since we know that
// nothing will be changed.
if (affectedValues.isEmpty())
return false;
// Iterate over all affected values for this loop and insert Phi nodes
// for them in the appropriate exit blocks
affectedValues.forEach(var->
{
processInstruction(var, exitBlocks);
});
return true;
}
示例9: openChest
import java.util.ArrayList; //导入方法依赖的package包/类
public void openChest(Chest chest, Player p){
AllItems items = new AllItems();
if (cooldown.isCoolingDown(chest)) {
WCTWD.getPlayer(p).sendMessage("&cEste cofre está en cooldown. Tiempo &6" + cooldown.getTimeLeft(chest));
return;
}
cooldown.setOnCooldown(chest);
Inventory inv = Bukkit.createInventory(null, 36, ChatColor.RED + "Cofre de Recursos");
//Ajustar cantidad
int i1 = r.nextInt(3);
int i2 = r.nextInt(3);
int i3 = r.nextInt(2);
ArrayList<ItemStack> aleatorios = new ArrayList<>();
for (int i = 0; i < i1; i++) {
if (r.nextInt(4) > 1) aleatorios.add(items.weapons.get(r.nextInt(items.weapons.size())));
}
for (int i = 0; i < i2; i++) {
if (r.nextInt(4) > 1) aleatorios.add(items.health.get(r.nextInt(items.health.size())));
}
for (int i = 0; i < i3; i++) {
if (r.nextInt(3) == 2) aleatorios.add(items.weapons2.get(r.nextInt(items.weapons2.size())));
}
aleatorios.forEach(i -> setItem(inv, getSlot(r, inv), i));
p.closeInventory();
p.openInventory(inv);
}
示例10: DagInit
import java.util.ArrayList; //导入方法依赖的package包/类
public DagInit(Init val, String vn, ArrayList<Pair<Init, String>> args)
{
super(new RecTy.DagRecTy());
this.val = val;
varName = vn;
this.args = new ArrayList<>(args.size());
argNames = new ArrayList<>(args.size());
args.forEach(pair->{
this.args.add(pair.first);
argNames.add(pair.second);
});
}
示例11: addAlerta
import java.util.ArrayList; //导入方法依赖的package包/类
public void addAlerta(ArrayList<AlertaInternacional> al){
//for(int i=0;i<=al.length;i++){
// dtm.setRowCount(dtm.getRowCount()+1);
// dtm.setValueAt(al[i], i, 0);
//}
//TODO: TRABAJANDO AQUI
i=0;
al.forEach((_item) -> {
if(!al.isEmpty()){
dtm.setRowCount(al.size());
//showMessageDialog(null, _item.toString()+"\n ID: "+_item.getId()+"\nSize: "+al.size());
dtm.setValueAt(_item, i, 0);
if (i <= al.size()) {
i++;
} else {
}
}else{
}
//valor, row, columna(titulo cabeza)
//dtm.setValueAt(a, i, 0);
});
}
示例12: input
import java.util.ArrayList; //导入方法依赖的package包/类
public void input(){
ArrayList<ClickType> clicks = new ArrayList<ClickType>();
for(int k : Keyboard.events){
clicks.add(new ClickType(false, k));
}
//focused element listens to the keyboard clicks
for(ClickType click : clicks){
options[current].onClick(click);
}
clicks.clear();
for(int m : Mouse.events){
clicks.add(new ClickType(true, m));
}
Vector2f mPos = scene.flipY(Mouse.x, Mouse.y);
if(clicks.size() != 0){
for(UIElement option : options){
if(option.contains(mPos)){
clicks.forEach((click)->option.onClick(click));
}
}
clicks.clear();
}
Input();
}
示例13: getAllUnitDefinitions
import java.util.ArrayList; //导入方法依赖的package包/类
public final EnumMap<Category, ArrayList<UnitDefinition>> getAllUnitDefinitions() {
final EnumMap<Category, ArrayList<UnitDefinition>> UNIT_TYPES = new EnumMap<>(Category.class);
final ArrayList<Category> CATEGORY_LIST = new ArrayList<>(Category.values().length);
CATEGORY_LIST.addAll(Arrays.asList(Category.values()));
CATEGORY_LIST.forEach(category -> UNIT_TYPES.put(category, new ArrayList<>()));
for (UnitDefinition unitDefinition : UnitDefinition.values()) {
UNIT_TYPES.get(unitDefinition.UNIT.getCategory()).add(unitDefinition);
}
return UNIT_TYPES;
}
示例14: saveRegionData
import java.util.ArrayList; //导入方法依赖的package包/类
public void saveRegionData(ArrayList<LoadedRegion> data) {
data.forEach(this::saveRegionData);
}
示例15: execute
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* Callback for the execution of a command.
*
* @param src The commander who is executing this command
* @param args The parsed command arguments for this command
* @return the result of executing this command
* @throws CommandException If a user-facing error occurs while executing this command
*/
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player))
return execServer(src, args);
User user = args.<User>getOne(USER).orElse((Player) src);
List<Text> listText = Lists.newArrayList();
ArrayList<LoadedRegion> loadedRegions = dataStore.getPlayerRegions(user);
Text header = Text.of(
"Listing ",
TextColors.GOLD, loadedRegions.size(),
TextColors.RESET, " region(s) across ",
TextColors.GOLD, dataStore.getPlayerRegionWorlds(user).size(),
TextColors.RESET, " worlds"
);
if (loadedRegions.isEmpty())
header = Text.of(TextColors.RED, "There are no loaded regions to display");
loadedRegions.forEach(region -> listText.add(Text.of(
TextColors.GOLD, region.getChunks().size(),
TextColors.GREEN, Text.of(" [", (region.getType() == LoadedRegion.ChunkType.WORLD) ? 'W' : 'P', "]")
.toBuilder().onHover(TextActions.showText(Text.of(TextColors.GREEN,
(region.getType() == LoadedRegion.ChunkType.WORLD) ? "World" : "Personal"
))),
TextColors.WHITE, (region.getChunks().size() > 1) ? " chunks in world " : " chunk in world ",
TextColors.GOLD, region.getWorld().getName(),
TextColors.WHITE, " from (", TextColors.LIGHT_PURPLE, region.getRegion().getFrom().getX(), TextColors.WHITE,
", ", TextColors.LIGHT_PURPLE, region.getRegion().getFrom().getZ(), TextColors.WHITE, ")",
TextColors.WHITE, " to (", TextColors.LIGHT_PURPLE, region.getRegion().getTo().getX(), TextColors.WHITE,
", ", TextColors.LIGHT_PURPLE, region.getRegion().getTo().getZ(), TextColors.WHITE, ")"
)));
PaginationList.builder()
.title(Text.of(TextColors.GOLD, "Loaded Regions"))
.padding(Text.of(TextColors.GOLD, TextStyles.STRIKETHROUGH, "-"))
.header(header)
.contents(listText)
.sendTo(src);
return CommandResult.success();
}