Example usage for java.util Collections EMPTY_LIST

List of usage examples for java.util Collections EMPTY_LIST

Introduction

In this page you can find the example usage for java.util Collections EMPTY_LIST.

Prototype

List EMPTY_LIST

To view the source code for java.util Collections EMPTY_LIST.

Click Source Link

Document

The empty list (immutable).

Usage

From source file:Main.java

public static void main(String args[]) {
    List list = Collections.EMPTY_LIST;
    Set set = Collections.EMPTY_SET;
    Map map = Collections.EMPTY_MAP;

    List<String> s = Collections.emptyList();
    Set<Long> l = Collections.emptySet();
    Map<Date, String> d = Collections.emptyMap();
}

From source file:Main.java

public static void main(String[] args) {
    long begTime = System.currentTimeMillis();

    String driver = DEFAULT_DRIVER;
    String url = DEFAULT_URL;
    String username = DEFAULT_USERNAME;
    String password = DEFAULT_PASSWORD;

    Connection connection = null;

    try {/*from ww  w.  j a v a2  s.  c  om*/
        connection = createConnection(driver, url, username, password);
        DatabaseMetaData meta = connection.getMetaData();
        System.out.println(meta.getDatabaseProductName());
        System.out.println(meta.getDatabaseProductVersion());

        String sqlQuery = "SELECT PERSON_ID, FIRST_NAME, LAST_NAME FROM PERSON";
        System.out.println("before insert: " + query(connection, sqlQuery, Collections.EMPTY_LIST));

        connection.setAutoCommit(false);
        String sqlUpdate = "INSERT INTO PERSON(FIRST_NAME, LAST_NAME) VALUES(?,?)";
        List parameters = Arrays.asList("Foo", "Bar");
        int numRowsUpdated = update(connection, sqlUpdate, parameters);
        connection.commit();

        System.out.println("# rows inserted: " + numRowsUpdated);
        System.out.println("after insert: " + query(connection, sqlQuery, Collections.EMPTY_LIST));
    } catch (Exception e) {
        rollback(connection);
        e.printStackTrace();
    } finally {
        close(connection);
        long endTime = System.currentTimeMillis();
        System.out.println("wall time: " + (endTime - begTime) + " ms");
    }
}

From source file:com.diversityarrays.kdxplore.trials.TrialSelectionDialog.java

static public void main(String[] args) {

    Transformer<BackgroundRunner, TrialSearchOptionsPanel> factory = new Transformer<BackgroundRunner, TrialSearchOptionsPanel>() {
        @Override// w w w. j a v  a  2s. co  m
        public TrialSearchOptionsPanel transform(BackgroundRunner backgroundRunner) {
            return TrialSelectionSearchOptionsPanel.create(backgroundRunner);
        }
    };

    boolean test = false;
    if (test) {
        @SuppressWarnings("unchecked")
        TrialSelectionDialog tsd = new TrialSelectionDialog(null, "Test Tree", null, Collections.EMPTY_LIST, //$NON-NLS-1$
                factory);
        //         tsd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        tsd.setVisible(true);
    } else {

        File propertiesFile = new File(System.getProperty("user.home"), //$NON-NLS-1$
                "LoginDialog.properties"); //$NON-NLS-1$
        //.getBundle("LoginDialog"); //, Locale.getDefault());

        ResourceBundle bundle = null;

        if (propertiesFile.exists()) {
            try {
                bundle = new PropertyResourceBundle(new FileReader(propertiesFile));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                System.exit(1);
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(1);
            }
        }

        Preferences loginPreferences = KdxplorePreferences.getInstance().getPreferences();
        //         Preferences loginPreferences = Preferences.userNodeForPackage(KdxConstants.class);

        LoginDialog ld = new LoginDialog(null, "Login Please", loginPreferences, bundle); //$NON-NLS-1$
        ld.setVisible(true);
        DALClient client = ld.getDALClient();
        if (client != null) {
            @SuppressWarnings("unchecked")
            TrialSelectionDialog tsd = new TrialSelectionDialog(null, "Test Tree", client, //$NON-NLS-1$
                    Collections.EMPTY_LIST, factory);
            //            tsd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            tsd.setVisible(true);
            if (tsd.trialRecords == null) {
                System.out.println("Cancelled !"); //$NON-NLS-1$
            } else {
                System.out.println(tsd.trialRecords.length + " chosen: "); //$NON-NLS-1$
                for (TrialPlus tr : tsd.trialRecords) {
                    System.out.println("\t" + tr.getTrialId() + ": " + tr.getTrialName()); //$NON-NLS-1$ //$NON-NLS-2$
                }
                System.out.println("- - -"); //$NON-NLS-1$
            }
        }
    }
    System.exit(0);
}

From source file:com.github.ambry.store.DiskReformatter.java

public static void main(String[] args) throws Exception {
    VerifiableProperties properties = ToolUtils.getVerifiableProperties(args);
    DiskReformatterConfig config = new DiskReformatterConfig(properties);
    StoreConfig storeConfig = new StoreConfig(properties);
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(properties);
    ServerConfig serverConfig = new ServerConfig(properties);
    ClusterAgentsFactory clusterAgentsFactory = Utils.getObj(clusterMapConfig.clusterMapClusterAgentsFactory,
            clusterMapConfig, config.hardwareLayoutFilePath, config.partitionLayoutFilePath);
    try (ClusterMap clusterMap = clusterAgentsFactory.getClusterMap()) {
        StoreKeyConverterFactory storeKeyConverterFactory = Utils.getObj(
                serverConfig.serverStoreKeyConverterFactory, properties, clusterMap.getMetricRegistry());
        StoreKeyFactory storeKeyFactory = Utils.getObj(storeConfig.storeKeyFactory, clusterMap);
        DataNodeId dataNodeId = clusterMap.getDataNodeId(config.datanodeHostname, config.datanodePort);
        if (dataNodeId == null) {
            throw new IllegalArgumentException("Did not find node in clustermap with hostname:port - "
                    + config.datanodeHostname + ":" + config.datanodePort);
        }// w ww .j  a va2s.  co m
        DiskReformatter reformatter = new DiskReformatter(dataNodeId, Collections.EMPTY_LIST,
                config.fetchSizeInBytes, storeConfig, storeKeyFactory, clusterMap, SystemTime.getInstance(),
                storeKeyConverterFactory.getStoreKeyConverter());
        AtomicInteger exitStatus = new AtomicInteger(0);
        CountDownLatch latch = new CountDownLatch(config.diskMountPaths.length);
        for (int i = 0; i < config.diskMountPaths.length; i++) {
            int finalI = i;
            Runnable runnable = () -> {
                try {
                    reformatter.reformat(config.diskMountPaths[finalI], new File(config.scratchPaths[finalI]));
                    latch.countDown();
                } catch (Exception e) {
                    throw new IllegalStateException(e);
                }
            };
            Thread thread = Utils.newThread(config.diskMountPaths[finalI] + "-reformatter", runnable, true);
            thread.setUncaughtExceptionHandler((t, e) -> {
                exitStatus.set(1);
                logger.error("Reformatting {} failed", config.diskMountPaths[finalI], e);
                latch.countDown();
            });
            thread.start();
        }
        latch.await();
        System.exit(exitStatus.get());
    }
}

From source file:Main.java

public static <T> List<T> asList(T... objs) {
    if (objs == null) {
        return Collections.EMPTY_LIST;
    } else {/*  ww w. jav a 2s .c  o m*/
        ArrayList list = new ArrayList();
        Collections.addAll(list, objs);
        return list;
    }
}

From source file:Main.java

public static <T> List<T> asList(T... objs) {
    if (objs == null) {
        return Collections.EMPTY_LIST;
    }/* www.  jav a 2  s . c o m*/
    List<T> list = new ArrayList<T>();
    Collections.addAll(list, objs);
    return list;
}

From source file:Main.java

public static List safe(List list) {
    if (list == null)
        return Collections.EMPTY_LIST;
    return list;
}

From source file:Main.java

public static List getMy() {
    String nullFlag = null;//from   w  ww.j a va2s .  c  o  m
    if (nullFlag == null) {
        return Collections.EMPTY_LIST;
    }
    return null;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> List<T> emptyList() {
    return (List<T>) Collections.EMPTY_LIST;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> List<T> emptyList(Class<T> clazz) {
    return (List<T>) Collections.EMPTY_LIST;
}