# 示例

double[][][] rate = {
{{1,2,3}, {1,2,3}},
{{1,2,3}, {1,2,3}}
};

for (int gender = 0; gender < rate.length; gender++) {
System.out.println("Gender:" + gender);
double[][] genderRate = rate[gender];
for (int smoke = 0; smoke < genderRate.length; smoke++) {
System.out.println("\tSmoke:" + smoke);
double[] ageRate = genderRate[smoke];
System.out.print("\t\tAge:");
for (int age = 0; age < ageRate.length; age++) {
System.out.print(ageRate[age] + " ");
}
System.out.println();
}
}
// Output
Gender:0
Smoke:0
Age:1.0 2.0 3.0
Smoke:1
Age:1.0 2.0 3.0
Gender:1
Smoke:0
Age:1.0 2.0 3.0
Smoke:1
Age:1.0 2.0 3.0
当想取一种情况的费率时直接访问数组就行了，比如封装成下面的方法
private static double getRate(int gender, int smoke, int age) {
return rate[gender][smoke][age];
}

1. 读取每条消息的ID
2. 然后大量的if…else…或switch判断消息类型
3. 针对每种消息调用相应的处理函数

“Message Description”
Field1 Float “Prompt”
Field2 Date “Created Date”

• 读取消息ID
• 找到消息ID定义的消息描述
• 读取描述中的每一个字段，根据字段的类型调用相应的打印方法

# 实际应用

service zygote /system/bin/app_process -Xzygote/system/bin --zygote --start-system-server
class main
socket zygote stream 660 root system
onrestart write /sys/android_power/request_state wake
onrestart write /sys/power/state on
onrestart restart media
onrestart restart netd

#ifndef KEYWORD
int do_chroot(int nargs, char **args);
int do_chdir(int nargs, char **args);
...
int do_restart(int nargs, char **args);
...
int do_write(int nargs, char **args);
int do_copy(int nargs, char **args);
...
int do_wait(int nargs, char **args);
#define __MAKE_KEYWORD_ENUM__
#define KEYWORD(symbol, flags, nargs, func) K_##symbol,
enum {
K_UNKNOWN,
#endif
KEYWORD(capability,  OPTION,  0, 0)
KEYWORD(chdir,       COMMAND, 1, do_chdir)
...
KEYWORD(restart,     COMMAND, 1, do_restart)
...
KEYWORD(write,       COMMAND, 2, do_write)
KEYWORD(copy,        COMMAND, 2, do_copy)
...
KEYWORD(ioprio,      OPTION,  0, 0)
#ifdef __MAKE_KEYWORD_ENUM__
KEYWORD_COUNT,
};
#undef __MAKE_KEYWORD_ENUM__
#undef KEYWORD
#endif

#include "keywords.h"

#define KEYWORD(symbol, flags, nargs, func) \
[ K_##symbol ] = { #symbol, func, nargs + 1, flags, },

static struct {
const char *name;
int (*func)(int nargs, char **args);
unsigned char nargs;
unsigned char flags;
} keyword_info[KEYWORD_COUNT] = {
[ K_UNKNOWN ] = { "unknown", 0, 0, 0 },
#include "keywords.h"
};
#undef KEYWORD
在init_parser.c中include了两次keywords.h

#define KEYWORD(symbol, flags, nargs, func) K_##symbol,

enum {
K_UNKNOWN,

KEYWORD(restart,     COMMAND, 1, do_restart) -> K_restart,

enum {
K_UNKNOWN,
...
K_restart,
...
K_write,
...
KEYWORD_COUNT,
}

#define KEYWORD(symbol, flags, nargs, func) \
[ K_##symbol ] = { #symbol, func, nargs + 1, flags, },

static struct {
const char *name;
int (*func)(int nargs, char **args);
unsigned char nargs;
unsigned char flags;
} keyword_info[KEYWORD_COUNT] = {
[ K_UNKNOWN ] = { "unknown", 0, 0, 0 },
#include "keywords.h"
};
#undef KEYWORD

KEYWORD(restart,     COMMAND, 1, do_restart) -> [ K_restart ] = { "restart", do_restart, 2, COMMAND },

#define SECTION 0x01
#define COMMAND 0x02
#define OPTION  0x04

posted @ 2014-05-29 16:58  AngelDevil  阅读(12128)  评论(5编辑  收藏  举报