简约设计の艺术

讨论软件制造过程中的艺术与工程,软件哲学

丁亮ID:DL88250
修改头像
1347261次访问,排名10好友91人,关注者124
Linux、Java、C/C++,OpenSource热爱者,擅长JavaSE/JavaEE开发,熟悉JSF、EJB、Spring、JPA、OSGi等框架应用的架构,目前正在深入学习算法、OOAD、TDD以及敏捷实践。
[编辑我的资料]
DL88250的文章
原创 817 篇
翻译 8 篇
转载 157 篇
评论 619 篇
88250的公告


最近评论
DL88250:To jji: 不知道啊。。。。官方的消息应该不会假的。不过,短跳一下还是有可能的。:)
jji:都24了,该不会跳票吧?
88250:恩,不过我还是喜欢英语多一点,感觉英语很先进。。。。
李です:わたしは李です、
我在日本公司干了1年多了,刚刚才辞职,就是因为日语不会,看不懂设计书,希望你能努力学习
DL88250:To 425413740: 偶不会哦,呵呵。。。。
文章分类
收藏
    相册
    Beyond
    壁纸收集
    动漫Kiss图图
    我的珍藏
    我的桌面
    CSDN专家Blog
    孟岩的专栏
    袁萌的专栏
    Ubuntu/Linux相关
    ChinaUnix
    Compiz Themes
    Compiz-Fusion
    deviantART Search
    GetDeb
    Gnome-Look
    KDE-Look
    LinuxToy
    Linux桌面中文网
    Ubuntu中文官方论坛
    Ubuntu桌面中文网
    代码示例
    C++代码示例
    HTML代码示例
    Java Code examples
    技术站点
    Apache Software
    CSDN
    Eclipse.org
    Extreme Programming
    hibernate.org
    IBM软件技术
    JavaFX Home
    JavaFX Script Reference
    JavaWorld@TW
    Java开源大全
    JBoss.org
    LEX & YACC Page
    NetBeans中文社区
    PHP 官方
    Ruby on Rails
    Ruby中文社区论坛
    SOURCEFORGE.NET
    Springframework.org
    Sun中国技术社区
    UML官方
    图书下载
    CSDN下载频道
    e 书时空
    IT e Book
    中华电脑书库
    中国 E 书网
    中国 IT 认证实验室
    中文电子书网
    偶要雷锋 - 分享社区
    我爱 e 书
    网络中国 - E 书
    我的偶像 :-)
    Alan Turing
    Bjarne Stroustrup's Homepage
    Don Knuth's Home Page
    Martin Fowler
    Richard Stallman's Home Page
    Uncle Bob (Robert C. Martin)
    我的朋友
    Eleven的专栏
    Eric.Gao的空间
    Meteor的专栏
    mmchsusan的主页
    solonote的专栏
    Vanessa的小窝
    ZhiBaoDeng的专栏
    zyofprogrammer的学习历程
    先知罗庄的专栏
    光光的Blog~
    师傅dorainm的Blog
    皮皮的空间
    秋歌的专栏
    金秋风采
    阿明的专栏
    在CSDN的朋友
    老李的Blog
    存档
    订阅我的博客
    XML聚合  FeedSky

    原创 检查随机序列重复[Java]收藏

    新一篇: 检查随机序列重复[C++] | 旧一篇: NetBeans 时事通讯(刊号 # 6 - May 07, 2008)

    呃。。。。代码编辑坏了- -!

    /*
     * @(#)Main.java
     * Author: 88250 <DL88250@gmail.com>, http://blog.csdn.net/DL88250
     * Created on May 13, 2008, 4:11:44 PM
     *
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation; either version 3 of the License, or
     * (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     * GNU Library General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     */
    package checkthesame;

    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Comparator;
    import java.util.List;
    import java.util.Random;
    import java.util.logging.Level;
    import java.util.logging.Logger;

    /**
     * Check the same record in a file.
     * <p>
     * Every record in data file is a random serial, like the followings:<br>
     * // data file
     * 1902323484354370234844<br>
     * 1928473090393719374<br>
     * ....<br>
     * </p>
     * @author 88250 <DL88250@gmail.com>, http://blog.csdn.net/DL88250
     */
    public class Main {

        /**
         * store the data records
         */
        public static List<String> records = new ArrayList<String>();
        /**
         * statistics
         */
        public static List<List<String>> statistics = new ArrayList<List<String>>();

        /**
         * Read the records from the data file which named "data.txt" into memory,
         * using a <code>java.util.ArrayList</code> store them.
         * @see #records
         */
        public static void readRecords() {
            System.out.println("Get starting read records....");
            try {
                BufferedReader reader = new BufferedReader(
                        new FileReader("data.txt"));
                String aLine;
                while ((aLine = reader.readLine()) != null) {
                    records.add(aLine);
                }
                reader.close();
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
            System.out.println("The amount of records: " + records.size());
        }

        /**
         * Create some records for test.
         */
        public static void createTestRecords() {
            File file = new File("data.txt");
            if (file.exists()) {
                file.delete();
            }

            try {
                BufferedWriter writer =
                        new BufferedWriter(new FileWriter("data.txt"));

                Random random = new Random();
                byte[] bytes = new byte[16];
                for (int i = 0; i < 1000000; i++) {
                    StringBuffer aLine;
                    random.nextBytes(bytes);
                    aLine = new StringBuffer();
                    for (int j = 0; j < 16; j++) {
                        aLine.append((int) bytes[j]);
                    }

                    // System.out.println(aLine);

                    writer.write(aLine.toString());
                    //System.out.println();
                    writer.newLine();
                }
                writer.close();
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        /**
         * Main program entry.
         * @param args the command line arguments, should be <code>null</code>
         */
        public static void main(String[] args) {
            createTestRecords();
            readRecords();
            displayRecords(10);
            checkTheSame();
        }

        /**
         * Check the same data records in {@link #records}.
         */
        public static void checkTheSame() {
            sortTheRecords();   // sort them

            // displayRecords(10);
            for (int i = 0; i < records.size() - 1; i++) {
                String record1 = records.get(i);
                String record2 = records.get(i + 1);
                if (record1.equals(record2)) {
                    List<String> equalities = new ArrayList<String>();
                    equalities.add(record1);
                    equalities.add(record2);
                    statistics.add(equalities);
                }
            }
            displayStats();
        }

        /**
         * Display the data records in console.
         * @param amount display amount, start from {@link #records}'s beginning
         */
        public static void displayRecords(int amount) {
            if (amount < 0 || amount > records.size()) {
                System.out.println("The specified amount exceeds the Data records" +
                        "size!");
            }
            System.out.println("Display: ");
            for (int i = 0; i < amount; i++) {
                System.out.println(records.get(i));
            }
            System.out.println();
        }

        /**
         * Display the statistic results in console.
         */
        private static void displayStats() {
            System.out.println("Statistics: ");
            System.out.println("A amount of the same data records: " + statistics.
                    size());
            for (List<String> aEqualities : statistics) {
                System.out.println(aEqualities.get(0) + " occurs " + aEqualities.
                        size());
            }
        }

        /**
         * Using {@link java.util.Collections#sort(java.util.List)} to sort the
         * data records.
         */
        @SuppressWarnings("unchecked")
        private static void sortTheRecords() {
            java.util.Collections.sort(records,
                    new Comparator() {

                        @Override
                        public int compare(Object o1,
                                Object o2) {
                            String r1 =
                                    (String) o1;
                            String r2 =
                                    (String) o2;
                            return r1.compareTo(r2);
                        }
                    });
        }
    }

    发表于 @ 2008年05月15日 12:46:00|评论(loading...)|收藏

    新一篇: 检查随机序列重复[C++] | 旧一篇: NetBeans 时事通讯(刊号 # 6 - May 07, 2008)

    评论:没有评论。

    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © 88250