List of usage examples for com.google.common.collect Iterables toArray
static <T> T[] toArray(Iterable<? extends T> iterable, T[] array)
From source file:org.apache.lens.cli.commands.LensDimensionCommands.java
/** * Update dimension./*www .java 2 s. co m*/ * * @param specPair the spec pair * @return the string */ @CliCommand(value = "update dimension", help = "update dimension") public String updateDimension(@CliOption(key = { "", "dimension" }, mandatory = true, help = "<dimension-name> <path to dimension-spec file>") String specPair) { Iterable<String> parts = Splitter.on(' ').trimResults().omitEmptyStrings().split(specPair); String[] pair = Iterables.toArray(parts, String.class); if (pair.length != 2) { return "Syntax error, please try in following " + "format. create fact <fact spec path> <storage spec path>"; } File f = new File(pair[1]); if (!f.exists()) { return "Fact spec path" + f.getAbsolutePath() + " does not exist. Please check the path"; } APIResult result = getClient().updateDimension(pair[0], pair[1]); if (result.getStatus() == APIResult.Status.SUCCEEDED) { return "Update of " + pair[0] + " succeeded"; } else { return "Update of " + pair[0] + " failed"; } }
From source file:org.sonar.plsqlopen.CustomAnnotationBasedRulesDefinition.java
@SuppressWarnings("rawtypes") public void addRuleClasses(boolean failIfSqaleNotFound, boolean failIfNoExplicitKey, Iterable<Class> ruleClasses) { new RulesDefinitionAnnotationLoader().load(repository, Iterables.toArray(ruleClasses, Class.class)); List<NewRule> newRules = new ArrayList<>(); for (Class<?> ruleClass : ruleClasses) { NewRule rule = newRule(ruleClass, failIfNoExplicitKey); externalDescriptionLoader.addHtmlDescription(rule); rule.setTemplate(AnnotationUtils.getAnnotation(ruleClass, RuleTemplate.class) != null); if (!isSqaleAnnotated(ruleClass) && failIfSqaleNotFound) { throw new IllegalArgumentException( "No SqaleSubCharacteristic annotation was found on " + ruleClass); }/*from w w w.jav a 2s. c o m*/ try { setupSqaleModel(rule, ruleClass); } catch (RuntimeException e) { throw new IllegalArgumentException("Could not setup SQALE model on " + ruleClass, e); } newRules.add(rule); } setupExternalNames(newRules); }
From source file:us.eharning.atomun.mnemonic.spi.electrum.legacy.LegacyElectrumMnemonicUtility.java
/** * Decode a space-delimited sequence of mnemonic words. * * @param mnemonicSequence//from w w w.j av a 2 s .co m * space-delimited sequence of mnemonic words to toEntropy. * * @return encoded value. */ @Nonnull static byte[] toEntropy(@Nonnull CharSequence mnemonicSequence) { String[] mnemonicWords = Iterables.toArray(WORD_SPLITTER.split(mnemonicSequence), String.class); byte[] entropy = new byte[mnemonicWords.length * 4 / 3]; int entropyIndex = 0; Converter<String, Integer> reverseDictionary = DICTIONARY.reverse(); if (mnemonicWords.length % 3 != 0) { throw new IllegalArgumentException("Mnemonic sequence is not a multiple of 3"); } for (int i = 0; i < mnemonicWords.length; i += 3) { String word1 = mnemonicWords[i].toLowerCase(); String word2 = mnemonicWords[i + 1].toLowerCase(); String word3 = mnemonicWords[i + 2].toLowerCase(); Integer w1 = reverseDictionary.convert(word1); Integer w2 = reverseDictionary.convert(word2); Integer w3 = reverseDictionary.convert(word3); if (null == w1 || null == w2 || null == w3) { throw new IllegalArgumentException("Unknown mnemonic word used"); } int subValue = w1 + N * mn_mod(w2 - w1, N) + N * N * mn_mod(w3 - w2, N); /* Convert to 4 bytes */ putInteger(entropy, entropyIndex, subValue); entropyIndex += 4; } return entropy; }
From source file:org.eclipse.xtext.xtext.ui.wizard.ecore2xtext.WizardSelectImportedEPackagePage.java
@Override public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(2, false)); Label label = new Label(composite, SWT.NONE); label.setText(Messages.WizardSelectImportedEPackagePage_ListTitle); label.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1)); importedEPackagesViewer = new TableViewer(composite, SWT.BORDER); importedEPackagesViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3)); importedEPackagesViewer.setContentProvider(new IStructuredContentProvider() { @Override/*from w ww . jav a2 s . c o m*/ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } @Override public void dispose() { } @Override public Object[] getElements(Object inputElement) { return Iterables.toArray(ePackageInfos, EPackageInfo.class); } }); importedEPackagesViewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { if (element instanceof EPackageInfo) { String label = ((EPackageInfo) element).getEPackageJavaFQN(); if (element == getDefaultEPackageInfo()) { return label + Messages.WizardSelectImportedEPackagePage_DefaultMarker; } else { return label; } } return element.toString(); } }); Button addButton = new Button(composite, SWT.PUSH); addButton.setText(Messages.WizardSelectImportedEPackagePage_AddButtonText); addButton.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1)); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { addEPackageInfos(new EPackageChooser(getShell(), jdtHelper).open()); } }); Button defaultButton = new Button(composite, SWT.PUSH); defaultButton.setText(Messages.WizardSelectImportedEPackagePage_SetDefault); defaultButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); defaultButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ISelection selection = importedEPackagesViewer.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; if (structuredSelection.size() == 1) { Object firstElement = structuredSelection.getFirstElement(); if (firstElement instanceof EPackageInfo) { defaultEPackageInfo = (EPackageInfo) firstElement; } } } updateUI(); } }); Button removeButton = new Button(composite, SWT.PUSH); removeButton.setText(Messages.WizardSelectImportedEPackagePage_RemoveButtonText); removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ISelection selection = importedEPackagesViewer.getSelection(); if (selection instanceof IStructuredSelection) { for (Iterator<?> i = ((IStructuredSelection) selection).iterator(); i.hasNext();) { Object ePackageInfo = i.next(); ePackageInfos.remove(ePackageInfo); if (defaultEPackageInfo == ePackageInfo) { defaultEPackageInfo = null; } } } updateUI(); } }); Label entryRuleLabel = new Label(composite, SWT.NONE); entryRuleLabel.setText(Messages.WizardSelectImportedEPackagePage_entryRuleLabelText); entryRuleLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1)); CCombo rootElementComboBoxCellEditor = new CCombo(composite, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY); GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); layoutData.heightHint = 20; rootElementComboBoxCellEditor.setLayoutData(layoutData); rootElementComboBoxCellEditor.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { validatePage(); } }); rootElementComboViewer = new ComboViewer(rootElementComboBoxCellEditor); rootElementComboViewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { return (element instanceof EClass) ? ((EClass) element).getName() + " - " + ((EClass) element).getEPackage().getName() : super.getText(element); } }); rootElementComboViewer.setContentProvider(new IStructuredContentProvider() { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } @Override public void dispose() { } @Override public Object[] getElements(Object inputElement) { Iterable<EClass> eClasses = Iterables.filter(Iterables .concat(Iterables.transform(ePackageInfos, new Function<EPackageInfo, List<EClassifier>>() { @Override public List<EClassifier> apply(EPackageInfo from) { return from.getEPackage().getEClassifiers(); } })), EClass.class); List<EClass> result = Lists.newArrayList(eClasses); Collections.sort(result, new Comparator<EClass>() { @Override public int compare(EClass o1, EClass o2) { return o1.getName().compareTo(o2.getName()); } }); return Iterables.toArray(result, EClass.class); } }); updateUI(); setControl(composite); Dialog.applyDialogFont(getControl()); }
From source file:edu.umn.msi.tropix.grid.credentials.impl.DelegatedCredentialFactoryGridImpl.java
public DelegatedCredentialReference createDelegatedCredential(final Credential proxy) { if (proxy == null || !StringUtils.hasText(cdsUrl)) { return null; }/*from w w w . j a va 2s. c o m*/ final IdentityDelegationPolicy policy = new IdentityDelegationPolicy(); final AllowedParties allowedParties = new AllowedParties(); policy.setAllowedParties(allowedParties); allowedParties.setGridIdentity(Iterables.toArray(allowedPartiesIterable, String.class)); final DelegationUserClient delClient = clientFactory.getService(cdsUrl, proxy); LOG.trace("Creating a delegated credential for identity " + proxy.getIdentity() + " delegationLifetime is " + toString(delegationLifetime) + " issuedCredentialLifetime is " + toString(issuedCredentialLifetime)); try { final DelegatedCredentialReference reference = delClient.delegateCredential(delegationLifetime, delegationPathLength, policy, issuedCredentialLifetime, issuedCredentialPathLength, keySize); return reference; } catch (final Exception e) { throw new IllegalStateException("Failed to create delegated credential reference.", e); } }
From source file:com.datatorrent.lib.db.jdbc.JdbcStore.java
/** * Sets the connection properties on JDBC connection. Connection properties are provided as a string. * * @param connectionProps Comma separated list of properties. Property key and value are separated by colon. * eg. user:xyz,password:ijk *//*from ww w . j ava 2s. c o m*/ public void setConnectionProperties(String connectionProps) { String[] properties = Iterables.toArray( Splitter.on(CharMatcher.anyOf(":,")).omitEmptyStrings().trimResults().split(connectionProps), String.class); for (int i = 0; i < properties.length; i += 2) { if (i + 1 < properties.length) { connectionProperties.put(properties[i], properties[i + 1]); } } }
From source file:org.apache.brooklyn.util.core.javalang.ReflectionScanner.java
/** scanner which will look in the given urls * (or if those are null attempt to infer from the first entry in the classloaders, * although currently that seems to only pick up directories, not JAR's), * optionally filtering for the given prefix; * any or all arguments can be null to accept all (and use default classpath for classloading). **//*from ww w . j av a 2 s. c om*/ public ReflectionScanner(final Iterable<URL> urlsToScan, final String optionalPrefix, final ClassLoader... classLoaders) { reflections = new Reflections(new ConfigurationBuilder() { { final Predicate<String> filter = Strings.isNonEmpty(optionalPrefix) ? new FilterBuilder.Include(FilterBuilder.prefix(optionalPrefix)) : null; if (urlsToScan != null) setUrls(ImmutableSet.copyOf(urlsToScan)); else if (classLoaders.length > 0 && classLoaders[0] != null) setUrls(ClasspathHelper.forPackage(Strings.isNonEmpty(optionalPrefix) ? optionalPrefix : "", asClassLoaderVarArgs(classLoaders[0]))); if (filter != null) filterInputsBy(filter); Scanner typeScanner = new TypeAnnotationsScanner(); if (filter != null) typeScanner = typeScanner.filterResultsBy(filter); Scanner subTypeScanner = new SubTypesScanner(); if (filter != null) subTypeScanner = subTypeScanner.filterResultsBy(filter); setScanners(typeScanner, subTypeScanner); for (ClassLoader cl : classLoaders) if (cl != null) addClassLoader(cl); } }); this.classLoaders = Iterables.toArray(Iterables.filter(Arrays.asList(classLoaders), Predicates.notNull()), ClassLoader.class); }
From source file:org.apache.samza.table.remote.TableReadFunction.java
/** * Asynchronously fetch the table {@code records} for specified {@code keys}. This method must be thread-safe. * The default implementation calls getAsync for each key and return a combined future. * @param keys keys for the table records * @return CompletableFuture for the get request *///from w w w. ja v a 2 s . c o m default CompletableFuture<Map<K, V>> getAllAsync(Collection<K> keys) { Map<K, CompletableFuture<V>> getFutures = keys.stream().collect(Collectors.toMap(k -> k, k -> getAsync(k))); return CompletableFuture.allOf(Iterables.toArray(getFutures.values(), CompletableFuture.class)) .thenApply(future -> getFutures.entrySet().stream() .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().join()))); }
From source file:org.eclipse.viatra.query.tooling.ui.queryexplorer.BackendSelectionControl.java
@Override protected Control createControl(Composite parent) { final ComboViewer viewer = new ComboViewer(parent, SWT.BORDER | SWT.READ_ONLY); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider() { @Override//from www . ja v a 2s . c o m public String getText(Object element) { if (element instanceof IQueryBackendFactory) { return DisplayUtil.getQueryBackendName((IQueryBackendFactory) element); } return super.getText(element); } }); viewer.setInput(Iterables.toArray(getRegisteredQueryBackendImplementations(), IQueryBackendFactory.class)); IQueryBackendFactory queryBackendFactory = getQueryExplorer().getHints().getQueryBackendFactory(); viewer.setSelection(queryBackendFactory != null ? new StructuredSelection(queryBackendFactory) : new StructuredSelection()); viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { final ISelection select = event.getSelection(); if (select instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) select; Object o = selection.getFirstElement(); if (o instanceof IQueryBackendFactory) { applyBackendSelection((IQueryBackendFactory) o); } } } }); viewer.getControl().setToolTipText("Select query backend engine to be used on subsequent loads."); return viewer.getControl(); }
From source file:org.sonar.squidbridge.annotations.AnnotationBasedRulesDefinition.java
public void addRuleClasses(boolean failIfSqaleNotFound, boolean failIfNoExplicitKey, Iterable<Class> ruleClasses) { new RulesDefinitionAnnotationLoader().load(repository, Iterables.toArray(ruleClasses, Class.class)); List<NewRule> newRules = Lists.newArrayList(); for (Class<?> ruleClass : ruleClasses) { NewRule rule = newRule(ruleClass, failIfNoExplicitKey); externalDescriptionLoader.addHtmlDescription(rule); rule.setTemplate(AnnotationUtils.getAnnotation(ruleClass, RuleTemplate.class) != null); if (!isSqaleAnnotated(ruleClass) && failIfSqaleNotFound) { throw new IllegalArgumentException( "No SqaleSubCharacteristic annotation was found on " + ruleClass); }// w w w .j av a2 s. c o m try { setupSqaleModel(rule, ruleClass); } catch (RuntimeException e) { throw new IllegalArgumentException("Could not setup SQALE model on " + ruleClass, e); } newRules.add(rule); } setupExternalNames(newRules); }