提交 55c9fa63 编写于 作者: R reeco

add p3c-gitbook

上级 6cc59402
## (四) ORM映射
1. 【强制】在表查询中,一律不要使用 * 作为查询的字段列表,需要哪些字段必须明确写明。
<br><span style="color:orange">说明</span>:1)增加查询分析器解析成本。2)增减字段容易与resultMap配置不一致。
2. 【强制】POJO类的布尔属性不能加is,而数据库字段必须加is_,要求在resultMap中进行字段与属性之间的映射。
<br><span style="color:orange">说明</span>:参见定义POJO类以及数据库字段定义规定,在<resultMap>中增加映射,是必须的。在MyBatis Generator生成的代码中,需要进行对应的修改。
3. 【强制】不要用resultClass当返回参数,即使所有类属性名与数据库字段一一对应,也需要定义;反过来,每一个表也必然有一个与之对应。
<br><span style="color:orange">说明</span>:配置映射关系,使字段与DO类解耦,方便维护。
4. 【强制】sql.xml配置参数使用:#{},#param# 不要使用${} 此种方式容易出现SQL注入。
5. 【强制】iBATIS自带的queryForList(String statementName,int start,int size)不推荐使用。
<br><span style="color:orange">说明</span>:其实现方式是在数据库取到statementName对应的SQL语句的所有记录,再通过subList取start,size的子集合。
<br><span style="color:green">正例</span>
Map<String, Object> map = new HashMap<String, Object>();
map.put("start", start);
map.put("size", size);
6. 【强制】不允许直接拿HashMap与Hashtable作为查询结果集的输出。
<br><span style="color:orange">说明</span>:resultClass=”Hashtable”,会置入字段名和属性值,但是值的类型不可控。
7. 【强制】更新数据表记录时,必须同时更新记录对应的gmt_modified字段值为当前时间。
8. 【推荐】不要写一个大而全的数据更新接口。传入为POJO类,不管是不是自己的目标更新字段,都进行update table set c1=value1,c2=value2,c3=value3; 这是不对的。执行SQL时,不要更新无改动的字段,一是易出错;二是效率低;三是增加binlog存储。
9. 【参考】`@Transactional`事务不要滥用。事务会影响数据库的QPS,另外使用事务的地方需要考虑各方面的回滚方案,包括缓存回滚、搜索引擎回滚、消息补偿、统计修正等。
10. 【参考】`<isEqual>`中的compareValue是与属性值对比的常量,一般是数字,表示相等时带上此条件;`<isNotEmpty>`表示不为空且不为null时执行;`<isNotNull>`表示不为null值时执行。
\ No newline at end of file
## (三) SQL语句
1. 【强制】不要使用count(列名)或count(常量)来替代count(*),count(*)是SQL92定义的标准统计行数的语法,跟数据库无关,跟NULL和非NULL无关。
<br><span style="color:orange">说明</span>:count(*)会统计值为NULL的行,而count(列名)不会统计此列为NULL值的行。
2. 【强制】count(distinct col) 计算该列除NULL之外的不重复行数,注意 count(distinct col1, col2) 如果其中一列全为NULL,那么即使另一列有不同的值,也返回为0。
3. 【强制】当某一列的值全是NULL时,count(col)的返回结果为0,但sum(col)的返回结果为NULL,因此使用sum()时需注意NPE问题。
<br><span style="color:green">正例</span>:可以使用如下方式来避免sum的NPE问题:
<pre>SELECT IF(ISNULL(SUM(g)),0,SUM(g)) FROM table; </pre>
4. 【强制】使用`ISNULL()`来判断是否为NULL值。 说明:NULL与任何值的直接比较都为NULL。
1) `NULL<>NULL`的返回结果是NULL,而不是`false`
2) `NULL=NULL`的返回结果是NULL,而不是`true`
3) `NULL<>1`的返回结果是NULL,而不是`true`
5. 【强制】 在代码中写分页查询逻辑时,若count为0应直接返回,避免执行后面的分页语句。
6. 【强制】不得使用外键与级联,一切外键概念必须在应用层解决。
<br><span style="color:orange">说明</span>:以学生和成绩的关系为例,学生表中的student_id是主键,那么成绩表中的student_id则为外键。如果更新学生表中的student_id,同时触发成绩表中的student_id更新,即为级联更新。外键与级联更新适用于单机低并发,不适合分布式、高并发集群;级联更新是强阻塞,存在数据库更新风暴的风险;外键影响数据库的插入速度。
7. 【强制】禁止使用存储过程,存储过程难以调试和扩展,更没有移植性。
8. 【强制】数据订正(特别是删除、修改记录操作)时,要先select,避免出现误删除,确认无误才能执行更新语句。
9. 【推荐】in操作能避免则避免,若实在避免不了,需要仔细评估in后边的集合元素数量,控制在1000个之内。
10. 【参考】如果有全球化需要,所有的字符存储与表示,均以utf-8编码,注意字符统计函数的区别。
<br><span style="color:orange">说明</span>
<pre>SELECT LENGTH("轻松工作"); 返回为12
SELECT CHARACTER_LENGTH("轻松工作"); 返回为4</pre>
如果需要存储表情,那么选择utf8mb4来进行存储,注意它与utf-8编码的区别。
11. 【参考】 TRUNCATE TABLE 比 DELETE 速度快,且使用的系统和事务日志资源少,但TRUNCATE无事务且不触发trigger,有可能造成事故,故不建议在开发代码中使用此语句。
<br><span style="color:orange">说明</span>:TRUNCATE TABLE 在功能上与不带 WHERE 子句的 DELETE 语句相同。
\ No newline at end of file
# 五、MySQL数据库
## (一) 建表规约
1. 【强制】表达是与否概念的字段,必须使用is_xxx的方式命名,数据类型是unsigned tinyint( 1表示是,0表示否)。
<br><span style="color:orange">说明</span>:任何字段如果为非负数,必须是`unsigned`
<br><span style="color:green">正例</span>:表达逻辑删除的字段名`is_deleted`,1表示删除,0表示未删除。
2. 【强制】表名、字段名必须使用小写字母或数字,禁止出现数字开头,禁止两个下划线中间只出现数字。数据库字段名的修改代价很大,因为无法进行预发布,所以字段名称需要慎重考虑。 <br><span style="color:orange">说明</span>:MySQL在Windows下不区分大小写,但在Linux下默认是区分大小写。因此,数据库名、表名、字段名,都不允许出现任何大写字母,避免节外生枝。 <br><span style="color:green">正例</span>:aliyun_admin,rdc_config,level3_name <br><span style="color:red">反例</span>:AliyunAdmin,rdcConfig,level_3_name
3. 【强制】表名不使用复数名词。
<br><span style="color:orange">说明</span>:表名应该仅仅表示表里面的实体内容,不应该表示实体数量,对应于DO类名也是单数形式,符合表达习惯。
4. 【强制】禁用保留字,如`desc``range``match``delayed`等,请参考MySQL官方保留字。
5. 【强制】主键索引名为pk_字段名;唯一索引名为uk_字段名;普通索引名则为idx_字段名。
<br><span style="color:orange">说明</span>:pk_ 即primary key;uk_ 即 unique key;idx_ 即index的简称。
6. 【强制】小数类型为decimal,禁止使用float和double。
<br><span style="color:orange">说明</span>:float和double在存储的时候,存在精度损失的问题,很可能在值的比较时,得到不正确的结果。如果存储的数据范围超过decimal的范围,建议将数据拆成整数和小数分开存储。
7. 【强制】如果存储的字符串长度几乎相等,使用char定长字符串类型。
8. 【强制】varchar是可变长字符串,不预先分配存储空间,长度不要超过5000,如果存储长度大于此值,定义字段类型为text,独立出来一张表,用主键来对应,避免影响其它字段索引效率。
9. 【强制】表必备三字段:id, gmt_create, gmt_modified。
<br><span style="color:orange">说明</span>:其中id必为主键,类型为unsigned bigint、单表时自增、步长为1。gmt_create, gmt_modified的类型均为datetime类型,前者现在时表示主动创建,后者过去分词表示被动更新。
10. 【推荐】表的命名最好是加上“业务名称_表的作用”。
<br><span style="color:green">正例</span>:alipay_task / force_project / trade_config
11. 【推荐】库名与应用名称尽量一致。
12. 【推荐】如果修改字段含义或对字段表示的状态追加时,需要及时更新字段注释。
13. 【推荐】字段允许适当冗余,以提高查询性能,但必须考虑数据一致。冗余字段应遵循:
1)不是频繁修改的字段。
2)不是varchar超长字段,更不能是text字段。
<br><span style="color:green">正例</span>:商品类目名称使用频率高,字段长度短,名称基本一成不变,可在相关联的表中冗余存储类目名称,避免关联查询。
14. 【推荐】单表行数超过500万行或者单表容量超过2GB,才推荐进行分库分表。 <br><span style="color:orange">说明</span>:如果预计三年后的数据量根本达不到这个级别,请不要在创建表时就分库分表。
15. 【参考】合适的字符存储长度,不但节约数据库表空间、节约索引存储,更重要的是提升检索速度。 <br><span style="color:green">正例</span>:如下表,其中无符号值可以避免误存负数,且扩大了表示范围。
| 对象 | 年龄区间 | 类型 | 字节 |
| ------------- |:-------------| :----- |:----- |
| 人 |150岁之内 | unsigned tinyint|1|
| 龟 |数百岁 | unsigned smallint |2|
| 恐龙化石 |数千万岁 | unsigned int |4|
| 太阳 |约50亿年 | unsigned bigint |8|
\ No newline at end of file
## (二) 索引规约
1. 【强制】业务上具有唯一特性的字段,即使是多个字段的组合,也必须建成唯一索引。
<br><span style="color:orange">说明</span>:不要以为唯一索引影响了insert速度,这个速度损耗可以忽略,但提高查找速度是明显的;另外,即使在应用层做了非常完善的校验控制,只要没有唯一索引,根据墨菲定律,必然有脏数据产生。
2. 【强制】超过三个表禁止join。需要join的字段,数据类型必须绝对一致;多表关联查询时,保证被关联的字段需要有索引。
<br><span style="color:orange">说明</span>:即使双表join也要注意表索引、SQL性能。
3. 【强制】在varchar字段上建立索引时,必须指定索引长度,没必要对全字段建立索引,根据实际文本区分度决定索引长度即可。
<br><span style="color:orange">说明</span>:索引的长度与区分度是一对矛盾体,一般对字符串类型数据,长度为20的索引,区分度会高达90%以上,可以使用count(distinct left(列名, 索引长度))/count(*)的区分度来确定。
4. 【强制】页面搜索严禁左模糊或者全模糊,如果需要请走搜索引擎来解决。
<br><span style="color:orange">说明</span>:索引文件具有B-Tree的最左前缀匹配特性,如果左边的值未确定,那么无法使用此索引。
5. 【推荐】如果有order by的场景,请注意利用索引的有序性。order by 最后的字段是组合索引的一部分,并且放在索引组合顺序的最后,避免出现file_sort的情况,影响查询性能。
<br><span style="color:green">正例</span>:where a=? and b=? order by c; 索引:a_b_c
<br><span style="color:red">反例</span>:索引中有范围查找,那么索引有序性无法利用,如:WHERE a>10 ORDER BY b; 索引a_b无法排序。
6. 【推荐】利用覆盖索引来进行查询操作,避免回表。
<br><span style="color:orange">说明</span>:如果一本书需要知道第11章是什么标题,会翻开第11章对应的那一页吗?目录浏览一下就好,这个目录就是起到覆盖索引的作用。
<br><span style="color:green">正例</span>:能够建立索引的种类分为主键索引、唯一索引、普通索引三种,而覆盖索引只是一种查询的一种效果,用explain的结果,extra列会出现:using index。
7. 【推荐】利用延迟关联或者子查询优化超多分页场景。 <br><span style="color:orange">说明</span>:MySQL并不是跳过offset行,而是取offset+N行,然后返回放弃前offset行,返回N行,那当offset特别大的时候,效率就非常的低下,要么控制返回的总页数,要么对超过特定阈值的页数进行SQL改写。
<br><span style="color:green">正例</span>:先快速定位需要获取的id段,然后再关联:
<pre>SELECT a.* FROM 表1 a, (select id from 表1 where 条件 LIMIT 100000,20 ) b where a.id=b.id </pre>
8. 【推荐】 SQL性能优化的目标:至少要达到 range 级别,要求是ref级别,如果可以是consts最好。
<br><span style="color:orange">说明</span>
1)consts 单表中最多只有一个匹配行(主键或者唯一索引),在优化阶段即可读取到数据。
2)ref 指的是使用普通的索引(normal index)。
3)range 对索引进行范围检索。 <br><span style="color:red">反例</span>:explain表的结果,type=index,索引物理文件全扫描,速度非常慢,这个index级别比较range还低,与全表扫描是小巫见大巫。
9. 【推荐】建组合索引的时候,区分度最高的在最左边。 <br><span style="color:green">正例</span>:如果where a=? and b=? ,a列的几乎接近于唯一值,那么只需要单建idx_a索引即可。
<br><span style="color:orange">说明</span>:存在非等号和等号混合判断条件时,在建索引时,请把等号条件的列前置。如:where a>? and b=? 那么即使a的区分度更高,也必须把b放在索引的最前列。
10. 【推荐】防止因字段类型不同造成的隐式转换,导致索引失效。
11. 【参考】创建索引时避免有如下极端误解: 1)宁滥勿缺。认为一个查询就需要建一个索引。 2)宁缺勿滥。认为索引会消耗空间、严重拖慢更新和新增速度。 3)抵制惟一索引。认为业务的惟一性一律需要在应用层通过“先查后插”方式解决。
\ No newline at end of file
## <center>前言</center>
&nbsp;&nbsp;&nbsp;&nbsp;《阿里巴巴Java开发手册》是阿里巴巴集团技术团队的集体智慧结晶和经验总结,经历了多次大规模一线实战的检验及不断的完善,系统化地整理成册,回馈给广大开发者。现代软件行业的高速发展对开发者的综合素质要求越来越高,因为不仅是编程知识点,其它维度的知识点也会影响到软件的最终交付质量。比如:数据库的表结构和索引设计缺陷可能带来软件上的架构缺陷或性能风险;工程结构混乱导致后续维护艰难;没有鉴权的漏洞代码易被黑客攻击等等。所以本手册以Java开发者为中心视角,划分为编程规约、异常日志、单元测试、安全规约、工程结构、MySQL数据库六个维度,再根据内容特征,细分成若干二级子目录。根据约束力强弱及故障敏感性,规约依次分为强制、推荐、参考三大类。对于规约条目的延伸信息中,“说明”对内容做了适当扩展和解释;“正例”提倡什么样的编码和实现方式;“反例”说明需要提防的雷区,以及真实的错误案例。
<br>&nbsp;&nbsp;&nbsp;&nbsp;本手册的愿景是<strong>码出高效,码出质量</strong>。现代软件架构都需要协同开发完成,高效协作即降低协同成本,提升沟通效率,所谓无规矩不成方圆,无规范不能协作。众所周知,制订交通法规表面上是要限制行车权,实际上是保障公众的人身安全。试想如果没有限速,没有红绿灯,谁还敢上路行驶。对软件来说,适当的规范和标准绝不是消灭代码内容的创造性、优雅性,而是限制过度个性化,以一种普遍认可的统一方式一起做事,提升协作效率。代码的字里行间流淌的是软件生命中的血液,质量的提升是尽可能少踩坑,杜绝踩重复的坑,切实提升质量意识。
<br>&nbsp;&nbsp;&nbsp;&nbsp;考虑到可以零距离地与众多开发同学进行互动,决定未来在线维护《手册》内容,此1.3.1的PDF版本,是对外释放的最终纪念版,铭记发布第一版以来的358天旅程;我们已经在杭州云栖大会上进行了阿里巴巴Java开发规约插件[点此下载](https://github.com/alibaba/p3c),阿里云效(一站式企业协同研发云)也集成了代码规约扫描引擎。最后,《码出高效——阿里巴巴Java开发手册详解》即将出版,敬请关注。
\ No newline at end of file
# Summary
* [前言](README.md)
* 一、编程规约
- [(一)命名风格](编程规约/命名风格.md)
- [(二)常量定义](编程规约/常量定义.md)
- [(三)代码格式](编程规约/代码格式.md)
- [(四)OOP规范](编程规约/OOP规范.md)
- [(五)集合处理](编程规约/集合处理.md)
- [(六)并发处理](编程规约/并发处理.md)
- [(七)控制语句](编程规约/控制语句.md)
- [(八)注释规约](编程规约/注释规约.md)
* 二、异常日志
- [(一)异常处理](异常日志/异常处理.md)
- [(二)日志规范](异常日志/日志规约.md)
- [(三)其他](异常日志/其他.md)
* [三、单元测试](单元测试.md)
* [四、安全规约](安全规约.md)
* 五、MySQL数据库
- [(一)建表规约](MySQL数据库/建表规约.md)
- [(二)索引规约](MySQL数据库/索引规约.md)
- [(三)SQL语句](MySQL数据库/SQL语句.md)
- [(四)ORM映射](MySQL数据库/ORM映射.md)
* 六、工程结构
- [(一)应用分层](工程结构/应用分层.md)
- [(二)二方库依赖](工程结构/二方库依赖.md)
- [(三)服务器](工程结构/服务器.md)
* [附1:版本历史 ](版本历史.md)
* [附2:本手册专有名词 ](本手册专有名词.md)
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
因为 它太大了无法显示 source diff 。你可以改为 查看blob
require(['gitbook', 'jquery'], function(gitbook, $) {
// Configuration
var MAX_SIZE = 4,
MIN_SIZE = 0,
BUTTON_ID;
// Current fontsettings state
var fontState;
// Default themes
var THEMES = [
{
config: 'white',
text: 'White',
id: 0
},
{
config: 'sepia',
text: 'Sepia',
id: 1
},
{
config: 'night',
text: 'Night',
id: 2
}
];
// Default font families
var FAMILIES = [
{
config: 'serif',
text: 'Serif',
id: 0
},
{
config: 'sans',
text: 'Sans',
id: 1
}
];
// Return configured themes
function getThemes() {
return THEMES;
}
// Modify configured themes
function setThemes(themes) {
THEMES = themes;
updateButtons();
}
// Return configured font families
function getFamilies() {
return FAMILIES;
}
// Modify configured font families
function setFamilies(families) {
FAMILIES = families;
updateButtons();
}
// Save current font settings
function saveFontSettings() {
gitbook.storage.set('fontState', fontState);
update();
}
// Increase font size
function enlargeFontSize(e) {
e.preventDefault();
if (fontState.size >= MAX_SIZE) return;
fontState.size++;
saveFontSettings();
}
// Decrease font size
function reduceFontSize(e) {
e.preventDefault();
if (fontState.size <= MIN_SIZE) return;
fontState.size--;
saveFontSettings();
}
// Change font family
function changeFontFamily(configName, e) {
if (e && e instanceof Event) {
e.preventDefault();
}
var familyId = getFontFamilyId(configName);
fontState.family = familyId;
saveFontSettings();
}
// Change type of color theme
function changeColorTheme(configName, e) {
if (e && e instanceof Event) {
e.preventDefault();
}
var $book = gitbook.state.$book;
// Remove currently applied color theme
if (fontState.theme !== 0)
$book.removeClass('color-theme-'+fontState.theme);
// Set new color theme
var themeId = getThemeId(configName);
fontState.theme = themeId;
if (fontState.theme !== 0)
$book.addClass('color-theme-'+fontState.theme);
saveFontSettings();
}
// Return the correct id for a font-family config key
// Default to first font-family
function getFontFamilyId(configName) {
// Search for plugin configured font family
var configFamily = $.grep(FAMILIES, function(family) {
return family.config == configName;
})[0];
// Fallback to default font family
return (!!configFamily)? configFamily.id : 0;
}
// Return the correct id for a theme config key
// Default to first theme
function getThemeId(configName) {
// Search for plugin configured theme
var configTheme = $.grep(THEMES, function(theme) {
return theme.config == configName;
})[0];
// Fallback to default theme
return (!!configTheme)? configTheme.id : 0;
}
function update() {
var $book = gitbook.state.$book;
$('.font-settings .font-family-list li').removeClass('active');
$('.font-settings .font-family-list li:nth-child('+(fontState.family+1)+')').addClass('active');
$book[0].className = $book[0].className.replace(/\bfont-\S+/g, '');
$book.addClass('font-size-'+fontState.size);
$book.addClass('font-family-'+fontState.family);
if(fontState.theme !== 0) {
$book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, '');
$book.addClass('color-theme-'+fontState.theme);
}
}
function init(config) {
// Search for plugin configured font family
var configFamily = getFontFamilyId(config.family),
configTheme = getThemeId(config.theme);
// Instantiate font state object
fontState = gitbook.storage.get('fontState', {
size: config.size || 2,
family: configFamily,
theme: configTheme
});
update();
}
function updateButtons() {
// Remove existing fontsettings buttons
if (!!BUTTON_ID) {
gitbook.toolbar.removeButton(BUTTON_ID);
}
// Create buttons in toolbar
BUTTON_ID = gitbook.toolbar.createButton({
icon: 'fa fa-font',
label: 'Font Settings',
className: 'font-settings',
dropdown: [
[
{
text: 'A',
className: 'font-reduce',
onClick: reduceFontSize
},
{
text: 'A',
className: 'font-enlarge',
onClick: enlargeFontSize
}
],
$.map(FAMILIES, function(family) {
family.onClick = function(e) {
return changeFontFamily(family.config, e);
};
return family;
}),
$.map(THEMES, function(theme) {
theme.onClick = function(e) {
return changeColorTheme(theme.config, e);
};
return theme;
})
]
});
}
// Init configuration at start
gitbook.events.bind('start', function(e, config) {
var opts = config.fontsettings;
// Generate buttons at start
updateButtons();
// Init current settings
init(opts);
});
// Expose API
gitbook.fontsettings = {
enlargeFontSize: enlargeFontSize,
reduceFontSize: reduceFontSize,
setTheme: changeColorTheme,
setFamily: changeFontFamily,
getThemes: getThemes,
setThemes: setThemes,
getFamilies: getFamilies,
setFamilies: setFamilies
};
});
/*
* Theme 1
*/
.color-theme-1 .dropdown-menu {
background-color: #111111;
border-color: #7e888b;
}
.color-theme-1 .dropdown-menu .dropdown-caret .caret-inner {
border-bottom: 9px solid #111111;
}
.color-theme-1 .dropdown-menu .buttons {
border-color: #7e888b;
}
.color-theme-1 .dropdown-menu .button {
color: #afa790;
}
.color-theme-1 .dropdown-menu .button:hover {
color: #73553c;
}
/*
* Theme 2
*/
.color-theme-2 .dropdown-menu {
background-color: #2d3143;
border-color: #272a3a;
}
.color-theme-2 .dropdown-menu .dropdown-caret .caret-inner {
border-bottom: 9px solid #2d3143;
}
.color-theme-2 .dropdown-menu .buttons {
border-color: #272a3a;
}
.color-theme-2 .dropdown-menu .button {
color: #62677f;
}
.color-theme-2 .dropdown-menu .button:hover {
color: #f4f4f5;
}
.book .book-header .font-settings .font-enlarge {
line-height: 30px;
font-size: 1.4em;
}
.book .book-header .font-settings .font-reduce {
line-height: 30px;
font-size: 1em;
}
.book.color-theme-1 .book-body {
color: #704214;
background: #f3eacb;
}
.book.color-theme-1 .book-body .page-wrapper .page-inner section {
background: #f3eacb;
}
.book.color-theme-2 .book-body {
color: #bdcadb;
background: #1c1f2b;
}
.book.color-theme-2 .book-body .page-wrapper .page-inner section {
background: #1c1f2b;
}
.book.font-size-0 .book-body .page-inner section {
font-size: 1.2rem;
}
.book.font-size-1 .book-body .page-inner section {
font-size: 1.4rem;
}
.book.font-size-2 .book-body .page-inner section {
font-size: 1.6rem;
}
.book.font-size-3 .book-body .page-inner section {
font-size: 2.2rem;
}
.book.font-size-4 .book-body .page-inner section {
font-size: 4rem;
}
.book.font-family-0 {
font-family: Georgia, serif;
}
.book.font-family-1 {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal {
color: #704214;
}
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal a {
color: inherit;
}
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h1,
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h2,
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h3,
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h4,
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h5,
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h6 {
color: inherit;
}
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h1,
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h2 {
border-color: inherit;
}
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h6 {
color: inherit;
}
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal hr {
background-color: inherit;
}
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal blockquote {
border-color: inherit;
}
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal pre,
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal code {
background: #fdf6e3;
color: #657b83;
border-color: #f8df9c;
}
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal .highlight {
background-color: inherit;
}
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table th,
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table td {
border-color: #f5d06c;
}
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table tr {
color: inherit;
background-color: #fdf6e3;
border-color: #444444;
}
.book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n) {
background-color: #fbeecb;
}
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal {
color: #bdcadb;
}
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal a {
color: #3eb1d0;
}
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h1,
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h2,
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h3,
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h4,
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h5,
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h6 {
color: #fffffa;
}
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h1,
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h2 {
border-color: #373b4e;
}
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h6 {
color: #373b4e;
}
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal hr {
background-color: #373b4e;
}
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal blockquote {
border-color: #373b4e;
}
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal pre,
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal code {
color: #9dbed8;
background: #2d3143;
border-color: #2d3143;
}
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal .highlight {
background-color: #282a39;
}
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table th,
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table td {
border-color: #3b3f54;
}
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table tr {
color: #b6c2d2;
background-color: #2d3143;
border-color: #3b3f54;
}
.book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n) {
background-color: #35394b;
}
.book.color-theme-1 .book-header {
color: #afa790;
background: transparent;
}
.book.color-theme-1 .book-header .btn {
color: #afa790;
}
.book.color-theme-1 .book-header .btn:hover {
color: #73553c;
background: none;
}
.book.color-theme-1 .book-header h1 {
color: #704214;
}
.book.color-theme-2 .book-header {
color: #7e888b;
background: transparent;
}
.book.color-theme-2 .book-header .btn {
color: #3b3f54;
}
.book.color-theme-2 .book-header .btn:hover {
color: #fffff5;
background: none;
}
.book.color-theme-2 .book-header h1 {
color: #bdcadb;
}
.book.color-theme-1 .book-body .navigation {
color: #afa790;
}
.book.color-theme-1 .book-body .navigation:hover {
color: #73553c;
}
.book.color-theme-2 .book-body .navigation {
color: #383f52;
}
.book.color-theme-2 .book-body .navigation:hover {
color: #fffff5;
}
/*
* Theme 1
*/
.book.color-theme-1 .book-summary {
color: #afa790;
background: #111111;
border-right: 1px solid rgba(0, 0, 0, 0.07);
}
.book.color-theme-1 .book-summary .book-search {
background: transparent;
}
.book.color-theme-1 .book-summary .book-search input,
.book.color-theme-1 .book-summary .book-search input:focus {
border: 1px solid transparent;
}
.book.color-theme-1 .book-summary ul.summary li.divider {
background: #7e888b;
box-shadow: none;
}
.book.color-theme-1 .book-summary ul.summary li i.fa-check {
color: #33cc33;
}
.book.color-theme-1 .book-summary ul.summary li.done > a {
color: #877f6a;
}
.book.color-theme-1 .book-summary ul.summary li a,
.book.color-theme-1 .book-summary ul.summary li span {
color: #877f6a;
background: transparent;
font-weight: normal;
}
.book.color-theme-1 .book-summary ul.summary li.active > a,
.book.color-theme-1 .book-summary ul.summary li a:hover {
color: #704214;
background: transparent;
font-weight: normal;
}
/*
* Theme 2
*/
.book.color-theme-2 .book-summary {
color: #bcc1d2;
background: #2d3143;
border-right: none;
}
.book.color-theme-2 .book-summary .book-search {
background: transparent;
}
.book.color-theme-2 .book-summary .book-search input,
.book.color-theme-2 .book-summary .book-search input:focus {
border: 1px solid transparent;
}
.book.color-theme-2 .book-summary ul.summary li.divider {
background: #272a3a;
box-shadow: none;
}
.book.color-theme-2 .book-summary ul.summary li i.fa-check {
color: #33cc33;
}
.book.color-theme-2 .book-summary ul.summary li.done > a {
color: #62687f;
}
.book.color-theme-2 .book-summary ul.summary li a,
.book.color-theme-2 .book-summary ul.summary li span {
color: #c1c6d7;
background: transparent;
font-weight: 600;
}
.book.color-theme-2 .book-summary ul.summary li.active > a,
.book.color-theme-2 .book-summary ul.summary li a:hover {
color: #f4f4f5;
background: #252737;
font-weight: 600;
}
pre,
code {
/* http://jmblog.github.io/color-themes-for-highlightjs */
/* Tomorrow Comment */
/* Tomorrow Red */
/* Tomorrow Orange */
/* Tomorrow Yellow */
/* Tomorrow Green */
/* Tomorrow Aqua */
/* Tomorrow Blue */
/* Tomorrow Purple */
}
pre .hljs-comment,
code .hljs-comment,
pre .hljs-title,
code .hljs-title {
color: #8e908c;
}
pre .hljs-variable,
code .hljs-variable,
pre .hljs-attribute,
code .hljs-attribute,
pre .hljs-tag,
code .hljs-tag,
pre .hljs-regexp,
code .hljs-regexp,
pre .hljs-deletion,
code .hljs-deletion,
pre .ruby .hljs-constant,
code .ruby .hljs-constant,
pre .xml .hljs-tag .hljs-title,
code .xml .hljs-tag .hljs-title,
pre .xml .hljs-pi,
code .xml .hljs-pi,
pre .xml .hljs-doctype,
code .xml .hljs-doctype,
pre .html .hljs-doctype,
code .html .hljs-doctype,
pre .css .hljs-id,
code .css .hljs-id,
pre .css .hljs-class,
code .css .hljs-class,
pre .css .hljs-pseudo,
code .css .hljs-pseudo {
color: #c82829;
}
pre .hljs-number,
code .hljs-number,
pre .hljs-preprocessor,
code .hljs-preprocessor,
pre .hljs-pragma,
code .hljs-pragma,
pre .hljs-built_in,
code .hljs-built_in,
pre .hljs-literal,
code .hljs-literal,
pre .hljs-params,
code .hljs-params,
pre .hljs-constant,
code .hljs-constant {
color: #f5871f;
}
pre .ruby .hljs-class .hljs-title,
code .ruby .hljs-class .hljs-title,
pre .css .hljs-rules .hljs-attribute,
code .css .hljs-rules .hljs-attribute {
color: #eab700;
}
pre .hljs-string,
code .hljs-string,
pre .hljs-value,
code .hljs-value,
pre .hljs-inheritance,
code .hljs-inheritance,
pre .hljs-header,
code .hljs-header,
pre .hljs-addition,
code .hljs-addition,
pre .ruby .hljs-symbol,
code .ruby .hljs-symbol,
pre .xml .hljs-cdata,
code .xml .hljs-cdata {
color: #718c00;
}
pre .css .hljs-hexcolor,
code .css .hljs-hexcolor {
color: #3e999f;
}
pre .hljs-function,
code .hljs-function,
pre .python .hljs-decorator,
code .python .hljs-decorator,
pre .python .hljs-title,
code .python .hljs-title,
pre .ruby .hljs-function .hljs-title,
code .ruby .hljs-function .hljs-title,
pre .ruby .hljs-title .hljs-keyword,
code .ruby .hljs-title .hljs-keyword,
pre .perl .hljs-sub,
code .perl .hljs-sub,
pre .javascript .hljs-title,
code .javascript .hljs-title,
pre .coffeescript .hljs-title,
code .coffeescript .hljs-title {
color: #4271ae;
}
pre .hljs-keyword,
code .hljs-keyword,
pre .javascript .hljs-function,
code .javascript .hljs-function {
color: #8959a8;
}
pre .hljs,
code .hljs {
display: block;
background: white;
color: #4d4d4c;
padding: 0.5em;
}
pre .coffeescript .javascript,
code .coffeescript .javascript,
pre .javascript .xml,
code .javascript .xml,
pre .tex .hljs-formula,
code .tex .hljs-formula,
pre .xml .javascript,
code .xml .javascript,
pre .xml .vbscript,
code .xml .vbscript,
pre .xml .css,
code .xml .css,
pre .xml .hljs-cdata,
code .xml .hljs-cdata {
opacity: 0.5;
}
(function() {
var newEl = document.createElement('script'),
firstScriptTag = document.getElementsByTagName('script')[0];
if (firstScriptTag) {
newEl.async = 1;
newEl.src = '//' + window.location.hostname + ':35729/livereload.js';
firstScriptTag.parentNode.insertBefore(newEl, firstScriptTag);
}
})();
/**
* lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 0.5.12
* Copyright (C) 2015 Oliver Nightingale
* MIT Licensed
* @license
*/
!function(){var t=function(e){var n=new t.Index;return n.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),e&&e.call(n,n),n};t.version="0.5.12",t.utils={},t.utils.warn=function(t){return function(e){t.console&&console.warn&&console.warn(e)}}(this),t.EventEmitter=function(){this.events={}},t.EventEmitter.prototype.addListener=function(){var t=Array.prototype.slice.call(arguments),e=t.pop(),n=t;if("function"!=typeof e)throw new TypeError("last argument must be a function");n.forEach(function(t){this.hasHandler(t)||(this.events[t]=[]),this.events[t].push(e)},this)},t.EventEmitter.prototype.removeListener=function(t,e){if(this.hasHandler(t)){var n=this.events[t].indexOf(e);this.events[t].splice(n,1),this.events[t].length||delete this.events[t]}},t.EventEmitter.prototype.emit=function(t){if(this.hasHandler(t)){var e=Array.prototype.slice.call(arguments,1);this.events[t].forEach(function(t){t.apply(void 0,e)})}},t.EventEmitter.prototype.hasHandler=function(t){return t in this.events},t.tokenizer=function(t){return arguments.length&&null!=t&&void 0!=t?Array.isArray(t)?t.map(function(t){return t.toLowerCase()}):t.toString().trim().toLowerCase().split(/[\s\-]+/):[]},t.Pipeline=function(){this._stack=[]},t.Pipeline.registeredFunctions={},t.Pipeline.registerFunction=function(e,n){n in this.registeredFunctions&&t.utils.warn("Overwriting existing registered function: "+n),e.label=n,t.Pipeline.registeredFunctions[e.label]=e},t.Pipeline.warnIfFunctionNotRegistered=function(e){var n=e.label&&e.label in this.registeredFunctions;n||t.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},t.Pipeline.load=function(e){var n=new t.Pipeline;return e.forEach(function(e){var i=t.Pipeline.registeredFunctions[e];if(!i)throw new Error("Cannot load un-registered function: "+e);n.add(i)}),n},t.Pipeline.prototype.add=function(){var e=Array.prototype.slice.call(arguments);e.forEach(function(e){t.Pipeline.warnIfFunctionNotRegistered(e),this._stack.push(e)},this)},t.Pipeline.prototype.after=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._stack.indexOf(e);if(-1==i)throw new Error("Cannot find existingFn");i+=1,this._stack.splice(i,0,n)},t.Pipeline.prototype.before=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._stack.indexOf(e);if(-1==i)throw new Error("Cannot find existingFn");this._stack.splice(i,0,n)},t.Pipeline.prototype.remove=function(t){var e=this._stack.indexOf(t);-1!=e&&this._stack.splice(e,1)},t.Pipeline.prototype.run=function(t){for(var e=[],n=t.length,i=this._stack.length,o=0;n>o;o++){for(var r=t[o],s=0;i>s&&(r=this._stack[s](r,o,t),void 0!==r);s++);void 0!==r&&e.push(r)}return e},t.Pipeline.prototype.reset=function(){this._stack=[]},t.Pipeline.prototype.toJSON=function(){return this._stack.map(function(e){return t.Pipeline.warnIfFunctionNotRegistered(e),e.label})},t.Vector=function(){this._magnitude=null,this.list=void 0,this.length=0},t.Vector.Node=function(t,e,n){this.idx=t,this.val=e,this.next=n},t.Vector.prototype.insert=function(e,n){this._magnitude=void 0;var i=this.list;if(!i)return this.list=new t.Vector.Node(e,n,i),this.length++;if(e<i.idx)return this.list=new t.Vector.Node(e,n,i),this.length++;for(var o=i,r=i.next;void 0!=r;){if(e<r.idx)return o.next=new t.Vector.Node(e,n,r),this.length++;o=r,r=r.next}return o.next=new t.Vector.Node(e,n,r),this.length++},t.Vector.prototype.magnitude=function(){if(this._magnitude)return this._magnitude;for(var t,e=this.list,n=0;e;)t=e.val,n+=t*t,e=e.next;return this._magnitude=Math.sqrt(n)},t.Vector.prototype.dot=function(t){for(var e=this.list,n=t.list,i=0;e&&n;)e.idx<n.idx?e=e.next:e.idx>n.idx?n=n.next:(i+=e.val*n.val,e=e.next,n=n.next);return i},t.Vector.prototype.similarity=function(t){return this.dot(t)/(this.magnitude()*t.magnitude())},t.SortedSet=function(){this.length=0,this.elements=[]},t.SortedSet.load=function(t){var e=new this;return e.elements=t,e.length=t.length,e},t.SortedSet.prototype.add=function(){var t,e;for(t=0;t<arguments.length;t++)e=arguments[t],~this.indexOf(e)||this.elements.splice(this.locationFor(e),0,e);this.length=this.elements.length},t.SortedSet.prototype.toArray=function(){return this.elements.slice()},t.SortedSet.prototype.map=function(t,e){return this.elements.map(t,e)},t.SortedSet.prototype.forEach=function(t,e){return this.elements.forEach(t,e)},t.SortedSet.prototype.indexOf=function(t){for(var e=0,n=this.elements.length,i=n-e,o=e+Math.floor(i/2),r=this.elements[o];i>1;){if(r===t)return o;t>r&&(e=o),r>t&&(n=o),i=n-e,o=e+Math.floor(i/2),r=this.elements[o]}return r===t?o:-1},t.SortedSet.prototype.locationFor=function(t){for(var e=0,n=this.elements.length,i=n-e,o=e+Math.floor(i/2),r=this.elements[o];i>1;)t>r&&(e=o),r>t&&(n=o),i=n-e,o=e+Math.floor(i/2),r=this.elements[o];return r>t?o:t>r?o+1:void 0},t.SortedSet.prototype.intersect=function(e){for(var n=new t.SortedSet,i=0,o=0,r=this.length,s=e.length,a=this.elements,h=e.elements;;){if(i>r-1||o>s-1)break;a[i]!==h[o]?a[i]<h[o]?i++:a[i]>h[o]&&o++:(n.add(a[i]),i++,o++)}return n},t.SortedSet.prototype.clone=function(){var e=new t.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},t.SortedSet.prototype.union=function(t){var e,n,i;return this.length>=t.length?(e=this,n=t):(e=t,n=this),i=e.clone(),i.add.apply(i,n.toArray()),i},t.SortedSet.prototype.toJSON=function(){return this.toArray()},t.Index=function(){this._fields=[],this._ref="id",this.pipeline=new t.Pipeline,this.documentStore=new t.Store,this.tokenStore=new t.TokenStore,this.corpusTokens=new t.SortedSet,this.eventEmitter=new t.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},t.Index.prototype.on=function(){var t=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,t)},t.Index.prototype.off=function(t,e){return this.eventEmitter.removeListener(t,e)},t.Index.load=function(e){e.version!==t.version&&t.utils.warn("version mismatch: current "+t.version+" importing "+e.version);var n=new this;return n._fields=e.fields,n._ref=e.ref,n.documentStore=t.Store.load(e.documentStore),n.tokenStore=t.TokenStore.load(e.tokenStore),n.corpusTokens=t.SortedSet.load(e.corpusTokens),n.pipeline=t.Pipeline.load(e.pipeline),n},t.Index.prototype.field=function(t,e){var e=e||{},n={name:t,boost:e.boost||1};return this._fields.push(n),this},t.Index.prototype.ref=function(t){return this._ref=t,this},t.Index.prototype.add=function(e,n){var i={},o=new t.SortedSet,r=e[this._ref],n=void 0===n?!0:n;this._fields.forEach(function(n){var r=this.pipeline.run(t.tokenizer(e[n.name]));i[n.name]=r,t.SortedSet.prototype.add.apply(o,r)},this),this.documentStore.set(r,o),t.SortedSet.prototype.add.apply(this.corpusTokens,o.toArray());for(var s=0;s<o.length;s++){var a=o.elements[s],h=this._fields.reduce(function(t,e){var n=i[e.name].length;if(!n)return t;var o=i[e.name].filter(function(t){return t===a}).length;return t+o/n*e.boost},0);this.tokenStore.add(a,{ref:r,tf:h})}n&&this.eventEmitter.emit("add",e,this)},t.Index.prototype.remove=function(t,e){var n=t[this._ref],e=void 0===e?!0:e;if(this.documentStore.has(n)){var i=this.documentStore.get(n);this.documentStore.remove(n),i.forEach(function(t){this.tokenStore.remove(t,n)},this),e&&this.eventEmitter.emit("remove",t,this)}},t.Index.prototype.update=function(t,e){var e=void 0===e?!0:e;this.remove(t,!1),this.add(t,!1),e&&this.eventEmitter.emit("update",t,this)},t.Index.prototype.idf=function(t){var e="@"+t;if(Object.prototype.hasOwnProperty.call(this._idfCache,e))return this._idfCache[e];var n=this.tokenStore.count(t),i=1;return n>0&&(i=1+Math.log(this.documentStore.length/n)),this._idfCache[e]=i},t.Index.prototype.search=function(e){var n=this.pipeline.run(t.tokenizer(e)),i=new t.Vector,o=[],r=this._fields.reduce(function(t,e){return t+e.boost},0),s=n.some(function(t){return this.tokenStore.has(t)},this);if(!s)return[];n.forEach(function(e,n,s){var a=1/s.length*this._fields.length*r,h=this,l=this.tokenStore.expand(e).reduce(function(n,o){var r=h.corpusTokens.indexOf(o),s=h.idf(o),l=1,u=new t.SortedSet;if(o!==e){var c=Math.max(3,o.length-e.length);l=1/Math.log(c)}return r>-1&&i.insert(r,a*s*l),Object.keys(h.tokenStore.get(o)).forEach(function(t){u.add(t)}),n.union(u)},new t.SortedSet);o.push(l)},this);var a=o.reduce(function(t,e){return t.intersect(e)});return a.map(function(t){return{ref:t,score:i.similarity(this.documentVector(t))}},this).sort(function(t,e){return e.score-t.score})},t.Index.prototype.documentVector=function(e){for(var n=this.documentStore.get(e),i=n.length,o=new t.Vector,r=0;i>r;r++){var s=n.elements[r],a=this.tokenStore.get(s)[e].tf,h=this.idf(s);o.insert(this.corpusTokens.indexOf(s),a*h)}return o},t.Index.prototype.toJSON=function(){return{version:t.version,fields:this._fields,ref:this._ref,documentStore:this.documentStore.toJSON(),tokenStore:this.tokenStore.toJSON(),corpusTokens:this.corpusTokens.toJSON(),pipeline:this.pipeline.toJSON()}},t.Index.prototype.use=function(t){var e=Array.prototype.slice.call(arguments,1);e.unshift(this),t.apply(this,e)},t.Store=function(){this.store={},this.length=0},t.Store.load=function(e){var n=new this;return n.length=e.length,n.store=Object.keys(e.store).reduce(function(n,i){return n[i]=t.SortedSet.load(e.store[i]),n},{}),n},t.Store.prototype.set=function(t,e){this.has(t)||this.length++,this.store[t]=e},t.Store.prototype.get=function(t){return this.store[t]},t.Store.prototype.has=function(t){return t in this.store},t.Store.prototype.remove=function(t){this.has(t)&&(delete this.store[t],this.length--)},t.Store.prototype.toJSON=function(){return{store:this.store,length:this.length}},t.stemmer=function(){var t={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},e={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},n="[^aeiou]",i="[aeiouy]",o=n+"[^aeiouy]*",r=i+"[aeiou]*",s="^("+o+")?"+r+o,a="^("+o+")?"+r+o+"("+r+")?$",h="^("+o+")?"+r+o+r+o,l="^("+o+")?"+i,u=new RegExp(s),c=new RegExp(h),f=new RegExp(a),d=new RegExp(l),p=/^(.+?)(ss|i)es$/,m=/^(.+?)([^s])s$/,v=/^(.+?)eed$/,y=/^(.+?)(ed|ing)$/,g=/.$/,S=/(at|bl|iz)$/,w=new RegExp("([^aeiouylsz])\\1$"),x=new RegExp("^"+o+i+"[^aeiouwxy]$"),k=/^(.+?[^aeiou])y$/,b=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,E=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,_=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,F=/^(.+?)(s|t)(ion)$/,O=/^(.+?)e$/,P=/ll$/,N=new RegExp("^"+o+i+"[^aeiouwxy]$"),T=function(n){var i,o,r,s,a,h,l;if(n.length<3)return n;if(r=n.substr(0,1),"y"==r&&(n=r.toUpperCase()+n.substr(1)),s=p,a=m,s.test(n)?n=n.replace(s,"$1$2"):a.test(n)&&(n=n.replace(a,"$1$2")),s=v,a=y,s.test(n)){var T=s.exec(n);s=u,s.test(T[1])&&(s=g,n=n.replace(s,""))}else if(a.test(n)){var T=a.exec(n);i=T[1],a=d,a.test(i)&&(n=i,a=S,h=w,l=x,a.test(n)?n+="e":h.test(n)?(s=g,n=n.replace(s,"")):l.test(n)&&(n+="e"))}if(s=k,s.test(n)){var T=s.exec(n);i=T[1],n=i+"i"}if(s=b,s.test(n)){var T=s.exec(n);i=T[1],o=T[2],s=u,s.test(i)&&(n=i+t[o])}if(s=E,s.test(n)){var T=s.exec(n);i=T[1],o=T[2],s=u,s.test(i)&&(n=i+e[o])}if(s=_,a=F,s.test(n)){var T=s.exec(n);i=T[1],s=c,s.test(i)&&(n=i)}else if(a.test(n)){var T=a.exec(n);i=T[1]+T[2],a=c,a.test(i)&&(n=i)}if(s=O,s.test(n)){var T=s.exec(n);i=T[1],s=c,a=f,h=N,(s.test(i)||a.test(i)&&!h.test(i))&&(n=i)}return s=P,a=c,s.test(n)&&a.test(n)&&(s=g,n=n.replace(s,"")),"y"==r&&(n=r.toLowerCase()+n.substr(1)),n};return T}(),t.Pipeline.registerFunction(t.stemmer,"stemmer"),t.stopWordFilter=function(e){return e&&t.stopWordFilter.stopWords[e]!==e?e:void 0},t.stopWordFilter.stopWords={a:"a",able:"able",about:"about",across:"across",after:"after",all:"all",almost:"almost",also:"also",am:"am",among:"among",an:"an",and:"and",any:"any",are:"are",as:"as",at:"at",be:"be",because:"because",been:"been",but:"but",by:"by",can:"can",cannot:"cannot",could:"could",dear:"dear",did:"did","do":"do",does:"does",either:"either","else":"else",ever:"ever",every:"every","for":"for",from:"from",get:"get",got:"got",had:"had",has:"has",have:"have",he:"he",her:"her",hers:"hers",him:"him",his:"his",how:"how",however:"however",i:"i","if":"if","in":"in",into:"into",is:"is",it:"it",its:"its",just:"just",least:"least",let:"let",like:"like",likely:"likely",may:"may",me:"me",might:"might",most:"most",must:"must",my:"my",neither:"neither",no:"no",nor:"nor",not:"not",of:"of",off:"off",often:"often",on:"on",only:"only",or:"or",other:"other",our:"our",own:"own",rather:"rather",said:"said",say:"say",says:"says",she:"she",should:"should",since:"since",so:"so",some:"some",than:"than",that:"that",the:"the",their:"their",them:"them",then:"then",there:"there",these:"these",they:"they","this":"this",tis:"tis",to:"to",too:"too",twas:"twas",us:"us",wants:"wants",was:"was",we:"we",were:"were",what:"what",when:"when",where:"where",which:"which","while":"while",who:"who",whom:"whom",why:"why",will:"will","with":"with",would:"would",yet:"yet",you:"you",your:"your"},t.Pipeline.registerFunction(t.stopWordFilter,"stopWordFilter"),t.trimmer=function(t){var e=t.replace(/^\W+/,"").replace(/\W+$/,"");return""===e?void 0:e},t.Pipeline.registerFunction(t.trimmer,"trimmer"),t.TokenStore=function(){this.root={docs:{}},this.length=0},t.TokenStore.load=function(t){var e=new this;return e.root=t.root,e.length=t.length,e},t.TokenStore.prototype.add=function(t,e,n){var n=n||this.root,i=t[0],o=t.slice(1);return i in n||(n[i]={docs:{}}),0===o.length?(n[i].docs[e.ref]=e,void(this.length+=1)):this.add(o,e,n[i])},t.TokenStore.prototype.has=function(t){if(!t)return!1;for(var e=this.root,n=0;n<t.length;n++){if(!e[t[n]])return!1;e=e[t[n]]}return!0},t.TokenStore.prototype.getNode=function(t){if(!t)return{};for(var e=this.root,n=0;n<t.length;n++){if(!e[t[n]])return{};e=e[t[n]]}return e},t.TokenStore.prototype.get=function(t,e){return this.getNode(t,e).docs||{}},t.TokenStore.prototype.count=function(t,e){return Object.keys(this.get(t,e)).length},t.TokenStore.prototype.remove=function(t,e){if(t){for(var n=this.root,i=0;i<t.length;i++){if(!(t[i]in n))return;n=n[t[i]]}delete n.docs[e]}},t.TokenStore.prototype.expand=function(t,e){var n=this.getNode(t),i=n.docs||{},e=e||[];return Object.keys(i).length&&e.push(t),Object.keys(n).forEach(function(n){"docs"!==n&&e.concat(this.expand(t+n,e))},this),e},t.TokenStore.prototype.toJSON=function(){return{root:this.root,length:this.length}},function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e():t.lunr=e()}(this,function(){return t})}();
\ No newline at end of file
require([
'gitbook',
'jquery'
], function(gitbook, $) {
// Define global search engine
function LunrSearchEngine() {
this.index = null;
this.store = {};
this.name = 'LunrSearchEngine';
}
// Initialize lunr by fetching the search index
LunrSearchEngine.prototype.init = function() {
var that = this;
var d = $.Deferred();
$.getJSON(gitbook.state.basePath+'/search_index.json')
.then(function(data) {
// eslint-disable-next-line no-undef
that.index = lunr.Index.load(data.index);
that.store = data.store;
d.resolve();
});
return d.promise();
};
// Search for a term and return results
LunrSearchEngine.prototype.search = function(q, offset, length) {
var that = this;
var results = [];
if (this.index) {
results = $.map(this.index.search(q), function(result) {
var doc = that.store[result.ref];
return {
title: doc.title,
url: doc.url,
body: doc.summary || doc.body
};
});
}
return $.Deferred().resolve({
query: q,
results: results.slice(0, length),
count: results.length
}).promise();
};
// Set gitbook research
gitbook.events.bind('start', function(e, config) {
var engine = gitbook.search.getEngine();
if (!engine) {
gitbook.search.setEngine(LunrSearchEngine, config);
}
});
});
/**
* lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 0.5.12
* Copyright (C) 2015 Oliver Nightingale
* MIT Licensed
* @license
*/
!function(){var t=function(e){var n=new t.Index;return n.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),e&&e.call(n,n),n};t.version="0.5.12",t.utils={},t.utils.warn=function(t){return function(e){t.console&&console.warn&&console.warn(e)}}(this),t.EventEmitter=function(){this.events={}},t.EventEmitter.prototype.addListener=function(){var t=Array.prototype.slice.call(arguments),e=t.pop(),n=t;if("function"!=typeof e)throw new TypeError("last argument must be a function");n.forEach(function(t){this.hasHandler(t)||(this.events[t]=[]),this.events[t].push(e)},this)},t.EventEmitter.prototype.removeListener=function(t,e){if(this.hasHandler(t)){var n=this.events[t].indexOf(e);this.events[t].splice(n,1),this.events[t].length||delete this.events[t]}},t.EventEmitter.prototype.emit=function(t){if(this.hasHandler(t)){var e=Array.prototype.slice.call(arguments,1);this.events[t].forEach(function(t){t.apply(void 0,e)})}},t.EventEmitter.prototype.hasHandler=function(t){return t in this.events},t.tokenizer=function(t){return arguments.length&&null!=t&&void 0!=t?Array.isArray(t)?t.map(function(t){return t.toLowerCase()}):t.toString().trim().toLowerCase().split(/[\s\-]+/):[]},t.Pipeline=function(){this._stack=[]},t.Pipeline.registeredFunctions={},t.Pipeline.registerFunction=function(e,n){n in this.registeredFunctions&&t.utils.warn("Overwriting existing registered function: "+n),e.label=n,t.Pipeline.registeredFunctions[e.label]=e},t.Pipeline.warnIfFunctionNotRegistered=function(e){var n=e.label&&e.label in this.registeredFunctions;n||t.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},t.Pipeline.load=function(e){var n=new t.Pipeline;return e.forEach(function(e){var i=t.Pipeline.registeredFunctions[e];if(!i)throw new Error("Cannot load un-registered function: "+e);n.add(i)}),n},t.Pipeline.prototype.add=function(){var e=Array.prototype.slice.call(arguments);e.forEach(function(e){t.Pipeline.warnIfFunctionNotRegistered(e),this._stack.push(e)},this)},t.Pipeline.prototype.after=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._stack.indexOf(e);if(-1==i)throw new Error("Cannot find existingFn");i+=1,this._stack.splice(i,0,n)},t.Pipeline.prototype.before=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._stack.indexOf(e);if(-1==i)throw new Error("Cannot find existingFn");this._stack.splice(i,0,n)},t.Pipeline.prototype.remove=function(t){var e=this._stack.indexOf(t);-1!=e&&this._stack.splice(e,1)},t.Pipeline.prototype.run=function(t){for(var e=[],n=t.length,i=this._stack.length,o=0;n>o;o++){for(var r=t[o],s=0;i>s&&(r=this._stack[s](r,o,t),void 0!==r);s++);void 0!==r&&e.push(r)}return e},t.Pipeline.prototype.reset=function(){this._stack=[]},t.Pipeline.prototype.toJSON=function(){return this._stack.map(function(e){return t.Pipeline.warnIfFunctionNotRegistered(e),e.label})},t.Vector=function(){this._magnitude=null,this.list=void 0,this.length=0},t.Vector.Node=function(t,e,n){this.idx=t,this.val=e,this.next=n},t.Vector.prototype.insert=function(e,n){this._magnitude=void 0;var i=this.list;if(!i)return this.list=new t.Vector.Node(e,n,i),this.length++;if(e<i.idx)return this.list=new t.Vector.Node(e,n,i),this.length++;for(var o=i,r=i.next;void 0!=r;){if(e<r.idx)return o.next=new t.Vector.Node(e,n,r),this.length++;o=r,r=r.next}return o.next=new t.Vector.Node(e,n,r),this.length++},t.Vector.prototype.magnitude=function(){if(this._magnitude)return this._magnitude;for(var t,e=this.list,n=0;e;)t=e.val,n+=t*t,e=e.next;return this._magnitude=Math.sqrt(n)},t.Vector.prototype.dot=function(t){for(var e=this.list,n=t.list,i=0;e&&n;)e.idx<n.idx?e=e.next:e.idx>n.idx?n=n.next:(i+=e.val*n.val,e=e.next,n=n.next);return i},t.Vector.prototype.similarity=function(t){return this.dot(t)/(this.magnitude()*t.magnitude())},t.SortedSet=function(){this.length=0,this.elements=[]},t.SortedSet.load=function(t){var e=new this;return e.elements=t,e.length=t.length,e},t.SortedSet.prototype.add=function(){var t,e;for(t=0;t<arguments.length;t++)e=arguments[t],~this.indexOf(e)||this.elements.splice(this.locationFor(e),0,e);this.length=this.elements.length},t.SortedSet.prototype.toArray=function(){return this.elements.slice()},t.SortedSet.prototype.map=function(t,e){return this.elements.map(t,e)},t.SortedSet.prototype.forEach=function(t,e){return this.elements.forEach(t,e)},t.SortedSet.prototype.indexOf=function(t){for(var e=0,n=this.elements.length,i=n-e,o=e+Math.floor(i/2),r=this.elements[o];i>1;){if(r===t)return o;t>r&&(e=o),r>t&&(n=o),i=n-e,o=e+Math.floor(i/2),r=this.elements[o]}return r===t?o:-1},t.SortedSet.prototype.locationFor=function(t){for(var e=0,n=this.elements.length,i=n-e,o=e+Math.floor(i/2),r=this.elements[o];i>1;)t>r&&(e=o),r>t&&(n=o),i=n-e,o=e+Math.floor(i/2),r=this.elements[o];return r>t?o:t>r?o+1:void 0},t.SortedSet.prototype.intersect=function(e){for(var n=new t.SortedSet,i=0,o=0,r=this.length,s=e.length,a=this.elements,h=e.elements;;){if(i>r-1||o>s-1)break;a[i]!==h[o]?a[i]<h[o]?i++:a[i]>h[o]&&o++:(n.add(a[i]),i++,o++)}return n},t.SortedSet.prototype.clone=function(){var e=new t.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},t.SortedSet.prototype.union=function(t){var e,n,i;return this.length>=t.length?(e=this,n=t):(e=t,n=this),i=e.clone(),i.add.apply(i,n.toArray()),i},t.SortedSet.prototype.toJSON=function(){return this.toArray()},t.Index=function(){this._fields=[],this._ref="id",this.pipeline=new t.Pipeline,this.documentStore=new t.Store,this.tokenStore=new t.TokenStore,this.corpusTokens=new t.SortedSet,this.eventEmitter=new t.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},t.Index.prototype.on=function(){var t=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,t)},t.Index.prototype.off=function(t,e){return this.eventEmitter.removeListener(t,e)},t.Index.load=function(e){e.version!==t.version&&t.utils.warn("version mismatch: current "+t.version+" importing "+e.version);var n=new this;return n._fields=e.fields,n._ref=e.ref,n.documentStore=t.Store.load(e.documentStore),n.tokenStore=t.TokenStore.load(e.tokenStore),n.corpusTokens=t.SortedSet.load(e.corpusTokens),n.pipeline=t.Pipeline.load(e.pipeline),n},t.Index.prototype.field=function(t,e){var e=e||{},n={name:t,boost:e.boost||1};return this._fields.push(n),this},t.Index.prototype.ref=function(t){return this._ref=t,this},t.Index.prototype.add=function(e,n){var i={},o=new t.SortedSet,r=e[this._ref],n=void 0===n?!0:n;this._fields.forEach(function(n){var r=this.pipeline.run(t.tokenizer(e[n.name]));i[n.name]=r,t.SortedSet.prototype.add.apply(o,r)},this),this.documentStore.set(r,o),t.SortedSet.prototype.add.apply(this.corpusTokens,o.toArray());for(var s=0;s<o.length;s++){var a=o.elements[s],h=this._fields.reduce(function(t,e){var n=i[e.name].length;if(!n)return t;var o=i[e.name].filter(function(t){return t===a}).length;return t+o/n*e.boost},0);this.tokenStore.add(a,{ref:r,tf:h})}n&&this.eventEmitter.emit("add",e,this)},t.Index.prototype.remove=function(t,e){var n=t[this._ref],e=void 0===e?!0:e;if(this.documentStore.has(n)){var i=this.documentStore.get(n);this.documentStore.remove(n),i.forEach(function(t){this.tokenStore.remove(t,n)},this),e&&this.eventEmitter.emit("remove",t,this)}},t.Index.prototype.update=function(t,e){var e=void 0===e?!0:e;this.remove(t,!1),this.add(t,!1),e&&this.eventEmitter.emit("update",t,this)},t.Index.prototype.idf=function(t){var e="@"+t;if(Object.prototype.hasOwnProperty.call(this._idfCache,e))return this._idfCache[e];var n=this.tokenStore.count(t),i=1;return n>0&&(i=1+Math.log(this.documentStore.length/n)),this._idfCache[e]=i},t.Index.prototype.search=function(e){var n=this.pipeline.run(t.tokenizer(e)),i=new t.Vector,o=[],r=this._fields.reduce(function(t,e){return t+e.boost},0),s=n.some(function(t){return this.tokenStore.has(t)},this);if(!s)return[];n.forEach(function(e,n,s){var a=1/s.length*this._fields.length*r,h=this,l=this.tokenStore.expand(e).reduce(function(n,o){var r=h.corpusTokens.indexOf(o),s=h.idf(o),l=1,u=new t.SortedSet;if(o!==e){var c=Math.max(3,o.length-e.length);l=1/Math.log(c)}return r>-1&&i.insert(r,a*s*l),Object.keys(h.tokenStore.get(o)).forEach(function(t){u.add(t)}),n.union(u)},new t.SortedSet);o.push(l)},this);var a=o.reduce(function(t,e){return t.intersect(e)});return a.map(function(t){return{ref:t,score:i.similarity(this.documentVector(t))}},this).sort(function(t,e){return e.score-t.score})},t.Index.prototype.documentVector=function(e){for(var n=this.documentStore.get(e),i=n.length,o=new t.Vector,r=0;i>r;r++){var s=n.elements[r],a=this.tokenStore.get(s)[e].tf,h=this.idf(s);o.insert(this.corpusTokens.indexOf(s),a*h)}return o},t.Index.prototype.toJSON=function(){return{version:t.version,fields:this._fields,ref:this._ref,documentStore:this.documentStore.toJSON(),tokenStore:this.tokenStore.toJSON(),corpusTokens:this.corpusTokens.toJSON(),pipeline:this.pipeline.toJSON()}},t.Index.prototype.use=function(t){var e=Array.prototype.slice.call(arguments,1);e.unshift(this),t.apply(this,e)},t.Store=function(){this.store={},this.length=0},t.Store.load=function(e){var n=new this;return n.length=e.length,n.store=Object.keys(e.store).reduce(function(n,i){return n[i]=t.SortedSet.load(e.store[i]),n},{}),n},t.Store.prototype.set=function(t,e){this.has(t)||this.length++,this.store[t]=e},t.Store.prototype.get=function(t){return this.store[t]},t.Store.prototype.has=function(t){return t in this.store},t.Store.prototype.remove=function(t){this.has(t)&&(delete this.store[t],this.length--)},t.Store.prototype.toJSON=function(){return{store:this.store,length:this.length}},t.stemmer=function(){var t={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},e={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},n="[^aeiou]",i="[aeiouy]",o=n+"[^aeiouy]*",r=i+"[aeiou]*",s="^("+o+")?"+r+o,a="^("+o+")?"+r+o+"("+r+")?$",h="^("+o+")?"+r+o+r+o,l="^("+o+")?"+i,u=new RegExp(s),c=new RegExp(h),f=new RegExp(a),d=new RegExp(l),p=/^(.+?)(ss|i)es$/,m=/^(.+?)([^s])s$/,v=/^(.+?)eed$/,y=/^(.+?)(ed|ing)$/,g=/.$/,S=/(at|bl|iz)$/,w=new RegExp("([^aeiouylsz])\\1$"),x=new RegExp("^"+o+i+"[^aeiouwxy]$"),k=/^(.+?[^aeiou])y$/,b=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,E=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,_=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,F=/^(.+?)(s|t)(ion)$/,O=/^(.+?)e$/,P=/ll$/,N=new RegExp("^"+o+i+"[^aeiouwxy]$"),T=function(n){var i,o,r,s,a,h,l;if(n.length<3)return n;if(r=n.substr(0,1),"y"==r&&(n=r.toUpperCase()+n.substr(1)),s=p,a=m,s.test(n)?n=n.replace(s,"$1$2"):a.test(n)&&(n=n.replace(a,"$1$2")),s=v,a=y,s.test(n)){var T=s.exec(n);s=u,s.test(T[1])&&(s=g,n=n.replace(s,""))}else if(a.test(n)){var T=a.exec(n);i=T[1],a=d,a.test(i)&&(n=i,a=S,h=w,l=x,a.test(n)?n+="e":h.test(n)?(s=g,n=n.replace(s,"")):l.test(n)&&(n+="e"))}if(s=k,s.test(n)){var T=s.exec(n);i=T[1],n=i+"i"}if(s=b,s.test(n)){var T=s.exec(n);i=T[1],o=T[2],s=u,s.test(i)&&(n=i+t[o])}if(s=E,s.test(n)){var T=s.exec(n);i=T[1],o=T[2],s=u,s.test(i)&&(n=i+e[o])}if(s=_,a=F,s.test(n)){var T=s.exec(n);i=T[1],s=c,s.test(i)&&(n=i)}else if(a.test(n)){var T=a.exec(n);i=T[1]+T[2],a=c,a.test(i)&&(n=i)}if(s=O,s.test(n)){var T=s.exec(n);i=T[1],s=c,a=f,h=N,(s.test(i)||a.test(i)&&!h.test(i))&&(n=i)}return s=P,a=c,s.test(n)&&a.test(n)&&(s=g,n=n.replace(s,"")),"y"==r&&(n=r.toLowerCase()+n.substr(1)),n};return T}(),t.Pipeline.registerFunction(t.stemmer,"stemmer"),t.stopWordFilter=function(e){return e&&t.stopWordFilter.stopWords[e]!==e?e:void 0},t.stopWordFilter.stopWords={a:"a",able:"able",about:"about",across:"across",after:"after",all:"all",almost:"almost",also:"also",am:"am",among:"among",an:"an",and:"and",any:"any",are:"are",as:"as",at:"at",be:"be",because:"because",been:"been",but:"but",by:"by",can:"can",cannot:"cannot",could:"could",dear:"dear",did:"did","do":"do",does:"does",either:"either","else":"else",ever:"ever",every:"every","for":"for",from:"from",get:"get",got:"got",had:"had",has:"has",have:"have",he:"he",her:"her",hers:"hers",him:"him",his:"his",how:"how",however:"however",i:"i","if":"if","in":"in",into:"into",is:"is",it:"it",its:"its",just:"just",least:"least",let:"let",like:"like",likely:"likely",may:"may",me:"me",might:"might",most:"most",must:"must",my:"my",neither:"neither",no:"no",nor:"nor",not:"not",of:"of",off:"off",often:"often",on:"on",only:"only",or:"or",other:"other",our:"our",own:"own",rather:"rather",said:"said",say:"say",says:"says",she:"she",should:"should",since:"since",so:"so",some:"some",than:"than",that:"that",the:"the",their:"their",them:"them",then:"then",there:"there",these:"these",they:"they","this":"this",tis:"tis",to:"to",too:"too",twas:"twas",us:"us",wants:"wants",was:"was",we:"we",were:"were",what:"what",when:"when",where:"where",which:"which","while":"while",who:"who",whom:"whom",why:"why",will:"will","with":"with",would:"would",yet:"yet",you:"you",your:"your"},t.Pipeline.registerFunction(t.stopWordFilter,"stopWordFilter"),t.trimmer=function(t){var e=t.replace(/^\W+/,"").replace(/\W+$/,"");return""===e?void 0:e},t.Pipeline.registerFunction(t.trimmer,"trimmer"),t.TokenStore=function(){this.root={docs:{}},this.length=0},t.TokenStore.load=function(t){var e=new this;return e.root=t.root,e.length=t.length,e},t.TokenStore.prototype.add=function(t,e,n){var n=n||this.root,i=t[0],o=t.slice(1);return i in n||(n[i]={docs:{}}),0===o.length?(n[i].docs[e.ref]=e,void(this.length+=1)):this.add(o,e,n[i])},t.TokenStore.prototype.has=function(t){if(!t)return!1;for(var e=this.root,n=0;n<t.length;n++){if(!e[t[n]])return!1;e=e[t[n]]}return!0},t.TokenStore.prototype.getNode=function(t){if(!t)return{};for(var e=this.root,n=0;n<t.length;n++){if(!e[t[n]])return{};e=e[t[n]]}return e},t.TokenStore.prototype.get=function(t,e){return this.getNode(t,e).docs||{}},t.TokenStore.prototype.count=function(t,e){return Object.keys(this.get(t,e)).length},t.TokenStore.prototype.remove=function(t,e){if(t){for(var n=this.root,i=0;i<t.length;i++){if(!(t[i]in n))return;n=n[t[i]]}delete n.docs[e]}},t.TokenStore.prototype.expand=function(t,e){var n=this.getNode(t),i=n.docs||{},e=e||[];return Object.keys(i).length&&e.push(t),Object.keys(n).forEach(function(n){"docs"!==n&&e.concat(this.expand(t+n,e))},this),e},t.TokenStore.prototype.toJSON=function(){return{root:this.root,length:this.length}},function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e():t.lunr=e()}(this,function(){return t})}();
\ No newline at end of file
require([
'gitbook',
'jquery'
], function(gitbook, $) {
// Global search objects
var engine = null;
var initialized = false;
// Set a new search engine
function setEngine(Engine, config) {
initialized = false;
engine = new Engine(config);
init(config);
}
// Initialize search engine with config
function init(config) {
if (!engine) throw new Error('No engine set for research. Set an engine using gitbook.research.setEngine(Engine).');
return engine.init(config)
.then(function() {
initialized = true;
gitbook.events.trigger('search.ready');
});
}
// Launch search for query q
function query(q, offset, length) {
if (!initialized) throw new Error('Search has not been initialized');
return engine.search(q, offset, length);
}
// Get stats about search
function getEngine() {
return engine? engine.name : null;
}
function isInitialized() {
return initialized;
}
// Initialize gitbook.search
gitbook.search = {
setEngine: setEngine,
getEngine: getEngine,
query: query,
isInitialized: isInitialized
};
});
\ No newline at end of file
/*
This CSS only styled the search results section, not the search input
It defines the basic interraction to hide content when displaying results, etc
*/
#book-search-results .search-results {
display: none;
}
#book-search-results .search-results ul.search-results-list {
list-style-type: none;
padding-left: 0;
}
#book-search-results .search-results ul.search-results-list li {
margin-bottom: 1.5rem;
padding-bottom: 0.5rem;
/* Highlight results */
}
#book-search-results .search-results ul.search-results-list li p em {
background-color: rgba(255, 220, 0, 0.4);
font-style: normal;
}
#book-search-results .search-results .no-results {
display: none;
}
#book-search-results.open .search-results {
display: block;
}
#book-search-results.open .search-noresults {
display: none;
}
#book-search-results.no-results .search-results .has-results {
display: none;
}
#book-search-results.no-results .search-results .no-results {
display: block;
}
require([
'gitbook',
'jquery'
], function(gitbook, $) {
var MAX_RESULTS = 15;
var MAX_DESCRIPTION_SIZE = 500;
var usePushState = (typeof history.pushState !== 'undefined');
// DOM Elements
var $body = $('body');
var $bookSearchResults;
var $searchInput;
var $searchList;
var $searchTitle;
var $searchResultsCount;
var $searchQuery;
// Throttle search
function throttle(fn, wait) {
var timeout;
return function() {
var ctx = this, args = arguments;
if (!timeout) {
timeout = setTimeout(function() {
timeout = null;
fn.apply(ctx, args);
}, wait);
}
};
}
function displayResults(res) {
$bookSearchResults.addClass('open');
var noResults = res.count == 0;
$bookSearchResults.toggleClass('no-results', noResults);
// Clear old results
$searchList.empty();
// Display title for research
$searchResultsCount.text(res.count);
$searchQuery.text(res.query);
// Create an <li> element for each result
res.results.forEach(function(res) {
var $li = $('<li>', {
'class': 'search-results-item'
});
var $title = $('<h3>');
var $link = $('<a>', {
'href': gitbook.state.basePath + '/' + res.url,
'text': res.title
});
var content = res.body.trim();
if (content.length > MAX_DESCRIPTION_SIZE) {
content = content.slice(0, MAX_DESCRIPTION_SIZE).trim()+'...';
}
var $content = $('<p>').html(content);
$link.appendTo($title);
$title.appendTo($li);
$content.appendTo($li);
$li.appendTo($searchList);
});
}
function launchSearch(q) {
// Add class for loading
$body.addClass('with-search');
$body.addClass('search-loading');
// Launch search query
throttle(gitbook.search.query(q, 0, MAX_RESULTS)
.then(function(results) {
displayResults(results);
})
.always(function() {
$body.removeClass('search-loading');
}), 1000);
}
function closeSearch() {
$body.removeClass('with-search');
$bookSearchResults.removeClass('open');
}
function launchSearchFromQueryString() {
var q = getParameterByName('q');
if (q && q.length > 0) {
// Update search input
$searchInput.val(q);
// Launch search
launchSearch(q);
}
}
function bindSearch() {
// Bind DOM
$searchInput = $('#book-search-input input');
$bookSearchResults = $('#book-search-results');
$searchList = $bookSearchResults.find('.search-results-list');
$searchTitle = $bookSearchResults.find('.search-results-title');
$searchResultsCount = $searchTitle.find('.search-results-count');
$searchQuery = $searchTitle.find('.search-query');
// Launch query based on input content
function handleUpdate() {
var q = $searchInput.val();
if (q.length == 0) {
closeSearch();
}
else {
launchSearch(q);
}
}
// Detect true content change in search input
// Workaround for IE < 9
var propertyChangeUnbound = false;
$searchInput.on('propertychange', function(e) {
if (e.originalEvent.propertyName == 'value') {
handleUpdate();
}
});
// HTML5 (IE9 & others)
$searchInput.on('input', function(e) {
// Unbind propertychange event for IE9+
if (!propertyChangeUnbound) {
$(this).unbind('propertychange');
propertyChangeUnbound = true;
}
handleUpdate();
});
// Push to history on blur
$searchInput.on('blur', function(e) {
// Update history state
if (usePushState) {
var uri = updateQueryString('q', $(this).val());
history.pushState({ path: uri }, null, uri);
}
});
}
gitbook.events.on('page.change', function() {
bindSearch();
closeSearch();
// Launch search based on query parameter
if (gitbook.search.isInitialized()) {
launchSearchFromQueryString();
}
});
gitbook.events.on('search.ready', function() {
bindSearch();
// Launch search from query param at start
launchSearchFromQueryString();
});
function getParameterByName(name) {
var url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)', 'i'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
function updateQueryString(key, value) {
value = encodeURIComponent(value);
var url = window.location.href;
var re = new RegExp('([?&])' + key + '=.*?(&|#|$)(.*)', 'gi'),
hash;
if (re.test(url)) {
if (typeof value !== 'undefined' && value !== null)
return url.replace(re, '$1' + key + '=' + value + '$2$3');
else {
hash = url.split('#');
url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, '');
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
url += '#' + hash[1];
return url;
}
}
else {
if (typeof value !== 'undefined' && value !== null) {
var separator = url.indexOf('?') !== -1 ? '&' : '?';
hash = url.split('#');
url = hash[0] + separator + key + '=' + value;
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
url += '#' + hash[1];
return url;
}
else
return url;
}
}
});
require(['gitbook', 'jquery'], function(gitbook, $) {
var SITES = {
'facebook': {
'label': 'Facebook',
'icon': 'fa fa-facebook',
'onClick': function(e) {
e.preventDefault();
window.open('http://www.facebook.com/sharer/sharer.php?s=100&p[url]='+encodeURIComponent(location.href));
}
},
'twitter': {
'label': 'Twitter',
'icon': 'fa fa-twitter',
'onClick': function(e) {
e.preventDefault();
window.open('http://twitter.com/home?status='+encodeURIComponent(document.title+' '+location.href));
}
},
'google': {
'label': 'Google+',
'icon': 'fa fa-google-plus',
'onClick': function(e) {
e.preventDefault();
window.open('https://plus.google.com/share?url='+encodeURIComponent(location.href));
}
},
'weibo': {
'label': 'Weibo',
'icon': 'fa fa-weibo',
'onClick': function(e) {
e.preventDefault();
window.open('http://service.weibo.com/share/share.php?content=utf-8&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title));
}
},
'instapaper': {
'label': 'Instapaper',
'icon': 'fa fa-instapaper',
'onClick': function(e) {
e.preventDefault();
window.open('http://www.instapaper.com/text?u='+encodeURIComponent(location.href));
}
},
'vk': {
'label': 'VK',
'icon': 'fa fa-vk',
'onClick': function(e) {
e.preventDefault();
window.open('http://vkontakte.ru/share.php?url='+encodeURIComponent(location.href));
}
}
};
gitbook.events.bind('start', function(e, config) {
var opts = config.sharing;
// Create dropdown menu
var menu = $.map(opts.all, function(id) {
var site = SITES[id];
return {
text: site.label,
onClick: site.onClick
};
});
// Create main button with dropdown
if (menu.length > 0) {
gitbook.toolbar.createButton({
icon: 'fa fa-share-alt',
label: 'Share',
position: 'right',
dropdown: [menu]
});
}
// Direct actions to share
$.each(SITES, function(sideId, site) {
if (!opts[sideId]) return;
gitbook.toolbar.createButton({
icon: site.icon,
label: site.text,
position: 'right',
onClick: site.onClick
});
});
});
});
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
## 三、单元测试
1. 【强制】好的单元测试必须遵守AIR原则。
<br><span style="color:orange">说明</span>:单元测试在线上运行时,感觉像空气(AIR)一样并不存在,但在测试质量的保障上,却是非常关键的。好的单元测试宏观上来说,具有自动化、独立性、可重复执行的特点。
- A:Automatic(自动化)
- I:Independent(独立性)
- R:Repeatable(可重复)
2. 【强制】单元测试应该是全自动执行的,并且非交互式的。测试用例通常是被定期执行的,执行过程必须完全自动化才有意义。输出结果需要人工检查的测试不是一个好的单元测试。单元测试中不准使用System.out来进行人肉验证,必须使用assert来验证。
3. 【强制】保持单元测试的独立性。为了保证单元测试稳定可靠且便于维护,单元测试用例之间决不能互相调用,也不能依赖执行的先后次序。 <br><span style="color:red">反例</span>:method2需要依赖method1的执行,将执行结果作为method2的输入。
4. 【强制】单元测试是可以重复执行的,不能受到外界环境的影响。
<br><span style="color:orange">说明</span>:单元测试通常会被放到持续集成中,每次有代码check in时单元测试都会被执行。如果单测对外部环境(网络、服务、中间件等)有依赖,容易导致持续集成机制的不可用。 <br><span style="color:green">正例</span>:为了不受外界环境影响,要求设计代码时就把SUT的依赖改成注入,在测试时用spring 这样的DI框架注入一个本地(内存)实现或者Mock实现。
5. 【强制】对于单元测试,要保证测试粒度足够小,有助于精确定位问题。单测粒度至多是类级别,一般是方法级别。
<br><span style="color:orange">说明</span>:只有测试粒度小才能在出错时尽快定位到出错位置。单测不负责检查跨类或者跨系统的交互逻辑,那是集成测试的领域。
6. 【强制】核心业务、核心应用、核心模块的增量代码确保单元测试通过。
<br><span style="color:orange">说明</span>:新增代码及时补充单元测试,如果新增代码影响了原有单元测试,请及时修正。
7. 【强制】单元测试代码必须写在如下工程目录:src/test/java,不允许写在业务代码目录下。
<br><span style="color:orange">说明</span>:源码构建时会跳过此目录,而单元测试框架默认是扫描此目录。
8. 【推荐】单元测试的基本目标:语句覆盖率达到70%;核心模块的语句覆盖率和分支覆盖率都要达到100%
<br><span style="color:orange">说明</span>:在工程规约的应用分层中提到的DAO层,Manager层,可重用度高的Service,都应该进行单元测试。
9. 【推荐】编写单元测试代码遵守BCDE原则,以保证被测试模块的交付质量。
- B:Border,边界值测试,包括循环边界、特殊取值、特殊时间点、数据顺序等。
- C:Correct,正确的输入,并得到预期的结果。
- D:Design,与设计文档相结合,来编写单元测试。
- E:Error,强制错误信息输入(如:非法数据、异常流程、非业务允许输入等),并得到预期的结果。
10. 【推荐】对于数据库相关的查询,更新,删除等操作,不能假设数据库里的数据是存在的,或者直接操作数据库把数据插入进去,请使用程序插入或者导入数据的方式来准备数据。 <br><span style="color:red">反例</span>:删除某一行数据的单元测试,在数据库中,先直接手动增加一行作为删除目标,但是这一行新增数据并不符合业务插入规则,导致测试结果异常。
11. 【推荐】和数据库相关的单元测试,可以设定自动回滚机制,不给数据库造成脏数据。或者对单元测试产生的数据有明确的前后缀标识。 <br><span style="color:green">正例</span>:在RDC内部单元测试中,使用RDC_UNIT_TEST_的前缀标识数据。
12. 【推荐】对于不可测的代码建议做必要的重构,使代码变得可测,避免为了达到测试要求而书写不规范测试代码。
13. 【推荐】在设计评审阶段,开发人员需要和测试人员一起确定单元测试范围,单元测试最好覆盖所有测试用例(UC)。
14. 【推荐】单元测试作为一种质量保障手段,不建议项目发布后补充单元测试用例,建议在项目提测前完成单元测试。
15. 【参考】为了更方便地进行单元测试,业务代码应避免以下情况:
- 构造方法中做的事情过多。
- 存在过多的全局变量和静态方法。
- 存在过多的外部依赖。
- 存在过多的条件语句。
<br><span style="color:orange">说明</span>:多层条件语句建议使用卫语句、策略模式、状态模式等方式重构。
16. 【参考】不要对单元测试存在如下误解:
- 那是测试同学干的事情。本文是开发手册,凡是本文内容都是与开发同学强相关的。
- 单元测试代码是多余的。汽车的整体功能与各单元部件的测试正常与否是强相关的。
- 单元测试代码不需要维护。一年半载后,那么单元测试几乎处于废弃状态。
- 单元测试与线上故障没有辩证关系。好的单元测试能够最大限度地规避线上故障。
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
## 附2:本手册专有名词
1. POJO(Plain Ordinary Java Object): 在本手册中,POJO专指只有setter / getter / toString的简单类,包括DO/DTO/BO/VO等。
2. GAV(GroupId、ArtifactctId、Version): Maven坐标,是用来唯一标识jar包。
3. OOP(Object Oriented Programming): 本手册泛指类、对象的编程处理方式。
4. ORM(Object Relation Mapping): 对象关系映射,对象领域模型与底层数据之间的转换,本文泛指iBATIS, mybatis等框架。
5. NPE(java.lang.NullPointerException): 空指针异常。
6. SOA(Service-Oriented Architecture): 面向服务架构,它可以根据需求通过网络对松散耦合的粗粒度应用组件进行分布式部署、组合和使用,有利于提升组件可重用性,可维护性。
7. 一方库: 本工程内部子项目模块依赖的库(jar包)。
8. 二方库: 公司内部发布到中央仓库,可供公司内部其它应用依赖的库(jar包)。
9. 三方库: 公司之外的开源库(jar包)。
10. IDE(Integrated Development Environment): 用于提供程序开发环境的应用程序,一般包括代码编辑器、编译器、调试器和图形用户界面等工具,本《手册》泛指IntelliJ IDEA和eclipse。
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册