隨筆 - 55  文章 - 187  trackbacks - 0
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(12)

          隨筆分類(lèi)

          隨筆檔案

          groovy

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

               摘要: 頁(yè)面代碼:  1<html>  2    <head>  3        <meta http-equiv="Content-Type" content="text/html; ch...  閱讀全文
          posted @ 2008-03-07 16:11 大衛(wèi) 閱讀(5104) | 評(píng)論 (1)編輯 收藏
           1package test;
           2
           3import java.lang.reflect.Method;
           4import java.lang.reflect.ParameterizedType;
           5import java.lang.reflect.Type;
           6import java.util.List;
           7import java.util.Map;
           8
           9public class TempTest {
          10
          11    public static void main(String[] args) throws Exception {
          12        Method[] methods = TempTest.class.getDeclaredMethods();
          13        for (Method method : methods) {
          14            System.out.println("method:" + method.getName());// 方法名
          15
          16            // //////////////方法的參數(shù)
          17            System.out.println(" paramTypeType: ");
          18            Type[] paramTypeList = method.getGenericParameterTypes();// 方法的參數(shù)列表
          19            for (Type paramType : paramTypeList) {
          20                System.out.println("  " + paramType);// 參數(shù)類(lèi)型
          21                if (paramType instanceof ParameterizedType)/* 如果是泛型類(lèi)型 */{
          22                    Type[] types = ((ParameterizedType) paramType)
          23                            .getActualTypeArguments();// 泛型類(lèi)型列表
          24                    System.out.println("  TypeArgument: ");
          25                    for (Type type : types) {
          26                        System.out.println("   " + type);
          27                    }

          28                }

          29            }

          30
          31            // //////////////方法的返回值
          32            System.out.println(" returnType: ");
          33            Type returnType = method.getGenericReturnType();// 返回類(lèi)型
          34            System.out.println("  " + returnType);
          35            if (returnType instanceof ParameterizedType)/* 如果是泛型類(lèi)型 */{
          36                Type[] types = ((ParameterizedType) returnType)
          37                        .getActualTypeArguments();// 泛型類(lèi)型列表
          38                System.out.println("  TypeArgument: ");
          39                for (Type type : types) {
          40                    System.out.println("   " + type);
          41                }

          42            }

          43
          44        }

          45
          46    }

          47
          48    public static String method1(List list) {
          49        return null;
          50    }

          51
          52    private static Map<String, Double> method2(Map<String, Object> map) {
          53        return null;
          54    }

          55
          56}
          posted @ 2008-02-28 10:29 大衛(wèi) 閱讀(5819) | 評(píng)論 (3)編輯 收藏

          算法程序題:

              該公司筆試題就1個(gè),要求在10分鐘內(nèi)作完。

              題目如下:用1、2、2、3、4、5這六個(gè)數(shù)字,用java寫(xiě)一個(gè)main函數(shù),打印出所有不同的排列,如:512234、412345等,要求:"4"不能在第三位,"3"與"5"不能相連。

            基本思路:
          1 把問(wèn)題歸結(jié)為圖結(jié)構(gòu)的遍歷問(wèn)題。實(shí)際上6個(gè)數(shù)字就是六個(gè)結(jié)點(diǎn),把六個(gè)結(jié)點(diǎn)連接成無(wú)向連通圖,對(duì)于每一個(gè)結(jié)點(diǎn)求這個(gè)圖形的遍歷路徑,所有結(jié)點(diǎn)的遍歷路徑就是最后對(duì)這6個(gè)數(shù)字的排列組合結(jié)果集。
          2 顯然這個(gè)結(jié)果集還未達(dá)到題目的要求。從以下幾個(gè)方面考慮:
            1. 3,5不能相連:實(shí)際要求這個(gè)連通圖的結(jié)點(diǎn)3,5之間不能連通, 可在構(gòu)造圖結(jié)構(gòu)時(shí)就滿足改條件,然后再遍歷圖。
            2. 不能有重復(fù): 考慮到有兩個(gè)2,明顯會(huì)存在重復(fù)結(jié)果,可以把結(jié)果集放在TreeSet中過(guò)濾重復(fù)結(jié)果。//TreeSet用于過(guò)濾一個(gè)集合中相同的東西還真是個(gè)挺不錯(cuò)的方法
            3. 4不能在第三位: 仍舊在結(jié)果集中去除滿足此條件的結(jié)果。

          采用二維數(shù)組定義圖結(jié)構(gòu),最后的代碼是:

           1package test;
           2
           3import java.util.Iterator;
           4import java.util.TreeSet;
           5
           6public class TestQuestion {
           7
           8    private String[] b = new String[] "1""2""2""3""4""5" };
           9    private int n = b.length;
          10    private boolean[] visited = new boolean[n];
          11    private int[][] a = new int[n][n];
          12    private String result = "";
          13    private TreeSet treeSet = new TreeSet();// 用于保存結(jié)果,具有過(guò)濾相同結(jié)果的作用。
          14
          15    public static void main(String[] args) {
          16        new TestQuestion().start();
          17    }

          18
          19    private void start() {
          20        // 創(chuàng)建合法路徑標(biāo)識(shí)集合
          21        for (int i = 0; i < n; i++{
          22            for (int j = 0; j < n; j++{
          23                if (i == j) {
          24                    a[i][j] = 0;
          25                }
           else {
          26                    a[i][j] = 1;
          27                }

          28            }

          29        }

          30        a[3][5= 0;
          31        a[5][3= 0;
          32        for (int i = 0; i < n; i++{
          33            this.depthFirstSearch(i);// 深度遞歸遍歷
          34        }

          35        Iterator it = treeSet.iterator();
          36        while (it.hasNext()) {
          37            String string = (String) it.next();
          38
          39            if (string.indexOf("4"!= 2{
          40                System.out.println(string);
          41            }

          42        }

          43    }

          44
          45    /**
          46     * 深度優(yōu)先遍歷
          47     * 
          48     * @param startIndex
          49     */

          50    private void depthFirstSearch(int startIndex) {
          51        // 遞歸的工作
          52        visited[startIndex] = true;// 用于標(biāo)識(shí)已經(jīng)走過(guò)的節(jié)點(diǎn)
          53        result = result + b[startIndex];// 構(gòu)造結(jié)果
          54        if (result.length() == n) {
          55            treeSet.add(result);// 添加到TreeSet類(lèi)型中,具有過(guò)濾相同結(jié)果的作用
          56        }

          57        // 每走到一個(gè)節(jié)點(diǎn),挨個(gè)遍歷下一個(gè)節(jié)點(diǎn)
          58        for (int j = 0; j < n; j++{
          59            if (a[startIndex][j] == 1 && visited[j] == false{
          60                depthFirstSearch(j);// 深度遞歸遍歷
          61            }
           else {
          62                continue;
          63            }

          64        }

          65        // 遞歸的收尾工作
          66        result = result.substring(0, result.length() - 1);
          67        visited[startIndex] = false;// 取消訪問(wèn)標(biāo)識(shí)
          68    }

          69}

          70

          --------------------

              WE準(zhǔn)高手
          posted @ 2008-02-27 14:30 大衛(wèi) 閱讀(3000) | 評(píng)論 (12)編輯 收藏
          TreeSet類(lèi)型是J2SE中唯一可實(shí)現(xiàn)自動(dòng)排序的類(lèi)型,用法如下:

          MyComparator.java
           1package test;
           2
           3import java.util.Comparator;
           4
           5public class MyComparator<T> implements Comparator<T> {
           6
           7    public int compare(T arg0, T arg1) {
           8        if (arg0.equals(arg1)) {
           9            return 0;
          10        }

          11        return ((Comparable<T>) arg0).compareTo(arg1) * -1;
          12    }

          13
          14}

          TreeSetTest.java
           1package test;
           2
           3import java.util.Iterator;
           4import java.util.TreeSet;
           5
           6public class TreeSetTest {
           7
           8    /**
           9     * @param args
          10     */

          11    public static void main(String[] args) {
          12
          13        MyComparator<String> myComparator = new MyComparator<String>();
          14
          15        // /////////////////////不添加自定義排序
          16        TreeSet<String> treeSet1 = new TreeSet<String>();
          17        treeSet1.add("c");
          18        treeSet1.add("a");
          19        treeSet1.add("b");
          20
          21        Iterator<String> iterator1 = treeSet1.iterator();
          22        while (iterator1.hasNext()) {
          23            System.out.println(iterator1.next());
          24        }

          25
          26        // /////////////////////添加自定義排序
          27        TreeSet<String> treeSet2 = new TreeSet<String>(myComparator);
          28        treeSet2.add("c");
          29        treeSet2.add("a");
          30        treeSet2.add("b");
          31
          32        Iterator<String> iterator2 = treeSet2.iterator();
          33        while (iterator2.hasNext()) {
          34            System.out.println(iterator2.next());
          35        }

          36    }

          37
          38}

          39

          運(yùn)行結(jié)果:
          a
          b
          c
          c
          b
          a

          --------------------

              WE準(zhǔn)高手
          posted @ 2008-02-27 13:34 大衛(wèi) 閱讀(8433) | 評(píng)論 (3)編輯 收藏
          假設(shè)要添加庫(kù)文件richfaces-ui-3.1.3.GA.jar
          1、為庫(kù)richfaces-ui-3.1.3.GA.jar文件建立pom文件richfaces-ui-3.1.3.GA.pom
          <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
           <modelVersion>4.0.0</modelVersion>
           <groupId>org.richfaces</groupId>
           <artifactId>richfaces-ui</artifactId>
           <version>3.1.3.GA</version>
           <name>RichFaces JSF components library</name>
           <packaging>jar</packaging>
          </project>
          2、用ant為jar和pom文件分別生成校驗(yàn)文件.sha1
          <project default="main">
           <target name="main" description="Generate checksum file for jar and pom">  
                 <checksum algorithm="SHA" fileext=".sha1">  
                     <fileset dir="F:/software/java/richfaces-ui-3.1.3.GA/lib" id="id">   
                        <include name="**/*.pom" />  
                        <include name="**/*.jar" />  
                        <include name="**/*.xml" />  
                        <exclude name="**/*.sh1" />  
                     </fileset>  
                 </checksum>  
           </target>
          </project>
          3、在.m2目錄中創(chuàng)建該庫(kù)文件的代碼庫(kù)目錄.m2\repository\org\richfaces\richfaces-ui\3.1.3.GA
          其中,org\richfaces為包路徑,richfaces-ui為包名,3.1.3.GA為版本,這三項(xiàng)是與pom文件中的groupId,artifactId,version分別對(duì)應(yīng)的。
          richfaces-ui-3.1.3.GA.jar,richfaces-ui-3.1.3.GA.jar.sha1,richfaces-ui-3.1.3.GA.pom,richfaces-ui-3.1.3.GA.pom.sha1拷貝到該目錄下。
          4、在工程的pom文件中添加依賴(lài)
          <dependency>
           <groupId>org.richfaces</groupId>
           <artifactId>richfaces-ui</artifactId>
           <version>3.1.3.GA</version>
          </dependency>

          --------------------

              WE準(zhǔn)高手
          posted @ 2008-02-12 15:07 大衛(wèi) 閱讀(1459) | 評(píng)論 (0)編輯 收藏
          僅列出標(biāo)題
          共10頁(yè): First 上一頁(yè) 2 3 4 5 6 7 8 9 10 下一頁(yè) 
          主站蜘蛛池模板: 栖霞市| 吉隆县| 扶风县| 茂名市| 平塘县| 江永县| 吴江市| 东城区| 泸定县| 苏尼特左旗| 宜黄县| 黔江区| 新平| 尤溪县| 山丹县| 富川| 抚顺县| 万宁市| 汉寿县| 马山县| 合山市| 安庆市| 麻城市| 紫金县| 九江市| 灵璧县| 肃北| 堆龙德庆县| 山阳县| 新宾| 潜江市| 馆陶县| 合川市| 海兴县| 炉霍县| 荥阳市| 潼南县| 平谷区| 平度市| 万盛区| 盈江县|