List of usage examples for java.util Collections addAll
@SafeVarargs public static <T> boolean addAll(Collection<? super T> c, T... elements)
From source file:net.atomique.ksar.graph.Graph.java
private JFreeChart makegraph(LocalDateTime start, LocalDateTime end) { long begingenerate = System.currentTimeMillis(); CombinedDomainXYPlot plot = new CombinedDomainXYPlot(axisofdate); // do the stacked stuff for (PlotStackConfig tmp : graphconfig.getStacklist().values()) { if (tmp == null) { continue; }// w w w.j ava2 s . c o m TimeTableXYDataset tmp2 = StackListbyName.get(tmp.getTitle()); if (tmp2 != null) { StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(); NumberAxis graphaxistitle = tmp.getAxis(); XYPlot temp_plot = new XYPlot(tmp2, axisofdate, graphaxistitle, renderer); for (int i = 0; i < tmp2.getSeriesCount(); i++) { Color color = GlobalOptions.getDataColor(tmp2.getSeriesKey(i).toString()); if (color != null) { renderer.setSeriesPaint(i, color); renderer.setDefaultStroke(new BasicStroke(1.0F)); } } plot.add(temp_plot, tmp.getSize()); } } // do the line stuff for (PlotStackConfig tmp : graphconfig.getPlotlist().values()) { XYItemRenderer renderer = new StandardXYItemRenderer(); ArrayList<String> t = new ArrayList<>(); String[] s = tmp.getHeaderStr().split("\\s+"); Collections.addAll(t, s); XYDataset c = create_collection(t); NumberAxis graphaxistitle = tmp.getAxis(); XYPlot tmpplot = new XYPlot(c, axisofdate, graphaxistitle, renderer); for (int i = 0; i < s.length; i++) { Color color = GlobalOptions.getDataColor(s[i]); if (color != null) { renderer.setSeriesPaint(i, color); renderer.setDefaultStroke(new BasicStroke(1.0F)); } } plot.add(tmpplot, tmp.getSize()); } if (plot.getSubplots().isEmpty()) { return null; } if (start != null && end != null) { Second g_start = convertLocalDateTimeToSecond(start); Second g_end = convertLocalDateTimeToSecond(end); axisofdate.setRange(g_start.getStart(), g_end.getEnd()); } plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart mychart = new JFreeChart(graphtitle, Config.getDEFAULT_FONT(), plot, true); long endgenerate = System.currentTimeMillis(); mychart.setBackgroundPaint(Color.white); if (GlobalOptions.isDodebug()) { log.debug("graph generation: {} ms", (endgenerate - begingenerate)); } return mychart; }
From source file:com.puppycrawl.tools.checkstyle.checks.coding.IllegalTypeCheck.java
/** * Set the list of legal abstract class names. * @param classNames array of legal abstract class names *//*from www .j a va2s . c o m*/ public void setLegalAbstractClassNames(String... classNames) { legalAbstractClassNames.clear(); Collections.addAll(legalAbstractClassNames, classNames); }
From source file:org.jboss.aerogear.unifiedpush.utils.installation.InstallationUtils.java
public static Set<String> getSimplepushDefaultCategories() { HashSet<String> categories = new HashSet<String>(); Collections.addAll(categories, SIMPLEPUSH_DEFAULT_CATEGORIES); return categories; }
From source file:co.marcin.novaguilds.enums.Message.java
/** * The constructor//from www .jav a2s . c om * * @param flags flags */ Message(Flag... flags) { for (Flag flag : flags) { if (flag == Flag.LIST) { this.flags.add(Flag.NOPREFIX); } } Collections.addAll(this.flags, flags); }
From source file:com.izforge.izpack.util.SelfModifier.java
/** * Run a new jvm with all the system parameters needed for phases 2 and 3. * * @param args the command line arguments * @param nextPhase the next phase/* w w w . j ava 2 s.c om*/ * @return the spawned process * @throws IOException if there is an error getting the canonical name of a path */ private Process spawn(String[] args, int nextPhase) throws IOException { String base = logFile.getAbsolutePath(); base = base.substring(0, base.length() - 4); // invoke from tmpdir, passing target method arguments as args, and // SelfModifier parameters as system properties String javaCommand = ProcessHelper.getJavaCommand(); List<String> command = new ArrayList<String>(); command.add(javaCommand); command.addAll(new JVMHelper().getJVMArguments()); if (nextPhase == 2) { if (debugPort2 != -1) { command.add(getDebug(debugPort2)); } if (debugPort3 != -1) { // propagate the phase3 debug port command.add("-D" + DEBUG_PORT3_KEY + "=" + debugPort3); } } else if (nextPhase == 3 && debugPort3 != -1) { command.add(getDebug(debugPort3)); } command.add("-classpath"); command.add(sandbox.getAbsolutePath()); command.add("-D" + BASE_KEY + "=" + base); command.add("-D" + JAR_KEY + "=" + jarFile.getPath() + ""); command.add("-D" + CLASS_KEY + "=" + method.getDeclaringClass().getName()); command.add("-D" + METHOD_KEY + "=" + method.getName()); command.add("-D" + PHASE_KEY + "=" + nextPhase); command.add(getClass().getName()); Collections.addAll(command, args); StringBuilder buffer = new StringBuilder("Spawning phase "); buffer.append(nextPhase).append(": "); for (String anEntireCmd : command) { buffer.append("\n\t").append(anEntireCmd); } log(buffer.toString()); return ProcessHelper.exec(command); }
From source file:net.firejack.platform.core.config.meta.construct.ConfigElementFactory.java
/** * * * @param fieldElementContainer/*from w w w . j a v a 2 s . c o m*/ * @param model * @return */ public IFieldElement produceField(IFieldElementContainer fieldElementContainer, FieldModel model) { String name = model.getName(); FieldType type = model.getFieldType(); if (fieldElementContainer == null) { throw new IllegalArgumentException("Field-holder domain object should not be null."); } else if (!(fieldElementContainer instanceof EntityConfigElement || fieldElementContainer instanceof RelationshipConfigElement || fieldElementContainer instanceof DirectoryElement)) { throw new IllegalArgumentException("Inconsistent parent domain object argument."); } else { if (StringUtils.isBlank(name)) { throw new IllegalArgumentException("The name of field should not be blank."); } else { if (type == null) { throw new IllegalArgumentException("The type of field should not be null."); } } } IFieldElement[] fields = fieldElementContainer.getFields(); if (fields != null) { IFieldElement field = DiffUtils.findNamedElement(fields, name); if (field != null) { return null; } } FieldConfigElement fieldConfigElement = new FieldConfigElement(name); //checkElementName(field); normalizeName(fieldConfigElement); fieldConfigElement.setType(type); fieldConfigElement.setRequired(model.getRequired()); fieldConfigElement.setSearchable(model.getSearchable()); fieldConfigElement.setAutoGenerated(model.getAutoGenerated()); Object defaultValue = getDefaultValue(type, model.getDefaultValue()); fieldConfigElement.setDefaultValue(defaultValue); fieldConfigElement.setCustomType(model.getCustomFieldType()); fieldConfigElement.setDescription(model.getDescription()); fieldConfigElement.setDisplayName(model.getDisplayName()); fieldConfigElement.setDisplayDescription(model.getDisplayDescription()); fieldConfigElement.setAllowValues(StringUtils.join(model.getAllowedFieldValueList().getEntries(), "|")); List<EntityModel> options = model.getOptions(); if (options != null) { List<Reference> references = new ArrayList<Reference>(options.size()); for (EntityModel option : options) { references.add(new Reference(option.getName(), option.getPath())); } fieldConfigElement.setOptions(references); } List<IFieldElement> fieldsList = new ArrayList<IFieldElement>(); if (fields != null) { Collections.addAll(fieldsList, fieldElementContainer.getFields()); } fieldsList.add(fieldConfigElement); fieldElementContainer.setFields(fieldsList); if (model.getUid() != null) { fieldConfigElement.setUid(model.getUid().getUid()); } return fieldConfigElement; }
From source file:info.evanchik.eclipse.karaf.ui.KarafConfigurationTab.java
@Override public void initializeFrom(final ILaunchConfiguration configuration) { try {//w w w. j a v a 2 s .c o m localConsole.setSelection(configuration .getAttribute(KarafLaunchConfigurationConstants.KARAF_LAUNCH_START_LOCAL_CONSOLE, true)); remoteConsole.setSelection(configuration .getAttribute(KarafLaunchConfigurationConstants.KARAF_LAUNCH_START_REMOTE_CONSOLE, false)); enableFeaturesManagement.setSelection(configuration .getAttribute(KarafLaunchConfigurationConstants.KARAF_LAUNCH_FEATURES_MANAGEMENT, true)); initializeKarafPlatformModel(); final String featuresString = configuration .getAttribute(KarafLaunchConfigurationConstants.KARAF_LAUNCH_BOOT_FEATURES, ""); final String[] features = featuresString.split(","); selectedFeatures.clear(); selectedFeatures.addAll(Arrays.asList(features)); } catch (final CoreException e) { // TODO: Do something sensible here } featuresResolverJob.addJobChangeListener(new JobChangeAdapter() { @Override public void done(final IJobChangeEvent event) { if (event.getResult().isOK()) { featuresResolverJob.removeJobChangeListener(this); try { final String storedBootFeatures = configuration .getAttribute(KarafLaunchConfigurationConstants.KARAF_LAUNCH_BOOT_FEATURES, ""); final FeatureResolverImpl fr = new FeatureResolverImpl( featuresResolverJob.featuresRepositories); final List<Object> checkedFeatures = new ArrayList<Object>(); for (final String s : storedBootFeatures.split(",")) { final Object[] path = fr.getFeaturePath(s); Collections.addAll(checkedFeatures, path); } Display.getDefault().syncExec(new Runnable() { @Override public void run() { if (!getControl().isDisposed()) { installedFeatures.setInput(featuresResolverJob.featuresRepositories); installedFeatures.setCheckedElements(checkedFeatures.toArray()); } }; }); } catch (final CoreException e) { // TODO: Do something sensible } } } }); if (featuresResolverJob.getState() == Job.NONE) { featuresResolverJob.schedule(); } }
From source file:edu.hawaii.soest.hioos.storx.StorXDispatcher.java
/** * A method that executes the reading of data from the email account to the * RBNB server after all configuration of settings, connections to hosts, * and thread initiatizing occurs. This method contains the detailed code * for reading the data and interpreting the data files. *//* w ww . j ava 2 s . c o m*/ protected boolean execute() { logger.debug("StorXDispatcher.execute() called."); boolean failed = true; // indicates overall success of execute() boolean messageProcessed = false; // indicates per message success // declare the account properties that will be pulled from the // email.account.properties.xml file String accountName = ""; String server = ""; String username = ""; String password = ""; String protocol = ""; String dataMailbox = ""; String processedMailbox = ""; String prefetch = ""; // fetch data from each sensor in the account list List accountList = this.xmlConfiguration.getList("account.accountName"); for (Iterator aIterator = accountList.iterator(); aIterator.hasNext();) { int aIndex = accountList.indexOf(aIterator.next()); // populate the email connection variables from the xml properties // file accountName = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").accountName"); server = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").server"); username = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").username"); password = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").password"); protocol = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").protocol"); dataMailbox = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").dataMailbox"); processedMailbox = (String) this.xmlConfiguration .getProperty("account(" + aIndex + ").processedMailbox"); prefetch = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").prefetch"); logger.debug("\n\nACCOUNT DETAILS: \n" + "accountName : " + accountName + "\n" + "server : " + server + "\n" + "username : " + username + "\n" + "password : " + password + "\n" + "protocol : " + protocol + "\n" + "dataMailbox : " + dataMailbox + "\n" + "processedMailbox: " + processedMailbox + "\n" + "prefetch : " + prefetch + "\n"); // get a connection to the mail server Properties props = System.getProperties(); props.setProperty("mail.store.protocol", protocol); props.setProperty("mail.imaps.partialfetch", prefetch); try { // create the imaps mail session this.mailSession = Session.getDefaultInstance(props, null); this.mailStore = mailSession.getStore(protocol); } catch (NoSuchProviderException nspe) { try { // pause for 10 seconds logger.debug( "There was a problem connecting to the IMAP server. " + "Waiting 10 seconds to retry."); Thread.sleep(10000L); this.mailStore = mailSession.getStore(protocol); } catch (NoSuchProviderException nspe2) { logger.debug("There was an error connecting to the mail server. The " + "message was: " + nspe2.getMessage()); nspe2.printStackTrace(); failed = true; return !failed; } catch (InterruptedException ie) { logger.debug("The thread was interrupted: " + ie.getMessage()); failed = true; return !failed; } } try { this.mailStore.connect(server, username, password); // get folder references for the inbox and processed data box Folder inbox = mailStore.getFolder(dataMailbox); inbox.open(Folder.READ_WRITE); Folder processed = this.mailStore.getFolder(processedMailbox); processed.open(Folder.READ_WRITE); Message[] msgs; while (!inbox.isOpen()) { inbox.open(Folder.READ_WRITE); } msgs = inbox.getMessages(); List<Message> messages = new ArrayList<Message>(); Collections.addAll(messages, msgs); // sort the messages found in the inbox by date sent Collections.sort(messages, new Comparator<Message>() { public int compare(Message message1, Message message2) { int value = 0; try { value = message1.getSentDate().compareTo(message2.getSentDate()); } catch (MessagingException e) { e.printStackTrace(); } return value; } }); logger.debug("Number of messages: " + messages.size()); for (Message message : messages) { // Copy the message to ensure we have the full attachment MimeMessage mimeMessage = (MimeMessage) message; MimeMessage copiedMessage = new MimeMessage(mimeMessage); // determine the sensor serial number for this message String messageSubject = copiedMessage.getSubject(); Date sentDate = copiedMessage.getSentDate(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM"); // The subfolder of the processed mail folder (e.g. 2016-12); String destinationFolder = formatter.format(sentDate); logger.debug("Message date: " + sentDate + "\tNumber: " + copiedMessage.getMessageNumber()); String[] subjectParts = messageSubject.split("\\s"); String loggerSerialNumber = "SerialNumber"; if (subjectParts.length > 1) { loggerSerialNumber = subjectParts[2]; } // Do we have a data attachment? If not, there's no data to // process if (copiedMessage.isMimeType("multipart/mixed")) { logger.debug("Message size: " + copiedMessage.getSize()); MimeMessageParser parser = new MimeMessageParser(copiedMessage); try { parser.parse(); } catch (Exception e) { logger.error("Failed to parse the MIME message: " + e.getMessage()); continue; } ByteBuffer messageAttachment = ByteBuffer.allocate(256); // init only logger.debug("Has attachments: " + parser.hasAttachments()); for (DataSource dataSource : parser.getAttachmentList()) { if (StringUtils.isNotBlank(dataSource.getName())) { logger.debug( "Attachment: " + dataSource.getName() + ", " + dataSource.getContentType()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); IOUtils.copy(dataSource.getInputStream(), outputStream); messageAttachment = ByteBuffer.wrap(outputStream.toByteArray()); } } // We now have the attachment and serial number. Parse the attachment // for the data components, look up the storXSource based on the serial // number, and push the data to the DataTurbine // parse the binary attachment StorXParser storXParser = new StorXParser(messageAttachment); // iterate through the parsed framesMap and handle each // frame // based on its instrument type BasicHierarchicalMap framesMap = (BasicHierarchicalMap) storXParser.getFramesMap(); Collection frameCollection = framesMap.getAll("/frames/frame"); Iterator framesIterator = frameCollection.iterator(); while (framesIterator.hasNext()) { BasicHierarchicalMap frameMap = (BasicHierarchicalMap) framesIterator.next(); // logger.debug(frameMap.toXMLString(1000)); String frameType = (String) frameMap.get("type"); String sensorSerialNumber = (String) frameMap.get("serialNumber"); // handle each instrument type if (frameType.equals("HDR")) { logger.debug("This is a header frame. Skipping it."); } else if (frameType.equals("STX")) { try { // handle StorXSource StorXSource source = (StorXSource) sourceMap.get(sensorSerialNumber); // process the data using the StorXSource // driver messageProcessed = source.process(this.xmlConfiguration, frameMap); } catch (ClassCastException cce) { } } else if (frameType.equals("SBE")) { try { // handle CTDSource CTDSource source = (CTDSource) sourceMap.get(sensorSerialNumber); // process the data using the CTDSource // driver messageProcessed = source.process(this.xmlConfiguration, frameMap); } catch (ClassCastException cce) { } } else if (frameType.equals("NLB")) { try { // handle ISUSSource ISUSSource source = (ISUSSource) sourceMap.get(sensorSerialNumber); // process the data using the ISUSSource // driver messageProcessed = source.process(this.xmlConfiguration, frameMap); } catch (ClassCastException cce) { } } else if (frameType.equals("NDB")) { try { // handle ISUSSource ISUSSource source = (ISUSSource) sourceMap.get(sensorSerialNumber); // process the data using the ISUSSource // driver messageProcessed = source.process(this.xmlConfiguration, frameMap); } catch (ClassCastException cce) { } } else { logger.debug("The frame type " + frameType + " is not recognized. Skipping it."); } } // end while() if (this.sourceMap.get(loggerSerialNumber) != null) { // Note: Use message (not copiedMessage) when setting flags if (!messageProcessed) { logger.info("Failed to process message: " + "Message Number: " + message.getMessageNumber() + " " + "Logger Serial:" + loggerSerialNumber); // leave it in the inbox, flagged as seen (read) message.setFlag(Flags.Flag.SEEN, true); logger.debug("Saw message " + message.getMessageNumber()); } else { // message processed successfully. Create a by-month sub folder if it doesn't exist // Copy the message and flag it deleted Folder destination = processed.getFolder(destinationFolder); boolean created = destination.create(Folder.HOLDS_MESSAGES); inbox.copyMessages(new Message[] { message }, destination); message.setFlag(Flags.Flag.DELETED, true); logger.debug("Deleted message " + message.getMessageNumber()); } // end if() } else { logger.debug("There is no configuration information for " + "the logger serial number " + loggerSerialNumber + ". Please add the configuration to the " + "email.account.properties.xml configuration file."); } // end if() } else { logger.debug("This is not a data email since there is no " + "attachment. Skipping it. Subject: " + messageSubject); } // end if() } // end for() // expunge messages and close the mail server store once we're // done inbox.expunge(); this.mailStore.close(); } catch (MessagingException me) { try { this.mailStore.close(); } catch (MessagingException me2) { failed = true; return !failed; } logger.info( "There was an error reading the mail message. The " + "message was: " + me.getMessage()); me.printStackTrace(); failed = true; return !failed; } catch (IOException me) { try { this.mailStore.close(); } catch (MessagingException me3) { failed = true; return !failed; } logger.info("There was an I/O error reading the message part. The " + "message was: " + me.getMessage()); me.printStackTrace(); failed = true; return !failed; } catch (IllegalStateException ese) { try { this.mailStore.close(); } catch (MessagingException me4) { failed = true; return !failed; } logger.info("There was an error reading messages from the folder. The " + "message was: " + ese.getMessage()); failed = true; return !failed; } finally { try { this.mailStore.close(); } catch (MessagingException me2) { logger.debug("Couldn't close the mail store: " + me2.getMessage()); } } } return !failed; }
From source file:com.baidu.rigel.biplatform.ma.model.builder.impl.DirectorImpl.java
/** * //from ww w . j ava2 s. c o m * @param newMeasures * @param refNames * @return */ private boolean checkRefMeasuer(Set<String> refNames, Map<String, Measure> newMeasures) { boolean rs = true; if (refNames == null || refNames.size() == 0) { return rs; } String[] measuerNames = newMeasures.values().stream().map(m -> { return m.getName(); }).toArray(String[]::new); List<String> tmp = Lists.newArrayList(); Collections.addAll(tmp, measuerNames); for (String ref : refNames) { if (!tmp.contains(ref)) { return false; } } // for (String str : refNames) { // if (refNames.contains(entry.getKey()) || refNames.contains(entry.getValue().getName())) { // continue; // } // } return rs; }
From source file:com.bosscs.spark.commons.utils.Utils.java
/** * Returns an instance clone./*from w w w.jav a2s . c o m*/ * this method gets every class property by reflection, including its parents properties * @param t * @param <T> * @return T object. */ public static <T> T cloneObjectWithParents(T t) throws IllegalAccessException, InstantiationException { T clone = (T) t.getClass().newInstance(); List<Field> allFields = new ArrayList<>(); Class parentClass = t.getClass().getSuperclass(); while (parentClass != null) { Collections.addAll(allFields, parentClass.getDeclaredFields()); parentClass = parentClass.getSuperclass(); } Collections.addAll(allFields, t.getClass().getDeclaredFields()); for (Field field : allFields) { int modifiers = field.getModifiers(); //We skip final and static fields if ((Modifier.FINAL & modifiers) != 0 || (Modifier.STATIC & modifiers) != 0) { continue; } field.setAccessible(true); Object value = field.get(t); if (Collection.class.isAssignableFrom(field.getType())) { Collection collection = (Collection) field.get(clone); if (collection == null) { collection = (Collection) field.get(t).getClass().newInstance(); } collection.addAll((Collection) field.get(t)); value = collection; } else if (Map.class.isAssignableFrom(field.getType())) { Map clonMap = (Map) field.get(t).getClass().newInstance(); clonMap.putAll((Map) field.get(t)); value = clonMap; } field.set(clone, value); } return clone; }