List of usage examples for java.util ArrayList addAll
public boolean addAll(Collection<? extends E> c)
From source file:co.mcme.warps.commands.WarpListCommand.java
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { ArrayList<PlayerWarp> list = new ArrayList(); if (sender instanceof Player) { for (PlayerWarp warp : WarpDatabase.getWarps().values()) { if (warp.canWarp((Player) sender)) { list.add(warp);/* w w w .j a v a 2 s. co m*/ } } } else { list.addAll(WarpDatabase.getWarps().values()); } StringBuilder lines = new StringBuilder(); boolean first = true; for (PlayerWarp warp : list) { if (!first) { lines.append("\n"); } ChatColor col = ChatColor.GREEN; if (warp.isInviteonly()) { col = ChatColor.RED; } Date date = new Date(warp.getCreateStamp()); lines.append(col).append(warp.getName()).append(ChatColor.GRAY).append(" by ").append(ChatColor.AQUA) .append(warp.getOwner()).append(ChatColor.GRAY).append(" on ").append(ChatColor.AQUA) .append(Warps.getShortDateformat().format(date)); if (first) { first = false; } } if (args.length > 0 && StringUtils.isNumeric(args[0])) { ChatPaginator.ChatPage page = ChatPaginator.paginate(lines.toString(), Integer.valueOf(args[0]), ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH, 8); sender.sendMessage(ChatColor.GRAY + "Warp List page " + ChatColor.AQUA + page.getPageNumber() + ChatColor.GRAY + " of " + ChatColor.AQUA + page.getTotalPages()); for (String line : page.getLines()) { sender.sendMessage(line); } return true; } else { ChatPaginator.ChatPage page = ChatPaginator.paginate(lines.toString(), 1, ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH, 8); sender.sendMessage(ChatColor.GRAY + "Warp List page " + ChatColor.AQUA + page.getPageNumber() + ChatColor.GRAY + " of " + ChatColor.AQUA + page.getTotalPages()); for (String line : page.getLines()) { sender.sendMessage(line); } return true; } }
From source file:com.amalto.workbench.providers.datamodel.SchemaTreeContentProvider.java
protected Object[] getXSDAnnotationChildren(XSDAnnotation parent) { ArrayList<Object> list = new ArrayList<Object>(); list.addAll(parent.getUserInformation()); list.addAll(parent.getApplicationInformation()); return list.toArray(new Object[list.size()]); }
From source file:com.thoughtworks.go.server.service.ElasticAgentPluginService.java
public void createAgentsFor(List<JobPlan> old, List<JobPlan> newPlan) { Collection<JobPlan> starvingJobs = new ArrayList<>(); for (JobPlan jobPlan : newPlan) { if (jobPlan.requiresElasticAgent()) { if (!jobCreationTimeMap.containsKey(jobPlan.getJobId())) { continue; }//from ww w. j a va 2 s . c o m long lastTryTime = jobCreationTimeMap.get(jobPlan.getJobId()); if ((timeProvider.currentTimeMillis() - lastTryTime) >= goConfigService .elasticJobStarvationThreshold()) { starvingJobs.add(jobPlan); } } } ArrayList<JobPlan> jobsThatRequireAgent = new ArrayList<>(); jobsThatRequireAgent.addAll(Sets.difference(new HashSet<>(newPlan), new HashSet<>(old))); jobsThatRequireAgent.addAll(starvingJobs); List<JobPlan> plansThatRequireElasticAgent = jobsThatRequireAgent.stream().filter(isElasticAgent()) .collect(Collectors.toList()); // messageTimeToLive is lesser than the starvation threshold to ensure there are no duplicate create agent message long messageTimeToLive = goConfigService.elasticJobStarvationThreshold() - 10000; for (JobPlan plan : plansThatRequireElasticAgent) { jobCreationTimeMap.put(plan.getJobId(), timeProvider.currentTimeMillis()); ElasticProfile elasticProfile = plan.getElasticProfile(); ClusterProfile clusterProfile = plan.getClusterProfile(); if (clusterProfile == null) { String cancellationMessage = "\nThis job was cancelled by GoCD. The version of your GoCD server requires elastic profiles to be associated with a cluster(required from Version 19.3.0). " + "This job is configured to run on an Elastic Agent, but the associated elastic profile does not have information about the cluster. \n\n" + "The possible reason for the missing cluster information on the elastic profile could be, an upgrade of the GoCD server to a version >= 19.3.0 before the completion of the job.\n\n" + "A re-run of this job should fix this issue."; logToJobConsole(plan.getIdentifier(), cancellationMessage); scheduleService.cancelJob(plan.getIdentifier()); } else if (elasticAgentPluginRegistry.has(clusterProfile.getPluginId())) { String environment = environmentConfigService.envForPipeline(plan.getPipelineName()); createAgentQueue.post( new CreateAgentMessage(goConfigService.serverConfig().getAgentAutoRegisterKey(), environment, elasticProfile, clusterProfile, plan.getIdentifier()), messageTimeToLive); serverHealthService.removeByScope(HealthStateScope.forJob(plan.getIdentifier().getPipelineName(), plan.getIdentifier().getStageName(), plan.getIdentifier().getBuildName())); } else { String jobConfigIdentifier = plan.getIdentifier().jobConfigIdentifier().toString(); String description = format( "Plugin [%s] associated with %s is missing. Either the plugin is not " + "installed or could not be registered. Please check plugins tab " + "and server logs for more details.", clusterProfile.getPluginId(), jobConfigIdentifier); serverHealthService.update(ServerHealthState.error( format("Unable to find agent for %s", jobConfigIdentifier), description, HealthStateType.general(HealthStateScope.forJob(plan.getIdentifier().getPipelineName(), plan.getIdentifier().getStageName(), plan.getIdentifier().getBuildName())))); LOGGER.error(description); } } }
From source file:ca.brood.softlogger.Softlogger.java
public void softloggerStart() { try {/*from w ww. ja v a 2 s. c o m*/ File f = new File("lut/LUT1.dat"); if (!f.exists()) LookupTableGenerator.generate("lut/LUT1.dat", new TestGenerator(), 4, "Test lookup table... ", 65536); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //Start all the softloggerChannels, which will in turn start all the devices for (int i = 0; i < softloggerChannels.size(); i++) { softloggerChannels.get(i).start(); } ArrayList<Device> devices = new ArrayList<Device>(); for (SoftloggerChannel channel : softloggerChannels) { devices.addAll(channel.getDevices()); } dataOutputManager.initializeSchedulers(devices); dataOutputManager.start(); }
From source file:ddf.catalog.data.dynamic.impl.MetacardFactoryImpl.java
@Override public DynamicMetacard addAttributesForType(DynamicMetacard metacard, String name) { String newName = metacard.getName() + '.' + name; // If this combination hasn't been registered, combine attributes and register LazyDynaClass dynaClass = typeClasses.get(newName); if (dynaClass == null) { ArrayList<MetacardPropertyDescriptor> combinedDescriptors = new ArrayList<>(); MetacardPropertyDescriptor[] newDescriptors = typeProperties.get(name); if (newDescriptors != null) { combinedDescriptors.addAll(Arrays.asList(typeProperties.get(metacard.getName()))); combinedDescriptors.addAll(Arrays.asList(newDescriptors)); registerDynamicMetacardType(newName, combinedDescriptors); }//w w w . jav a2s.com } return newInstance(newName); }
From source file:fredboat.command.util.MALCommand.java
private boolean handleAnime(TextChannel channel, Member invoker, String terms, String body) { String msg = MessageFormat.format(I18n.get(channel.getGuild()).getString("malRevealAnime"), invoker.getEffectiveName()); //Read JSON//from w w w.j a v a 2 s . c o m log.info(body); JSONObject root = XML.toJSONObject(body); JSONObject data; try { data = root.getJSONObject("anime").getJSONArray("entry").getJSONObject(0); } catch (JSONException ex) { data = root.getJSONObject("anime").getJSONObject("entry"); } ArrayList<String> titles = new ArrayList<>(); titles.add(data.getString("title")); if (data.has("synonyms")) { titles.addAll(Arrays.asList(data.getString("synonyms").split(";"))); } if (data.has("english")) { titles.add(data.getString("english")); } int minDeviation = Integer.MAX_VALUE; for (String str : titles) { str = str.replace(' ', '+').trim(); int deviation = str.compareToIgnoreCase(terms); deviation = deviation - Math.abs(str.length() - terms.length()); if (deviation < minDeviation) { minDeviation = deviation; } } log.debug("Anime search deviation: " + minDeviation); if (minDeviation > 3) { return false; } msg = data.has("title") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malTitle"), msg, data.get("title")) : msg; msg = data.has("english") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malEnglishTitle"), msg, data.get("english")) : msg; msg = data.has("synonyms") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malSynonyms"), msg, data.get("synonyms")) : msg; msg = data.has("episodes") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malEpisodes"), msg, data.get("episodes")) : msg; msg = data.has("score") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malScore"), msg, data.get("score")) : msg; msg = data.has("type") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malType"), msg, data.get("type")) : msg; msg = data.has("status") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malStatus"), msg, data.get("status")) : msg; msg = data.has("start_date") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malStartDate"), msg, data.get("start_date")) : msg; msg = data.has("end_date") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malEndDate"), msg, data.get("end_date")) + "\n" : msg; if (data.has("synopsis")) { Matcher m = Pattern.compile("^[^\\n\\r<]+") .matcher(StringEscapeUtils.unescapeHtml4(data.getString("synopsis"))); m.find(); msg = data.has("synopsis") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malSynopsis"), msg, m.group(0)) : msg; } msg = data.has("id") ? msg + "http://myanimelist.net/anime/" + data.get("id") + "/" : msg; channel.sendMessage(msg).queue(); return true; }
From source file:com.moadbus.banking.iso.core.protocol.MessageFactory.java
/** * Sets a map with the fields that are to be expected when parsing a certain * type of message./*w ww . ja v a2 s.co m*/ * * @param type * The message type. * @param map * A map of DataElementParseInfo instances, each of which define * what type and length of field to expect. The keys will be the * field numbers. */ public void setParseMap(int type, Map<Integer, FieldParseInfo> map) { parseMap.put(type, map); ArrayList<Integer> index = new ArrayList<Integer>(); index.addAll(map.keySet()); Collections.sort(index); log.debug("Adding parse map for type " + Integer.toHexString(type) + " with fields " + index); parseOrder.put(type, index); }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.OperatorDeepCopyVisitor.java
@Override public ILogicalOperator visitProjectOperator(ProjectOperator op, Void arg) throws AlgebricksException { ArrayList<LogicalVariable> newList = new ArrayList<LogicalVariable>(); newList.addAll(op.getVariables()); return new ProjectOperator(newList); }
From source file:de.tolina.common.validation.AnnotationValidation.java
/** * Calls dependent on the type of the given Object: * <br> - {@link AnnotationUtils#getAnnotations(Method)} or * <br> - {@link AnnotationUtils#getAnnotations(java.lang.reflect.AnnotatedElement)} */// ww w.ja v a 2 s . co m @Nullable private Annotation[] getAllAnnotationsFor(@Nonnull final Object annotated) { if (annotated instanceof Field) { return getAnnotations((Field) annotated); } if (annotated instanceof Method) { final Method annotatedMethod = (Method) annotated; final Class<?> declaringClass = annotatedMethod.getDeclaringClass(); final List<Class<?>> allClasses = new ArrayList<>(); allClasses.add(declaringClass); allClasses.addAll(ClassUtils.getAllSuperclasses(declaringClass)); final ArrayList<Annotation> allAnnotations = new ArrayList<>(); for (final Class<?> aClass : allClasses) { final ArrayList<Method> allMethods = new ArrayList<>(); allMethods.addAll(Arrays.asList(aClass.getDeclaredMethods())); final List<Class<?>> interfaces = ClassUtils.getAllInterfaces(aClass); for (final Class<?> anInterface : interfaces) { allMethods.addAll(Arrays.asList(anInterface.getDeclaredMethods())); } allMethods.stream().filter(method -> isSameMethod(method, annotatedMethod)) .forEachOrdered(method -> addIfNotPresent(allAnnotations, getAnnotations(method))); } return allAnnotations.toArray(new Annotation[] {}); } final Class<?> annotatedClass = (Class<?>) annotated; final List<Class<?>> allClasses = new ArrayList<>(); allClasses.add(annotatedClass); allClasses.addAll(ClassUtils.getAllSuperclasses(annotatedClass)); final ArrayList<Annotation> allAnnotations = new ArrayList<>(); for (final Class<?> aClass : allClasses) { addIfNotPresent(allAnnotations, getAnnotations(aClass)); final List<Class<?>> interfaces = ClassUtils.getAllInterfaces(aClass); for (final Class<?> anInterface : interfaces) { addIfNotPresent(allAnnotations, getAnnotations(anInterface)); } } return allAnnotations.toArray(new Annotation[] {}); }
From source file:com.amalto.workbench.providers.datamodel.SchemaTreeContentProvider.java
protected Object[] getXSDElementDeclarationChildren(XSDElementDeclaration parent) { // abstract elements do not have children if (parent.isAbstract()) { return new Object[0]; }/* w w w. j a v a 2 s .co m*/ ArrayList<Object> list = new ArrayList<Object>(); list.addAll(Arrays.asList(getXSDElementDeclarationChildren_TypeDef(parent))); // the keys list.addAll(Arrays.asList(getXSDElementDeclarationChildren_IDs(parent))); // the annotations addEleDeclarationAnn2List(list, parent); return list.toArray(new Object[list.size()]); }