Example usage for java.util ArrayList toArray

List of usage examples for java.util ArrayList toArray

Introduction

In this page you can find the example usage for java.util ArrayList toArray.

Prototype

@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) 

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

Usage

From source file:com.microsoftopentechnologies.intellij.helpers.AndroidStudioHelper.java

public static void newActivityTemplateManager() throws IOException, InterruptedException {
    String[] cmd = null;/*from  w w w.j a v a  2  s .  co  m*/

    String templatePath = URLDecoder
            .decode(ApplicationComponent.class.getResource("").getPath().replace("file:/", ""), "UTF-8");
    templatePath = templatePath.replace("/", File.separator);
    templatePath = templatePath.substring(0, templatePath.indexOf(File.separator + "lib"));
    templatePath = templatePath + File.separator + "plugins" + File.separator + "android" + File.separator;
    templatePath = templatePath + "lib" + File.separator + "templates" + File.separator + "activities"
            + File.separator;

    String[] env = null;

    if (!new File(templatePath + mobileServicesTemplateName).exists()) {
        String tmpdir = getTempLocation();
        BufferedInputStream bufferedInputStream = new BufferedInputStream(
                ServiceCodeReferenceHelper.getTemplateResource("ActivityTemplate.zip"));
        unZip(bufferedInputStream, tmpdir);

        if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
            try {
                copyFolder(new File(tmpdir + mobileServicesTemplateName),
                        new File(templatePath + mobileServicesTemplateName));
                copyFolder(new File(tmpdir + officeTemplateName), new File(templatePath + officeTemplateName));
            } catch (IOException ex) {
                PrintWriter printWriter = new PrintWriter(tmpdir + "\\script.bat");
                printWriter.println("@echo off");
                printWriter.println("md \"" + templatePath + mobileServicesTemplateName + "\"");
                printWriter.println("md \"" + templatePath + officeTemplateName + "\"");
                printWriter.println("xcopy \"" + tmpdir + mobileServicesTemplateName + "\" \"" + templatePath
                        + mobileServicesTemplateName + "\" /s /i /Y");
                printWriter.println("xcopy \"" + tmpdir + officeTemplateName + "\" \"" + templatePath
                        + officeTemplateName + "\" /s /i /Y");
                printWriter.flush();
                printWriter.close();

                String[] tmpcmd = { tmpdir + "\\elevate.exe", "script.bat", "1" };

                cmd = tmpcmd;

                ArrayList<String> tempenvlist = new ArrayList<String>();
                for (String envval : System.getenv().keySet())
                    tempenvlist.add(String.format("%s=%s", envval, System.getenv().get(envval)));

                tempenvlist.add("PRECOMPILE_STREAMLINE_FILES=1");
                env = new String[tempenvlist.size()];
                tempenvlist.toArray(env);

                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec(cmd, env, new File(tmpdir));
                proc.waitFor();

                //wait for elevate command to finish
                Thread.sleep(3000);

                if (!new File(templatePath + mobileServicesTemplateName).exists())
                    UIHelper.showException(
                            "Error copying template files. Please refer to documentation to copy manually.",
                            new Exception());
            }
        } else {
            if (System.getProperty("os.name").toLowerCase().startsWith("mac")) {

                String[] strings = { "osascript",
                        //        "-e",
                        //        "do shell script \"mkdir -p \\\"/" + templatePath + mobileServicesTemplateName + "\\\"\"",
                        //        "-e",
                        //        "do shell script \"mkdir -p \\\"/" + templatePath + officeTemplateName + "\\\"\"",
                        "-e",
                        "do shell script \"cp -Rp \\\"" + tmpdir + mobileServicesTemplateName + "\\\" \\\"/"
                                + templatePath + "\\\"\"",
                        "-e", "do shell script \"cp -Rp \\\"" + tmpdir + officeTemplateName + "\\\" \\\"/"
                                + templatePath + "\\\"\"" };

                exec(strings, tmpdir);
            } else {
                try {

                    copyFolder(new File(tmpdir + mobileServicesTemplateName),
                            new File(templatePath + mobileServicesTemplateName));
                    copyFolder(new File(tmpdir + officeTemplateName),
                            new File(templatePath + officeTemplateName));

                } catch (IOException ex) {

                    JPasswordField pf = new JPasswordField();
                    int okCxl = JOptionPane.showConfirmDialog(null, pf,
                            "To copy Microsoft Services templates, the plugin needs your password:",
                            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

                    if (okCxl == JOptionPane.OK_OPTION) {
                        String password = new String(pf.getPassword());

                        exec(new String[] { "echo", password, "|", "sudo", "-S", "cp", "-Rp",
                                tmpdir + mobileServicesTemplateName,
                                templatePath + mobileServicesTemplateName }, tmpdir);

                        exec(new String[] { "echo", password, "|", "sudo", "-S", "cp", "-Rp",
                                tmpdir + officeTemplateName, templatePath + officeTemplateName }, tmpdir);
                    }
                }
            }
        }
    }
}

From source file:com.felkertech.n.ActivityUtils.java

public static void openSuggestedChannels(final Activity mActivity, final GoogleApiClient gapi) {
    final CumulusChannel[] channels = getSuggestedChannels();
    ArrayList<String> channeltext = new ArrayList<String>();
    for (CumulusChannel j : channels) {
        channeltext.add(j.getName());/*w w  w.ja v a2  s .  c om*/
    }
    final String[] channelList = channeltext.toArray(new String[channeltext.size()]);
    new MaterialDialog.Builder(mActivity).title(R.string.here_are_suggested_channels).items(channelList)
            .itemsCallback(new MaterialDialog.ListCallback() {
                @Override
                public void onSelection(MaterialDialog materialDialog, View view, int i,
                        CharSequence charSequence) {
                    CumulusChannel j = channels[i];
                    addChannel(mActivity, gapi, j);
                }
            }).show();
}

From source file:info.varden.anatychia.Main.java

private static File[] listRegionContainers(File base) {
    ArrayList<File> ret = new ArrayList<File>();
    File[] contents = base.listFiles();
    for (File f : contents) {
        if (f.isDirectory()) {
            ret.addAll(Arrays.asList(listRegionContainers(f)));
        } else {/*from w  w  w. j a v a2 s.  c  o  m*/
            if (f.getName().endsWith(".mca") && !ret.contains(base)) {
                ret.add(base);
            }
        }
    }
    return ret.toArray(new File[0]);
}

From source file:com.github.chenxiaolong.dualbootpatcher.pathchooser.PathChooserDialog.java

@Nullable
private static File[] listFilesWithFilter(@NonNull File directory, @Nullable String mimeType,
        @NonNull Comparator<File> comparator) {
    File[] contents = directory.listFiles();
    ArrayList<File> results = new ArrayList<>();

    if (contents != null) {
        MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
        for (File file : contents) {
            if (file.isDirectory() || isMimeType(file, mimeType, mimeTypeMap)) {
                results.add(file);//from ww w .ja va 2s.  c o m
            }
        }

        Collections.sort(results, comparator);
        return results.toArray(new File[results.size()]);
    }

    return null;
}

From source file:it.unibz.instasearch.InstaSearchPlugin.java

/**
 * Returns project names within working set
 * @param workingSet //  w  ww.j a v a  2 s .co m
 * @return WorkingSetProjects
 */
public static String[] getWorkingSetProjects(String workingSet) {

    String emptyResults[] = new String[0];

    IWorkingSetManager wsManager = getDefault().getWorkbench().getWorkingSetManager();
    if (wsManager == null)
        return emptyResults;

    IWorkingSet ws = wsManager.getWorkingSet(workingSet);
    if (ws == null)
        return emptyResults;

    ArrayList<String> projects = new ArrayList<String>();
    IAdaptable elements[] = ws.getElements();

    for (IAdaptable elem : elements) {
        if (elem instanceof IProject) {
            IProject proj = (IProject) elem;
            projects.add(proj.getName());
        } else {
            IProject proj = (IProject) elem.getAdapter(IProject.class);
            if (proj != null)
                projects.add(proj.getName());
        }
    }

    return projects.toArray(emptyResults);
}

From source file:org.kalypso.ogc.sensor.timeseries.TimeseriesUtils.java

/**
 * Finds out which metadata of the given observation begin with the given prefix.
 * <p>//from  w  w  w .j  a  v  a2s. c  o  m
 * This is for instance useful for the Alarmstufen
 *
 * @param obs
 * @param mdPrefix
 * @return list of metadata keys or empty array if nothing found
 */
public static String[] findOutMDBeginningWith(final IObservation obs, final String mdPrefix) {
    if (obs == null)
        return ArrayUtils.EMPTY_STRING_ARRAY;

    final MetadataList mdl = obs.getMetadataList();

    final ArrayList<String> mds = new ArrayList<>();

    final Set<Object> keySet = mdl.keySet();
    for (final Object object : keySet) {
        final String md = object.toString();

        if (md.startsWith(mdPrefix))
            mds.add(md);
    }

    return mds.toArray(new String[mds.size()]);
}

From source file:com.monarchapis.driver.exception.ConfigurationBundleApiErrorFactory.java

/**
 * Returns the array of strings based on the request locales.
 * /*from   ww  w. j  a  va2s  .c  o  m*/
 * @param request
 *            The API request
 * @return the array of variant strings
 */
private static String[] getLocaleArray(ApiRequest request) {
    Enumeration<Locale> locales = request.getLocales();
    ArrayList<String> localeList = new ArrayList<String>(5);

    while (locales.hasMoreElements()) {
        Locale locale = locales.nextElement();
        locale = new Locale(locale.getLanguage(), locale.getCountry());
        String lang = locale.getLanguage();

        if (StringUtils.isNotBlank(lang) && !"null".equals(lang)) {
            if (StringUtils.isNotBlank(locale.getCountry())) {
                localeList.add(locale.getLanguage() + '-' + locale.getCountry());
            }

            localeList.add(locale.getLanguage());
        }
    }

    return localeList.toArray(new String[localeList.size()]);
}

From source file:com.qtplaf.library.util.StringUtils.java

/**
 * Parses a string of the form "en-US,es-ES,fr,FR" or "en_US,es_ES,fr_FR" into an array of locales.
 *
 * @param str The argument string.// ww  w.j  ava  2 s  .co  m
 * @return The parsed array of locales.
 */
public static Locale[] parseLocales(String str) {
    ArrayList<Locale> locales = new ArrayList<>();
    String[] strLoc = split(str, ",");
    for (String strLoc1 : strLoc) {
        Locale locale = parseLocale(strLoc1);
        if (locale == null) {
            continue;
        }
        locales.add(locale);
    }
    return locales.toArray(new Locale[locales.size()]);
}

From source file:com.felkertech.n.ActivityUtils.java

public static void browsePlugins(final Activity activity) {
    //Same opening
    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<>();
    for (ResolveInfo ri : plugins) {
        plugin_names.add(ri.loadLabel(pm).toString());
    }/*  ww  w  . jav  a 2 s .c  o m*/
    String[] plugin_names2 = plugin_names.toArray(new String[plugin_names.size()]);

    new MaterialDialog.Builder(activity).title(R.string.installed_plugins).items(plugin_names2)
            .itemsCallback(new MaterialDialog.ListCallback() {
                @Override
                public void onSelection(MaterialDialog materialDialog, View view, int i,
                        CharSequence charSequence) {
                    // Load the given plugin with some additional info
                    ChannelDatabase cd = ChannelDatabase.getInstance(activity);
                    String s = cd.toString();
                    Intent intent = new Intent();
                    if (DEBUG) {
                        Log.d(TAG, "Try to start");
                    }
                    ResolveInfo plugin_info = plugins.get(i);
                    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_EXTRA_READ_ALL);
                    intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ALL_CHANNELS, s);
                    activity.startActivity(intent);
                }
            }).positiveText(R.string.download_more_plugins)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse("http://play.google.com/store/search?q=cumulustv&c=apps"));
                    activity.startActivity(i);
                }
            }).show();
}

From source file:com.groupon.odo.HttpUtilities.java

/**
 * Obtain collection of Parameters from request
 *
 * @param httpServletRequest// w w  w . j a  v a2  s. c om
 * @return
 * @throws Exception
 */
public static Map<String, String[]> mapUrlEncodedParameters(HttpServletRequest httpServletRequest)
        throws Exception {

    InputStream body = httpServletRequest.getInputStream();
    java.util.Scanner s = new java.util.Scanner(body).useDelimiter("\\A");
    Map<String, String[]> mapPostParameters = new HashMap<String, String[]>();

    try {
        if (s.hasNext()) {
            String requestData = s.next();
            String[] splitRequestData = requestData.split("&");
            for (String requestPart : splitRequestData) {
                String[] parts = requestPart.split("=");
                ArrayList<String> values = new ArrayList<String>();
                if (mapPostParameters.containsKey(parts[0])) {
                    values = new ArrayList<String>(Arrays.asList(mapPostParameters.get(parts[0])));
                    mapPostParameters.remove(parts[0]);
                }

                if (parts.length > 1) {
                    values.add(parts[1]);
                }

                mapPostParameters.put(parts[0], values.toArray(new String[values.size()]));
            }
        }
    } catch (Exception e) {
        throw new Exception("Could not parse request data: " + e.getMessage());
    }

    return mapPostParameters;
}