List of usage examples for java.util Collections addAll
@SafeVarargs public static <T> boolean addAll(Collection<? super T> c, T... elements)
From source file:com.google.gdt.eclipse.designer.uibinder.model.util.NameSupport.java
/** * Adds @UiField with given type, name and initializer. *///from w w w. java 2s .com public void addUiFieldJava(Class<?> fieldClass, String fieldTypeName, String name, String initializer) throws Exception { AstEditor editor = getEditor(); TypeDeclaration typeDeclaration = editor.getPrimaryType(); // prepare source lines List<String> lines; { lines = Lists.newArrayList(); String source = "@com.google.gwt.uibinder.client.UiField(provided=true) "; source += fieldTypeName + " " + name + " = " + initializer + ";"; Collections.addAll(lines, StringUtils.split(source, '\n')); } // add field BodyDeclarationTarget target = getNewFieldTarget(typeDeclaration); editor.addFieldDeclaration(lines, target); // add new JField into "form" JType addFormJField(fieldClass, name); }
From source file:ezbake.data.mongo.HandlerForDriverFindCalls.java
protected QueryResultIterator convertFindForDriver(String collectionName, DBObject jsonQuery, DBObject projection, String jsonSort, int skip, int limit, int batchSize, ReadPreference readPref, EzSecurityToken token, String operationType) throws Exception { appLog.info("convertFindForDriver() query: " + jsonQuery); AggregationOptions opts = null;/*from w w w. ja v a2 s . c o m*/ if (batchSize > 0) { opts = AggregationOptions.builder().outputMode(AggregationOptions.OutputMode.CURSOR) .batchSize(batchSize).build(); } else { opts = AggregationOptions.builder().build(); } Object distinct = jsonQuery.get("distinct"); Object key = null; if (distinct != null) { key = jsonQuery.get("key"); Object q = jsonQuery.get("query"); if (q != null) { jsonQuery = (DBObject) q; } } jsonQuery = checkForQueryComment(jsonQuery); jsonQuery = checkForshowDiskLoc(jsonQuery); Object returnKey = jsonQuery.get("$returnKey"); if (returnKey != null) { Object q = jsonQuery.get("$query"); if (q != null) { jsonQuery = (DBObject) q; } } Object snapshot = jsonQuery.get("$snapshot"); if (snapshot != null) { Object ob = jsonQuery.get("$orderby"); if (ob != null) { throw new MongoException("Do not use $snapshot with cursor.hint() and cursor.sort() methods"); } Object hint = jsonQuery.get("$hint"); if (hint != null) { throw new MongoException("Do not use $snapshot with cursor.hint() and cursor.sort() methods"); } Object q = jsonQuery.get("$query"); if (q != null) { jsonQuery = (DBObject) q; } } Object explain = jsonQuery.get("$explain"); if (explain != null) { Object q = jsonQuery.get("$query"); if (q != null) { jsonQuery = (DBObject) q; } } Object orderby = jsonQuery.get("$orderby"); if (orderby != null) { Object q = jsonQuery.get("$query"); if (q != null) { jsonQuery = (DBObject) q; } jsonSort = orderby.toString(); } Object maxScan = jsonQuery.get("$maxScan"); if (maxScan != null) { Object q = jsonQuery.get("$query"); if (q != null) { jsonQuery = (DBObject) q; } limit = (Integer) maxScan; } Object min = jsonQuery.get("$min"); if (min != null) { Object q = jsonQuery.get("$query"); if (q != null) { jsonQuery = (DBObject) q; } } Object max = jsonQuery.get("$max"); if (max != null) { Object q = jsonQuery.get("$query"); if (q != null) { jsonQuery = (DBObject) q; } } QueryResultIterator qri = null; DBObject query = null; if (jsonQuery != null && jsonQuery.keySet().size() > 0) { query = new BasicDBObject("$match", jsonQuery); } DBObject[] additionalOps = parent_handler.handler.getMongoFindHelper().getFindAggregationCommandsArray(skip, limit, (projection != null && projection.keySet().size() > 0) ? projection.toString() : "", jsonSort, token, operationType); List<DBObject> pipeline = new ArrayList<DBObject>(); if (query != null) { pipeline.add(query); } Collections.addAll(pipeline, additionalOps); appLog.info("convertFindForDriver() final pipeline query: " + pipeline); Cursor cursor = null; if (distinct != null) { qri = handleDistinctCall(jsonQuery, readPref, token, opts, distinct, key, pipeline); } else if (max != null && min != null) { // TODO can max AND min be possible? investigate... } else if (max != null) { qri = handleMaxCall(collectionName, max, jsonQuery, readPref, token, opts, pipeline); } else if (min != null) { qri = handleMinCall(collectionName, min, jsonQuery, readPref, token, opts, pipeline); } else { cursor = parent_handler.handler.db.getCollection(collectionName).aggregate(pipeline, opts, readPref); if (cursor instanceof QueryResultIterator) { qri = (QueryResultIterator) cursor; } else { appLog.info("UNKNOWN CURSOR RETURNED: {}", cursor.toString()); throw new Exception("Find converted to Aggregate pipeline did not return a QueryResultIterator: " + cursor.toString()); } } return qri; }
From source file:net.sf.keystore_explorer.crypto.x509.X509CertUtil.java
/** * PKCS #7 encode a number of certificates. * * @return The encoding/*from w w w . j a v a2 s.c o m*/ * @param certs * The certificates * @throws CryptoException * If there was a problem encoding the certificates */ public static byte[] getCertsEncodedPkcs7(X509Certificate[] certs) throws CryptoException { try { ArrayList<Certificate> encodedCerts = new ArrayList<Certificate>(); Collections.addAll(encodedCerts, certs); CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce()); CertPath cp = cf.generateCertPath(encodedCerts); return cp.getEncoded(PKCS7_ENCODING); } catch (CertificateException e) { throw new CryptoException(res.getString("NoPkcs7Encode.exception.message"), e); } catch (NoSuchProviderException e) { throw new CryptoException(res.getString("NoPkcs7Encode.exception.message"), e); } }
From source file:net.sf.jabref.external.ExternalFilePanel.java
/** * Creates a Runnable that searches the external file directory for the given * field name, including subdirectories, and looks for files named after the * current entry's bibtex key./*from w w w .j a va2 s .co m*/ * * @param fieldName * The field to set. * @param editor * An EntryEditor instance where to set the value found. * @return A reference to the Runnable that can perform the operation. */ public Runnable autoSetFile(final String fieldName, final FieldEditor editor) { Object o = getKey(); if ((o == null) || (Globals.prefs.get(fieldName + Globals.DIR_SUFFIX) == null)) { output(Localization.lang("You must set both BibTeX key and %0 directory", fieldName.toUpperCase()) + '.'); return null; } output(Localization.lang("Searching for %0 file", fieldName.toUpperCase()) + " '" + o + '.' + fieldName + "'..."); return new Runnable() { @Override public void run() { /* * Find the following directories to look in for: * * default directory for this field type. * * directory of bibtex-file. // NOT POSSIBLE at the moment. * * JabRef-directory. */ LinkedList<String> list = new LinkedList<>(); String[] dirs = metaData.getFileDirectory(fieldName); Collections.addAll(list, dirs); String found = FileFinder.findPdf(getEntry(), fieldName, list.toArray(new String[list.size()]));// , off); // To activate findFile: // String found = Util.findFile(getEntry(), null, dir, // ".*[bibtexkey].*"); if (found != null) { editor.setText(found); if (entryEditor != null) { entryEditor.updateField(editor); } output(Localization.lang("%0 field set", fieldName.toUpperCase()) + '.'); } else { output(Localization.lang("No %0 found", fieldName.toUpperCase()) + '.'); } } }; }
From source file:com.newatlanta.appengine.nio.file.GaePath.java
private static Set<OpenOption> getOpenOptionSet(OpenOption... options) { Set<OpenOption> optionSet = new HashSet<OpenOption>(options.length); Collections.addAll(optionSet, options); return optionSet; }
From source file:com.heliosapm.script.AbstractDeployedScript.java
/** * Builds the path segments for this file * @return the path segments for this file *//*from www . ja v a 2 s . c o m*/ protected String[] calcPathSegments() { final File rootFile = new File(rootDir); if (rootFile.equals(sourceFile.getParentFile())) { return new String[] { rootFile.getName() }; } final List<String> segments = new ArrayList<String>(); segments.add(rootFile.getName()); Collections.addAll(segments, rootFile.toPath().relativize(sourceFile.getParentFile().toPath()).toString() .replace("\\", "/").split("/")); return segments.toArray(new String[segments.size()]); }
From source file:com.diversityarrays.kdxplore.KDXploreFrame.java
private void initialiseKdxApps() throws IOException { String[] classNames = KdxploreConfig.getInstance().getMainPluginClassNames(); if (classNames != null && classNames.length > 0) { List<String> classNamesToLoad = new ArrayList<>(); Collections.addAll(classNamesToLoad, classNames); if (!classNamesToLoad.contains(OFFLINE_DATA_APP_SERVICE_CLASS_NAME)) { classNamesToLoad.add(0, OFFLINE_DATA_APP_SERVICE_CLASS_NAME); classNames = classNamesToLoad.toArray(new String[classNamesToLoad.size()]); }//from w w w.j av a2s .c om } Map<KdxApp, Component> componentByApp = collectKdxApps(classNames); appByComponent.clear(); for (KdxApp app : componentByApp.keySet()) { Component comp = componentByApp.get(app); if (comp != null) { appByComponent.put(comp, app); } } allKdxApps.clear(); allKdxApps.addAll(componentByApp.keySet()); // Initialise the apps in initialisation order. allKdxApps.sort(Comparator.comparing(KdxApp::getInitialisationOrder)); // And while we're initialising them we collect // those that can perform a databaseBackup (i.e. have a BackupProvider). backupProviders.clear(); List<KdxApp> wantedAppsWithUi = new ArrayList<>(); for (KdxApp app : allKdxApps) { BackupProvider bp = app.getBackupProvider(); if (bp != null) { backupProviders.add(bp); } /** * See {@link com.diversityarrays.kdxplore.prefs.KdxplorePreferences#SHOW_ALL_APPS} */ if (appIsWanted(app)) { try { app.initialiseAppBeforeUpdateCheck(appInitContext); } catch (Exception e) { String msg = Msg.MSG_KDXAPP_INIT_PROBLEM(app.getAppName()); Shared.Log.w(TAG, msg, e); messagesPanel.println(msg); messagesPanel.println(e.getMessage()); } } if (appIsWanted(app) && null != componentByApp.get(app)) { wantedAppsWithUi.add(app); } } // - - - - - - - - - - - - - - - - - - - - - // Display the apps in display order. wantedAppsWithUi.sort(Comparator.comparing(KdxApp::getDisplayOrder)); backupProviders.sort(Comparator.comparing(BackupProvider::getDisplayOrder)); switch (wantedAppsWithUi.size()) { case 0: JLabel label = new JLabel(Msg.MSG_NO_KDXPLORE_APPS_AVAILABLE()); label.setHorizontalAlignment(JLabel.CENTER); cardPanel.add(label, CARD_KDXAPPS); break; case 1: KdxApp kdxApp = wantedAppsWithUi.get(0); Component uiComponent = componentByApp.get(kdxApp); Component appComponent = makeComponentForTab(kdxApp, uiComponent); cardPanel.add(appComponent, CARD_KDXAPPS); getRootPane().setDefaultButton(kdxApp.getDefaultButton()); String msg = Msg.MSG_SHOWING_KDXAPP(kdxApp.getAppName()); messagesPanel.println(msg); System.err.println(msg + " uiClass=" //$NON-NLS-1$ + uiComponent.getClass().getName()); break; default: kdxAppTabs = new JTabbedPane(JTabbedPane.LEFT); cardPanel.add(kdxAppTabs, CARD_KDXAPPS); Bag<String> tabsSeen = new HashBag<>(); for (KdxApp app : wantedAppsWithUi) { Component ui = componentByApp.get(app); String tabName = app.getAppName(); DevelopmentState devState = app.getDevelopmentState(); switch (devState) { case ALPHA: tabName = tabName + " (\u03b1)"; // TODO move to UnicodeChars break; case BETA: tabName = tabName + " (\u03b2)"; // TODO move to UnicodeChars break; case PRODUCTION: break; default: tabName = tabName + " " + devState.name(); break; } tabsSeen.add(tabName); int count = tabsSeen.getCount(tabName); if (count > 1) { tabName = tabName + "_" + count; //$NON-NLS-1$ } Component tabComponent = makeComponentForTab(app, ui); kdxAppTabs.addTab(tabName, tabComponent); if (macapp == null) { int index = kdxAppTabs.indexOfTab(tabName); if (index >= 0) { JLabel tabLabel = new JLabel(tabName); tabLabel.setBorder(new EmptyBorder(2, 2, 2, 2)); tabLabel.setUI(new VerticalLabelUI(VerticalLabelUI.UPWARDS)); kdxAppTabs.setTabComponentAt(index, tabLabel); } } messagesPanel.println(Msg.MSG_SHOWING_KDXAPP(tabName)); } kdxAppTabs.addChangeListener(kdxAppTabsChangeListener); kdxAppTabs.setSelectedIndex(0); break; } }
From source file:com.liferay.ide.server.core.portal.PortalServerBehavior.java
private String[] _getRuntimeStartVMArguments() { boolean launchSetting = _getPortalServer().getLaunchSettings(); IPath liferayHome = _getPortalRuntime().getLiferayHome(); IPath portalExtPath = liferayHome.append("portal-ext.properties"); if (!launchSetting) { File portalext = portalExtPath.toFile(); if (_getPortalServer().getDeveloperMode()) { try { if (FileUtil.notExists(portalext)) { portalext.createNewFile(); }/*from www.j a v a 2s. co m*/ PortalPropertiesConfiguration config = new PortalPropertiesConfiguration(); try (InputStream in = Files.newInputStream(portalext.toPath())) { config.load(in); } String[] p = config.getStringArray("include-and-override"); boolean existing = false; for (String prop : p) { if (prop.equals("portal-developer.properties")) { existing = true; break; } } if (!existing) { config.addProperty("include-and-override", "portal-developer.properties"); } config.save(portalext); } catch (Exception e) { LiferayServerCore.logError(e); } } else if (FileUtil.exists(portalext)) { String contents = FileUtil.readContents(portalext, true); contents = contents.replace("include-and-override=portal-developer.properties", ""); try { FileUtils.write(portalext, contents); } catch (IOException ioe) { LiferayServerCore.logError(ioe); } } } List<String> retval = new ArrayList<>(); Collections.addAll(retval, _getPortalServer().getMemoryArgs()); PortalBundle portalBundle = _getPortalRuntime().getPortalBundle(); Collections.addAll(retval, portalBundle.getRuntimeStartVMArgs()); return retval.toArray(new String[0]); }
From source file:com.zimbra.cs.mailclient.smtp.SmtpConnection.java
private void sendInternal(String sender, String[] recipients, MimeMessage javaMailMessage, String messageString) throws IOException, MessagingException { invalidRecipients.clear();//ww w . j a v a 2 s . c om validRecipients.clear(); Collections.addAll(validRecipients, recipients); mail(sender); String notify = null; if (serverExtensions.contains("DSN")) { if (javaMailMessage instanceof SMTPMessage) notify = getDSNNotify((SMTPMessage) javaMailMessage); if (notify == null) notify = getSmtpConfig().getDsn(); } rcpt(recipients, notify); Reply reply = sendCommand(DATA, null); if (reply.code != 354) { throw new CommandFailedException(DATA, reply.toString()); } SmtpDataOutputStream smtpData = new SmtpDataOutputStream(mailOut); try { if (javaMailMessage != null) { javaMailMessage.writeTo(smtpData, IGNORE_HEADERS); } else { smtpData.write(messageString.getBytes()); } } catch (MessagingException e) { // close without QUIT close(); throw e; } catch (IOException e) { // close without QUIT close(); throw e; } smtpData.end(); mailOut.flush(); mailOut.trace(); reply = Reply.parse(mailIn.readLine()); mailIn.trace(); if (reply == null) { throw new CommandFailedException(DATA, "No response"); } if (!reply.isPositive()) { throw new CommandFailedException(DATA, reply.toString()); } }
From source file:com.liferay.ide.server.core.portal.PortalServerBehavior.java
private String[] _getRuntimeStopVMArguments() { List<String> retval = new ArrayList<>(); String[] memoryArgs = _getPortalServer().getMemoryArgs(); if (memoryArgs != null) { Collections.addAll(retval, memoryArgs); }//from w w w . j av a2 s. c om PortalBundle portalBundle = _getPortalRuntime().getPortalBundle(); Collections.addAll(retval, portalBundle.getRuntimeStopVMArgs()); return retval.toArray(new String[0]); }