Example usage for java.util LinkedList add

List of usage examples for java.util LinkedList add

Introduction

In this page you can find the example usage for java.util LinkedList add.

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:SearchStyleText.java

public SearchStyleText() {
    shell.setLayout(new GridLayout(2, false));

    styledText = new StyledText(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.horizontalSpan = 2;//from   w  w  w .j  a  v  a  2s. c o m
    styledText.setLayoutData(gridData);

    keywordText = new Text(shell, SWT.SINGLE | SWT.BORDER);
    keywordText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Font font = new Font(shell.getDisplay(), "Courier New", 12, SWT.NORMAL);
    styledText.setFont(font);

    button = new Button(shell, SWT.PUSH);
    button.setText("Search");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            keyword = keywordText.getText();
            styledText.redraw();
        }
    });

    styledText.addLineStyleListener(new LineStyleListener() {
        public void lineGetStyle(LineStyleEvent event) {
            if (keyword == null || keyword.length() == 0) {
                event.styles = new StyleRange[0];
                return;
            }

            String line = event.lineText;
            int cursor = -1;

            LinkedList list = new LinkedList();
            while ((cursor = line.indexOf(keyword, cursor + 1)) >= 0) {
                list.add(getHighlightStyle(event.lineOffset + cursor, keyword.length()));
            }

            event.styles = (StyleRange[]) list.toArray(new StyleRange[list.size()]);
        }
    });

    keyword = "SW";

    styledText.setText("AWT, SWING \r\nSWT & JFACE");

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}

From source file:com.shopzilla.hadoop.mapreduce.MiniMRClusterContextMRTest.java

@Test
public void testWordCount() throws Exception {
    Path input = new Path("/user/test/keywords_data");
    Path output = new Path("/user/test/word_count");

    Job job = new Job(configuration);

    job.setJobName("Word Count Test");

    job.setMapperClass(WordCountMapper.class);
    job.setReducerClass(SumReducer.class);

    job.setInputFormatClass(TextInputFormat.class);
    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(LongWritable.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(LongWritable.class);
    job.setNumReduceTasks(1);//w ww . ja v a2  s . co m
    FileInputFormat.setInputPaths(job, input);
    FileOutputFormat.setOutputPath(job, output);

    assertTrue("All files from /data classpath directory should have been copied into HDFS",
            miniMRClusterContext.getFileSystem().exists(input));

    job.waitForCompletion(true);

    assertTrue("Output file should have been created", miniMRClusterContext.getFileSystem().exists(output));

    final LinkedList<String> expectedLines = new LinkedList<String>();
    expectedLines.add("goodbye\t1");
    expectedLines.add("hello\t1");
    expectedLines.add("world\t2");

    miniMRClusterContext.processData(output, new Function<String, Void>() {
        @Override
        public Void apply(String line) {
            assertEquals(expectedLines.pop(), line);
            return null;
        }
    });
    assertEquals(0, expectedLines.size());
}

From source file:com.cloud.agent.resource.virtualnetwork.ConfigHelper.java

private static List<ConfigItem> generateConfig(DnsMasqConfigCommand cmd) {
    LinkedList<ConfigItem> cfg = new LinkedList<>();

    List<DhcpTO> dhcpTos = cmd.getIps();
    StringBuffer buff = new StringBuffer();
    for (DhcpTO dhcpTo : dhcpTos) {
        buff.append(dhcpTo.getRouterIp());
        buff.append(":");
        buff.append(dhcpTo.getGateway());
        buff.append(":");
        buff.append(dhcpTo.getNetmask());
        buff.append(":");
        buff.append(dhcpTo.getStartIpOfSubnet());
        buff.append("-");
    }/*from   w ww .  ja v a2 s . c  o m*/
    cfg.add(new ScriptConfigItem(VRScripts.DNSMASQ_CONFIG, buff.toString()));
    return cfg;
}

From source file:free.yhc.feeder.model.Utils.java

public static void getFilesRecursive(LinkedList<File> l, File f) {
    if (!f.exists())
        return;/*from w  ww.j a va2  s  .  c om*/

    if (f.isDirectory()) {
        for (File c : f.listFiles())
            getFilesRecursive(l, c);
    } else
        l.add(f);
}

From source file:com.ryan.ryanreader.cache.PersistentCookieStore.java

@Override
public String toString() {

    final LinkedList<String> cookieStrings = new LinkedList<String>();

    for (final Cookie c : cookies) {
        cookieStrings.add(String.format("%s=%s", c.getName(), c.getValue()));
    }/*ww w.java  2  s  .  c o m*/

    return StringUtils.join(cookieStrings, "; ");
}

From source file:org.bremersee.common.security.core.context.RunAsAuthentication.java

/**
 * Create an authority with the specified name and roles (granted authorities).
 *
 * @param name               the name//from  w w w .  j  a v  a 2s .  c  o m
 * @param grantedAuthorities the roles (granted authorities)
 */
public RunAsAuthentication(final String name, final String[] grantedAuthorities) {
    this.name = name;
    if (grantedAuthorities == null) {
        authorities = new LinkedList<>();
    } else {
        LinkedList<GrantedAuthority> list = new LinkedList<>();
        for (String ga : grantedAuthorities) {
            list.add(new SimpleGrantedAuthority(ga));
        }
        authorities = list;
    }
}

From source file:com.data.RetrieveDataTask.java

protected Boolean doInBackground(Object... params) {

    try {// w  w w.j  a v a 2s .  c  om
        Timber.d("check for updates...");
        DataProvider dataProvider = new DataProvider();
        boolean isAlreadyStored = false;
        isAlreadyStored = dataProvider.isDataStored((Activity) params[0]);

        if (!isAlreadyStored) {
            Timber.d("no data available, so retrieve data...");
            HttpResponse response = new DefaultHttpClient().execute(new HttpGet(Constants.NAME_ROOM_URL));
            BufferedInputStream in = new BufferedInputStream(response.getEntity().getContent());

            LinkedList<Byte> bytes = new LinkedList<>();
            int b;
            while ((b = in.read()) != -1) {
                bytes.add((byte) b);
            }

            byte[] decryptedData = DecryptionService.decryptData(bytes, (String) params[1]);
            String data = new String(decryptedData);
            for (String l : data.split("\n")) {
                dataProvider.addNewEntry(l, (Activity) params[0]);
            }
        }
        SharedPreferences spData = ((Activity) params[0]).getApplicationContext().getSharedPreferences("Data",
                0);
        int remoteVersion = spData.getInt("DataVersionRemote", 0);
        spData.edit().putInt("DataVersion", remoteVersion).apply();

        Timber.d("... update success");
        return true;
    } catch (Exception e) {
        Timber.e(e, "... update failure " + e.getMessage());
    }
    return false;

}

From source file:com.frostwire.search.AlbumCluster.java

/**
 * Try to extract album and artist from path.
 *
 * @param/* w w  w.j ava 2  s. c o m*/
 * @return
 */
/*public static final Pair<String, String> albumArtistFromPath(String filepath, String defaultAlbum, String defaultArtist) {
String album = defaultAlbum;
String artist = defaultArtist;
        
if (!filepath.contains("/")) { // does not contain directory parts
    return ImmutablePair.of(album, artist);
}
ArrayList<String> dirs = new ArrayList<String>(Arrays.asList(filepath.split("/")));
        
if (dirs.get(0).equals("")) {
    dirs.remove(0);
}
        
if (dirs.size() > 0) {
    dirs.remove(dirs.size() - 1);
}
        
// strip disc subdirectory from list
if (dirs.size() > 0) {
    String last = dirs.get(dirs.size() - 1);
    if (last.matches("(?is)(^|\\s)(CD|DVD|Disc)\\s*\\d+(\\s|$)")) {
        dirs.remove(dirs.size() - 1);
    }
}
        
if (dirs.size() > 0) {
    // for clustering assume %artist%/%album%/file or %artist% - %album%/file
    album = dirs.get(dirs.size() - 1);
    if (album.contains(" - ")) {
        String[] parts = album.split(" - ");
        artist = parts[0];
        album = parts[1];
    } else if (dirs.size() > 1) {
        artist = dirs.get(dirs.size() - 2);
    }
}
        
return ImmutablePair.of(album, artist);
}*/

public LinkedList<TorrentCrawledAlbumSearchResult> detect(TorrentCrawlableSearchResult parent,
        List<? extends TorrentItemSearchResult> results) {
    LinkedList<TorrentCrawledAlbumSearchResult> albums = new LinkedList<TorrentCrawledAlbumSearchResult>();

    Map<String, LinkedList<TorrentItemSearchResult>> dirs = new HashMap<String, LinkedList<TorrentItemSearchResult>>();

    for (TorrentItemSearchResult sr : results) {
        String path = sr.getFilePath();
        String dir = FilenameUtils.getPathNoEndSeparator(path);

        if (!dirs.containsKey(dir)) {
            dirs.put(dir, new LinkedList<TorrentItemSearchResult>());
        }

        LinkedList<TorrentItemSearchResult> items = dirs.get(dir);
        items.add(sr);
    }

    for (Map.Entry<String, LinkedList<TorrentItemSearchResult>> kv : dirs.entrySet()) {
        int numAudio = 0;

        for (TorrentItemSearchResult sr : kv.getValue()) {
            String mime = MimeDetector.getMimeType(sr.getFilePath());
            if (mime.startsWith("audio")) {
                numAudio++;
            }
        }

        //            if (numAudio >= ALBUM_SIZE_THRESHOLD) {
        //                Pair<String, String> p = albumArtistFromPath(kv.getKey(), "", "");
        //                TorrentCrawledAlbumSearchResult sr = new TorrentCrawledAlbumSearchResult(parent, p.getRight(), p.getLeft(), kv.getValue());
        //                System.out.println(sr);
        //                albums.add(sr);
        //            }
    }

    return albums;
}

From source file:net.datapipe.CloudStack.CloudStackAPI.java

public Document deleteCondition(String id) throws Exception {
    LinkedList<NameValuePair> arguments = newQueryValues("deleteCondition", null);
    arguments.add(new NameValuePair("id", id));
    return Request(arguments);
}

From source file:org.deegree.securityproxy.wcs.responsefilter.capabilities.WcsCapabilitiesModificationManagerCreator.java

private LinkedList<ElementPathStep> createPath(String operation, String method) {
    LinkedList<ElementPathStep> path = new LinkedList<ElementPathStep>();
    path.add(new ElementPathStep(new QName(WCS_1_0_0_NS_URI, "WCS_Capabilities")));
    path.add(new ElementPathStep(new QName(WCS_1_0_0_NS_URI, "Capability")));
    path.add(new ElementPathStep(new QName(WCS_1_0_0_NS_URI, "Request")));
    path.add(new ElementPathStep(new QName(WCS_1_0_0_NS_URI, operation)));
    path.add(new ElementPathStep(new QName(WCS_1_0_0_NS_URI, "DCPType")));
    path.add(new ElementPathStep(new QName(WCS_1_0_0_NS_URI, "HTTP")));
    path.add(new ElementPathStep(new QName(WCS_1_0_0_NS_URI, method)));
    path.add(new ElementPathStep(new QName(WCS_1_0_0_NS_URI, "OnlineResource")));
    return path;//from w  w  w. jav  a 2 s . com
}