List of usage examples for java.util ArrayList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:gov.llnl.lc.smt.command.route.SmtMulticast.java
public static SBN_MulticastGroup[] getWellKnownGroups(LinkedHashMap<String, SBN_MulticastGroup> mcGroups, boolean wellKnown) { // if wellKnown is true, only return the well_known groups // if wellKnown is false, only return the non-well_known groups java.util.ArrayList<SBN_MulticastGroup> gMems = new java.util.ArrayList<SBN_MulticastGroup>(); for (SBN_MulticastGroup g : mcGroups.values()) { // if this is a well known group, return it if (!(g.well_known ^ wellKnown)) gMems.add(g);/* www .j ava 2s. c o m*/ } SBN_MulticastGroup list[] = new SBN_MulticastGroup[gMems.size()]; return gMems.toArray(list); }
From source file:Main.java
/** * Splits the specified step into parts. * <p/>// w w w .ja v a 2 s . c o m * Examples: * <ul> * <li><code>"a"</code> returns <code>{"a"}</code>. * <li><code>"a[p]"</code> returns <code>{"a", "p"}</code>. * <li><code>"a[p][q]"</code> returns <code>{"a", "p", "q"}</code>. * <li><code>"child::a[p][q]"</code> returns <code>{"child::a", "p", "q"}</code>. * <li><code>"a[b[p]][c/d[q]]"</code> returns <code>{"a", "b[p]", "c/d[q]"}</code>. * </ul> * * @param step the step. * @return the specified step in parts. */ public static String[] splitStep(String step) { if (step == null) { return null; } int offset = 0; int braces = 0; ArrayList list = new ArrayList(); for (int index = 0; index < step.length(); index++) { switch (step.charAt(index)) { case '[': if (braces == 0) { if (offset == 0) { list.add(step.substring(offset, index)); } offset = index + 1; } braces++; break; case ']': if (braces == 1) { list.add(step.substring(offset, index)); offset = index + 1; } braces--; break; } } if (offset < step.length()) { list.add(step.substring(offset, step.length())); } return (String[]) list.toArray(new String[0]); }
From source file:com.pinterest.secor.util.FileUtil.java
public static String[] list(String path) throws IOException { FileSystem fs = getFileSystem(path); Path fsPath = new Path(path); ArrayList<String> paths = new ArrayList<String>(); FileStatus[] statuses = fs.listStatus(fsPath); if (statuses != null) { for (FileStatus status : statuses) { Path statusPath = status.getPath(); if (path.startsWith("s3://") || path.startsWith("s3n://") || path.startsWith("s3a://") || path.startsWith("swift://") || path.startsWith("gs://")) { paths.add(statusPath.toUri().toString()); } else { paths.add(statusPath.toUri().getPath()); }//from www . j a v a 2 s.co m } } return paths.toArray(new String[] {}); }
From source file:com.dtolabs.rundeck.core.utils.ScriptExecUtil.java
/** * Generate argument array for a script file invocation * * @param localDataContext data context properties to expand among the args * @param node node to use for os-type argument quoting. * @param scriptargs arguments to the script file * @param scriptargsarr arguments to the script file as an array * @param scriptinterpreter interpreter invocation for the file, or null to invoke it directly * @param interpreterargsquoted if true, pass the script file and args as a single argument to the interpreter * @param filepath remote filepath for the script *///from w w w. ja v a 2 s . co m public static String[] createScriptArgs(final Map<String, Map<String, String>> localDataContext, final INodeEntry node, final String scriptargs, final String[] scriptargsarr, final String scriptinterpreter, final boolean interpreterargsquoted, final String filepath) { final ArrayList<String> arglist = new ArrayList<String>(); if (null != scriptinterpreter) { arglist.addAll(Arrays.asList(OptsUtil.burst(scriptinterpreter))); } if (null != scriptinterpreter && interpreterargsquoted) { final ArrayList<String> sublist = new ArrayList<String>(); sublist.add(filepath); addQuotedArgs(localDataContext, node, scriptargs, scriptargsarr, sublist, true); arglist.add(DataContextUtils.join(sublist, " ")); } else { arglist.add(filepath); addQuotedArgs(localDataContext, node, scriptargs, scriptargsarr, arglist, false); } return arglist.toArray(new String[arglist.size()]); }
From source file:gov.llnl.lc.smt.command.route.SmtMulticast.java
public static SBN_MulticastGroup[] getGroupsWithMember(LinkedHashMap<String, SBN_MulticastGroup> mcGroups, IB_Guid guid) {/*from w w w .ja v a2 s . c o m*/ if (guid == null) return null; // look through the groups, and build a new list which contains this guid as a member java.util.ArrayList<SBN_MulticastGroup> gMems = new java.util.ArrayList<SBN_MulticastGroup>(); for (SBN_MulticastGroup g : mcGroups.values()) { // if this contains this guid, then add it to the return list if (g.isMember(guid.getGuid())) gMems.add(g); } SBN_MulticastGroup list[] = new SBN_MulticastGroup[gMems.size()]; return gMems.toArray(list); }
From source file:com.felkertech.n.ActivityUtils.java
public static void openPluginPicker(final boolean newChannel, final JsonChannel queriedChannel, final Activity activity) { final PackageManager pm = activity.getPackageManager(); final Intent plugin_addchannel = new Intent(CumulusTvPlugin.ACTION_ADD_CHANNEL); final List<ResolveInfo> plugins = pm.queryIntentActivities(plugin_addchannel, 0); ArrayList<String> plugin_names = new ArrayList<String>(); for (ResolveInfo ri : plugins) { plugin_names.add(ri.loadLabel(pm).toString()); }//from w ww . ja va 2s.c o m String[] plugin_names2 = plugin_names.toArray(new String[plugin_names.size()]); if (DEBUG) { Log.d(TAG, "Load plugins " + plugin_names.toString()); } if (plugin_names.size() == 1) { Intent intent = new Intent(); if (newChannel) { if (DEBUG) { Log.d(TAG, "Try to start "); } ResolveInfo plugin_info = plugins.get(0); if (DEBUG) { Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " " + plugin_info.activityInfo.name); } intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName, plugin_info.activityInfo.name); intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_ADD); } else { ResolveInfo plugin_info = plugins.get(0); Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " " + plugin_info.activityInfo.name); intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName, plugin_info.activityInfo.name); intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT); intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, queriedChannel.toString()); } activity.startActivity(intent); } else { new MaterialDialog.Builder(activity).items(plugin_names2).title(R.string.choose_an_app) .content(R.string.choose_default_app).itemsCallback(new MaterialDialog.ListCallback() { @Override public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) { Intent intent = new Intent(); if (newChannel) { if (DEBUG) { Log.d(TAG, "Try to start"); } ResolveInfo plugin_info = plugins.get(i); if (DEBUG) { Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " " + plugin_info.activityInfo.name); } intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName, plugin_info.activityInfo.name); intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_ADD); } else { ResolveInfo plugin_info = plugins.get(i); intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName, plugin_info.activityInfo.name); intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT); intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, queriedChannel.toString()); } activity.startActivity(intent); } }).show(); } }
From source file:com.ricemap.spateDB.core.SpatialSite.java
public static CellInfo[] cellsOf(FileSystem fs, Path path) throws IOException { GlobalIndex<Partition> gindex = getGlobalIndex(fs, path); if (gindex == null) return null; // Find all partitions of the given file. If two partitions overlap, // we consider the union of them. This case corresponds to an R-tree // index where a partition is stored as multiple R-tree. Since we compact // each R-tree when it is stored, different compactions might lead to // different partitions all overlapping the same area. In this case, we // union them to ensure the whole area is covered without having overlaps // between returned partitions. ArrayList<CellInfo> cellSet = new ArrayList<CellInfo>(); for (Partition p : gindex) { Prism r = p;/*from ww w. j a v a2 s . co m*/ boolean overlapping = false; for (int i = 0; i < cellSet.size(); i++) { if (r.isIntersected(cellSet.get(i))) { overlapping = true; cellSet.get(i).expand(r); r = cellSet.get(i); } } if (overlapping == false) { cellSet.add(new CellInfo(cellSet.size() + 1, p)); } } return cellSet.toArray(new CellInfo[cellSet.size()]); }
From source file:Utilities.java
/** Convert a space-separated list of Emacs-like key binding names to a list of Swing key strokes. * @param s the string with keys//from w w w .j av a2s . com * @return array of key strokes, or <code>null</code> if the string description is not valid * @see #stringToKey */ public static KeyStroke[] stringToKeys(String s) { StringTokenizer st = new StringTokenizer(s.toUpperCase(Locale.ENGLISH), " "); // NOI18N ArrayList<KeyStroke> arr = new ArrayList<KeyStroke>(); while (st.hasMoreElements()) { s = st.nextToken(); KeyStroke k = stringToKey(s); if (k == null) { return null; } arr.add(k); } return arr.toArray(new KeyStroke[arr.size()]); }
From source file:org.obiba.onyx.engine.ActionDefinitionConfiguration.java
/** * Returns an array of hierarchical codes that are used to find an associated {@code ActionDefinition} instance. This * method will build an array of codes with the first element being the most specific: * <ul>/*from w w w . java2 s . c om*/ * <li>ACTION_PREFIX.type.stateName.module.stage</li> * <li>ACTION_PREFIX.type.stateName.module</li> * <li>ACTION_PREFIX.type.stateName</li> * <li>ACTION_PREFIX.type</li> * <li>ACTION_PREFIX * <li> * </ul> * @param type the {@link ActionType} of the {@code ActionDefinition} * @param stateName the name of the state on which the action is performed * @param module the module that contributed the stage * @param stage the stage on which the action is performed * @return an array of codes */ static public String[] calculateCodes(ActionType type, String stateName, String module, String stage) { ArrayList<String> codes = new ArrayList<String>(); StringBuilder sb = new StringBuilder(ACTION_PREFIX); codes.add(sb.toString()); sb.append(SEPARATOR).append(type); codes.add(sb.toString()); if (stateName != null) { sb.append(SEPARATOR).append(stateName); codes.add(sb.toString()); } if (module != null) { sb.append(SEPARATOR).append(module); codes.add(sb.toString()); } if (stage != null) { sb.append(SEPARATOR).append(stage); codes.add(sb.toString()); } Collections.reverse(codes); return codes.toArray(new String[codes.size()]); }
From source file:gov.llnl.lc.smt.command.route.SmtMulticast.java
public static SBN_MulticastGroup[] getGroupsWithMembers(LinkedHashMap<String, SBN_MulticastGroup> mcGroups, int minimumNumber) { java.util.ArrayList<SBN_MulticastGroup> gMems = new java.util.ArrayList<SBN_MulticastGroup>(); for (SBN_MulticastGroup g : mcGroups.values()) { // if this has the minimum number of members, then add it to the return list if (g.port_guids.length >= minimumNumber) gMems.add(g);/*w w w. j ava 2s . com*/ } SBN_MulticastGroup list[] = new SBN_MulticastGroup[gMems.size()]; return gMems.toArray(list); }