Example usage for java.util LinkedHashSet toArray

List of usage examples for java.util LinkedHashSet toArray

Introduction

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

Prototype

Object[] toArray();

Source Link

Document

Returns an array containing all of the elements in this set.

Usage

From source file:Main.java

public static void main(String[] args) {

    LinkedHashSet linkedHashSet = new LinkedHashSet(10);

    linkedHashSet.add("1");
    linkedHashSet.add("2");
    linkedHashSet.add("java2s.com");

    Object[] objArray = linkedHashSet.toArray();
    System.out.println(Arrays.toString(objArray));
}

From source file:Main.java

public static void main(String[] args) {

    LinkedHashSet linkedHashSet = new LinkedHashSet(10, 0.75F);

    linkedHashSet.add("1");
    linkedHashSet.add("2");
    linkedHashSet.add("java2s.com");

    Object[] objArray = linkedHashSet.toArray();
    System.out.println(Arrays.toString(objArray));
}

From source file:Main.java

public static void main(String[] args) {
    LinkedHashSet<Integer> lhashSet = new LinkedHashSet<Integer>();

    lhashSet.add(new Integer("1"));
    lhashSet.add(new Integer("2"));
    lhashSet.add(new Integer("3"));

    Object[] objArray = lhashSet.toArray();

    for (Object inte : objArray) {
        System.out.println(inte);
    }/*w  w  w .  jav a2  s . c  o m*/
}

From source file:com.pimp.companionforband.utils.jsontocsv.writer.CSVWriter.java

public void writeAsCSV(List<LinkedHashMap<String, String>> flatJson, String fileName)
        throws FileNotFoundException {
    LinkedHashSet<String> headers = collectHeaders(flatJson);
    String output = StringUtils.join(headers.toArray(), ",") + "\n";
    for (LinkedHashMap<String, String> map : flatJson) {
        output = output + getCommaSeperatedRow(headers, map) + "\n";
    }/*ww w.j a v  a2 s  .c  o  m*/
    writeToFile(output, fileName);
}

From source file:com.google.gwt.emultest.java.util.LinkedHashSetTest.java

@SuppressWarnings("unchecked")
public void testClone() {
    LinkedHashSet<String> srcSet = new LinkedHashSet<String>();
    checkEmptyLinkedHashSetAssumptions(srcSet);

    // Check empty clone behavior
    LinkedHashSet<String> dstSet = (LinkedHashSet<String>) srcSet.clone();
    assertNotNull(dstSet);//from w w  w. j a va 2 s. co m
    assertEquals(dstSet.size(), srcSet.size());
    assertEquals(dstSet.toArray(), srcSet.toArray());

    // Check non-empty clone behavior
    srcSet.add(VALUE_1);
    srcSet.add(VALUE_2);
    srcSet.add(VALUE_3);
    srcSet.add(VALUE_4);
    dstSet = (LinkedHashSet<String>) srcSet.clone();
    assertNotNull(dstSet);
    assertEquals(dstSet.size(), srcSet.size());
    assertEquals(dstSet.toArray(), srcSet.toArray());
}

From source file:com.amashchenko.struts2.pdfstream.PdfStreamResultTest.java

@Test
public void testStringToSet2() throws Exception {
    Assert.assertNotNull(pdfStreamResult);

    final String paths = "somepath/style.css,    /another/style2.css, ";
    LinkedHashSet<String> set = pdfStreamResult.stringToSet(paths);
    Assert.assertNotNull(set);//from ww  w .  j  a v  a 2  s .c  o m
    Assert.assertEquals(2, set.size());
    Assert.assertEquals("somepath/style.css", set.toArray()[0]);
    Assert.assertEquals("/another/style2.css", set.toArray()[1]);
}

From source file:com.amashchenko.struts2.pdfstream.PdfStreamResultTest.java

@Test
public void testStringToSet() throws Exception {
    Assert.assertNotNull(pdfStreamResult);

    final String paths = "/somepath/style.css";
    final LinkedHashSet<String> set = pdfStreamResult.stringToSet(paths);
    Assert.assertNotNull(set);//from  w  w w .j  ava 2s  .com
    Assert.assertEquals(1, set.size());
    Assert.assertEquals("/somepath/style.css", set.toArray()[0]);
}

From source file:org.springframework.extensions.webscripts.AbstractWebScript.java

/**
 * <p>Returns a {@link ResourceBundle} containing all the properties defined in the extension modules evaluated
 * for a request. This method will cope with a base bundle having been found or not but the parameters must
 * be supplied accordingly.</p>/*  w  w  w . j a  v a  2s  .  com*/
 * 
 * @param container This should be an object that implements the {@link HandlesExtensibility} interface.
 * @param result This should be the base provided {@link ResourceBundle} but can be <code>null</code> if 
 * a base {@link ResourceBundle} does not exist.
 * @param bundlePath If the <code>result</code> parameter is <code>null</code> (i.e. if no base {@link ResourceBundle}
 * was found then this needs to be a valid path to attempt to look for in the extensions.</p>
 * @return A {@link ResourceBundle} containing properties merged from all evaluated extension modules.
 */
private WebScriptPropertyResourceBundle getExtensionBundle(HandlesExtensibility container,
        ResourceBundle result, String bundlePath) {
    WebScriptPropertyResourceBundle extensionBundle = new WebScriptPropertyResourceBundle(result, bundlePath);
    if (container != null) {
        if (result instanceof WebScriptPropertyResourceBundle) {
            // If a base ResourceBundle was supplied then use it's resource path (assuming
            // that it is a WebScriptPropertyResourceBundle, which it will always be unless
            // the getBundleFromPath method has been overridden in the class hierarchy.
            bundlePath = ((WebScriptPropertyResourceBundle) result).getResourcePath();
        }

        if (bundlePath != null) {
            // Get the current WebScript id and generate a new id from the prefix (i.e. the package) and
            // the suffix (i.e. the bit after the package). Build a list of locale paths for this new path
            // to allow for degrading of locale (e.g. from en_GB -> en -> default). 
            String webScriptId = getDescription().getId();
            String suffix = webScriptId.substring(lastSlashIndex(webScriptId));
            String prefix = bundlePath.substring(0, lastSlashIndex(bundlePath));
            LinkedHashSet<String> paths = buildLocalePathList(prefix + suffix, I18NUtil.getLocale());

            // Iterate over the different locale paths in REVERSE order so that the most specific locale
            // file is merged into the bundle last. This means that all extension properties files will
            // be applied... this *could* mean a mixture of English with other languages but should ensure
            // that no keys are displayed (unless the messages have genuinely not been provided)...
            Object[] arrayOfPaths = paths.toArray();
            for (int i = arrayOfPaths.length - 1; i >= 0; i--) {
                String currPath = arrayOfPaths[i].toString();
                // If the bundle path is not null then iterate over the list of possible files 
                // that the evaluated modules suggest could provide extensions to the current WebScript...
                for (String moduleBundlePath : container.getExtendingModuleFiles(currPath)) {
                    try {
                        // Check the cache to see if we've previously loaded a bundle for this path...
                        ResourceBundle moduleBundle = checkModuleBundleCache(moduleBundlePath);
                        if (moduleBundle == null) {
                            // If the cache does not contain a bundle mapped against the path then
                            // we know that it hasn't previously been requested (if it had been requested
                            // and couldn't be found then we'd have been returned the sentinel).
                            moduleBundle = getBundleFromPath(moduleBundlePath);
                            if (moduleBundle == null) {
                                // If a bundle truly doesn't exist for this path (which is a perfectly
                                // valid situation as modules do not have to provide additional i18n
                                // properties) then we should cache the sentinel to ensure that we 
                                // don't needlessly look up the bundle again...
                                this.addModuleBundleToCache(moduleBundlePath,
                                        ModuleBundleSentinel.getInstance());
                            } else {
                                // If the bundle does exist then add it to the cache...
                                this.addModuleBundleToCache(moduleBundlePath, moduleBundle);
                            }
                        }

                        // If we've found a module bundle and its NOT the sentinel then we can process it...
                        if (moduleBundle != null && moduleBundle != ModuleBundleSentinel.getInstance()) {
                            // If we have a bundle (regardless of whether or not it has been retrieved from the 
                            // cache or whether we have just loaded it) we need to add a record of its use for the
                            // current thread of execution.
                            extensionBundle.merge(moduleBundlePath, moduleBundle);
                        }
                    } catch (IOException e) {
                        if (logger.isDebugEnabled()) {
                            logger.error("It was not possible to merge properties from: " + moduleBundlePath,
                                    e);
                        }
                    }
                }
            }
        }
    }
    return extensionBundle;
}