├── .gitignore ├── pom.xml ├── src └── org │ └── algorithm │ ├── tree │ ├── TreeNode.java │ └── BinarySearchTree.java │ └── sorting │ ├── ArraysSortDemo.java │ ├── InsertionSortingDemo.java │ ├── ShellSortingDemo.java │ └── comparable │ └── StringComparisonDemo.java ├── README.md ├── test └── org │ └── algorithm │ └── tree │ └── BinarySearchTreeTest.java └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | algorithm-core-learning 7 | algorithm-core-learning 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | algorithm-core-learning 12 | 13 | 关于Java 数据结构与算法 学习积累的例子,是初学者及设计模式巩固的最佳实践。 14 | 15 | 16 | 17 | 18 | 19 | org.apache.maven.plugins 20 | maven-compiler-plugin 21 | 22 | 1.7 23 | 1.7 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/org/algorithm/tree/TreeNode.java: -------------------------------------------------------------------------------- 1 | package org.algorithm.tree; 2 | /* 3 | * Copyright [2015-2019] [泥瓦匠BYSocket] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * 节点 20 | */ 21 | class TreeNode { 22 | 23 | /** 24 | * 节点值 25 | */ 26 | int value; 27 | 28 | /** 29 | * 左节点 30 | */ 31 | TreeNode left; 32 | 33 | /** 34 | * 右节点 35 | */ 36 | TreeNode right; 37 | 38 | public TreeNode(int value) { 39 | this.value = value; 40 | left = null; 41 | right = null; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/org/algorithm/sorting/ArraysSortDemo.java: -------------------------------------------------------------------------------- 1 | package org.algorithm.sorting; 2 | 3 | import java.util.Arrays; 4 | 5 | /* 6 | * Copyright [2015-2019] [泥瓦匠BYSocket] 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | /** 22 | * Arrays.sort 排序案例 23 | *

24 | * Created by 泥瓦匠@bysocket.com on 19/5/28. 25 | */ 26 | public class ArraysSortDemo { 27 | 28 | public static void main(String[] args) { 29 | 30 | Integer[] intArr = new Integer[] {2, 3, 1, 4, 3}; 31 | 32 | System.out.println(Arrays.toString(intArr)); 33 | Arrays.sort(intArr); 34 | System.out.println(Arrays.toString(intArr)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 推荐工具: 2 | 3 | [微信公众号 Markdown 编辑器 - OpenWrite](https://md.openwrite.cn/):Markdown 微信编辑器是一款专业强大的微信公众平台在线编辑排版工具,提供手机预览功能,让用户在微信图文 、文章、内容排版、文本编辑、素材编辑上更加方便。 - [更多介绍](https://openwrite.cn/product-markdown) 4 | 5 | # 程序兵法:算法与数据结构 Java 快速教程 6 | 关于 Java 数据结构与算法 学习积累的例子,是初学者及设计模式巩固的最佳实践。 7 | 8 | ### 一、支持泥瓦匠 9 | 1. 拿起微信,关注公众号:「泥瓦匠BYSocket 」 10 | 2. 给教程的开源代码仓库点个 **Star** 吧 11 | * Github:[https://github.com/JeffLi1993/algorithm-core-learning](https://github.com/JeffLi1993/algorithm-core-learning) 12 | * Gitee:[https://gitee.com/jeff1993/algorithm-core-learning](https://gitee.com/jeff1993/algorithm-core-learning) 13 | 3. 帮忙分享该系列文章链接给更多的朋友 14 | 15 | 16 | ### 文章目录 17 | - [程序兵法: Java 源码的插入排序算法 (二)](https://www.bysocket.com/technique/%E7%AE%97%E6%B3%95/2369.html) 18 | - [程序兵法:Java String 源码的排序算法(一)](https://www.bysocket.com/technique/2334.html) 19 | - [图解:二叉搜索树算法(BST)](https://www.bysocket.com/technique/2337.html) 20 | 21 | ### 包目录: 22 | 23 | ├── org.algorithm.tree // 树的算法 24 | ├── org.algorithm.sorting // 排序算法 25 | │ 26 | 拼命更新!顶!d=====( ̄▽ ̄*)b 27 | 28 | 29 | ### 三、最后推荐 30 | 31 | - [我的博客](http://www.bysocket.com "我的博客"):分享学习可落地的技术博文 32 | - [我的GitHub](https://github.com/JeffLi1993 "我的GitHub"):Follow 下呗 33 | - [我的Gitee](https://gitee.com/jeff1993 "我的Gitee"):Follow 下呗 34 | - [Spring问答社区](http://www.spring4all.com/ "Spring问答社区"):如果您有什么问题,可以去这里发帖 35 | 36 | ### 四、我的公号 37 | 关注微信公众号,领取 Java 精选干货学习资料 38 | 39 | 40 | -------------------------------------------------------------------------------- /test/org/algorithm/tree/BinarySearchTreeTest.java: -------------------------------------------------------------------------------- 1 | package org.algorithm.tree; 2 | /* 3 | * Copyright [2015-2019] [Jeff Lee] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * 二叉搜索树(BST)测试案例 {@link BinarySearchTree} 20 | * 21 | * Created by bysocket on 16/7/10. 22 | */ 23 | public class BinarySearchTreeTest { 24 | 25 | public static void main(String[] args) { 26 | BinarySearchTree b = new BinarySearchTree(); 27 | b.insert(3);b.insert(8);b.insert(1);b.insert(4);b.insert(6); 28 | b.insert(2);b.insert(10);b.insert(9);b.insert(20);b.insert(25); 29 | 30 | // 打印二叉树 31 | b.toString(b.root); 32 | System.out.println(); 33 | 34 | // 是否存在节点值10 35 | TreeNode node01 = b.search(10); 36 | System.out.println("是否存在节点值为10 => " + node01.value); 37 | // 是否存在节点值11 38 | TreeNode node02 = b.search(11); 39 | System.out.println("是否存在节点值为11 => " + node02); 40 | 41 | // 删除节点8 42 | TreeNode node03 = b.delete(8); 43 | System.out.println("删除节点8 => " + node03.value); 44 | b.toString(b.root); 45 | 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/org/algorithm/sorting/InsertionSortingDemo.java: -------------------------------------------------------------------------------- 1 | package org.algorithm.sorting; 2 | 3 | import java.util.Arrays; 4 | 5 | /* 6 | * Copyright [2015-2019] [泥瓦匠BYSocket] 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | 22 | /** 23 | * 插入排序案例 24 | *

25 | * Created by 泥瓦匠@bysocket.com on 19/5/15. 26 | */ 27 | public class InsertionSortingDemo { 28 | 29 | /** 30 | * 插入排序 31 | * 32 | * @param arr 能比较的对象数组 33 | * @param 已排序的对象数组 34 | */ 35 | public static void insertionSort(T[] arr) { 36 | int j; 37 | 38 | // 从数组第二个元素开始,向前比较 39 | for (int p = 1; p < arr.length; p++) { 40 | T tmp = arr[p]; 41 | // 循环,向前依次比较 42 | // 如果比前面元素小,交换位置 43 | for (j = p; (j > 0) && (tmp.compareTo(arr[j - 1]) < 0); j--) { 44 | arr[j] = arr[j - 1]; 45 | } 46 | // 如果比前面元素大或者相等,那么这就是元素的位置,交换 47 | arr[j] = tmp; 48 | } 49 | } 50 | 51 | public static void main(String[] args) { 52 | Integer[] intArr = new Integer[] {2, 3, 1, 4, 3}; 53 | 54 | System.out.println(Arrays.toString(intArr)); 55 | insertionSort(intArr); 56 | System.out.println(Arrays.toString(intArr)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/org/algorithm/sorting/ShellSortingDemo.java: -------------------------------------------------------------------------------- 1 | package org.algorithm.sorting; 2 | 3 | /* 4 | * Copyright [2015-2019] [泥瓦匠BYSocket] 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | 20 | import java.util.Arrays; 21 | 22 | /** 23 | * 哈希排序案例 24 | *

25 | * Created by 泥瓦匠@bysocket.com on 19/5/21. 26 | */ 27 | public class ShellSortingDemo { 28 | 29 | /** 30 | * 哈希排序(二分插入排序) 31 | * 32 | * @param arr 能比较的对象数组 33 | * @param 已排序的对象数组 34 | */ 35 | public static void shellSort(T[] arr) { 36 | int j; 37 | 38 | for (int gap = arr.length / 2 ; gap > 0; gap /= 2) { 39 | // 从数组第 gap 个元素开始,向前比较 40 | for (int p = gap; p < arr.length; p++) { 41 | T tmp = arr[p]; 42 | // 循环,向前依次比较 43 | // 如果比前面元素小,交换位置 44 | for (j = p; (j >= gap) && (tmp.compareTo(arr[j - gap]) < 0); j-= gap) { 45 | arr[j] = arr[j - gap]; 46 | } 47 | // 如果比前面元素大或者相等,那么这就是元素的位置,交换 48 | arr[j] = tmp; 49 | } 50 | } 51 | } 52 | 53 | public static void main(String[] args) { 54 | Integer[] intArr = new Integer[] {2, 3, 1, 4, 3}; 55 | 56 | System.out.println(Arrays.toString(intArr)); 57 | shellSort(intArr); 58 | System.out.println(Arrays.toString(intArr)); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/org/algorithm/sorting/comparable/StringComparisonDemo.java: -------------------------------------------------------------------------------- 1 | package org.algorithm.sorting.comparable; 2 | 3 | /* 4 | * Copyright [2015-2019] [泥瓦匠BYSocket] 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | 20 | /** 21 | * 字符串比较案例 22 | * 23 | * Created by bysocket on 19/5/10. 24 | */ 25 | public class StringComparisonDemo { 26 | 27 | public static void main(String[] args) { 28 | String foo = "ABC"; 29 | 30 | // 前面和后面每个字符完全一样,返回 0 31 | String bar01 = "ABC"; 32 | System.out.println(foo.compareTo(bar01)); 33 | 34 | // 前面每个字符完全一样,返回:后面就是字符串长度差 35 | String bar02 = "ABCD"; 36 | String bar03 = "ABCDE"; 37 | System.out.println(foo.compareTo(bar02)); // -1 (前面相等,foo 长度小 1) 38 | System.out.println(foo.compareTo(bar03)); // -2 (前面相等,foo 长度小 2) 39 | 40 | // 前面每个字符不完全一样,返回:出现不一样的字符 ASCII 差 41 | String bar04 = "ABD"; 42 | String bar05 = "aABCD"; 43 | System.out.println(foo.compareTo(bar04)); // -1 (foo 的 'C' 字符 ASCII 码值为 67,bar04 的 'D' 字符 ASCII 码值为 68。返回 67 - 68 = -1) 44 | System.out.println(foo.compareTo(bar05)); // -32 (foo 的 'A' 字符 ASCII 码值为 65,bar04 的 'a' 字符 ASCII 码值为 97。返回 65 - 97 = -32) 45 | 46 | String bysocket01 = "泥瓦匠"; 47 | String bysocket02 = "瓦匠"; 48 | System.out.println(bysocket01.compareTo(bysocket02));// -2049 (泥 和 瓦的 Unicode 差值) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/org/algorithm/tree/BinarySearchTree.java: -------------------------------------------------------------------------------- 1 | package org.algorithm.tree; 2 | /* 3 | * Copyright [2015-2019] [泥瓦匠BYSocket] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * 二叉搜索树(BST)实现 20 | * 21 | * Created by bysocket on 16/7/7. 22 | */ 23 | public class BinarySearchTree { 24 | /** 25 | * 根节点 26 | */ 27 | public static TreeNode root; 28 | 29 | public BinarySearchTree() { 30 | this.root = null; 31 | } 32 | 33 | /** 34 | * 查找 35 | * 树深(N) O(lgN) 36 | * 1. 从root节点开始 37 | * 2. 比当前节点值小,则找其左节点 38 | * 3. 比当前节点值大,则找其右节点 39 | * 4. 与当前节点值相等,查找到返回TRUE 40 | * 5. 查找完毕未找到, 41 | * @param key 42 | * @return 43 | */ 44 | public TreeNode search (int key) { 45 | TreeNode current = root; 46 | while (current != null 47 | && key != current.value) { 48 | if (key < current.value ) 49 | current = current.left; 50 | else 51 | current = current.right; 52 | } 53 | return current; 54 | } 55 | 56 | /** 57 | * 插入 58 | * 1. 从root节点开始 59 | * 2. 如果root为空,root为插入值 60 | * 循环: 61 | * 3. 如果当前节点值大于插入值,找左节点 62 | * 4. 如果当前节点值小于插入值,找右节点 63 | * @param key 64 | * @return 65 | */ 66 | public TreeNode insert (int key) { 67 | // 新增节点 68 | TreeNode newNode = new TreeNode(key); 69 | // 当前节点 70 | TreeNode current = root; 71 | // 上个节点 72 | TreeNode parent = null; 73 | // 如果根节点为空 74 | if (current == null) { 75 | root = newNode; 76 | return newNode; 77 | } 78 | while (true) { 79 | parent = current; 80 | if (key < current.value) { 81 | current = current.left; 82 | if (current == null) { 83 | parent.left = newNode; 84 | return newNode; 85 | } 86 | } else { 87 | current = current.right; 88 | if (current == null) { 89 | parent.right = newNode; 90 | return newNode; 91 | } 92 | } 93 | } 94 | } 95 | 96 | /** 97 | * 删除节点 98 | * 1.找到删除节点 99 | * 2.如果删除节点左节点为空 , 右节点也为空; 100 | * 3.如果删除节点只有一个子节点 右节点 或者 左节点 101 | * 4.如果删除节点左右子节点都不为空 102 | * @param key 103 | * @return 104 | */ 105 | public TreeNode delete (int key) { 106 | TreeNode parent = root; 107 | TreeNode current = root; 108 | boolean isLeftChild = false; 109 | // 找到删除节点 及 是否在左子树 110 | while (current.value != key) { 111 | parent = current; 112 | if (current.value > key) { 113 | isLeftChild = true; 114 | current = current.left; 115 | } else { 116 | isLeftChild = false; 117 | current = current.right; 118 | } 119 | 120 | if (current == null) { 121 | return current; 122 | } 123 | } 124 | 125 | // 如果删除节点左节点为空 , 右节点也为空 126 | if (current.left == null && current.right == null) { 127 | if (current == root) { 128 | root = null; 129 | } 130 | // 在左子树 131 | if (isLeftChild == true) { 132 | parent.left = null; 133 | } else { 134 | parent.right = null; 135 | } 136 | } 137 | // 如果删除节点只有一个子节点 右节点 或者 左节点 138 | else if (current.right == null) { 139 | if (current == root) { 140 | root = current.left; 141 | } else if (isLeftChild) { 142 | parent.left = current.left; 143 | } else { 144 | parent.right = current.left; 145 | } 146 | 147 | } 148 | else if (current.left == null) { 149 | if (current == root) { 150 | root = current.right; 151 | } else if (isLeftChild) { 152 | parent.left = current.right; 153 | } else { 154 | parent.right = current.right; 155 | } 156 | } 157 | // 如果删除节点左右子节点都不为空 158 | else if (current.left != null && current.right != null) { 159 | // 找到删除节点的后继者 160 | TreeNode successor = getDeleteSuccessor(current); 161 | if (current == root) { 162 | root = successor; 163 | } else if (isLeftChild) { 164 | parent.left = successor; 165 | } else { 166 | parent.right = successor; 167 | } 168 | successor.left = current.left; 169 | } 170 | return current; 171 | } 172 | 173 | /** 174 | * 获取删除节点的后继者 175 | * 删除节点的后继者是在其右节点树种最小的节点 176 | * @param deleteNode 177 | * @return 178 | */ 179 | public TreeNode getDeleteSuccessor(TreeNode deleteNode) { 180 | // 后继者 181 | TreeNode successor = null; 182 | TreeNode successorParent = null; 183 | TreeNode current = deleteNode.right; 184 | 185 | while (current != null) { 186 | successorParent = successor; 187 | successor = current; 188 | current = current.left; 189 | } 190 | 191 | // 检查后继者(不可能有左节点树)是否有右节点树 192 | // 如果它有右节点树,则替换后继者位置,加到后继者父亲节点的左节点. 193 | if (successor != deleteNode.right) { 194 | successorParent.left = successor.right; 195 | successor.right = deleteNode.right; 196 | } 197 | 198 | return successor; 199 | } 200 | 201 | public void toString(TreeNode root) { 202 | if (root != null) { 203 | toString(root.left); 204 | System.out.print(" value = " + root.value); 205 | if (root.right != null ) { 206 | System.out.print(" -> "); 207 | } 208 | toString(root.right); 209 | } 210 | } 211 | } 212 | 213 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------