List of usage examples for java.util HashSet toArray
<T> T[] toArray(T[] a);
From source file:SerialVersionUID.java
/** * Create a Map<String, ClassVersionInfo> for the jboss dist jars. * /*from w w w. j ava 2s . c o m*/ * @param jbossHome - * the jboss dist root directory * @return Map<String, ClassVersionInfo> * @throws IOException */ public static Map generateJBossSerialVersionUIDReport(File jbossHome) throws IOException { // Obtain the jars from the /lib, common/ and /server/all locations HashSet jarFiles = new HashSet(); File lib = new File(jbossHome, "lib"); buildJarSet(lib, jarFiles); File common = new File(jbossHome, "common"); buildJarSet(common, jarFiles); File all = new File(jbossHome, "server/all"); buildJarSet(all, jarFiles); URL[] cp = new URL[jarFiles.size()]; jarFiles.toArray(cp); ClassLoader parent = Thread.currentThread().getContextClassLoader(); URLClassLoader completeClasspath = new URLClassLoader(cp, parent); TreeMap classVersionMap = new TreeMap(); Iterator jarIter = jarFiles.iterator(); while (jarIter.hasNext()) { URL jar = (URL) jarIter.next(); try { generateJarSerialVersionUIDs(jar, classVersionMap, completeClasspath, ""); } catch (IOException e) { log.info("Failed to process jar: " + jar); } } return classVersionMap; }
From source file:ru.objective.jni.utils.Utils.java
public static <T> T[] mergeUniqueArray(T[] arr1, T[] arr2) { HashSet<T> result = new HashSet<>(); if (arr1 == null) { return arr2; } else if (arr2 == null) return arr1; for (T obj : arr1) { result.add(obj);//w ww . j av a 2 s . c o m } for (T obj : arr2) { result.add(obj); } return result.toArray((T[]) Array.newInstance(arr1.getClass().getComponentType(), result.size())); }
From source file:com.wellsandwhistles.android.redditsp.reddit.api.RedditAPICommentAction.java
public static void onActionMenuItemSelected(final RedditRenderableComment renderableComment, final RedditCommentView commentView, final AppCompatActivity activity, final CommentListingFragment commentListingFragment, final RedditCommentAction action, final RedditChangeDataManager changeDataManager) { final RedditComment comment = renderableComment.getParsedComment().getRawComment(); switch (action) { case UPVOTE://from w w w. j a v a 2 s . c o m action(activity, comment, RedditAPI.ACTION_UPVOTE, changeDataManager); break; case DOWNVOTE: action(activity, comment, RedditAPI.ACTION_DOWNVOTE, changeDataManager); break; case UNVOTE: action(activity, comment, RedditAPI.ACTION_UNVOTE, changeDataManager); break; case SAVE: action(activity, comment, RedditAPI.ACTION_SAVE, changeDataManager); break; case UNSAVE: action(activity, comment, RedditAPI.ACTION_UNSAVE, changeDataManager); 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) { action(activity, comment, RedditAPI.ACTION_REPORT, changeDataManager); } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case REPLY: { final Intent intent = new Intent(activity, CommentReplyActivity.class); intent.putExtra(CommentReplyActivity.PARENT_ID_AND_TYPE_KEY, comment.getIdAndType()); intent.putExtra(CommentReplyActivity.PARENT_MARKDOWN_KEY, StringEscapeUtils.unescapeHtml4(comment.body)); activity.startActivity(intent); break; } case EDIT: { final Intent intent = new Intent(activity, CommentEditActivity.class); intent.putExtra("commentIdAndType", comment.getIdAndType()); intent.putExtra("commentText", StringEscapeUtils.unescapeHtml4(comment.body)); activity.startActivity(intent); 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) { action(activity, comment, RedditAPI.ACTION_DELETE, changeDataManager); } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; } case COMMENT_LINKS: final HashSet<String> linksInComment = comment.computeAllLinks(); if (linksInComment.isEmpty()) { General.quickToast(activity, R.string.error_toast_no_urls_in_comment); } 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); dialog.dismiss(); } }); final AlertDialog alert = builder.create(); alert.setTitle(R.string.action_comment_links); alert.setCanceledOnTouchOutside(true); alert.show(); } break; case SHARE: final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, "Comment by " + comment.author + " on Reddit"); // TODO this currently just dumps the markdown mailer.putExtra(Intent.EXTRA_TEXT, StringEscapeUtils.unescapeHtml4(comment.body) + "\r\n\r\n" + comment.getContextUrl().generateNonJsonUri().toString()); activity.startActivityForResult(Intent.createChooser(mailer, activity.getString(R.string.action_share)), 1); break; case COPY_TEXT: { ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); // TODO this currently just dumps the markdown manager.setText(StringEscapeUtils.unescapeHtml4(comment.body)); break; } case COPY_URL: { ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); // TODO this currently just dumps the markdown manager.setText(comment.getContextUrl().context(null).generateNonJsonUri().toString()); break; } case COLLAPSE: { commentListingFragment.handleCommentVisibilityToggle(commentView); break; } case USER_PROFILE: LinkHandler.onLinkClicked(activity, new UserProfileURL(comment.author).toString()); break; case PROPERTIES: CommentPropertiesDialog.newInstance(comment).show(activity.getSupportFragmentManager(), null); break; case GO_TO_COMMENT: { LinkHandler.onLinkClicked(activity, comment.getContextUrl().context(null).toString()); break; } case CONTEXT: { LinkHandler.onLinkClicked(activity, comment.getContextUrl().toString()); break; } case ACTION_MENU: showActionMenu(activity, commentListingFragment, renderableComment, commentView, changeDataManager, comment.isArchived()); break; case BACK: activity.onBackPressed(); break; } }
From source file:org.nuxeo.ecm.webengine.app.WebEngineModule.java
private static Class<?>[] readWebTypes(WebLoader loader, InputStream in) throws Exception { HashSet<Class<?>> types = new HashSet<Class<?>>(); BufferedReader reader = null; try {//from w ww.jav a2 s .co m reader = new BufferedReader(new InputStreamReader(in)); String line; while ((line = reader.readLine()) != null) { line = line.trim(); if (line.length() == 0 || line.startsWith("#")) { continue; } int p = line.indexOf('|'); if (p > -1) { line = line.substring(0, p); } Class<?> cl = loader.loadClass(line); types.add(cl); } } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { } } } return types.toArray(new Class<?>[types.size()]); }
From source file:ru.objective.jni.utils.OJNIClassLoader.java
public String[] getClassNamesFromPackage(String packageName) throws IOException { HashSet<String> result = getClassNamesSetFromPackage(packageName); return result.toArray(new String[result.size()]); }
From source file:no.group09.connection.ConnectionMetadata.java
/** * Returns an array of all associated pins to the service * @param service which service we want to retrieve the pins for * @return an array of Integer objects (empty if there are no specific pins) *//*from ww w . j a v a 2 s.c o m*/ public Integer[] getServicePins(String service) { HashSet<Integer> set = servicePin.get(service); return set.toArray(new Integer[set.size()]); }
From source file:com.cyclopsgroup.waterview.servlet.ServletRequestParameters.java
/** * Override method doGetAttributeNames in class ServletRequestValueParser * * @see com.cyclopsgroup.waterview.Attributes#doGetAttributeNames() *///w w w.j a v a 2s . c o m protected String[] doGetAttributeNames() { HashSet names = new HashSet(); CollectionUtils.addAll(names, httpServletRequest.getParameterNames()); names.addAll(extra.keySet()); return (String[]) names.toArray(ArrayUtils.EMPTY_STRING_ARRAY); }
From source file:cm.confide.ex.chips.RecipientAlternatesAdapter.java
/** * Get a HashMap of address to RecipientEntry that contains all contact * information for a contact with the provided address, if one exists. This * may block the UI, so run it in an async task. * * @param context Context.//from w w w.j a v a2 s .c o m * @param inAddresses Array of addresses on which to perform the lookup. * @param callback RecipientMatchCallback called when a match or matches are found. * @return HashMap<String,RecipientEntry> */ public static void getMatchingRecipients(Context context, BaseRecipientAdapter adapter, ArrayList<String> inAddresses, int addressType, Account account, RecipientMatchCallback callback) { Queries.Query query; if (addressType == QUERY_TYPE_EMAIL) { query = Queries.EMAIL; } else { query = Queries.PHONE; } int addressesSize = Math.min(MAX_LOOKUPS, inAddresses.size()); HashSet<String> addresses = new HashSet<String>(); StringBuilder bindString = new StringBuilder(); // Create the "?" string and set up arguments. for (int i = 0; i < addressesSize; i++) { Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(inAddresses.get(i).toLowerCase()); addresses.add(tokens.length > 0 ? tokens[0].getAddress() : inAddresses.get(i)); bindString.append("?"); if (i < addressesSize - 1) { bindString.append(","); } } if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Doing reverse lookup for " + addresses.toString()); } String[] addressArray = new String[addresses.size()]; addresses.toArray(addressArray); HashMap<String, RecipientEntry> recipientEntries = null; Cursor c = null; try { c = context.getContentResolver().query(query.getContentUri(), query.getProjection(), query.getProjection()[Queries.Query.DESTINATION] + " IN (" + bindString.toString() + ")", addressArray, null); recipientEntries = processContactEntries(c); callback.matchesFound(recipientEntries); } finally { if (c != null) { c.close(); } } // See if any entries did not resolve; if so, we need to check other // directories final Set<String> matchesNotFound = new HashSet<String>(); if (recipientEntries.size() < addresses.size()) { final List<DirectorySearchParams> paramsList; Cursor directoryCursor = null; try { directoryCursor = context.getContentResolver().query(DirectoryListQuery.URI, DirectoryListQuery.PROJECTION, null, null, null); if (directoryCursor == null) { paramsList = null; } else { paramsList = BaseRecipientAdapter.setupOtherDirectories(context, directoryCursor, account); } } finally { if (directoryCursor != null) { directoryCursor.close(); } } // Run a directory query for each unmatched recipient. HashSet<String> unresolvedAddresses = new HashSet<String>(); for (String address : addresses) { if (!recipientEntries.containsKey(address)) { unresolvedAddresses.add(address); } } matchesNotFound.addAll(unresolvedAddresses); if (paramsList != null) { Cursor directoryContactsCursor = null; for (String unresolvedAddress : unresolvedAddresses) { for (int i = 0; i < paramsList.size(); i++) { try { directoryContactsCursor = doQuery(unresolvedAddress, 1, paramsList.get(i).directoryId, account, context.getContentResolver(), query); } finally { if (directoryContactsCursor != null && directoryContactsCursor.getCount() == 0) { directoryContactsCursor.close(); directoryContactsCursor = null; } else { break; } } } if (directoryContactsCursor != null) { try { final Map<String, RecipientEntry> entries = processContactEntries( directoryContactsCursor); for (final String address : entries.keySet()) { matchesNotFound.remove(address); } callback.matchesFound(entries); } finally { directoryContactsCursor.close(); } } } } } // If no matches found in contact provider or the directories, try the extension // matcher. // todo (aalbert): This whole method needs to be in the adapter? if (adapter != null) { final Map<String, RecipientEntry> entries = adapter.getMatchingRecipients(matchesNotFound); if (entries != null && entries.size() > 0) { callback.matchesFound(entries); for (final String address : entries.keySet()) { matchesNotFound.remove(address); } } } callback.matchesNotFound(matchesNotFound); }
From source file:com.redhat.lightblue.rest.metadata.hystrix.GetEntityNamesCommand.java
@Override protected String run() { LOGGER.debug("run:"); Error.reset();/* w w w . j av a2 s. c o m*/ Error.push(getClass().getSimpleName()); try { HashSet<MetadataStatus> statusSet = new HashSet<>(); for (String x : statuses) { statusSet.add(MetadataParser.statusFromString(x)); } String[] names = getMetadata().getEntityNames(statusSet.toArray(new MetadataStatus[statusSet.size()])); ObjectNode node = NODE_FACTORY.objectNode(); ArrayNode arr = NODE_FACTORY.arrayNode(); node.put("entities", arr); for (String x : names) { arr.add(NODE_FACTORY.textNode(x)); } return node.toString(); } catch (Error e) { return e.toString(); } catch (Exception e) { LOGGER.error("Failure: {}", e); return Error.get(RestMetadataConstants.ERR_REST_ERROR, e.toString()).toString(); } }
From source file:org.osaf.cosmo.atom.provider.mock.BaseMockRequestContext.java
@Override public String[] getParameterNames() { HashSet<String> names = new HashSet<String>(); names.addAll(params.keySet());/*from w ww. jav a2 s . c o m*/ for (String name : super.getParameterNames()) names.add(name); return names.toArray(new String[0]); }