List of usage examples for java.util HashSet toArray
<T> T[] toArray(T[] a);
From source file:com.marklogic.contentpump.DatabaseContentWriter.java
/** * fetch the options information from conf and metadata, set to the field * "options"/*from w w w . ja va 2 s . c o m*/ */ protected ContentCreateOptions newContentCreateOptions(DocumentMetadata meta) { ContentCreateOptions opt = (ContentCreateOptions) options.clone(); if (meta != null) { if (opt.getQuality() == 0) { opt.setQuality(meta.quality); } HashSet<String> colSet = new HashSet<String>(meta.collectionsList); if (opt.getCollections() != null) { // union copy_collection and output_collection for (String s : opt.getCollections()) { colSet.add(s); } } opt.setCollections(colSet.toArray(new String[colSet.size()])); HashSet<ContentPermission> pSet = new HashSet<ContentPermission>(meta.permissionsList); if (opt.getPermissions() != null) { // union of output_permission & copy_permission for (ContentPermission p : opt.getPermissions()) { pSet.add(p); } } opt.setPermissions(pSet.toArray(new ContentPermission[pSet.size()])); } return opt; }
From source file:org.apache.hadoop.hbase.master.GroupAssignmentManager.java
/** * balance regions which in the same group * //from w ww . j a v a2 s . co m * @param group * the group you want to balance */ public static void balanceGroup(String group) { HashSet<HServerInfo> servers = groupServers.get(group); if (servers == null || servers.size() < 2) return; HServerInfo[] infos = new HServerInfo[servers.size()]; servers.toArray(infos); HashMap<HRegionInfo, HServerInfo> map = CheckMeta.getServerRegions(infos, true); if (map == null || map.size() < 2) return; doBalance(servers, map); }
From source file:org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.java
@Override public OperationType[] getOperations() { HashSet<OperationType> values = new HashSet<>(operations.lookup().values()); return values.toArray(new OperationType[values.size()]); }
From source file:org.springframework.yarn.batch.partition.HdfsSplitBatchPartitionHandler.java
@Override protected Map<StepExecution, ContainerRequestHint> createResourceRequestData(Set<StepExecution> stepExecutions) throws Exception { Map<StepExecution, ContainerRequestHint> requests = new HashMap<StepExecution, ContainerRequestHint>(); for (StepExecution execution : stepExecutions) { String fileName = execution.getExecutionContext().getString("fileName"); long splitStart = execution.getExecutionContext().getLong("splitStart"); long splitLength = execution.getExecutionContext().getLong("splitLength"); log.debug("Creating request data for stepExecution=" + execution + " with fileName=" + fileName + " splitStart=" + splitStart + " splitLength=" + splitLength); FileSystem fs = FileSystem.get(configuration); Path path = new Path(execution.getExecutionContext().getString("fileName")); HashSet<String> hostsSet = new HashSet<String>(); BlockLocation[] fileBlockLocations = fs.getFileBlockLocations(path, splitStart, splitLength); for (BlockLocation blockLocation : fileBlockLocations) { for (String host : blockLocation.getHosts()) { hostsSet.add(host);/*from w w w. ja v a 2 s. com*/ } log.debug("block: " + blockLocation + " topologypaths=" + StringUtils.arrayToCommaDelimitedString(blockLocation.getTopologyPaths())); } String[] hosts = hostsSet.toArray(new String[0]); String[] racks = new String[0]; // hints only for hosts requests.put(execution, new ContainerRequestHint(execution, null, hosts, racks, null)); } return requests; }
From source file:org.jboss.dashboard.workspace.PanelsProvidersManagerImpl.java
/** * @return The providers installed, but not licensed for use in the workspace. */// www . j ava 2 s .c o m public PanelProvider[] getDisabledProviders() { HashSet<PanelProvider> panelProviders = new HashSet<PanelProvider>(); for (PanelProvider p : panels.values()) { if (!p.isEnabled()) panelProviders.add(p); } PanelProvider[] p = panelProviders.toArray(new PanelProvider[panels.size()]); // Sort providers by description (just for display purpouses) Arrays.sort(p, new PanelProviderComparator()); return p; }
From source file:org.eclipse.ecr.core.api.repository.cache.DocumentModelCacheUpdater.java
@Override public void handleEvents(OperationEvent[] events, boolean urgent) { HashSet<DocumentModel> updatedDocs = new HashSet<DocumentModel>(events.length); HashSet<DocumentModel> updatedTrees = new HashSet<DocumentModel>(events.length); for (OperationEvent event : events) { try {/* w w w. j ava 2 s .c o m*/ handleEvent(cache, updatedDocs, updatedTrees, event); } catch (Exception e) { log.error("Exception handling event", e); } } if (!listeners.isEmpty()) { if (!updatedDocs.isEmpty()) { DocumentModel[] docs = updatedDocs.toArray(new DocumentModel[updatedDocs.size()]); for (DocumentModelCacheListener listener : listeners) { try { listener.documentsChanged(docs, urgent); } catch (Throwable error) { log.error("An error while trying fire listener for document modifications", error); } } } if (!updatedTrees.isEmpty()) { DocumentModel[] docs = updatedTrees.toArray(new DocumentModel[updatedTrees.size()]); for (DocumentModelCacheListener listener : listeners) { try { listener.subreeChanged(docs, urgent); } catch (Throwable error) { log.error("An error while trying fire listener for document modifications", error); } } } } }
From source file:org.apache.taverna.activities.dependencyactivity.AbstractAsynchronousDependencyActivity.java
/** * Constructs a classloader capable of finding both local jar and artifact dependencies. * Called when classloader sharing policy is set to 'workflow'. * * @return A {@link ClassLoader} capable of accessing all the dependencies (both local jar and artifact) *//* ww w . j a va 2s . c om*/ private ClassLoader makeClassLoader(JsonNode json, String workflowID) { // Find all artifact dependencies // HashSet<URL> urls = findDependencies(ARTIFACTS, configurationBean, workflowID); // Add all local jar dependencies HashSet<URL> urls = findDependencies(LOCAL_JARS, json, workflowID); // Create the classloader capable of loading both local jar and artifact dependencies ClassLoader parent = this.getClass().getClassLoader(); // this will be a LocalArtifactClassLoader return new URLClassLoader(urls.toArray(new URL[0]), parent) { // For finding native libraries that have to be stored in TAVERNA_HOME/lib @Override protected String findLibrary(String libname) { String filename = System.mapLibraryName(libname); File libraryFile = new File(libDir, filename); if (libraryFile.isFile()) { logger.info("Found library " + libname + ": " + libraryFile.getAbsolutePath()); return libraryFile.getAbsolutePath(); } return super.findLibrary(libname); } }; }
From source file:com.amalto.workbench.compare.ResourceCompareInput.java
@Override public Object getAdapter(Class adapter) { if (IFile.class.equals(adapter)) { IProgressMonitor pm = new NullProgressMonitor(); // flush changes in any dirty viewer flushViewers(pm);//from w ww . ja va 2 s .co m IFile[] files = (IFile[]) getAdapter(IFile[].class); if (files != null && files.length > 0) { return files[0]; // can only return one: limitation on IDE.saveAllEditors; see #64617 } return null; } if (IFile[].class.equals(adapter)) { HashSet collector = new HashSet(); collectDirtyResources(fRoot, collector); return collector.toArray(new IFile[collector.size()]); } return super.getAdapter(adapter); }
From source file:org.eclipse.swt.examples.graphics.GraphicsExample.java
void createTabList(Composite parent) { tabList = new Tree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); Arrays.sort(tabs, (tab0, tab1) -> tab0.getText().compareTo(tab1.getText())); HashSet<String> set = new HashSet<>(); for (GraphicsTab tab : tabs) { set.add(tab.getCategory());//from w ww . j a v a2s. co m } String[] categories = new String[set.size()]; set.toArray(categories); Arrays.sort(categories); for (String text : categories) { TreeItem item = new TreeItem(tabList, SWT.NONE); item.setText(text); } tabs_in_order = new ArrayList<>(); TreeItem[] items = tabList.getItems(); for (TreeItem item : items) { for (GraphicsTab tab : tabs) { if (item.getText().equals(tab.getCategory())) { TreeItem item1 = new TreeItem(item, SWT.NONE); item1.setText(tab.getText()); item1.setData(tab); tabs_in_order.add(tab); } } } tabList.addListener(SWT.Selection, event -> { TreeItem item = (TreeItem) event.item; if (item != null) { GraphicsTab gt = (GraphicsTab) item.getData(); if (gt == tab) return; setTab((GraphicsTab) item.getData()); } }); }
From source file:com.wellsandwhistles.android.redditsp.reddit.prepared.RedditPreparedPost.java
public static void onActionMenuItemSelected(final RedditPreparedPost post, final AppCompatActivity activity, final Action action) { switch (action) { case UPVOTE:/*from www. j av a2 s.c o m*/ post.action(activity, RedditAPI.ACTION_UPVOTE); break; case DOWNVOTE: post.action(activity, RedditAPI.ACTION_DOWNVOTE); break; case UNVOTE: post.action(activity, RedditAPI.ACTION_UNVOTE); break; case SAVE: post.action(activity, RedditAPI.ACTION_SAVE); break; case UNSAVE: post.action(activity, RedditAPI.ACTION_UNSAVE); break; case HIDE: post.action(activity, RedditAPI.ACTION_HIDE); break; case UNHIDE: post.action(activity, RedditAPI.ACTION_UNHIDE); break; case EDIT: final Intent editIntent = new Intent(activity, CommentEditActivity.class); editIntent.putExtra("commentIdAndType", post.src.getIdAndType()); editIntent.putExtra("commentText", StringEscapeUtils.unescapeHtml4(post.src.getRawSelfText())); editIntent.putExtra("isSelfPost", true); activity.startActivity(editIntent); break; case DELETE: new AlertDialog.Builder(activity).setTitle(R.string.accounts_delete).setMessage(R.string.delete_confirm) .setPositiveButton(R.string.action_delete, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.ACTION_DELETE); } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case REPORT: new AlertDialog.Builder(activity).setTitle(R.string.action_report) .setMessage(R.string.action_report_sure) .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.ACTION_REPORT); // TODO update the view to show the result // TODO don't forget, this also hides } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case EXTERNAL: { final Intent intent = new Intent(Intent.ACTION_VIEW); String url = (activity instanceof WebViewActivity) ? ((WebViewActivity) activity).getCurrentUrl() : post.src.getUrl(); intent.setData(Uri.parse(url)); activity.startActivity(intent); break; } case SELFTEXT_LINKS: { final HashSet<String> linksInComment = LinkHandler .computeAllLinks(StringEscapeUtils.unescapeHtml4(post.src.getRawSelfText())); if (linksInComment.isEmpty()) { General.quickToast(activity, R.string.error_toast_no_urls_in_self); } else { final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]); final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setItems(linksArr, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { LinkHandler.onLinkClicked(activity, linksArr[which], false, post.src.getSrc()); dialog.dismiss(); } }); final AlertDialog alert = builder.create(); alert.setTitle(R.string.action_selftext_links); alert.setCanceledOnTouchOutside(true); alert.show(); } break; } case SAVE_IMAGE: { ((BaseActivity) activity).requestPermissionWithCallback(Manifest.permission.WRITE_EXTERNAL_STORAGE, new SaveImageCallback(activity, post.src.getUrl())); break; } case SHARE: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, post.src.getTitle()); mailer.putExtra(Intent.EXTRA_TEXT, post.src.getUrl()); activity.startActivity(Intent.createChooser(mailer, activity.getString(R.string.action_share))); break; } case SHARE_COMMENTS: { final boolean shareAsPermalink = PrefsUtility.pref_behaviour_share_permalink(activity, PreferenceManager.getDefaultSharedPreferences(activity)); final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, "Comments for " + post.src.getTitle()); if (shareAsPermalink) { mailer.putExtra(Intent.EXTRA_TEXT, Constants.Reddit.getNonAPIUri(post.src.getPermalink()).toString()); } else { mailer.putExtra(Intent.EXTRA_TEXT, Constants.Reddit .getNonAPIUri(Constants.Reddit.PATH_COMMENTS + post.src.getIdAlone()).toString()); } activity.startActivity( Intent.createChooser(mailer, activity.getString(R.string.action_share_comments))); break; } case SHARE_IMAGE: { ((BaseActivity) activity).requestPermissionWithCallback(Manifest.permission.WRITE_EXTERNAL_STORAGE, new ShareImageCallback(activity, post.src.getUrl())); break; } case COPY: { ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); manager.setText(post.src.getUrl()); break; } case GOTO_SUBREDDIT: { try { final Intent intent = new Intent(activity, PostListingActivity.class); intent.setData(SubredditPostListURL.getSubreddit(post.src.getSubreddit()).generateJsonUri()); activity.startActivityForResult(intent, 1); } catch (RedditSubreddit.InvalidSubredditNameException e) { Toast.makeText(activity, R.string.invalid_subreddit_name, Toast.LENGTH_LONG).show(); } break; } case USER_PROFILE: LinkHandler.onLinkClicked(activity, new UserProfileURL(post.src.getAuthor()).toString()); break; case PROPERTIES: PostPropertiesDialog.newInstance(post.src.getSrc()).show(activity.getSupportFragmentManager(), null); break; case COMMENTS: ((PostSelectionListener) activity).onPostCommentsSelected(post); new Thread() { @Override public void run() { post.markAsRead(activity); } }.start(); break; case LINK: ((PostSelectionListener) activity).onPostSelected(post); break; case COMMENTS_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((PostSelectionListener) activity).onPostCommentsSelected(post); break; case LINK_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((PostSelectionListener) activity).onPostSelected(post); break; case ACTION_MENU: showActionMenu(activity, post); break; case REPLY: final Intent intent = new Intent(activity, CommentReplyActivity.class); intent.putExtra(CommentReplyActivity.PARENT_ID_AND_TYPE_KEY, post.src.getIdAndType()); intent.putExtra(CommentReplyActivity.PARENT_MARKDOWN_KEY, post.src.getUnescapedSelfText()); activity.startActivity(intent); break; case BACK: activity.onBackPressed(); break; case PIN: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); List<String> pinnedSubreddits = PrefsUtility.pref_pinned_subreddits(activity, PreferenceManager.getDefaultSharedPreferences(activity)); if (!pinnedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_pinned_subreddits_add(activity, PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName); } else { Toast.makeText(activity, R.string.mainmenu_toast_pinned, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; case UNPIN: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); List<String> pinnedSubreddits = PrefsUtility.pref_pinned_subreddits(activity, PreferenceManager.getDefaultSharedPreferences(activity)); if (pinnedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_pinned_subreddits_remove(activity, PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName); } else { Toast.makeText(activity, R.string.mainmenu_toast_not_pinned, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; case BLOCK: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); List<String> blockedSubreddits = PrefsUtility.pref_blocked_subreddits(activity, PreferenceManager.getDefaultSharedPreferences(activity)); if (!blockedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_blocked_subreddits_add(activity, PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName); } else { Toast.makeText(activity, R.string.mainmenu_toast_blocked, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; case UNBLOCK: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); List<String> blockedSubreddits = PrefsUtility.pref_blocked_subreddits(activity, PreferenceManager.getDefaultSharedPreferences(activity)); if (blockedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_blocked_subreddits_remove(activity, PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName); } else { Toast.makeText(activity, R.string.mainmenu_toast_not_blocked, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; case SUBSCRIBE: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); RedditSubredditSubscriptionManager subMan = RedditSubredditSubscriptionManager .getSingleton(activity, RedditAccountManager.getInstance(activity).getDefaultAccount()); if (subMan.getSubscriptionState( subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.NOT_SUBSCRIBED) { subMan.subscribe(subredditCanonicalName, activity); Toast.makeText(activity, R.string.options_subscribing, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(activity, R.string.mainmenu_toast_subscribed, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; case UNSUBSCRIBE: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); RedditSubredditSubscriptionManager subMan = RedditSubredditSubscriptionManager .getSingleton(activity, RedditAccountManager.getInstance(activity).getDefaultAccount()); if (subMan.getSubscriptionState( subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.SUBSCRIBED) { subMan.unsubscribe(subredditCanonicalName, activity); Toast.makeText(activity, R.string.options_unsubscribing, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(activity, R.string.mainmenu_toast_not_subscribed, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; } }