Example usage for java.util List add

List of usage examples for java.util List add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Appends the specified element to the end of this list (optional operation).

Usage

From source file:net.sf.excelutils.tags.IfTag.java

public static void main(String[] args) {
    Interpreter in = new Interpreter();
    try {/*w ww.  j  a v a  2s.c o  m*/
        in.set("a", "5a");
        in.set("b", "5a");
        List errors = new ArrayList();
        errors.add("abc");
        Map context = new HashMap();
        context.put("errors", errors);

        in.set("context", context);

        in.eval("bar=\"5a\"==\"5a\"");
        System.out.println(in.get("bar"));
        System.out.println("ab${addd}dd${cccc}aa".replaceAll("\\$\\{|\\}", ""));
        System.out.println(in.eval("(context.get(\"errors\").size() == 2)"));
        System.out.println(in.eval("abc == null"));
    } catch (EvalError e) {
        e.printStackTrace();
    }
}

From source file:test.TestPredImpl.java

public static void main(String[] args) throws Exception {
    String[] opts = new String[] { "-query" };
    String[] defaults = new String[] { "field is null " };
    String[] paras = Utils.getOpts(args, opts, defaults);
    List<String> list = new ArrayList<String>();
    list.add("test1");
    Map<String, ClassInfo> map = new HashMap<String, ClassInfo>();
    ClassInfo classInfo = findClassInfo(list, map);
    //System.out.println( classInfo.toString());
    Result r1 = new Result(10);
    Result r2 = new Result(20L);
    Result r3 = new Result(new Integer(30));
    int i1 = (Integer) r1.getValue();

}

From source file:Shape.java

public static void main(String[] args) throws Exception {
    List shapeTypes, shapes;
    if (args.length == 0) {
        shapeTypes = new ArrayList();
        shapes = new ArrayList();

        shapeTypes.add(Circle.class);
        shapeTypes.add(Square.class);
        shapeTypes.add(Line.class);

        shapes.add(new Square(4, 3, 200));
        shapes.add(new Circle(1, 2, 100));
        shapes.add(new Line(1, 2, 100));

        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("CADState.out"));
        out.writeObject(shapeTypes);//from   ww w  . ja v a 2s  .  c o m
        Line.serializeStaticState(out);
        out.writeObject(shapes);
    } else {
        ObjectInputStream in = new ObjectInputStream(new FileInputStream(args[0]));
        shapeTypes = (List) in.readObject();
        Line.deserializeStaticState(in);
        shapes = (List) in.readObject();
    }

    System.out.println(shapes);
}

From source file:com.buaa.cfs.utils.JvmPauseMonitor.java

/**
 * Simple 'main' to facilitate manual testing of the pause monitor.
 * <p>/*from  w ww.jav  a  2 s. c o  m*/
 * This main function just leaks memory into a list. Running this class with a 1GB heap will very quickly go into
 * "GC hell" and result in log messages about the GC pauses.
 */
public static void main(String[] args) throws Exception {
    new JvmPauseMonitor(new Configuration()).start();
    List<String> list = Lists.newArrayList();
    int i = 0;
    while (true) {
        list.add(String.valueOf(i++));
    }
}

From source file:org.test.LookupSVNUsers.java

/**
 * @param args//from  www  .  j a v a 2s  . c o m
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {

    if (args.length != 2) {
        log.error("USAGE: <svn users file(input)> <git authors file (output)>");

        System.exit(-1);
    }

    Set<String> unmatchedNameSet = new LinkedHashSet<String>();

    Map<String, GitUser> gitUserMap = new LinkedHashMap<String, GitUser>();

    String svnAuthorsFile = args[0];

    List<String> lines = FileUtils.readLines(new File(svnAuthorsFile));

    for (String line : lines) {

        // intentionally handle both upper and lower case varients of the same name.
        String svnUserName = line.trim();

        if (svnUserName.contains("("))
            continue; // skip over this line as we can't use it on the url

        if (gitUserMap.keySet().contains(svnUserName))
            continue; // skip this duplicate.

        log.info("starting on user = " + svnUserName);

        String gitName = extractFullName(svnUserName);

        if (gitName == null) {

            gitName = extractFullName(svnUserName.toLowerCase());
        }

        if (gitName == null) {
            unmatchedNameSet.add(svnUserName);
        } else {

            gitUserMap.put(svnUserName, new GitUser(svnUserName, gitName));
            log.info("mapped user (" + svnUserName + ") to: " + gitName);

        }

    }

    List<String> mergedList = new ArrayList<String>();

    mergedList.add("# GENERATED ");

    List<String> userNameList = new ArrayList<String>();

    userNameList.addAll(gitUserMap.keySet());

    Collections.sort(userNameList);

    for (String userName : userNameList) {

        GitUser gUser = gitUserMap.get(userName);

        mergedList.add(gUser.getSvnAuthor() + " = " + gUser.getGitUser() + " <" + gUser.getSvnAuthor()
                + "@users.sourceforge.net>");

    }

    for (String username : unmatchedNameSet) {

        log.warn("failed to match SVN User = " + username);

        // add in the unmatched entries as is.
        mergedList.add(username + " = " + username + " <" + username + "@users.sourceforge.net>");
    }

    FileUtils.writeLines(new File(args[1]), "UTF-8", mergedList);

}

From source file:hdfs.MiniHDFS.java

public static void main(String[] args) throws Exception {
    if (args.length != 1 && args.length != 3) {
        throw new IllegalArgumentException(
                "Expected: MiniHDFS <baseDirectory> [<kerberosPrincipal> <kerberosKeytab>], " + "got: "
                        + Arrays.toString(args));
    }/* w  w  w .  j  a  v a 2 s .  co m*/
    boolean secure = args.length == 3;

    // configure Paths
    Path baseDir = Paths.get(args[0]);
    // hadoop-home/, so logs will not complain
    if (System.getenv("HADOOP_HOME") == null) {
        Path hadoopHome = baseDir.resolve("hadoop-home");
        Files.createDirectories(hadoopHome);
        System.setProperty("hadoop.home.dir", hadoopHome.toAbsolutePath().toString());
    }
    // hdfs-data/, where any data is going
    Path hdfsHome = baseDir.resolve("hdfs-data");

    // configure cluster
    Configuration cfg = new Configuration();
    cfg.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, hdfsHome.toAbsolutePath().toString());
    // lower default permission: TODO: needed?
    cfg.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_PERMISSION_KEY, "766");

    // optionally configure security
    if (secure) {
        String kerberosPrincipal = args[1];
        String keytabFile = args[2];

        cfg.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
        cfg.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, "true");
        cfg.set(DFSConfigKeys.DFS_NAMENODE_KERBEROS_PRINCIPAL_KEY, kerberosPrincipal);
        cfg.set(DFSConfigKeys.DFS_DATANODE_KERBEROS_PRINCIPAL_KEY, kerberosPrincipal);
        cfg.set(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY, kerberosPrincipal);
        cfg.set(DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY, keytabFile);
        cfg.set(DFSConfigKeys.DFS_DATANODE_KEYTAB_FILE_KEY, keytabFile);
        cfg.set(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, "true");
        cfg.set(DFSConfigKeys.DFS_BLOCK_ACCESS_TOKEN_ENABLE_KEY, "true");
        cfg.set(DFSConfigKeys.IGNORE_SECURE_PORTS_FOR_TESTING_KEY, "true");
    }

    UserGroupInformation.setConfiguration(cfg);

    // TODO: remove hardcoded port!
    MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(cfg);
    if (secure) {
        builder.nameNodePort(9998);
    } else {
        builder.nameNodePort(9999);
    }
    MiniDFSCluster dfs = builder.build();

    // Configure contents of the filesystem
    org.apache.hadoop.fs.Path esUserPath = new org.apache.hadoop.fs.Path("/user/elasticsearch");
    try (FileSystem fs = dfs.getFileSystem()) {

        // Set the elasticsearch user directory up
        fs.mkdirs(esUserPath);
        if (UserGroupInformation.isSecurityEnabled()) {
            List<AclEntry> acls = new ArrayList<>();
            acls.add(new AclEntry.Builder().setType(AclEntryType.USER).setName("elasticsearch")
                    .setPermission(FsAction.ALL).build());
            fs.modifyAclEntries(esUserPath, acls);
        }

        // Install a pre-existing repository into HDFS
        String directoryName = "readonly-repository";
        String archiveName = directoryName + ".tar.gz";
        URL readOnlyRepositoryArchiveURL = MiniHDFS.class.getClassLoader().getResource(archiveName);
        if (readOnlyRepositoryArchiveURL != null) {
            Path tempDirectory = Files.createTempDirectory(MiniHDFS.class.getName());
            File readOnlyRepositoryArchive = tempDirectory.resolve(archiveName).toFile();
            FileUtils.copyURLToFile(readOnlyRepositoryArchiveURL, readOnlyRepositoryArchive);
            FileUtil.unTar(readOnlyRepositoryArchive, tempDirectory.toFile());

            fs.copyFromLocalFile(true, true,
                    new org.apache.hadoop.fs.Path(
                            tempDirectory.resolve(directoryName).toAbsolutePath().toUri()),
                    esUserPath.suffix("/existing/" + directoryName));

            FileUtils.deleteDirectory(tempDirectory.toFile());
        }
    }

    // write our PID file
    Path tmp = Files.createTempFile(baseDir, null, null);
    String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
    Files.write(tmp, pid.getBytes(StandardCharsets.UTF_8));
    Files.move(tmp, baseDir.resolve(PID_FILE_NAME), StandardCopyOption.ATOMIC_MOVE);

    // write our port file
    tmp = Files.createTempFile(baseDir, null, null);
    Files.write(tmp, Integer.toString(dfs.getNameNodePort()).getBytes(StandardCharsets.UTF_8));
    Files.move(tmp, baseDir.resolve(PORT_FILE_NAME), StandardCopyOption.ATOMIC_MOVE);
}

From source file:Main.java

public static void main(String[] argv) {
    List list = new ArrayList();

    // Create a left-aligned tab stop at 100 pixels from the left margin
    float pos = 100;
    int align = TabStop.ALIGN_LEFT;
    int leader = TabStop.LEAD_NONE;
    TabStop tstop = new TabStop(pos, align, leader);
    list.add(tstop);
}

From source file:com.siemens.scr.avt.ad.io.AnnotationBatchLoader.java

public static void main(String[] args) {
    initLogging();//from   ww  w .j  av a2 s  .  c  o m
    assert args.length > 0 : "A directory should be provided!";

    String path = args[0];
    logger.debug("Loading from directory " + path);

    File directory = new File(path);

    assert directory != null : "Directory should exist!";
    assert directory.isDirectory() : "The path " + path + " should point to a directory!";

    List<String> argStrings = new ArrayList<String>();
    for (int i = 0; i < args.length; i++) {
        argStrings.add(args[i]);
    }

    AnnotationBatchLoader loader = new AnnotationBatchLoader();
    try {
        loader.parseSegDicomFromDirectroy(directory);
        loader.loadFromDirectory(directory);
    } catch (Exception e) {
        logger.error("Error while loading:");
        e.printStackTrace();
    }
    logger.info("done");
}

From source file:info.bitoo.utils.BiToorrentRemaker.java

public static void main(String[] args) throws IOException, TOTorrentException {
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;//from w  w w  .  j av a2 s  . co m
    try {
        cmd = parser.parse(createCommandLineOptions(), args);
    } catch (ParseException e) {
        System.err.println("Parsing failed.  Reason: " + e.getMessage());
    }

    StringTokenizer stLocations = new StringTokenizer(cmd.getOptionValue("l"), "|");
    List locations = new ArrayList(stLocations.countTokens());

    while (stLocations.hasMoreTokens()) {
        URL locationURL = new URL((String) stLocations.nextToken());
        locations.add(locationURL.toString());
    }

    String torrentFileName = cmd.getOptionValue("t");

    File torrentFile = new File(torrentFileName);

    TOTorrentDeserialiseImpl torrent = new TOTorrentDeserialiseImpl(torrentFile);

    torrent.setAdditionalListProperty("alternative locations", locations);

    torrent.serialiseToBEncodedFile(torrentFile);

}

From source file:SyntaxColoring.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);

    final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER);

    final String PUNCTUATION = "(){}";
    styledText.addExtendedModifyListener(new ExtendedModifyListener() {
        public void modifyText(ExtendedModifyEvent event) {
            int end = event.start + event.length - 1;

            if (event.start <= end) {
                String text = styledText.getText(event.start, end);
                java.util.List ranges = new java.util.ArrayList();

                for (int i = 0, n = text.length(); i < n; i++) {
                    if (PUNCTUATION.indexOf(text.charAt(i)) > -1) {
                        ranges.add(new StyleRange(event.start + i, 1, display.getSystemColor(SWT.COLOR_BLUE),
                                null, SWT.BOLD));
                    }/* www. ja  v a  2s  . c  om*/
                }
                if (!ranges.isEmpty()) {
                    styledText.replaceStyleRanges(event.start, event.length,
                            (StyleRange[]) ranges.toArray(new StyleRange[0]));
                }
            }
        }
    });

    styledText.setBounds(10, 10, 500, 100);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}