CodecComponent.java.html 147 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>CodecComponent.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> &gt; <a href="index.source.html" class="el_package">mtas.codec.util</a> &gt; <span class="el_source">CodecComponent.java</span></div><h1>CodecComponent.java</h1><pre class="source lang-java linenums"><span class="fc" id="L1">package mtas.codec.util;</span>

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.Base64.Decoder;
import java.util.Base64.Encoder;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import mtas.analysis.token.MtasToken;
import mtas.analysis.token.MtasTokenString;
import mtas.codec.util.CodecSearchTree.MtasTreeHit;
import mtas.codec.util.collector.MtasDataCollector;
import mtas.parser.function.MtasFunctionParser;
import mtas.parser.function.ParseException;
import mtas.parser.function.util.MtasFunctionParserFunction;
import mtas.parser.function.util.MtasFunctionParserFunctionDefault;
import mtas.search.spans.util.MtasSpanQuery;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.lucene.util.BytesRef;
import org.noggit.JSONParser;
import org.noggit.ObjectBuilder;

/**
 * The Class CodecComponent.
 */
/**
 * @author matthijs
 *
 */
public class CodecComponent {

  /**
   * Instantiates a new codec component.
   */
<span class="nc" id="L57">  private CodecComponent() {</span>
<span class="nc" id="L58">  }</span>

  /**
   * The Class ComponentFields.
   */
  public static class ComponentFields {

    /** The list. */
    public Map&lt;String, ComponentField&gt; list;

    /** The collection. */
    public List&lt;ComponentCollection&gt; collection;

    /** The do document. */
    public boolean doDocument;

    /** The do kwic. */
    public boolean doKwic;

    /** The do list. */
    public boolean doList;

    /** The do group. */
    public boolean doGroup;

    /** The do term vector. */
    public boolean doTermVector;

    /** The do stats. */
    public boolean doStats;

    /** The do stats spans. */
    public boolean doStatsSpans;

    /** The do stats positions. */
    public boolean doStatsPositions;

    /** The do stats tokens. */
    public boolean doStatsTokens;

    /** The do prefix. */
    public boolean doPrefix;

    /** The do facet. */
    public boolean doFacet;

    /** The do collection. */
    public boolean doCollection;

    /**
     * Instantiates a new component fields.
     */
<span class="fc" id="L110">    public ComponentFields() {</span>
<span class="fc" id="L111">      list = new HashMap&lt;&gt;();</span>
<span class="fc" id="L112">      collection = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L113">      doDocument = false;</span>
<span class="fc" id="L114">      doKwic = false;</span>
<span class="fc" id="L115">      doList = false;</span>
<span class="fc" id="L116">      doGroup = false;</span>
<span class="fc" id="L117">      doStats = false;</span>
<span class="fc" id="L118">      doTermVector = false;</span>
<span class="fc" id="L119">      doStatsSpans = false;</span>
<span class="fc" id="L120">      doStatsPositions = false;</span>
<span class="fc" id="L121">      doStatsTokens = false;</span>
<span class="fc" id="L122">      doPrefix = false;</span>
<span class="fc" id="L123">      doFacet = false;</span>
<span class="fc" id="L124">      doCollection = false;</span>
<span class="fc" id="L125">    }</span>
  }

  /**
   * The Interface BasicComponent.
   */
  public abstract static interface BasicComponent {
  }

  /**
   * The Class ComponentField.
   */
  public static class ComponentField implements BasicComponent {

    /** The unique key field. */
    public String uniqueKeyField;

    /** The document list. */
    public List&lt;ComponentDocument&gt; documentList;

    /** The kwic list. */
    public List&lt;ComponentKwic&gt; kwicList;

    /** The list list. */
    public List&lt;ComponentList&gt; listList;

    /** The group list. */
    public List&lt;ComponentGroup&gt; groupList;

    /** The facet list. */
    public List&lt;ComponentFacet&gt; facetList;

    /** The term vector list. */
    public List&lt;ComponentTermVector&gt; termVectorList;

    /** The stats position list. */
    public List&lt;ComponentPosition&gt; statsPositionList;

    /** The stats token list. */
    public List&lt;ComponentToken&gt; statsTokenList;

    /** The stats span list. */
    public List&lt;ComponentSpan&gt; statsSpanList;

    /** The span query list. */
    public List&lt;MtasSpanQuery&gt; spanQueryList;

    /** The prefix. */
    public ComponentPrefix prefix;

    /**
     * Instantiates a new component field.
     *
     * @param uniqueKeyField the unique key field
     */
<span class="fc" id="L180">    public ComponentField(String uniqueKeyField) {</span>
<span class="fc" id="L181">      this.uniqueKeyField = uniqueKeyField;</span>
      // initialise
<span class="fc" id="L183">      documentList = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L184">      kwicList = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L185">      listList = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L186">      groupList = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L187">      facetList = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L188">      termVectorList = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L189">      statsPositionList = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L190">      statsTokenList = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L191">      statsSpanList = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L192">      spanQueryList = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L193">      prefix = null;</span>
<span class="fc" id="L194">    }</span>
  }

  /**
   * The Class ComponentPrefix.
   */
  public static class ComponentPrefix implements BasicComponent {

    /** The key. */
    public String key;

    /** The single position list. */
    public SortedSet&lt;String&gt; singlePositionList;

    /** The multiple position list. */
    public SortedSet&lt;String&gt; multiplePositionList;

    /** The set position list. */
    public SortedSet&lt;String&gt; setPositionList;

    /** The intersecting list. */
    public SortedSet&lt;String&gt; intersectingList;

    /**
     * Instantiates a new component prefix.
     *
     * @param key the key
     */
<span class="fc" id="L222">    public ComponentPrefix(String key) {</span>
<span class="fc" id="L223">      this.key = key;</span>
<span class="fc" id="L224">      singlePositionList = new TreeSet&lt;&gt;();</span>
<span class="fc" id="L225">      multiplePositionList = new TreeSet&lt;&gt;();</span>
<span class="fc" id="L226">      setPositionList = new TreeSet&lt;&gt;();</span>
<span class="fc" id="L227">      intersectingList = new TreeSet&lt;&gt;();</span>
<span class="fc" id="L228">    }</span>

    /**
     * Adds the single position.
     *
     * @param prefix the prefix
     */
    public void addSinglePosition(String prefix) {
<span class="pc bpc" id="L236" title="1 of 4 branches missed.">      if (!prefix.trim().isEmpty() &amp;&amp; !singlePositionList.contains(prefix)</span>
<span class="pc bpc" id="L237" title="1 of 2 branches missed.">          &amp;&amp; !multiplePositionList.contains(prefix)) {</span>
<span class="fc" id="L238">        singlePositionList.add(prefix);</span>
      }
<span class="fc" id="L240">    }</span>

    /**
     * Adds the multiple position.
     *
     * @param prefix the prefix
     */
    public void addMultiplePosition(String prefix) {
<span class="pc bpc" id="L248" title="1 of 2 branches missed.">      if (!prefix.trim().isEmpty()) {</span>
<span class="pc bpc" id="L249" title="1 of 2 branches missed.">        if (!singlePositionList.contains(prefix)) {</span>
<span class="fc bfc" id="L250" title="All 2 branches covered.">          if (!multiplePositionList.contains(prefix)) {</span>
<span class="fc" id="L251">            multiplePositionList.add(prefix);</span>
          }
<span class="fc" id="L253">        } else {</span>
<span class="nc" id="L254">          singlePositionList.remove(prefix);</span>
<span class="nc" id="L255">          multiplePositionList.add(prefix);</span>
        }
      }
<span class="fc" id="L258">    }</span>

    /**
     * Adds the set position.
     *
     * @param prefix the prefix
     */
    public void addSetPosition(String prefix) {
<span class="pc bpc" id="L266" title="1 of 2 branches missed.">      if (!prefix.trim().isEmpty()) {</span>
<span class="pc bpc" id="L267" title="1 of 2 branches missed.">        if (!singlePositionList.contains(prefix)) {</span>
<span class="fc bfc" id="L268" title="All 2 branches covered.">          if (!setPositionList.contains(prefix)) {</span>
<span class="fc" id="L269">            setPositionList.add(prefix);</span>
          }
<span class="fc" id="L271">        } else {</span>
<span class="nc" id="L272">          singlePositionList.remove(prefix);</span>
<span class="nc" id="L273">          setPositionList.add(prefix);</span>
        }
      }
<span class="fc" id="L276">    }</span>

    /**
     * Adds the intersecting.
     *
     * @param prefix the prefix
     */
    public void addIntersecting(String prefix) {
<span class="pc bpc" id="L284" title="1 of 2 branches missed.">      if (!prefix.trim().isEmpty()) {</span>
<span class="fc" id="L285">        intersectingList.add(prefix);</span>
      }
<span class="fc" id="L287">    }</span>

  }

  /**
   * The Class ComponentDocument.
   */
  public static class ComponentDocument implements BasicComponent {

    /** The key. */
    public String key;

    /** The prefix. */
    public String prefix;

    /** The regexp. */
    public String regexp;

    /** The ignore regexp. */
    public String ignoreRegexp;

    /** The list. */
    public Set&lt;String&gt; list;

    /** The ignore list. */
    public Set&lt;String&gt; ignoreList;

    /** The list regexp. */
    public boolean listRegexp;

    /** The list expand. */
    public boolean listExpand;

    /** The ignore list regexp. */
    public boolean ignoreListRegexp;

    /** The list expand number. */
    public int listExpandNumber;

    /** The data type. */
    public String dataType;

    /** The stats type. */
    public String statsType;

    /** The stats items. */
    public SortedSet&lt;String&gt; statsItems;

    /** The list number. */
    public int listNumber;

    /** The unique key. */
    public Map&lt;Integer, String&gt; uniqueKey;

    /** The stats data. */
    public Map&lt;Integer, MtasDataCollector&lt;?, ?&gt;&gt; statsData;

    /** The stats list. */
    public Map&lt;Integer, MtasDataCollector&lt;?, ?&gt;&gt; statsList;

    /**
     * Instantiates a new component document.
     *
     * @param key the key
     * @param prefix the prefix
     * @param statsType the stats type
     * @param regexp the regexp
     * @param list the list
     * @param listNumber the list number
     * @param listRegexp the list regexp
     * @param listExpand the list expand
     * @param listExpandNumber the list expand number
     * @param ignoreRegexp the ignore regexp
     * @param ignoreList the ignore list
     * @param ignoreListRegexp the ignore list regexp
     * @throws IOException Signals that an I/O exception has occurred.
     */
<span class="nc" id="L364">    public ComponentDocument(String key, String prefix, String statsType,</span>
        String regexp, String[] list, int listNumber, Boolean listRegexp,
        Boolean listExpand, int listExpandNumber, String ignoreRegexp,
        String[] ignoreList, Boolean ignoreListRegexp) throws IOException {
<span class="nc" id="L368">      this.key = key;</span>
<span class="nc" id="L369">      this.prefix = prefix;</span>
<span class="nc" id="L370">      this.regexp = regexp;</span>
<span class="nc bnc" id="L371" title="All 4 branches missed.">      if (list != null &amp;&amp; list.length &gt; 0) {</span>
<span class="nc" id="L372">        this.list = new HashSet&lt;&gt;(Arrays.asList(list));</span>
<span class="nc bnc" id="L373" title="All 2 branches missed.">        this.listRegexp = listRegexp != null ? listRegexp : false;</span>
<span class="nc bnc" id="L374" title="All 4 branches missed.">        this.listExpand = (listExpand != null &amp;&amp; listExpandNumber &gt; 0)</span>
<span class="nc" id="L375">            ? listExpand : false;</span>
<span class="nc bnc" id="L376" title="All 2 branches missed.">        if (this.listExpand) {</span>
<span class="nc" id="L377">          this.listExpandNumber = listExpandNumber;</span>
<span class="nc" id="L378">        } else {</span>
<span class="nc" id="L379">          this.listExpandNumber = 0;</span>
        }
<span class="nc" id="L381">      } else {</span>
<span class="nc" id="L382">        this.list = null;</span>
<span class="nc" id="L383">        this.listRegexp = false;</span>
<span class="nc" id="L384">        this.listExpand = false;</span>
<span class="nc" id="L385">        this.listExpandNumber = 0;</span>
      }
<span class="nc" id="L387">      this.ignoreRegexp = ignoreRegexp;</span>
<span class="nc bnc" id="L388" title="All 4 branches missed.">      if (ignoreList != null &amp;&amp; ignoreList.length &gt; 0) {</span>
<span class="nc" id="L389">        this.ignoreList = new HashSet&lt;&gt;(Arrays.asList(ignoreList));</span>
<span class="nc bnc" id="L390" title="All 2 branches missed.">        this.ignoreListRegexp = ignoreListRegexp != null ? ignoreListRegexp</span>
<span class="nc" id="L391">            : false;</span>
<span class="nc" id="L392">      } else {</span>
<span class="nc" id="L393">        this.ignoreList = null;</span>
<span class="nc" id="L394">        this.ignoreListRegexp = false;</span>
      }
<span class="nc" id="L396">      this.listNumber = listNumber;</span>
<span class="nc" id="L397">      uniqueKey = new HashMap&lt;&gt;();</span>
<span class="nc" id="L398">      dataType = CodecUtil.DATA_TYPE_LONG;</span>
<span class="nc" id="L399">      statsItems = CodecUtil.createStatsItems(statsType);</span>
<span class="nc" id="L400">      this.statsType = CodecUtil.createStatsType(statsItems, null, null);</span>
<span class="nc" id="L401">      this.statsData = new HashMap&lt;&gt;();</span>
<span class="nc bnc" id="L402" title="All 2 branches missed.">      if (this.listNumber &gt; 0) {</span>
<span class="nc" id="L403">        this.statsList = new HashMap&lt;&gt;();</span>
<span class="nc" id="L404">      } else {</span>
<span class="nc" id="L405">        this.statsList = null;</span>
      }
<span class="nc" id="L407">    }</span>
  }

  /**
   * The Class ComponentKwic.
   */
  public static class ComponentKwic implements BasicComponent {

    /** The query. */
    public MtasSpanQuery query;

    /** The key. */
    public String key;

    /** The tokens. */
    public Map&lt;Integer, List&lt;KwicToken&gt;&gt; tokens;

    /** The hits. */
    public Map&lt;Integer, List&lt;KwicHit&gt;&gt; hits;

    /** The unique key. */
    public Map&lt;Integer, String&gt; uniqueKey;

    /** The sub total. */
    public Map&lt;Integer, Integer&gt; subTotal;

    /** The min position. */
    public Map&lt;Integer, Integer&gt; minPosition;

    /** The max position. */
    public Map&lt;Integer, Integer&gt; maxPosition;

    /** The prefixes. */
    public List&lt;String&gt; prefixes;

    /** The left. */
    public int left;

    /** The right. */
    public int right;

    /** The start. */
    public int start;

    /** The number. */
    public Integer number;

    /** The output. */
    public String output;

    /** The Constant KWIC_OUTPUT_TOKEN. */
    public static final String KWIC_OUTPUT_TOKEN = &quot;token&quot;;

    /** The Constant KWIC_OUTPUT_HIT. */
    public static final String KWIC_OUTPUT_HIT = &quot;hit&quot;;

    /**
     * Instantiates a new component kwic.
     *
     * @param query the query
     * @param key the key
     * @param prefixes the prefixes
     * @param number the number
     * @param start the start
     * @param left the left
     * @param right the right
     * @param output the output
     * @throws IOException Signals that an I/O exception has occurred.
     */
<span class="nc" id="L476">    public ComponentKwic(MtasSpanQuery query, String key, String prefixes,</span>
        Integer number, int start, int left, int right, String output)
        throws IOException {
<span class="nc" id="L479">      this.query = query;</span>
<span class="nc" id="L480">      this.key = key;</span>
<span class="nc bnc" id="L481" title="All 2 branches missed.">      this.left = (left &gt; 0) ? left : 0;</span>
<span class="nc bnc" id="L482" title="All 2 branches missed.">      this.right = (right &gt; 0) ? right : 0;</span>
<span class="nc bnc" id="L483" title="All 2 branches missed.">      this.start = (start &gt; 0) ? start : 0;</span>
<span class="nc bnc" id="L484" title="All 4 branches missed.">      this.number = (number != null &amp;&amp; number &gt;= 0) ? number : null;</span>
<span class="nc" id="L485">      this.output = output;</span>
<span class="nc" id="L486">      tokens = new HashMap&lt;&gt;();</span>
<span class="nc" id="L487">      hits = new HashMap&lt;&gt;();</span>
<span class="nc" id="L488">      uniqueKey = new HashMap&lt;&gt;();</span>
<span class="nc" id="L489">      subTotal = new HashMap&lt;&gt;();</span>
<span class="nc" id="L490">      minPosition = new HashMap&lt;&gt;();</span>
<span class="nc" id="L491">      maxPosition = new HashMap&lt;&gt;();</span>
<span class="nc" id="L492">      this.prefixes = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L493" title="All 4 branches missed.">      if ((prefixes != null) &amp;&amp; (prefixes.trim().length() &gt; 0)) {</span>
<span class="nc" id="L494">        List&lt;String&gt; l = Arrays.asList(prefixes.split(Pattern.quote(&quot;,&quot;)));</span>
<span class="nc bnc" id="L495" title="All 2 branches missed.">        for (String ls : l) {</span>
<span class="nc bnc" id="L496" title="All 2 branches missed.">          if (ls.trim().length() &gt; 0) {</span>
<span class="nc" id="L497">            this.prefixes.add(ls.trim());</span>
          }
        }
      }
<span class="nc bnc" id="L501" title="All 2 branches missed.">      if (this.output == null) {</span>
<span class="nc bnc" id="L502" title="All 2 branches missed.">        if (!this.prefixes.isEmpty()) {</span>
<span class="nc" id="L503">          this.output = ComponentKwic.KWIC_OUTPUT_HIT;</span>
<span class="nc" id="L504">        } else {</span>
<span class="nc" id="L505">          this.output = ComponentKwic.KWIC_OUTPUT_TOKEN;</span>
        }
<span class="nc bnc" id="L507" title="All 2 branches missed.">      } else if (!this.output.equals(ComponentKwic.KWIC_OUTPUT_HIT)</span>
<span class="nc bnc" id="L508" title="All 2 branches missed.">          &amp;&amp; !this.output.equals(ComponentKwic.KWIC_OUTPUT_TOKEN)) {</span>
<span class="nc" id="L509">        throw new IOException(&quot;unrecognized output '&quot; + this.output + &quot;'&quot;);</span>
      }
<span class="nc" id="L511">    }</span>
  }

  /**
   * The Class ComponentList.
   */
  public static class ComponentList implements BasicComponent {

    /** The span query. */
    public MtasSpanQuery spanQuery;

    /** The field. */
    public String field;

    /** The query value. */
    public String queryValue;

    /** The query type. */
    public String queryType;

    /** The query prefix. */
    public String queryPrefix;

    /** The query ignore. */
    public String queryIgnore;

    /** The query maximum ignore length. */
    public String queryMaximumIgnoreLength;

    /** The key. */
    public String key;

    /** The query variables. */
    public Map&lt;String, String[]&gt; queryVariables;

    /** The tokens. */
    public List&lt;ListToken&gt; tokens;

    /** The hits. */
    public List&lt;ListHit&gt; hits;

    /** The unique key. */
    public Map&lt;Integer, String&gt; uniqueKey;

    /** The sub total. */
    public Map&lt;Integer, Integer&gt; subTotal;

    /** The min position. */
    public Map&lt;Integer, Integer&gt; minPosition;

    /** The max position. */
    public Map&lt;Integer, Integer&gt; maxPosition;

    /** The prefixes. */
    public List&lt;String&gt; prefixes;

    /** The left. */
    public int left;

    /** The right. */
    public int right;

    /** The total. */
    public int total;

    /** The position. */
    public int position;

    /** The start. */
    public int start;

    /** The number. */
    public int number;

    /** The prefix. */
    public String prefix;

    /** The output. */
    public String output;

    /** The Constant LIST_OUTPUT_TOKEN. */
    public static final String LIST_OUTPUT_TOKEN = &quot;token&quot;;

    /** The Constant LIST_OUTPUT_HIT. */
    public static final String LIST_OUTPUT_HIT = &quot;hit&quot;;

    /**
     * Instantiates a new component list.
     *
     * @param spanQuery the span query
     * @param field the field
     * @param queryValue the query value
     * @param queryType the query type
     * @param queryPrefix the query prefix
     * @param queryVariables the query variables
     * @param queryIgnore the query ignore
     * @param queryMaximumIgnoreLength the query maximum ignore length
     * @param key the key
     * @param prefix the prefix
     * @param start the start
     * @param number the number
     * @param left the left
     * @param right the right
     * @param output the output
     * @throws IOException Signals that an I/O exception has occurred.
     */
<span class="nc" id="L617">    public ComponentList(MtasSpanQuery spanQuery, String field,</span>
        String queryValue, String queryType, String queryPrefix,
        Map&lt;String, String[]&gt; queryVariables, String queryIgnore,
        String queryMaximumIgnoreLength, String key, String prefix, int start,
        int number, int left, int right, String output) throws IOException {
<span class="nc" id="L622">      this.spanQuery = spanQuery;</span>
<span class="nc" id="L623">      this.field = field;</span>
<span class="nc" id="L624">      this.queryValue = queryValue;</span>
<span class="nc" id="L625">      this.queryType = queryType;</span>
<span class="nc" id="L626">      this.queryPrefix = queryPrefix;</span>
<span class="nc" id="L627">      this.queryIgnore = queryIgnore;</span>
<span class="nc" id="L628">      this.queryMaximumIgnoreLength = queryMaximumIgnoreLength;</span>
<span class="nc" id="L629">      this.queryVariables = queryVariables;</span>
<span class="nc" id="L630">      this.key = key;</span>
<span class="nc" id="L631">      this.left = left;</span>
<span class="nc" id="L632">      this.right = right;</span>
<span class="nc" id="L633">      this.start = start;</span>
<span class="nc" id="L634">      this.number = number;</span>
<span class="nc" id="L635">      this.output = output;</span>
<span class="nc" id="L636">      this.prefix = prefix;</span>
<span class="nc" id="L637">      total = 0;</span>
<span class="nc" id="L638">      position = 0;</span>
<span class="nc" id="L639">      tokens = new ArrayList&lt;&gt;();</span>
<span class="nc" id="L640">      hits = new ArrayList&lt;&gt;();</span>
<span class="nc" id="L641">      uniqueKey = new HashMap&lt;&gt;();</span>
<span class="nc" id="L642">      subTotal = new HashMap&lt;&gt;();</span>
<span class="nc" id="L643">      minPosition = new HashMap&lt;&gt;();</span>
<span class="nc" id="L644">      maxPosition = new HashMap&lt;&gt;();</span>
<span class="nc" id="L645">      this.prefixes = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L646" title="All 4 branches missed.">      if ((prefix != null) &amp;&amp; (prefix.trim().length() &gt; 0)) {</span>
<span class="nc" id="L647">        List&lt;String&gt; l = Arrays.asList(prefix.split(Pattern.quote(&quot;,&quot;)));</span>
<span class="nc bnc" id="L648" title="All 2 branches missed.">        for (String ls : l) {</span>
<span class="nc bnc" id="L649" title="All 2 branches missed.">          if (ls.trim().length() &gt; 0) {</span>
<span class="nc" id="L650">            this.prefixes.add(ls.trim());</span>
          }
        }
      }
      // check output
<span class="nc bnc" id="L655" title="All 2 branches missed.">      if (this.output == null) {</span>
<span class="nc bnc" id="L656" title="All 2 branches missed.">        if (!this.prefixes.isEmpty()) {</span>
<span class="nc" id="L657">          this.output = ComponentList.LIST_OUTPUT_HIT;</span>
<span class="nc" id="L658">        } else {</span>
<span class="nc" id="L659">          this.output = ComponentList.LIST_OUTPUT_TOKEN;</span>
        }
<span class="nc bnc" id="L661" title="All 2 branches missed.">      } else if (!this.output.equals(ComponentList.LIST_OUTPUT_HIT)</span>
<span class="nc bnc" id="L662" title="All 2 branches missed.">          &amp;&amp; !this.output.equals(ComponentList.LIST_OUTPUT_TOKEN)) {</span>
<span class="nc" id="L663">        throw new IOException(&quot;unrecognized output '&quot; + this.output + &quot;'&quot;);</span>
      }
<span class="nc" id="L665">    }</span>
  }

  /**
   * The Class ComponentGroup.
   */
  public static class ComponentGroup implements BasicComponent {

    /** The span query. */
    public MtasSpanQuery spanQuery;

    /** The data type. */
    public String dataType;

    /** The stats type. */
    public String statsType;

    /** The sort type. */
    public String sortType;

    /** The sort direction. */
    public String sortDirection;

    /** The stats items. */
    public SortedSet&lt;String&gt; statsItems;

    /** The start. */
    public Integer start;

    /** The number. */
    public Integer number;

    /** The key. */
    public String key;

    /** The data collector. */
    public MtasDataCollector&lt;?, ?&gt; dataCollector;

    /** The prefixes. */
    ArrayList&lt;String&gt; prefixes;

    /** The hit inside. */
    HashSet&lt;String&gt; hitInside;

    /** The hit inside left. */
    HashSet&lt;String&gt;[] hitInsideLeft;

    /** The hit inside right. */
    HashSet&lt;String&gt;[] hitInsideRight;

    /** The hit left. */
    HashSet&lt;String&gt;[] hitLeft;

    /** The hit right. */
    HashSet&lt;String&gt;[] hitRight;

    /** The left. */
    HashSet&lt;String&gt;[] left;

    /** The right. */
    HashSet&lt;String&gt;[] right;

    /**
     * Instantiates a new component group.
     *
     * @param spanQuery the span query
     * @param key the key
     * @param number the number
     * @param start the start
     * @param groupingHitInsidePrefixes the grouping hit inside prefixes
     * @param groupingHitInsideLeftPosition the grouping hit inside left position
     * @param groupingHitInsideLeftPrefixes the grouping hit inside left prefixes
     * @param groupingHitInsideRightPosition the grouping hit inside right position
     * @param groupingHitInsideRightPrefixes the grouping hit inside right prefixes
     * @param groupingHitLeftPosition the grouping hit left position
     * @param groupingHitLeftPrefixes the grouping hit left prefixes
     * @param groupingHitRightPosition the grouping hit right position
     * @param groupingHitRightPrefixes the grouping hit right prefixes
     * @param groupingLeftPosition the grouping left position
     * @param groupingLeftPrefixes the grouping left prefixes
     * @param groupingRightPosition the grouping right position
     * @param groupingRightPrefixes the grouping right prefixes
     * @throws IOException Signals that an I/O exception has occurred.
     */
<span class="fc" id="L749">    public ComponentGroup(MtasSpanQuery spanQuery, String key, int number,</span>
        int start, String groupingHitInsidePrefixes,
        String[] groupingHitInsideLeftPosition,
        String[] groupingHitInsideLeftPrefixes,
        String[] groupingHitInsideRightPosition,
        String[] groupingHitInsideRightPrefixes,
        String[] groupingHitLeftPosition, String[] groupingHitLeftPrefixes,
        String[] groupingHitRightPosition, String[] groupingHitRightPrefixes,
        String[] groupingLeftPosition, String[] groupingLeftPrefixes,
        String[] groupingRightPosition, String[] groupingRightPrefixes)
        throws IOException {
<span class="fc" id="L760">      this.spanQuery = spanQuery;</span>
<span class="fc" id="L761">      this.key = key;</span>
<span class="fc" id="L762">      this.dataType = CodecUtil.DATA_TYPE_LONG;</span>
<span class="fc" id="L763">      this.sortType = CodecUtil.STATS_TYPE_SUM;</span>
<span class="fc" id="L764">      this.sortDirection = CodecUtil.SORT_DESC;</span>
<span class="fc" id="L765">      this.statsItems = CodecUtil.createStatsItems(&quot;n,sum,mean&quot;);</span>
<span class="fc" id="L766">      this.statsType = CodecUtil.createStatsType(this.statsItems, this.sortType,</span>
<span class="fc" id="L767">          null);</span>
<span class="fc" id="L768">      this.start = start;</span>
<span class="fc" id="L769">      this.number = number;</span>
<span class="fc" id="L770">      HashSet&lt;String&gt; tmpPrefixes = new HashSet&lt;&gt;();</span>
      // analyze grouping condition
<span class="fc bfc" id="L772" title="All 2 branches covered.">      if (groupingHitInsidePrefixes != null) {</span>
<span class="fc" id="L773">        hitInside = new HashSet&lt;&gt;();</span>
<span class="fc" id="L774">        String[] tmpList = groupingHitInsidePrefixes.split(&quot;,&quot;);</span>
<span class="fc bfc" id="L775" title="All 2 branches covered.">        for (String tmpItem : tmpList) {</span>
<span class="pc bpc" id="L776" title="1 of 2 branches missed.">          if (!tmpItem.trim().isEmpty()) {</span>
<span class="fc" id="L777">            hitInside.add(tmpItem.trim());</span>
          }
        }
<span class="fc" id="L780">        tmpPrefixes.addAll(hitInside);</span>
<span class="fc" id="L781">      } else {</span>
<span class="fc" id="L782">        hitInside = null;</span>
      }
<span class="fc" id="L784">      hitInsideLeft = createPositionedPrefixes(tmpPrefixes,</span>
<span class="fc" id="L785">          groupingHitInsideLeftPosition, groupingHitInsideLeftPrefixes);</span>
<span class="fc" id="L786">      hitInsideRight = createPositionedPrefixes(tmpPrefixes,</span>
<span class="fc" id="L787">          groupingHitInsideRightPosition, groupingHitInsideRightPrefixes);</span>
<span class="fc" id="L788">      hitLeft = createPositionedPrefixes(tmpPrefixes, groupingHitLeftPosition,</span>
<span class="fc" id="L789">          groupingHitLeftPrefixes);</span>
<span class="fc" id="L790">      hitRight = createPositionedPrefixes(tmpPrefixes, groupingHitRightPosition,</span>
<span class="fc" id="L791">          groupingHitRightPrefixes);</span>
<span class="fc" id="L792">      left = createPositionedPrefixes(tmpPrefixes, groupingLeftPosition,</span>
<span class="fc" id="L793">          groupingLeftPrefixes);</span>
<span class="fc" id="L794">      right = createPositionedPrefixes(tmpPrefixes, groupingRightPosition,</span>
<span class="fc" id="L795">          groupingRightPrefixes);</span>
<span class="fc" id="L796">      prefixes = new ArrayList&lt;&gt;(tmpPrefixes);</span>
      // datacollector
<span class="fc" id="L798">      dataCollector = DataCollector.getCollector(</span>
<span class="fc" id="L799">          DataCollector.COLLECTOR_TYPE_LIST, this.dataType, this.statsType,</span>
<span class="fc" id="L800">          this.statsItems, this.sortType, this.sortDirection, this.start,</span>
<span class="fc" id="L801">          this.number, null, null);</span>
<span class="fc" id="L802">    }</span>

    /**
     * Creates the positioned prefixes.
     *
     * @param prefixList the prefix list
     * @param position the position
     * @param prefixes the prefixes
     * @return the hash set[]
     * @throws IOException Signals that an I/O exception has occurred.
     */
    private static HashSet&lt;String&gt;[] createPositionedPrefixes(
        HashSet&lt;String&gt; prefixList, String[] position, String[] prefixes)
        throws IOException {
<span class="fc" id="L816">      Pattern p = Pattern.compile(&quot;^([0-9]+)(\\-([0-9]+))?$&quot;);</span>
      Matcher m;
<span class="pc bpc" id="L818" title="1 of 4 branches missed.">      if (position == null &amp;&amp; prefixes == null) {</span>
<span class="fc" id="L819">        return null;</span>
<span class="pc bpc" id="L820" title="2 of 4 branches missed.">      } else if (prefixes == null || position == null</span>
<span class="pc bpc" id="L821" title="1 of 2 branches missed.">          || position.length != prefixes.length) {</span>
<span class="nc" id="L822">        throw new IOException(&quot;incorrect position/prefixes&quot;);</span>
<span class="fc bfc" id="L823" title="All 2 branches covered.">      } else if (position.length == 0) {</span>
<span class="fc" id="L824">        return null;</span>
      } else {
        // analyze positions
<span class="fc" id="L827">        int[][] tmpPosition = new int[position.length][];</span>
<span class="fc" id="L828">        int maxPosition = -1;</span>
<span class="fc bfc" id="L829" title="All 2 branches covered.">        for (int i = 0; i &lt; position.length; i++) {</span>
<span class="fc" id="L830">          m = p.matcher(position[i]);</span>
<span class="pc bpc" id="L831" title="1 of 2 branches missed.">          if (m.find()) {</span>
<span class="fc bfc" id="L832" title="All 2 branches covered.">            if (m.group(3) == null) {</span>
<span class="fc" id="L833">              int start = Integer.parseInt(m.group(1));</span>
<span class="fc" id="L834">              tmpPosition[i] = new int[] { start };</span>
<span class="fc" id="L835">              maxPosition = Math.max(maxPosition, start);</span>
<span class="fc" id="L836">            } else {</span>
<span class="fc" id="L837">              int start = Integer.parseInt(m.group(1));</span>
<span class="fc" id="L838">              int end = Integer.parseInt(m.group(3));</span>
<span class="pc bpc" id="L839" title="1 of 2 branches missed.">              if (start &gt; end) {</span>
<span class="nc" id="L840">                throw new IOException(&quot;incorrect position &quot; + position[i]);</span>
              } else {
<span class="fc" id="L842">                tmpPosition[i] = new int[end - start + 1];</span>
<span class="fc bfc" id="L843" title="All 2 branches covered.">                for (int t = start; t &lt;= end; t++)</span>
<span class="fc" id="L844">                  tmpPosition[i][t - start] = t;</span>
<span class="fc" id="L845">                maxPosition = Math.max(maxPosition, end);</span>
              }
            }
<span class="fc" id="L848">          } else {</span>
<span class="nc" id="L849">            throw new IOException(&quot;incorrect position &quot; + position[i]);</span>
          }
        }
        @SuppressWarnings(&quot;unchecked&quot;)
<span class="fc" id="L853">        HashSet&lt;String&gt;[] result = new HashSet[maxPosition + 1];</span>
<span class="fc" id="L854">        Arrays.fill(result, null);</span>
        List&lt;String&gt; tmpPrefixList;
        String[] tmpList;
<span class="fc bfc" id="L857" title="All 2 branches covered.">        for (int i = 0; i &lt; tmpPosition.length; i++) {</span>
<span class="fc" id="L858">          tmpList = prefixes[i].split(&quot;,&quot;);</span>
<span class="fc" id="L859">          tmpPrefixList = new ArrayList&lt;&gt;();</span>
<span class="fc bfc" id="L860" title="All 2 branches covered.">          for (String tmpItem : tmpList) {</span>
<span class="pc bpc" id="L861" title="1 of 2 branches missed.">            if (!tmpItem.trim().isEmpty()) {</span>
<span class="fc" id="L862">              tmpPrefixList.add(tmpItem.trim());</span>
            }
          }
<span class="pc bpc" id="L865" title="1 of 2 branches missed.">          if (tmpPrefixList.isEmpty()) {</span>
<span class="nc" id="L866">            throw new IOException(&quot;incorrect prefixes &quot; + prefixes[i]);</span>
          }
<span class="fc bfc" id="L868" title="All 2 branches covered.">          for (int t = 0; t &lt; tmpPosition[i].length; t++) {</span>
<span class="fc bfc" id="L869" title="All 2 branches covered.">            if (result[tmpPosition[i][t]] == null) {</span>
<span class="fc" id="L870">              result[tmpPosition[i][t]] = new HashSet&lt;&gt;();</span>
            }
<span class="fc" id="L872">            result[tmpPosition[i][t]].addAll(tmpPrefixList);</span>
          }
<span class="fc" id="L874">          prefixList.addAll(tmpPrefixList);</span>
        }
<span class="fc" id="L876">        return result;</span>
      }
    }

  }

  /**
   * The Class ComponentFacet.
   */
  public static class ComponentFacet implements BasicComponent {

    /** The span queries. */
    public MtasSpanQuery[] spanQueries;

    /** The base fields. */
    public String[] baseFields;

    /** The base field types. */
    public String[] baseFieldTypes;

    /** The base types. */
    public String[] baseTypes;

    /** The base sort types. */
    public String[] baseSortTypes;

    /** The base sort directions. */
    public String[] baseSortDirections;

    /** The base range sizes. */
    public Double[] baseRangeSizes;

    /** The base range bases. */
    public Double[] baseRangeBases;

    /** The base collector types. */
    public String[] baseCollectorTypes;

    /** The base data types. */
    public String[] baseDataTypes;

    /** The base stats types. */
    public String[] baseStatsTypes;

    /** The base stats items. */
    public SortedSet&lt;String&gt;[] baseStatsItems;

    /** The key. */
    public String key;

    /** The data collector. */
    public MtasDataCollector&lt;?, ?&gt; dataCollector;

    /** The base function list. */
    public HashMap&lt;MtasDataCollector&lt;?, ?&gt;, SubComponentFunction[]&gt;[] baseFunctionList;

    /** The base numbers. */
    public Integer[] baseNumbers;

    /** The base minimum longs. */
    public Long[] baseMinimumLongs;

    /** The base maximum longs. */
    public Long[] baseMaximumLongs;

    /** The base parsers. */
    public MtasFunctionParserFunction[] baseParsers;

    /** The base function keys. */
    public String[][] baseFunctionKeys;

    /** The base function expressions. */
    public String[][] baseFunctionExpressions;

    /** The base function types. */
    public String[][] baseFunctionTypes;

    /** The base function parser functions. */
    public MtasFunctionParserFunction[][] baseFunctionParserFunctions;

    /** The Constant TYPE_STRING. */
    public static final String TYPE_STRING = &quot;string&quot;;

    /** The Constant TYPE_POINTFIELD_WITHOUT_DOCVALUES. */
    public static final String TYPE_POINTFIELD_WITHOUT_DOCVALUES = &quot;pointfield_without_docvalues&quot;;

    /**
     * Instantiates a new component facet.
     *
     * @param spanQueries the span queries
     * @param field the field
     * @param key the key
     * @param baseFields the base fields
     * @param baseFieldTypes the base field types
     * @param baseTypes the base types
     * @param baseRangeSizes the base range sizes
     * @param baseRangeBases the base range bases
     * @param baseSortTypes the base sort types
     * @param baseSortDirections the base sort directions
     * @param baseNumbers the base numbers
     * @param baseMinimumDoubles the base minimum doubles
     * @param baseMaximumDoubles the base maximum doubles
     * @param baseFunctionKeys the base function keys
     * @param baseFunctionExpressions the base function expressions
     * @param baseFunctionTypes the base function types
     * @throws IOException Signals that an I/O exception has occurred.
     * @throws ParseException the parse exception
     */
    @SuppressWarnings(&quot;unchecked&quot;)
<span class="nc" id="L985">    public ComponentFacet(MtasSpanQuery[] spanQueries, String field, String key,</span>
        String[] baseFields, String[] baseFieldTypes, String[] baseTypes,
        Double[] baseRangeSizes, Double[] baseRangeBases,
        String[] baseSortTypes, String[] baseSortDirections,
        Integer[] baseNumbers, Double[] baseMinimumDoubles,
        Double[] baseMaximumDoubles, String[][] baseFunctionKeys,
        String[][] baseFunctionExpressions, String[][] baseFunctionTypes)
        throws IOException, ParseException {
<span class="nc" id="L993">      this.spanQueries = (MtasSpanQuery[]) spanQueries.clone();</span>
<span class="nc" id="L994">      this.key = key;</span>
<span class="nc" id="L995">      this.baseFields = (String[]) baseFields.clone();</span>
<span class="nc" id="L996">      this.baseFieldTypes = (String[]) baseFieldTypes.clone();</span>
<span class="nc" id="L997">      this.baseTypes = (String[]) baseTypes.clone();</span>
<span class="nc" id="L998">      this.baseRangeSizes = (Double[]) baseRangeSizes.clone();</span>
<span class="nc" id="L999">      this.baseRangeBases = (Double[]) baseRangeBases.clone();</span>
<span class="nc" id="L1000">      this.baseSortTypes = (String[]) baseSortTypes.clone();</span>
<span class="nc" id="L1001">      this.baseSortDirections = (String[]) baseSortDirections.clone();</span>
<span class="nc" id="L1002">      this.baseNumbers = (Integer[]) baseNumbers.clone();</span>
      // compute types
<span class="nc" id="L1004">      this.baseMinimumLongs = new Long[baseFields.length];</span>
<span class="nc" id="L1005">      this.baseMaximumLongs = new Long[baseFields.length];</span>
<span class="nc" id="L1006">      this.baseCollectorTypes = new String[baseFields.length];</span>
<span class="nc" id="L1007">      this.baseStatsItems = new SortedSet[baseFields.length];</span>
<span class="nc" id="L1008">      this.baseStatsTypes = new String[baseFields.length];</span>
<span class="nc" id="L1009">      this.baseDataTypes = new String[baseFields.length];</span>
<span class="nc" id="L1010">      this.baseParsers = new MtasFunctionParserFunction[baseFields.length];</span>
<span class="nc" id="L1011">      this.baseFunctionList = new HashMap[baseFields.length];</span>
<span class="nc" id="L1012">      this.baseFunctionParserFunctions = new MtasFunctionParserFunction[baseFields.length][];</span>
<span class="nc bnc" id="L1013" title="All 2 branches missed.">      for (int i = 0; i &lt; baseFields.length; i++) {</span>
<span class="nc bnc" id="L1014" title="All 2 branches missed.">        if (baseMinimumDoubles[i] != null) {</span>
<span class="nc" id="L1015">          this.baseMinimumLongs[i] = baseMinimumDoubles[i].longValue();</span>
<span class="nc" id="L1016">        } else {</span>
<span class="nc" id="L1017">          this.baseMinimumLongs[i] = null;</span>
        }
<span class="nc bnc" id="L1019" title="All 2 branches missed.">        if (baseMaximumDoubles[i] != null) {</span>
<span class="nc" id="L1020">          this.baseMaximumLongs[i] = baseMaximumDoubles[i].longValue();</span>
<span class="nc" id="L1021">        } else {</span>
<span class="nc" id="L1022">          this.baseMaximumLongs[i] = null;</span>
        }
<span class="nc" id="L1024">        baseDataTypes[i] = CodecUtil.DATA_TYPE_LONG;</span>
<span class="nc" id="L1025">        baseFunctionList[i] = new HashMap&lt;&gt;();</span>
<span class="nc" id="L1026">        baseFunctionParserFunctions[i] = null;</span>
<span class="nc" id="L1027">        baseParsers[i] = new MtasFunctionParserFunctionDefault(</span>
<span class="nc" id="L1028">            this.spanQueries.length);</span>
<span class="nc bnc" id="L1029" title="All 2 branches missed.">        if (this.baseSortDirections[i] == null) {</span>
<span class="nc" id="L1030">          this.baseSortDirections[i] = CodecUtil.SORT_ASC;</span>
<span class="nc bnc" id="L1031" title="All 2 branches missed.">        } else if (!this.baseSortDirections[i].equals(CodecUtil.SORT_ASC)</span>
<span class="nc bnc" id="L1032" title="All 2 branches missed.">            &amp;&amp; !this.baseSortDirections[i].equals(CodecUtil.SORT_DESC)) {</span>
<span class="nc" id="L1033">          throw new IOException(</span>
<span class="nc" id="L1034">              &quot;unrecognized sortDirection &quot; + this.baseSortDirections[i]);</span>
        }
<span class="nc bnc" id="L1036" title="All 2 branches missed.">        if (this.baseSortTypes[i] == null) {</span>
<span class="nc" id="L1037">          this.baseSortTypes[i] = CodecUtil.SORT_TERM;</span>
<span class="nc bnc" id="L1038" title="All 2 branches missed.">        } else if (!this.baseSortTypes[i].equals(CodecUtil.SORT_TERM)</span>
<span class="nc bnc" id="L1039" title="All 2 branches missed.">            &amp;&amp; !CodecUtil.isStatsType(this.baseSortTypes[i])) {</span>
<span class="nc" id="L1040">          throw new IOException(</span>
<span class="nc" id="L1041">              &quot;unrecognized sortType &quot; + this.baseSortTypes[i]);</span>
        }
<span class="nc" id="L1043">        this.baseCollectorTypes[i] = DataCollector.COLLECTOR_TYPE_LIST;</span>
<span class="nc" id="L1044">        this.baseStatsItems[i] = CodecUtil.createStatsItems(this.baseTypes[i]);</span>
<span class="nc" id="L1045">        this.baseStatsTypes[i] = CodecUtil.createStatsType(baseStatsItems[i],</span>
<span class="nc" id="L1046">            this.baseSortTypes[i], new MtasFunctionParserFunctionDefault(1));</span>
      }
      boolean doFunctions;
<span class="nc bnc" id="L1049" title="All 4 branches missed.">      doFunctions = baseFunctionKeys != null &amp;&amp; baseFunctionExpressions != null</span>
<span class="nc bnc" id="L1050" title="All 2 branches missed.">          &amp;&amp; baseFunctionTypes != null;</span>
<span class="nc bnc" id="L1051" title="All 4 branches missed.">      doFunctions = doFunctions ? baseFunctionKeys.length == baseFields.length</span>
<span class="nc" id="L1052">          : false;</span>
<span class="nc bnc" id="L1053" title="All 4 branches missed.">      doFunctions = doFunctions ? baseFunctionTypes.length == baseFields.length</span>
<span class="nc" id="L1054">          : false;</span>
<span class="nc bnc" id="L1055" title="All 2 branches missed.">      if (doFunctions) {</span>
<span class="nc" id="L1056">        this.baseFunctionKeys = new String[baseFields.length][];</span>
<span class="nc" id="L1057">        this.baseFunctionExpressions = new String[baseFields.length][];</span>
<span class="nc" id="L1058">        this.baseFunctionTypes = new String[baseFields.length][];</span>
<span class="nc bnc" id="L1059" title="All 2 branches missed.">        for (int i = 0; i &lt; baseFields.length; i++) {</span>
<span class="nc bnc" id="L1060" title="All 2 branches missed.">          if (baseFunctionKeys[i].length == baseFunctionExpressions[i].length</span>
<span class="nc bnc" id="L1061" title="All 2 branches missed.">              &amp;&amp; baseFunctionKeys[i].length == baseFunctionTypes[i].length) {</span>
<span class="nc" id="L1062">            this.baseFunctionKeys[i] = new String[baseFunctionKeys[i].length];</span>
<span class="nc" id="L1063">            this.baseFunctionExpressions[i] = new String[baseFunctionExpressions[i].length];</span>
<span class="nc" id="L1064">            this.baseFunctionTypes[i] = new String[baseFunctionTypes[i].length];</span>
<span class="nc" id="L1065">            baseFunctionParserFunctions[i] = new MtasFunctionParserFunction[baseFunctionExpressions[i].length];</span>
<span class="nc bnc" id="L1066" title="All 2 branches missed.">            for (int j = 0; j &lt; baseFunctionKeys[i].length; j++) {</span>
<span class="nc" id="L1067">              this.baseFunctionKeys[i][j] = baseFunctionKeys[i][j];</span>
<span class="nc" id="L1068">              this.baseFunctionExpressions[i][j] = baseFunctionExpressions[i][j];</span>
<span class="nc" id="L1069">              this.baseFunctionTypes[i][j] = baseFunctionTypes[i][j];</span>
<span class="nc" id="L1070">              baseFunctionParserFunctions[i][j] = new MtasFunctionParser(</span>
<span class="nc" id="L1071">                  new BufferedReader(</span>
<span class="nc" id="L1072">                      new StringReader(baseFunctionExpressions[i][j]))).parse();</span>
            }
<span class="nc" id="L1074">          } else {</span>
<span class="nc" id="L1075">            this.baseFunctionKeys[i] = new String[0];</span>
<span class="nc" id="L1076">            this.baseFunctionExpressions[i] = new String[0];</span>
<span class="nc" id="L1077">            this.baseFunctionTypes[i] = new String[0];</span>
<span class="nc" id="L1078">            baseFunctionParserFunctions[i] = new MtasFunctionParserFunction[0];</span>
          }
        }
      }
<span class="nc bnc" id="L1082" title="All 2 branches missed.">      if (baseFields.length &gt; 0) {</span>
<span class="nc bnc" id="L1083" title="All 2 branches missed.">        if (baseFields.length == 1) {</span>
<span class="nc" id="L1084">          dataCollector = DataCollector.getCollector(this.baseCollectorTypes[0],</span>
<span class="nc" id="L1085">              this.baseDataTypes[0], this.baseStatsTypes[0],</span>
<span class="nc" id="L1086">              this.baseStatsItems[0], this.baseSortTypes[0],</span>
<span class="nc" id="L1087">              this.baseSortDirections[0], 0, this.baseNumbers[0], null, null);</span>
<span class="nc" id="L1088">        } else {</span>
<span class="nc" id="L1089">          String[] subBaseCollectorTypes = Arrays</span>
<span class="nc" id="L1090">              .copyOfRange(baseCollectorTypes, 1, baseDataTypes.length);</span>
<span class="nc" id="L1091">          String[] subBaseDataTypes = Arrays.copyOfRange(baseDataTypes, 1,</span>
<span class="nc" id="L1092">              baseDataTypes.length);</span>
<span class="nc" id="L1093">          String[] subBaseStatsTypes = Arrays.copyOfRange(baseStatsTypes, 1,</span>
<span class="nc" id="L1094">              baseStatsTypes.length);</span>
<span class="nc" id="L1095">          SortedSet&lt;String&gt;[] subBaseStatsItems = Arrays</span>
<span class="nc" id="L1096">              .copyOfRange(baseStatsItems, 1, baseStatsItems.length);</span>
<span class="nc" id="L1097">          String[] subBaseSortTypes = Arrays.copyOfRange(baseSortTypes, 1,</span>
<span class="nc" id="L1098">              baseSortTypes.length);</span>
<span class="nc" id="L1099">          String[] subBaseSortDirections = Arrays</span>
<span class="nc" id="L1100">              .copyOfRange(baseSortDirections, 1, baseSortDirections.length);</span>
<span class="nc" id="L1101">          Integer[] subNumbers = Arrays.copyOfRange(baseNumbers, 1,</span>
<span class="nc" id="L1102">              baseNumbers.length);</span>
<span class="nc" id="L1103">          Integer[] subStarts = ArrayUtils.toObject(new int[subNumbers.length]);</span>
<span class="nc" id="L1104">          dataCollector = DataCollector.getCollector(this.baseCollectorTypes[0],</span>
<span class="nc" id="L1105">              this.baseDataTypes[0], this.baseStatsTypes[0],</span>
<span class="nc" id="L1106">              this.baseStatsItems[0], this.baseSortTypes[0],</span>
<span class="nc" id="L1107">              this.baseSortDirections[0], 0, this.baseNumbers[0],</span>
<span class="nc" id="L1108">              subBaseCollectorTypes, subBaseDataTypes, subBaseStatsTypes,</span>
<span class="nc" id="L1109">              subBaseStatsItems, subBaseSortTypes, subBaseSortDirections,</span>
<span class="nc" id="L1110">              subStarts, subNumbers, null, null);</span>
        }
<span class="nc" id="L1112">      } else {</span>
<span class="nc" id="L1113">        throw new IOException(&quot;no baseFields&quot;);</span>
      }
<span class="nc" id="L1115">    }</span>

    /**
     * Function sum rule.
     *
     * @return true, if successful
     */
    public boolean functionSumRule() {
<span class="nc bnc" id="L1123" title="All 2 branches missed.">      if (baseFunctionParserFunctions != null) {</span>
<span class="nc bnc" id="L1124" title="All 2 branches missed.">        for (int i = 0; i &lt; baseFields.length; i++) {</span>
<span class="nc bnc" id="L1125" title="All 2 branches missed.">          for (MtasFunctionParserFunction function : baseFunctionParserFunctions[i]) {</span>
<span class="nc bnc" id="L1126" title="All 2 branches missed.">            if (!function.sumRule()) {</span>
<span class="nc" id="L1127">              return false;</span>
            }
          }
        }
      }
<span class="nc" id="L1132">      return true;</span>
    }

    /**
     * Function need positions.
     *
     * @return true, if successful
     */
    public boolean functionNeedPositions() {
<span class="nc bnc" id="L1141" title="All 2 branches missed.">      if (baseFunctionParserFunctions != null) {</span>
<span class="nc bnc" id="L1142" title="All 2 branches missed.">        for (int i = 0; i &lt; baseFields.length; i++) {</span>
<span class="nc bnc" id="L1143" title="All 2 branches missed.">          for (MtasFunctionParserFunction function : baseFunctionParserFunctions[i]) {</span>
<span class="nc bnc" id="L1144" title="All 2 branches missed.">            if (function.needPositions()) {</span>
<span class="nc" id="L1145">              return true;</span>
            }
          }
        }
      }
<span class="nc" id="L1150">      return false;</span>
    }

    /**
     * Base parser sum rule.
     *
     * @return true, if successful
     */
    public boolean baseParserSumRule() {
<span class="nc bnc" id="L1159" title="All 2 branches missed.">      for (int i = 0; i &lt; baseFields.length; i++) {</span>
<span class="nc bnc" id="L1160" title="All 2 branches missed.">        if (!baseParsers[i].sumRule()) {</span>
<span class="nc" id="L1161">          return false;</span>
        }
      }
<span class="nc" id="L1164">      return true;</span>
    }

    /**
     * Base parser need positions.
     *
     * @return true, if successful
     */
    public boolean baseParserNeedPositions() {
<span class="nc bnc" id="L1173" title="All 2 branches missed.">      for (int i = 0; i &lt; baseFields.length; i++) {</span>
<span class="nc bnc" id="L1174" title="All 2 branches missed.">        if (baseParsers[i].needPositions()) {</span>
<span class="nc" id="L1175">          return true;</span>
        }
      }
<span class="nc" id="L1178">      return false;</span>
    }

  }

  /**
   * The Class ComponentTermVector.
   */
  public static class ComponentTermVector implements BasicComponent {

    /** The key. */
    public String key;

    /** The prefix. */
    public String prefix;

    /** The regexp. */
    public String regexp;

    /** The ignore regexp. */
    public String ignoreRegexp;

    /** The boundary. */
    public String boundary;

    /** The full. */
    public boolean full;

    /** The list. */
    public Set&lt;String&gt; list;

    /** The ignore list. */
    public Set&lt;String&gt; ignoreList;

    /** The list regexp. */
    public boolean listRegexp;

    /** The ignore list regexp. */
    public boolean ignoreListRegexp;

    /** The functions. */
    public List&lt;SubComponentFunction&gt; functions;

    /** The number. */
    public int number;

    /** The start value. */
    public BytesRef startValue;

    /** The sub component function. */
    public SubComponentFunction subComponentFunction;

    /** The boundary registration. */
    public boolean boundaryRegistration;

    /** The sort type. */
    public String sortType;

    /** The sort direction. */
    public String sortDirection;

    /**
     * Instantiates a new component term vector.
     *
     * @param key the key
     * @param prefix the prefix
     * @param regexp the regexp
     * @param full the full
     * @param type the type
     * @param sortType the sort type
     * @param sortDirection the sort direction
     * @param startValue the start value
     * @param number the number
     * @param functionKey the function key
     * @param functionExpression the function expression
     * @param functionType the function type
     * @param boundary the boundary
     * @param list the list
     * @param listRegexp the list regexp
     * @param ignoreRegexp the ignore regexp
     * @param ignoreList the ignore list
     * @param ignoreListRegexp the ignore list regexp
     * @throws IOException Signals that an I/O exception has occurred.
     * @throws ParseException the parse exception
     */
    @SuppressWarnings({ &quot;unchecked&quot;, &quot;rawtypes&quot; })
<span class="fc" id="L1264">    public ComponentTermVector(String key, String prefix, String regexp,</span>
        Boolean full, String type, String sortType, String sortDirection,
        String startValue, int number, String[] functionKey,
        String[] functionExpression, String[] functionType, String boundary,
        String[] list, Boolean listRegexp, String ignoreRegexp,
        String[] ignoreList, Boolean ignoreListRegexp)
        throws IOException, ParseException {
<span class="fc" id="L1271">      this.key = key;</span>
<span class="fc" id="L1272">      this.prefix = prefix;</span>
<span class="fc" id="L1273">      this.regexp = regexp;</span>
<span class="pc bpc" id="L1274" title="1 of 4 branches missed.">      this.full = (full != null &amp;&amp; full) ? true : false;</span>
<span class="fc bfc" id="L1275" title="All 2 branches covered.">      if (sortType == null) {</span>
<span class="fc" id="L1276">        this.sortType = CodecUtil.SORT_TERM;</span>
<span class="fc" id="L1277">      } else {</span>
<span class="fc" id="L1278">        this.sortType = sortType;</span>
      }
<span class="fc bfc" id="L1280" title="All 2 branches covered.">      if (sortDirection == null) {</span>
<span class="pc bpc" id="L1281" title="1 of 2 branches missed.">        if (this.sortType.equals(CodecUtil.SORT_TERM)) {</span>
<span class="fc" id="L1282">          this.sortDirection = CodecUtil.SORT_ASC;</span>
<span class="fc" id="L1283">        } else {</span>
<span class="nc" id="L1284">          this.sortDirection = CodecUtil.SORT_DESC;</span>
        }
<span class="nc" id="L1286">      } else {</span>
<span class="fc" id="L1287">        this.sortDirection = sortDirection;</span>
      }
<span class="pc bpc" id="L1289" title="1 of 4 branches missed.">      if (list != null &amp;&amp; list.length &gt; 0) {</span>
<span class="fc" id="L1290">        this.list = new HashSet(Arrays.asList(list));</span>
<span class="pc bpc" id="L1291" title="1 of 2 branches missed.">        this.listRegexp = listRegexp != null ? listRegexp : false;</span>
<span class="fc" id="L1292">        this.boundary = null;</span>
<span class="fc" id="L1293">        this.number = Integer.MAX_VALUE;</span>
<span class="pc bpc" id="L1294" title="1 of 2 branches missed.">        if (!this.full) {</span>
<span class="fc" id="L1295">          this.sortType = CodecUtil.SORT_TERM;</span>
<span class="fc" id="L1296">          this.sortDirection = CodecUtil.SORT_ASC;</span>
        }
<span class="fc" id="L1298">      } else {</span>
<span class="fc" id="L1299">        this.list = null;</span>
<span class="fc" id="L1300">        this.listRegexp = false;</span>
<span class="pc bpc" id="L1301" title="1 of 2 branches missed.">        this.startValue = (startValue != null)</span>
<span class="pc" id="L1302">            ? new BytesRef(prefix + MtasToken.DELIMITER + startValue) : null;</span>
<span class="pc bpc" id="L1303" title="1 of 2 branches missed.">        if (boundary == null) {</span>
<span class="fc" id="L1304">          this.boundary = null;</span>
<span class="pc bpc" id="L1305" title="1 of 2 branches missed.">          if (number &lt; -1) {</span>
<span class="nc" id="L1306">            throw new IOException(&quot;number should not be &quot; + number);</span>
<span class="fc bfc" id="L1307" title="All 2 branches covered.">          } else if (number &gt;= 0) {</span>
<span class="fc" id="L1308">            this.number = number;</span>
<span class="fc" id="L1309">          } else {</span>
<span class="pc bpc" id="L1310" title="1 of 2 branches missed.">            if (!full) {</span>
<span class="nc" id="L1311">              throw new IOException(</span>
<span class="nc" id="L1312">                  &quot;number &quot; + number + &quot; only supported for full termvector&quot;);</span>
            } else {
<span class="fc" id="L1314">              this.number = Integer.MAX_VALUE;</span>
            }
          }
<span class="fc" id="L1317">        } else {</span>
<span class="nc" id="L1318">          this.boundary = boundary;</span>
<span class="nc" id="L1319">          this.number = Integer.MAX_VALUE;</span>
        }
      }
<span class="fc" id="L1322">      this.ignoreRegexp = ignoreRegexp;</span>
<span class="pc bpc" id="L1323" title="1 of 4 branches missed.">      if (ignoreList != null &amp;&amp; ignoreList.length &gt; 0) {</span>
<span class="fc" id="L1324">        this.ignoreList = new HashSet(Arrays.asList(ignoreList));</span>
<span class="pc bpc" id="L1325" title="1 of 2 branches missed.">        this.ignoreListRegexp = ignoreListRegexp != null ? ignoreListRegexp</span>
<span class="nc" id="L1326">            : false;</span>
<span class="fc" id="L1327">      } else {</span>
<span class="fc" id="L1328">        this.ignoreList = null;</span>
<span class="fc" id="L1329">        this.ignoreListRegexp = false;</span>
      }
<span class="fc" id="L1331">      functions = new ArrayList&lt;&gt;();</span>
<span class="pc bpc" id="L1332" title="1 of 4 branches missed.">      if (functionKey != null &amp;&amp; functionExpression != null</span>
<span class="pc bpc" id="L1333" title="1 of 2 branches missed.">          &amp;&amp; functionType != null) {</span>
<span class="pc bpc" id="L1334" title="1 of 2 branches missed.">        if (functionKey.length == functionExpression.length</span>
<span class="pc bpc" id="L1335" title="1 of 2 branches missed.">            &amp;&amp; functionKey.length == functionType.length) {</span>
<span class="pc bpc" id="L1336" title="1 of 2 branches missed.">          for (int i = 0; i &lt; functionKey.length; i++) {</span>
<span class="nc" id="L1337">            functions</span>
<span class="nc" id="L1338">                .add(new SubComponentFunction(DataCollector.COLLECTOR_TYPE_LIST,</span>
<span class="nc" id="L1339">                    functionKey[i], functionExpression[i], functionType[i]));</span>
          }
        }
      }
<span class="fc bfc" id="L1343" title="All 2 branches covered.">      if (!this.sortType.equals(CodecUtil.SORT_TERM)</span>
<span class="pc bpc" id="L1344" title="1 of 2 branches missed.">          &amp;&amp; !CodecUtil.isStatsType(this.sortType)) {</span>
<span class="nc" id="L1345">        throw new IOException(&quot;unknown sortType '&quot; + this.sortType + &quot;'&quot;);</span>
<span class="fc bfc" id="L1346" title="All 4 branches covered.">      } else if (!full &amp;&amp; !this.sortType.equals(CodecUtil.SORT_TERM)) {</span>
<span class="pc bpc" id="L1347" title="1 of 2 branches missed.">        if (!(this.sortType.equals(CodecUtil.STATS_TYPE_SUM)</span>
<span class="nc bnc" id="L1348" title="All 2 branches missed.">            || this.sortType.equals(CodecUtil.STATS_TYPE_N))) {</span>
<span class="nc" id="L1349">          throw new IOException(&quot;sortType '&quot; + this.sortType</span>
<span class="nc" id="L1350">              + &quot;' only supported with full termVector&quot;);</span>
        }
      }
<span class="fc bfc" id="L1353" title="All 2 branches covered.">      if (!this.sortType.equals(CodecUtil.SORT_TERM)) {</span>
<span class="pc bpc" id="L1354" title="1 of 2 branches missed.">        if (startValue != null) {</span>
<span class="nc" id="L1355">          throw new IOException(&quot;startValue '&quot; + startValue</span>
<span class="nc" id="L1356">              + &quot;' only supported with termVector sorted on &quot;</span>
<span class="nc" id="L1357">              + CodecUtil.SORT_TERM);</span>
        }
      }
<span class="fc bfc" id="L1360" title="All 2 branches covered.">      if (!this.sortDirection.equals(CodecUtil.SORT_ASC)</span>
<span class="pc bpc" id="L1361" title="1 of 2 branches missed.">          &amp;&amp; !this.sortDirection.equals(CodecUtil.SORT_DESC)) {</span>
<span class="nc" id="L1362">        throw new IOException(</span>
<span class="nc" id="L1363">            &quot;unrecognized sortDirection '&quot; + this.sortDirection + &quot;'&quot;);</span>
      }
<span class="pc bpc" id="L1365" title="1 of 2 branches missed.">      boundaryRegistration = this.boundary != null;</span>
<span class="fc" id="L1366">      String segmentRegistration = null;</span>
<span class="fc bfc" id="L1367" title="All 2 branches covered.">      if (this.full) {</span>
<span class="fc" id="L1368">        this.boundary = null;</span>
<span class="fc" id="L1369">        segmentRegistration = null;</span>
<span class="pc bpc" id="L1370" title="1 of 2 branches missed.">      } else if (this.boundary != null) {</span>
<span class="nc bnc" id="L1371" title="All 2 branches missed.">        if (this.sortDirection.equals(CodecUtil.SORT_ASC)) {</span>
<span class="nc" id="L1372">          segmentRegistration = MtasDataCollector.SEGMENT_BOUNDARY_ASC;</span>
<span class="nc bnc" id="L1373" title="All 2 branches missed.">        } else if (this.sortDirection.equals(CodecUtil.SORT_DESC)) {</span>
<span class="nc" id="L1374">          segmentRegistration = MtasDataCollector.SEGMENT_BOUNDARY_DESC;</span>
        }
<span class="pc bfc" id="L1376" title="All 2 branches covered.">      } else if (!this.sortType.equals(CodecUtil.SORT_TERM)) {</span>
<span class="fc bfc" id="L1377" title="All 2 branches covered.">        if (this.sortDirection.equals(CodecUtil.SORT_ASC)) {</span>
<span class="fc" id="L1378">          segmentRegistration = MtasDataCollector.SEGMENT_SORT_ASC;</span>
<span class="pc bpc" id="L1379" title="1 of 2 branches missed.">        } else if (this.sortDirection.equals(CodecUtil.SORT_DESC)) {</span>
<span class="fc" id="L1380">          segmentRegistration = MtasDataCollector.SEGMENT_SORT_DESC;</span>
        }
      }
      // create main subComponentFunction
<span class="fc" id="L1384">      this.subComponentFunction = new SubComponentFunction(</span>
<span class="fc" id="L1385">          DataCollector.COLLECTOR_TYPE_LIST, key, type,</span>
<span class="fc" id="L1386">          new MtasFunctionParserFunctionDefault(1), this.sortType,</span>
<span class="fc" id="L1387">          this.sortDirection, 0, this.number, segmentRegistration, boundary);</span>
<span class="fc" id="L1388">    }</span>

    /**
     * Function sum rule.
     *
     * @return true, if successful
     */
    public boolean functionSumRule() {
<span class="nc bnc" id="L1396" title="All 2 branches missed.">      if (functions != null) {</span>
<span class="nc bnc" id="L1397" title="All 2 branches missed.">        for (SubComponentFunction function : functions) {</span>
<span class="nc bnc" id="L1398" title="All 2 branches missed.">          if (!function.parserFunction.sumRule()) {</span>
<span class="nc" id="L1399">            return false;</span>
          }
        }
      }
<span class="nc" id="L1403">      return true;</span>
    }

    /**
     * Function need positions.
     *
     * @return true, if successful
     */
    public boolean functionNeedPositions() {
<span class="pc bpc" id="L1412" title="1 of 2 branches missed.">      if (functions != null) {</span>
<span class="pc bpc" id="L1413" title="1 of 2 branches missed.">        for (SubComponentFunction function : functions) {</span>
<span class="nc bnc" id="L1414" title="All 2 branches missed.">          if (function.parserFunction.needPositions()) {</span>
<span class="nc" id="L1415">            return true;</span>
          }
        }
      }
<span class="fc" id="L1419">      return false;</span>
    }

  }

  /**
   * The Interface ComponentStats.
   */
  public abstract static interface ComponentStats extends BasicComponent {
  }

  /**
   * The Class ComponentSpan.
   */
  public static class ComponentSpan implements ComponentStats {

    /** The queries. */
    public MtasSpanQuery[] queries;

    /** The key. */
    public String key;

    /** The data type. */
    public String dataType;

    /** The stats type. */
    public String statsType;

    /** The stats items. */
    public SortedSet&lt;String&gt; statsItems;

    /** The minimum long. */
    public Long minimumLong;

    /** The maximum long. */
    public Long maximumLong;

    /** The data collector. */
    public MtasDataCollector&lt;?, ?&gt; dataCollector;

    /** The functions. */
    public List&lt;SubComponentFunction&gt; functions;

    /** The parser. */
    public MtasFunctionParserFunction parser;

    /**
     * Instantiates a new component span.
     *
     * @param queries the queries
     * @param key the key
     * @param minimumDouble the minimum double
     * @param maximumDouble the maximum double
     * @param type the type
     * @param functionKey the function key
     * @param functionExpression the function expression
     * @param functionType the function type
     * @throws IOException Signals that an I/O exception has occurred.
     * @throws ParseException the parse exception
     */
<span class="fc" id="L1479">    public ComponentSpan(MtasSpanQuery[] queries, String key,</span>
        Double minimumDouble, Double maximumDouble, String type,
        String[] functionKey, String[] functionExpression,
        String[] functionType) throws IOException, ParseException {
<span class="fc" id="L1483">      this.queries = (MtasSpanQuery[]) queries.clone();</span>
<span class="fc" id="L1484">      this.key = key;</span>
<span class="fc" id="L1485">      functions = new ArrayList&lt;&gt;();</span>
<span class="pc bpc" id="L1486" title="1 of 4 branches missed.">      if (functionKey != null &amp;&amp; functionExpression != null</span>
<span class="pc bpc" id="L1487" title="1 of 2 branches missed.">          &amp;&amp; functionType != null) {</span>
<span class="pc bpc" id="L1488" title="1 of 2 branches missed.">        if (functionKey.length == functionExpression.length</span>
<span class="pc bpc" id="L1489" title="1 of 2 branches missed.">            &amp;&amp; functionKey.length == functionType.length) {</span>
<span class="fc bfc" id="L1490" title="All 2 branches covered.">          for (int i = 0; i &lt; functionKey.length; i++) {</span>
<span class="fc" id="L1491">            functions</span>
<span class="fc" id="L1492">                .add(new SubComponentFunction(DataCollector.COLLECTOR_TYPE_DATA,</span>
<span class="fc" id="L1493">                    functionKey[i], functionExpression[i], functionType[i]));</span>
          }
        }
      }
<span class="fc" id="L1497">      parser = new MtasFunctionParserFunctionDefault(queries.length);</span>
<span class="fc" id="L1498">      dataType = parser.getType();</span>
<span class="fc" id="L1499">      statsItems = CodecUtil.createStatsItems(type);</span>
<span class="fc" id="L1500">      statsType = CodecUtil.createStatsType(this.statsItems, null, parser);</span>
<span class="fc bfc" id="L1501" title="All 2 branches covered.">      if (minimumDouble != null) {</span>
<span class="fc" id="L1502">        this.minimumLong = minimumDouble.longValue();</span>
<span class="fc" id="L1503">      } else {</span>
<span class="fc" id="L1504">        this.minimumLong = null;</span>
      }
<span class="fc bfc" id="L1506" title="All 2 branches covered.">      if (maximumDouble != null) {</span>
<span class="fc" id="L1507">        this.maximumLong = maximumDouble.longValue();</span>
<span class="fc" id="L1508">      } else {</span>
<span class="fc" id="L1509">        this.maximumLong = null;</span>
      }
<span class="fc" id="L1511">      dataCollector = DataCollector.getCollector(</span>
<span class="fc" id="L1512">          DataCollector.COLLECTOR_TYPE_DATA, dataType, this.statsType,</span>
<span class="fc" id="L1513">          this.statsItems, null, null, null, null, null, null);</span>
<span class="fc" id="L1514">    }</span>

    /**
     * Function sum rule.
     *
     * @return true, if successful
     */
    public boolean functionSumRule() {
<span class="pc bpc" id="L1522" title="1 of 2 branches missed.">      if (functions != null) {</span>
<span class="fc bfc" id="L1523" title="All 2 branches covered.">        for (SubComponentFunction function : functions) {</span>
<span class="pc bpc" id="L1524" title="1 of 2 branches missed.">          if (!function.parserFunction.sumRule()) {</span>
<span class="nc" id="L1525">            return false;</span>
          }
        }
      }
<span class="fc" id="L1529">      return true;</span>
    }

    /**
     * Function basic.
     *
     * @return true, if successful
     */
    public boolean functionBasic() {
<span class="pc bpc" id="L1538" title="1 of 2 branches missed.">      if (functions != null) {</span>
<span class="fc bfc" id="L1539" title="All 2 branches covered.">        for (SubComponentFunction function : functions) {</span>
<span class="pc bpc" id="L1540" title="1 of 2 branches missed.">          if (!function.statsType.equals(CodecUtil.STATS_BASIC)) {</span>
<span class="nc" id="L1541">            return false;</span>
          }
        }
      }
<span class="fc" id="L1545">      return true;</span>
    }

    /**
     * Function need positions.
     *
     * @return true, if successful
     */
    public boolean functionNeedPositions() {
<span class="pc bpc" id="L1554" title="1 of 2 branches missed.">      if (functions != null) {</span>
<span class="fc bfc" id="L1555" title="All 2 branches covered.">        for (SubComponentFunction function : functions) {</span>
<span class="pc bpc" id="L1556" title="1 of 2 branches missed.">          if (function.parserFunction.needPositions()) {</span>
<span class="nc" id="L1557">            return true;</span>
          }
        }
      }
<span class="fc" id="L1561">      return false;</span>
    }

    /**
     * Function need arguments.
     *
     * @return the sets the
     */
    public Set&lt;Integer&gt; functionNeedArguments() {
<span class="fc" id="L1570">      Set&lt;Integer&gt; list = new HashSet&lt;&gt;();</span>
<span class="pc bpc" id="L1571" title="1 of 2 branches missed.">      if (functions != null) {</span>
<span class="fc bfc" id="L1572" title="All 2 branches covered.">        for (SubComponentFunction function : functions) {</span>
<span class="fc" id="L1573">          list.addAll(function.parserFunction.needArgument());</span>
        }
      }
<span class="fc" id="L1576">      return list;</span>
    }

  }

  /**
   * The Class ComponentPosition.
   */
  public static class ComponentPosition implements ComponentStats {

    /** The key. */
    public String key;

    /** The data type. */
    public String dataType;

    /** The stats type. */
    public String statsType;

    /** The stats items. */
    public SortedSet&lt;String&gt; statsItems;

    /** The minimum long. */
    public Long minimumLong;

    /** The maximum long. */
    public Long maximumLong;

    /** The data collector. */
    public MtasDataCollector&lt;?, ?&gt; dataCollector;

    /**
     * Instantiates a new component position.
     *
     * @param key the key
     * @param minimumDouble the minimum double
     * @param maximumDouble the maximum double
     * @param statsType the stats type
     * @throws IOException Signals that an I/O exception has occurred.
     * @throws ParseException the parse exception
     */
<span class="fc" id="L1617">    public ComponentPosition(String key, Double minimumDouble,</span>
        Double maximumDouble, String statsType)
        throws IOException, ParseException {
<span class="fc" id="L1620">      this.key = key;</span>
<span class="fc" id="L1621">      dataType = CodecUtil.DATA_TYPE_LONG;</span>
<span class="fc" id="L1622">      this.statsItems = CodecUtil.createStatsItems(statsType);</span>
<span class="fc" id="L1623">      this.statsType = CodecUtil.createStatsType(this.statsItems, null, null);</span>
<span class="fc bfc" id="L1624" title="All 2 branches covered.">      if (minimumDouble != null) {</span>
<span class="fc" id="L1625">        this.minimumLong = minimumDouble.longValue();</span>
<span class="fc" id="L1626">      } else {</span>
<span class="fc" id="L1627">        this.minimumLong = null;</span>
      }
<span class="fc bfc" id="L1629" title="All 2 branches covered.">      if (maximumDouble != null) {</span>
<span class="fc" id="L1630">        this.maximumLong = maximumDouble.longValue();</span>
<span class="fc" id="L1631">      } else {</span>
<span class="fc" id="L1632">        this.maximumLong = null;</span>
      }
<span class="fc" id="L1634">      dataCollector = DataCollector.getCollector(</span>
<span class="fc" id="L1635">          DataCollector.COLLECTOR_TYPE_DATA, dataType, this.statsType,</span>
<span class="fc" id="L1636">          this.statsItems, null, null, null, null, null, null);</span>
<span class="fc" id="L1637">    }</span>
  }

  /**
   * The Class ComponentToken.
   */
  public static class ComponentToken implements ComponentStats {

    /** The key. */
    public String key;

    /** The data type. */
    public String dataType;

    /** The stats type. */
    public String statsType;

    /** The stats items. */
    public SortedSet&lt;String&gt; statsItems;

    /** The minimum long. */
    public Long minimumLong;

    /** The maximum long. */
    public Long maximumLong;

    /** The data collector. */
    public MtasDataCollector&lt;?, ?&gt; dataCollector;

    /**
     * Instantiates a new component token.
     *
     * @param key the key
     * @param minimumDouble the minimum double
     * @param maximumDouble the maximum double
     * @param statsType the stats type
     * @throws IOException Signals that an I/O exception has occurred.
     * @throws ParseException the parse exception
     */
<span class="fc" id="L1676">    public ComponentToken(String key, Double minimumDouble,</span>
        Double maximumDouble, String statsType)
        throws IOException, ParseException {
<span class="fc" id="L1679">      this.key = key;</span>
<span class="fc" id="L1680">      dataType = CodecUtil.DATA_TYPE_LONG;</span>
<span class="fc" id="L1681">      this.statsItems = CodecUtil.createStatsItems(statsType);</span>
<span class="fc" id="L1682">      this.statsType = CodecUtil.createStatsType(this.statsItems, null, null);</span>
<span class="fc bfc" id="L1683" title="All 2 branches covered.">      if (minimumDouble != null) {</span>
<span class="fc" id="L1684">        this.minimumLong = minimumDouble.longValue();</span>
<span class="fc" id="L1685">      } else {</span>
<span class="fc" id="L1686">        this.minimumLong = null;</span>
      }
<span class="fc bfc" id="L1688" title="All 2 branches covered.">      if (maximumDouble != null) {</span>
<span class="fc" id="L1689">        this.maximumLong = maximumDouble.longValue();</span>
<span class="fc" id="L1690">      } else {</span>
<span class="fc" id="L1691">        this.maximumLong = null;</span>
      }
<span class="fc" id="L1693">      dataCollector = DataCollector.getCollector(</span>
<span class="fc" id="L1694">          DataCollector.COLLECTOR_TYPE_DATA, dataType, this.statsType,</span>
<span class="fc" id="L1695">          this.statsItems, null, null, null, null, null, null);</span>
<span class="fc" id="L1696">    }</span>
  }

  /**
   * The Class ComponentCollection.
   */
  public static class ComponentCollection implements BasicComponent {

    /** The Constant ACTION_CREATE. */
    public static final String ACTION_CREATE = &quot;create&quot;;

    /** The Constant ACTION_CHECK. */
    public static final String ACTION_CHECK = &quot;check&quot;;

    /** The Constant ACTION_LIST. */
    public static final String ACTION_LIST = &quot;list&quot;;

    /** The Constant ACTION_POST. */
    public static final String ACTION_POST = &quot;post&quot;;

    /** The Constant ACTION_IMPORT. */
    public static final String ACTION_IMPORT = &quot;import&quot;;

    /** The Constant ACTION_DELETE. */
    public static final String ACTION_DELETE = &quot;delete&quot;;

    /** The Constant ACTION_EMPTY. */
    public static final String ACTION_EMPTY = &quot;empty&quot;;

    /** The Constant ACTION_GET. */
    public static final String ACTION_GET = &quot;get&quot;;

    /** The key. */
    public String key;

    /** The version. */
    public String version;

    /** The id. */
    public String id;

    /** The action. */
    private String action;

    /** The fields. */
    private Set&lt;String&gt; fields;

    /** The values. */
    private HashSet&lt;String&gt; values;

    /**
     * Instantiates a new component collection.
     *
     * @param key the key
     * @param action the action
     */
<span class="fc" id="L1752">    public ComponentCollection(String key, String action) {</span>
<span class="fc" id="L1753">      this.key = key;</span>
<span class="fc" id="L1754">      this.action = action;</span>
<span class="fc" id="L1755">      this.version = null;</span>
<span class="fc" id="L1756">      values = new HashSet&lt;&gt;();</span>
<span class="fc" id="L1757">    }</span>

    /**
     * Sets the list variables.
     *
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public void setListVariables() throws IOException {
<span class="pc bpc" id="L1765" title="1 of 2 branches missed.">      if (action.equals(ACTION_LIST)) {</span>
        // do nothing
      } else {
<span class="nc" id="L1768">        throw new IOException(&quot;not allowed with action &quot; + action);</span>
      }
<span class="fc" id="L1770">    }</span>

    /**
     * Sets the create variables.
     *
     * @param id the id
     * @param fields the fields
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public void setCreateVariables(String id, Set&lt;String&gt; fields)
        throws IOException {
<span class="pc bpc" id="L1781" title="1 of 2 branches missed.">      if (action.equals(ACTION_CREATE)) {</span>
<span class="fc" id="L1782">        this.id = id;</span>
<span class="fc" id="L1783">        this.fields = fields;</span>
<span class="fc" id="L1784">      } else {</span>
<span class="nc" id="L1785">        throw new IOException(&quot;not allowed with action &quot; + action);</span>
      }
<span class="fc" id="L1787">    }</span>

    /**
     * Sets the check variables.
     *
     * @param id the new check variables
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public void setCheckVariables(String id) throws IOException {
<span class="pc bpc" id="L1796" title="1 of 2 branches missed.">      if (action.equals(ACTION_CHECK)) {</span>
<span class="fc" id="L1797">        this.id = id;</span>
<span class="fc" id="L1798">      } else {</span>
<span class="nc" id="L1799">        throw new IOException(&quot;not allowed with action &quot; + action);</span>
      }
<span class="fc" id="L1801">    }</span>

    /**
     * Sets the gets the variables.
     *
     * @param id the new gets the variables
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public void setGetVariables(String id) throws IOException {
<span class="nc bnc" id="L1810" title="All 2 branches missed.">      if (action.equals(ACTION_GET)) {</span>
<span class="nc" id="L1811">        this.id = id;</span>
<span class="nc" id="L1812">      } else {</span>
<span class="nc" id="L1813">        throw new IOException(&quot;not allowed with action &quot; + action);</span>
      }
<span class="nc" id="L1815">    }</span>

    /**
     * Sets the post variables.
     *
     * @param id the id
     * @param values the values
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public void setPostVariables(String id, HashSet&lt;String&gt; values)
        throws IOException {
<span class="pc bpc" id="L1826" title="1 of 2 branches missed.">      if (action.equals(ACTION_POST)) {</span>
<span class="fc" id="L1827">        this.id = id;</span>
<span class="fc" id="L1828">        this.values = values;</span>
<span class="fc" id="L1829">      } else {</span>
<span class="nc" id="L1830">        throw new IOException(&quot;not allowed with action &quot; + action);</span>
      }
<span class="fc" id="L1832">    }</span>

    /**
     * Sets the import variables.
     *
     * @param id the id
     * @param url the url
     * @param collection the collection
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public void setImportVariables(String id, String url, String collection)
        throws IOException {
<span class="nc bnc" id="L1844" title="All 2 branches missed.">      if (action.equals(ACTION_IMPORT)) {</span>
<span class="nc" id="L1845">        this.id = id;</span>
<span class="nc" id="L1846">        StringBuilder importUrlBuffer = new StringBuilder(url);</span>
<span class="nc" id="L1847">        importUrlBuffer.append(&quot;select&quot;);</span>
<span class="nc" id="L1848">        importUrlBuffer.append(&quot;?q=*:*&amp;rows=0&amp;wt=json&quot;);</span>
<span class="nc" id="L1849">        importUrlBuffer.append(&quot;&amp;mtas=true&amp;mtas.collection=true&quot;);</span>
<span class="nc" id="L1850">        importUrlBuffer.append(&quot;&amp;mtas.collection.0.key=0&quot;);</span>
<span class="nc" id="L1851">        importUrlBuffer.append(&quot;&amp;mtas.collection.0.action=get&quot;);</span>
<span class="nc" id="L1852">        importUrlBuffer.append(</span>
<span class="nc" id="L1853">            &quot;&amp;mtas.collection.0.id=&quot; + URLEncoder.encode(collection, &quot;UTF-8&quot;));</span>
<span class="nc" id="L1854">        Map&lt;String, Object&gt; params = getImport(importUrlBuffer.toString());</span>
        try {
<span class="nc bnc" id="L1856" title="All 4 branches missed.">          if (params.containsKey(&quot;mtas&quot;) &amp;&amp; params.get(&quot;mtas&quot;) instanceof Map) {</span>
<span class="nc" id="L1857">            Map&lt;String, Object&gt; mtasParams = (Map&lt;String, Object&gt;) params</span>
<span class="nc" id="L1858">                .get(&quot;mtas&quot;);</span>
<span class="nc bnc" id="L1859" title="All 2 branches missed.">            if (mtasParams.containsKey(&quot;collection&quot;)</span>
<span class="nc bnc" id="L1860" title="All 2 branches missed.">                &amp;&amp; mtasParams.get(&quot;collection&quot;) instanceof List) {</span>
<span class="nc" id="L1861">              List&lt;Object&gt; mtasCollectionList = (List&lt;Object&gt;) mtasParams</span>
<span class="nc" id="L1862">                  .get(&quot;collection&quot;);</span>
<span class="nc bnc" id="L1863" title="All 2 branches missed.">              if (mtasCollectionList.size() == 1</span>
<span class="nc bnc" id="L1864" title="All 2 branches missed.">                  &amp;&amp; mtasCollectionList.get(0) instanceof Map) {</span>
<span class="nc" id="L1865">                Map&lt;String, Object&gt; collectionData = (Map&lt;String, Object&gt;) mtasCollectionList</span>
<span class="nc" id="L1866">                    .get(0);</span>
<span class="nc bnc" id="L1867" title="All 2 branches missed.">                if (collectionData.containsKey(&quot;values&quot;)</span>
<span class="nc bnc" id="L1868" title="All 2 branches missed.">                    &amp;&amp; collectionData.get(&quot;values&quot;) instanceof List) {</span>
<span class="nc" id="L1869">                  List&lt;String&gt; valuesList = (List&lt;String&gt;) collectionData</span>
<span class="nc" id="L1870">                      .get(&quot;values&quot;);</span>
<span class="nc bnc" id="L1871" title="All 2 branches missed.">                  for (String valueItem : valuesList) {</span>
<span class="nc" id="L1872">                    values.add(valueItem);</span>
                  }
<span class="nc" id="L1874">                } else {</span>
<span class="nc" id="L1875">                  throw new IOException(&quot;no values in response&quot;);</span>
                }
              } else {
<span class="nc" id="L1878">                throw new IOException(</span>
<span class="nc" id="L1879">                    &quot;no valid mtas collection item in response&quot;);</span>
              }
            } else {
<span class="nc" id="L1882">              throw new IOException(&quot;no valid mtas collection in response&quot;);</span>
            }
          } else {
<span class="nc" id="L1885">            throw new IOException(&quot;no valid mtas in response&quot;);</span>
          }
<span class="nc" id="L1887">        } catch (ClassCastException e) {</span>
<span class="nc" id="L1888">          throw new IOException(&quot;unexpected response&quot;, e);</span>
        }
      } else {
<span class="nc" id="L1891">        throw new IOException(&quot;not allowed with action &quot; + action);</span>
      }
<span class="nc" id="L1893">    }</span>

    /**
     * Gets the import.
     *
     * @param collectionGetUrl the collection get url
     * @return the import
     * @throws IOException Signals that an I/O exception has occurred.
     */
    private Map&lt;String, Object&gt; getImport(String collectionGetUrl)
        throws IOException {
      // get data
<span class="nc" id="L1905">      URL url = new URL(collectionGetUrl);</span>
<span class="nc" id="L1906">      HttpURLConnection connection = (HttpURLConnection) url.openConnection();</span>
<span class="nc" id="L1907">      connection.setDoOutput(false);</span>
<span class="nc" id="L1908">      connection.setDoInput(true);</span>
<span class="nc" id="L1909">      connection.setInstanceFollowRedirects(false);</span>
<span class="nc" id="L1910">      connection.setRequestMethod(&quot;GET&quot;);</span>
<span class="nc" id="L1911">      connection.setRequestProperty(&quot;Content-Type&quot;,</span>
<span class="nc" id="L1912">          &quot;application/json; charset=UTF-8&quot;);</span>
<span class="nc" id="L1913">      connection.setRequestProperty(&quot;charset&quot;, &quot;utf-8&quot;);</span>
<span class="nc" id="L1914">      connection.setUseCaches(false);</span>
      // process response
<span class="nc" id="L1916">      InputStream is = null;</span>
      try {
<span class="nc" id="L1918">        is = connection.getInputStream();</span>
<span class="nc" id="L1919">      } catch (IOException ioe) {</span>
<span class="nc" id="L1920">        throw new IOException(&quot;Couldn't get data from url&quot;);</span>
      }
<span class="nc" id="L1922">      InputStreamReader in = new InputStreamReader((InputStream) is, &quot;UTF8&quot;);</span>
<span class="nc" id="L1923">      Map&lt;String, Object&gt; params = new HashMap&lt;&gt;();</span>
<span class="nc" id="L1924">      getParamsFromJSON(params, IOUtils.toString(in));</span>
<span class="nc" id="L1925">      connection.disconnect();</span>
<span class="nc" id="L1926">      return params;</span>
    }

    /**
     * Sets the delete variables.
     *
     * @param id the new delete variables
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public void setDeleteVariables(String id) throws IOException {
<span class="pc bpc" id="L1936" title="1 of 2 branches missed.">      if (action.equals(ACTION_DELETE)) {</span>
<span class="fc" id="L1937">        this.id = id;</span>
<span class="fc" id="L1938">      } else {</span>
<span class="nc" id="L1939">        throw new IOException(&quot;not allowed with action &quot; + action);</span>
      }
<span class="fc" id="L1941">    }</span>

    /**
     * Action.
     *
     * @return the string
     */
    public String action() {
<span class="fc" id="L1949">      return action;</span>
    }

    /**
     * Values.
     *
     * @return the hash set
     */
    public HashSet&lt;String&gt; values() {
<span class="fc" id="L1958">      return values;</span>
    }

    /**
     * Fields.
     *
     * @return the sets the
     */
    public Set&lt;String&gt; fields() {
<span class="fc" id="L1967">      return fields;</span>
    }

    /**
     * Adds the value.
     *
     * @param value the value
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public void addValue(String value) throws IOException {
<span class="pc bpc" id="L1977" title="1 of 2 branches missed.">      if (action.equals(ACTION_CREATE)) {</span>
<span class="pc bpc" id="L1978" title="1 of 2 branches missed.">        if (version == null) {</span>
<span class="fc" id="L1979">          values.add(value);</span>
<span class="fc" id="L1980">        } else {</span>
<span class="nc" id="L1981">          throw new IOException(&quot;version already set&quot;);</span>
        }
      } else {
<span class="nc" id="L1984">        throw new IOException(&quot;not allowed for action '&quot; + action + &quot;'&quot;);</span>
      }
<span class="fc" id="L1986">    }</span>

    /**
     * Gets the params from JSON.
     *
     * @param params the params
     * @param json the json
     * @return the params from JSON
     */
    private static void getParamsFromJSON(Map&lt;String, Object&gt; params,
        String json) {
<span class="nc" id="L1997">      JSONParser parser = new JSONParser(json);</span>
      try {
<span class="nc" id="L1999">        Object o = ObjectBuilder.getVal(parser);</span>
<span class="nc bnc" id="L2000" title="All 2 branches missed.">        if (!(o instanceof Map))</span>
<span class="nc" id="L2001">          return;</span>
<span class="nc" id="L2002">        Map&lt;String, Object&gt; map = (Map&lt;String, Object&gt;) o;</span>
        // To make consistent with json.param handling, we should make query
        // params come after json params (i.e. query params should
        // appear to overwrite json params.

        // Solr params are based on String though, so we need to convert
<span class="nc bnc" id="L2008" title="All 2 branches missed.">        for (Map.Entry&lt;String, Object&gt; entry : map.entrySet()) {</span>
<span class="nc" id="L2009">          String key = entry.getKey();</span>
<span class="nc" id="L2010">          Object val = entry.getValue();</span>
<span class="nc bnc" id="L2011" title="All 2 branches missed.">          if (params.get(key) != null) {</span>
<span class="nc" id="L2012">            continue;</span>
          }

<span class="nc bnc" id="L2015" title="All 2 branches missed.">          if (val == null) {</span>
<span class="nc" id="L2016">            params.remove(key);</span>
<span class="nc" id="L2017">          } else {</span>
<span class="nc" id="L2018">            params.put(key, val);</span>
          }
        }

<span class="nc" id="L2022">      } catch (Exception e) {</span>
        // ignore parse exceptions at this stage, they may be caused by
        // incomplete
        // macro expansions
<span class="nc" id="L2026">        return;</span>
      }

<span class="nc" id="L2029">    }</span>

  }

  /**
   * The Class SubComponentFunction.
   */
  public static class SubComponentFunction {

    /** The key. */
    public String key;

    /** The expression. */
    public String expression;

    /** The type. */
    public String type;

    /** The parser function. */
    public MtasFunctionParserFunction parserFunction;

    /** The stats type. */
    public String statsType;

    /** The data type. */
    public String dataType;

    /** The sort type. */
    public String sortType;

    /** The sort direction. */
    public String sortDirection;

    /** The stats items. */
    public SortedSet&lt;String&gt; statsItems;

    /** The data collector. */
    public MtasDataCollector&lt;?, ?&gt; dataCollector;

    /**
     * Instantiates a new sub component function.
     *
     * @param collectorType the collector type
     * @param key the key
     * @param type the type
     * @param parserFunction the parser function
     * @param sortType the sort type
     * @param sortDirection the sort direction
     * @param start the start
     * @param number the number
     * @param segmentRegistration the segment registration
     * @param boundary the boundary
     * @throws ParseException the parse exception
     * @throws IOException Signals that an I/O exception has occurred.
     */
<span class="fc" id="L2084">    public SubComponentFunction(String collectorType, String key, String type,</span>
        MtasFunctionParserFunction parserFunction, String sortType,
        String sortDirection, Integer start, Integer number,
        String segmentRegistration, String boundary)
        throws ParseException, IOException {
<span class="fc" id="L2089">      this.key = key;</span>
<span class="fc" id="L2090">      this.expression = null;</span>
<span class="fc" id="L2091">      this.type = type;</span>
<span class="fc" id="L2092">      this.parserFunction = parserFunction;</span>
<span class="fc" id="L2093">      this.sortType = sortType;</span>
<span class="fc" id="L2094">      this.sortDirection = sortDirection;</span>
<span class="fc" id="L2095">      this.dataType = parserFunction.getType();</span>
<span class="fc" id="L2096">      this.statsItems = CodecUtil.createStatsItems(this.type);</span>
<span class="fc" id="L2097">      this.statsType = CodecUtil.createStatsType(statsItems, sortType,</span>
<span class="fc" id="L2098">          parserFunction);</span>
<span class="pc bpc" id="L2099" title="1 of 2 branches missed.">      if (collectorType.equals(DataCollector.COLLECTOR_TYPE_LIST)) {</span>
<span class="fc" id="L2100">        dataCollector = DataCollector.getCollector(</span>
<span class="fc" id="L2101">            DataCollector.COLLECTOR_TYPE_LIST, dataType, statsType, statsItems,</span>
<span class="fc" id="L2102">            sortType, sortDirection, start, number, null, null, null, null,</span>
<span class="fc" id="L2103">            null, null, null, null, segmentRegistration, boundary);</span>
<span class="pc bnc" id="L2104" title="All 2 branches missed.">      } else if (collectorType.equals(DataCollector.COLLECTOR_TYPE_DATA)) {</span>
<span class="nc" id="L2105">        dataCollector = DataCollector.getCollector(</span>
<span class="nc" id="L2106">            DataCollector.COLLECTOR_TYPE_DATA, dataType, statsType, statsItems,</span>
<span class="nc" id="L2107">            sortType, sortDirection, start, number, segmentRegistration,</span>
<span class="nc" id="L2108">            boundary);</span>
      }
<span class="fc" id="L2110">    }</span>

    /**
     * Instantiates a new sub component function.
     *
     * @param collectorType the collector type
     * @param key the key
     * @param expression the expression
     * @param type the type
     * @throws ParseException the parse exception
     * @throws IOException Signals that an I/O exception has occurred.
     */
<span class="fc" id="L2122">    public SubComponentFunction(String collectorType, String key,</span>
        String expression, String type) throws ParseException, IOException {
<span class="fc" id="L2124">      this.key = key;</span>
<span class="fc" id="L2125">      this.expression = expression;</span>
<span class="fc" id="L2126">      this.type = type;</span>
<span class="fc" id="L2127">      this.sortType = null;</span>
<span class="fc" id="L2128">      this.sortDirection = null;</span>
<span class="fc" id="L2129">      parserFunction = new MtasFunctionParser(</span>
<span class="fc" id="L2130">          new BufferedReader(new StringReader(this.expression))).parse();</span>
<span class="fc" id="L2131">      dataType = parserFunction.getType();</span>
<span class="fc" id="L2132">      statsItems = CodecUtil.createStatsItems(this.type);</span>
<span class="fc" id="L2133">      statsType = CodecUtil.createStatsType(statsItems, null, parserFunction);</span>
<span class="pc bpc" id="L2134" title="1 of 2 branches missed.">      if (collectorType.equals(DataCollector.COLLECTOR_TYPE_LIST)) {</span>
<span class="nc" id="L2135">        dataCollector = DataCollector.getCollector(</span>
<span class="nc" id="L2136">            DataCollector.COLLECTOR_TYPE_LIST, dataType, statsType, statsItems,</span>
<span class="nc" id="L2137">            sortType, sortDirection, 0, Integer.MAX_VALUE, null, null);</span>
<span class="pc bpc" id="L2138" title="1 of 2 branches missed.">      } else if (collectorType.equals(DataCollector.COLLECTOR_TYPE_DATA)) {</span>
<span class="fc" id="L2139">        dataCollector = DataCollector.getCollector(</span>
<span class="fc" id="L2140">            DataCollector.COLLECTOR_TYPE_DATA, dataType, statsType, statsItems,</span>
<span class="fc" id="L2141">            sortType, sortDirection, null, null, null, null);</span>
      }
<span class="fc" id="L2143">    }</span>
  }

  /**
   * The Class KwicToken.
   */
  public static class KwicToken {

    /** The start position. */
    public int startPosition;

    /** The end position. */
    public int endPosition;

    /** The tokens. */
    public List&lt;MtasTokenString&gt; tokens;

    /**
     * Instantiates a new kwic token.
     *
     * @param match the match
     * @param tokens the tokens
     */
<span class="nc" id="L2166">    public KwicToken(Match match, List&lt;MtasTokenString&gt; tokens) {</span>
<span class="nc" id="L2167">      startPosition = match.startPosition;</span>
<span class="nc" id="L2168">      endPosition = match.endPosition - 1;</span>
<span class="nc" id="L2169">      this.tokens = tokens;</span>
<span class="nc" id="L2170">    }</span>

  }

  /**
   * The Class KwicHit.
   */
  public static class KwicHit {

    /** The start position. */
    public int startPosition;

    /** The end position. */
    public int endPosition;

    /** The hits. */
    public Map&lt;Integer, List&lt;String&gt;&gt; hits;

    /**
     * Instantiates a new kwic hit.
     *
     * @param match the match
     * @param hits the hits
     */
<span class="nc" id="L2194">    public KwicHit(Match match, Map&lt;Integer, List&lt;String&gt;&gt; hits) {</span>
<span class="nc" id="L2195">      startPosition = match.startPosition;</span>
<span class="nc" id="L2196">      endPosition = match.endPosition - 1;</span>
<span class="nc" id="L2197">      this.hits = hits;</span>
<span class="nc" id="L2198">    }</span>
  }

  /**
   * The Class GroupHit.
   */
  public static class GroupHit {

    /** The hash. */
    private int hash;

    /** The hash left. */
    private int hashLeft;

    /** The hash hit. */
    private int hashHit;

    /** The hash right. */
    private int hashRight;

    /** The key. */
    private String key;

    /** The key left. */
    private String keyLeft;

    /** The key hit. */
    private String keyHit;

    /** The key right. */
    private String keyRight;

    /** The data hit. */
    public List&lt;String&gt;[] dataHit;

    /** The data left. */
    public List&lt;String&gt;[] dataLeft;

    /** The data right. */
    public List&lt;String&gt;[] dataRight;

    /** The missing hit. */
    public Set&lt;String&gt;[] missingHit;

    /** The missing left. */
    public Set&lt;String&gt;[] missingLeft;

    /** The missing right. */
    public Set&lt;String&gt;[] missingRight;

    /** The unknown hit. */
    public Set&lt;String&gt;[] unknownHit;

    /** The unknown left. */
    public Set&lt;String&gt;[] unknownLeft;

    /** The unknown right. */
    public Set&lt;String&gt;[] unknownRight;

    /** The Constant KEY_START. */
    public static final String KEY_START = MtasToken.DELIMITER + &quot;grouphit&quot;
        + MtasToken.DELIMITER;

    /**
     * Sort.
     *
     * @param data the data
     * @return the list
     */
    private List&lt;MtasTreeHit&lt;String&gt;&gt; sort(List&lt;MtasTreeHit&lt;String&gt;&gt; data) {
<span class="fc" id="L2268">      Collections.sort(data, new Comparator&lt;MtasTreeHit&lt;String&gt;&gt;() {</span>
        @Override
        public int compare(MtasTreeHit&lt;String&gt; hit1, MtasTreeHit&lt;String&gt; hit2) {
<span class="fc" id="L2271">          int compare = Integer.compare(hit1.additionalId, hit2.additionalId);</span>
<span class="fc bfc" id="L2272" title="All 2 branches covered.">          compare = (compare == 0)</span>
<span class="fc" id="L2273">              ? Long.compare(hit1.additionalRef, hit2.additionalRef) : compare;</span>
<span class="fc" id="L2274">          return compare;</span>
        }
      });
<span class="fc" id="L2277">      return data;</span>
    }

    /**
     * Instantiates a new group hit.
     *
     * @param list the list
     * @param start the start
     * @param end the end
     * @param hitStart the hit start
     * @param hitEnd the hit end
     * @param group the group
     * @param knownPrefixes the known prefixes
     * @throws UnsupportedEncodingException the unsupported encoding exception
     */
    @SuppressWarnings(&quot;unchecked&quot;)
<span class="fc" id="L2293">    public GroupHit(List&lt;MtasTreeHit&lt;String&gt;&gt; list, int start, int end,</span>
        int hitStart, int hitEnd, ComponentGroup group,
        Set&lt;String&gt; knownPrefixes) throws UnsupportedEncodingException {
      // compute dimensions
<span class="fc" id="L2297">      int leftRangeStart = start;</span>
<span class="fc" id="L2298">      int leftRangeEnd = Math.min(end, hitStart - 1);</span>
<span class="fc" id="L2299">      int leftRangeLength = Math.max(0, 1 + leftRangeEnd - leftRangeStart);</span>
<span class="fc" id="L2300">      int hitLength = 1 + hitEnd - hitStart;</span>
<span class="fc" id="L2301">      int rightRangeStart = Math.max(start, hitEnd + 1);</span>
<span class="fc" id="L2302">      int rightRangeEnd = end;</span>
<span class="fc" id="L2303">      int rightRangeLength = Math.max(0, 1 + rightRangeEnd - rightRangeStart);</span>
      // create initial arrays
<span class="fc bfc" id="L2305" title="All 2 branches covered.">      if (leftRangeLength &gt; 0) {</span>
<span class="fc" id="L2306">        keyLeft = &quot;&quot;;</span>
<span class="fc" id="L2307">        dataLeft = (ArrayList&lt;String&gt;[]) new ArrayList[leftRangeLength];</span>
<span class="fc" id="L2308">        missingLeft = (HashSet&lt;String&gt;[]) new HashSet[leftRangeLength];</span>
<span class="fc" id="L2309">        unknownLeft = (HashSet&lt;String&gt;[]) new HashSet[leftRangeLength];</span>
<span class="fc bfc" id="L2310" title="All 2 branches covered.">        for (int p = 0; p &lt; leftRangeLength; p++) {</span>
<span class="fc" id="L2311">          dataLeft[p] = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L2312">          missingLeft[p] = new HashSet&lt;&gt;();</span>
<span class="fc" id="L2313">          unknownLeft[p] = new HashSet&lt;&gt;();</span>
        }
<span class="fc" id="L2315">      } else {</span>
<span class="fc" id="L2316">        keyLeft = null;</span>
<span class="fc" id="L2317">        dataLeft = null;</span>
<span class="fc" id="L2318">        missingLeft = null;</span>
<span class="fc" id="L2319">        unknownLeft = null;</span>
      }
<span class="pc bpc" id="L2321" title="1 of 2 branches missed.">      if (hitLength &gt; 0) {</span>
<span class="fc" id="L2322">        keyHit = &quot;&quot;;</span>
<span class="fc" id="L2323">        dataHit = (ArrayList&lt;String&gt;[]) new ArrayList[hitLength];</span>
<span class="fc" id="L2324">        missingHit = (HashSet&lt;String&gt;[]) new HashSet[hitLength];</span>
<span class="fc" id="L2325">        unknownHit = (HashSet&lt;String&gt;[]) new HashSet[hitLength];</span>
<span class="fc bfc" id="L2326" title="All 2 branches covered.">        for (int p = 0; p &lt; hitLength; p++) {</span>
<span class="fc" id="L2327">          dataHit[p] = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L2328">          missingHit[p] = new HashSet&lt;&gt;();</span>
<span class="fc" id="L2329">          unknownHit[p] = new HashSet&lt;&gt;();</span>
        }
<span class="fc" id="L2331">      } else {</span>
<span class="nc" id="L2332">        keyHit = null;</span>
<span class="nc" id="L2333">        dataHit = null;</span>
<span class="nc" id="L2334">        missingHit = null;</span>
<span class="nc" id="L2335">        unknownHit = null;</span>
      }
<span class="fc bfc" id="L2337" title="All 2 branches covered.">      if (rightRangeLength &gt; 0) {</span>
<span class="fc" id="L2338">        keyRight = &quot;&quot;;</span>
<span class="fc" id="L2339">        dataRight = (ArrayList&lt;String&gt;[]) new ArrayList[rightRangeLength];</span>
<span class="fc" id="L2340">        missingRight = (HashSet&lt;String&gt;[]) new HashSet[rightRangeLength];</span>
<span class="fc" id="L2341">        unknownRight = (HashSet&lt;String&gt;[]) new HashSet[rightRangeLength];</span>
<span class="fc bfc" id="L2342" title="All 2 branches covered.">        for (int p = 0; p &lt; rightRangeLength; p++) {</span>
<span class="fc" id="L2343">          dataRight[p] = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L2344">          missingRight[p] = new HashSet&lt;&gt;();</span>
<span class="fc" id="L2345">          unknownRight[p] = new HashSet&lt;&gt;();</span>
        }
<span class="fc" id="L2347">      } else {</span>
<span class="fc" id="L2348">        keyRight = null;</span>
<span class="fc" id="L2349">        dataRight = null;</span>
<span class="fc" id="L2350">        missingRight = null;</span>
<span class="fc" id="L2351">        unknownRight = null;</span>
      }

      // construct missing sets
<span class="fc bfc" id="L2355" title="All 2 branches covered.">      if (group.hitInside != null) {</span>
<span class="fc bfc" id="L2356" title="All 2 branches covered.">        for (int p = hitStart; p &lt;= hitEnd; p++) {</span>
<span class="fc" id="L2357">          missingHit[p - hitStart].addAll(group.hitInside);</span>
        }
      }
<span class="fc bfc" id="L2360" title="All 2 branches covered.">      if (group.hitInsideLeft != null) {</span>
<span class="fc bfc" id="L2361" title="All 2 branches covered.">        for (int p = hitStart; p &lt;= Math.min(hitEnd,</span>
<span class="fc" id="L2362">            hitStart + group.hitInsideLeft.length - 1); p++) {</span>
<span class="pc bpc" id="L2363" title="1 of 2 branches missed.">          if (group.hitInsideLeft[p - hitStart] != null) {</span>
<span class="fc" id="L2364">            missingHit[p - hitStart].addAll(group.hitInsideLeft[p - hitStart]);</span>
          }
        }
      }
<span class="fc bfc" id="L2368" title="All 2 branches covered.">      if (group.hitLeft != null) {</span>
<span class="fc bfc" id="L2369" title="All 2 branches covered.">        for (int p = hitStart; p &lt;= Math.min(hitEnd,</span>
<span class="fc" id="L2370">            hitStart + group.hitLeft.length - 1); p++) {</span>
<span class="pc bpc" id="L2371" title="1 of 2 branches missed.">          if (group.hitLeft[p - hitStart] != null) {</span>
<span class="fc" id="L2372">            missingHit[p - hitStart].addAll(group.hitLeft[p - hitStart]);</span>
          }
        }
      }
<span class="fc bfc" id="L2376" title="All 2 branches covered.">      if (group.hitInsideRight != null) {</span>
<span class="fc bfc" id="L2377" title="All 2 branches covered.">        for (int p = Math.max(hitStart,</span>
<span class="fc" id="L2378">            hitEnd - group.hitInsideRight.length + 1); p &lt;= hitEnd; p++) {</span>
<span class="fc bfc" id="L2379" title="All 2 branches covered.">          if (group.hitInsideRight[hitEnd - p] != null) {</span>
<span class="fc" id="L2380">            missingHit[p - hitStart].addAll(group.hitInsideRight[hitEnd - p]);</span>
          }
        }
      }
<span class="fc bfc" id="L2384" title="All 2 branches covered.">      if (group.hitRight != null) {</span>
<span class="fc bfc" id="L2385" title="All 2 branches covered.">        for (int p = hitStart; p &lt;= Math.min(hitEnd,</span>
<span class="fc" id="L2386">            hitStart + group.hitRight.length - 1); p++) {</span>
<span class="fc bfc" id="L2387" title="All 2 branches covered.">          if (group.hitRight[p - hitStart] != null) {</span>
<span class="fc" id="L2388">            missingHit[p - hitStart].addAll(group.hitRight[p - hitStart]);</span>
          }
        }
      }
<span class="fc bfc" id="L2392" title="All 2 branches covered.">      if (group.left != null) {</span>
<span class="fc bfc" id="L2393" title="All 2 branches covered.">        for (int p = 0; p &lt; Math.min(leftRangeLength, group.left.length); p++) {</span>
<span class="fc bfc" id="L2394" title="All 2 branches covered.">          if (group.left[p] != null) {</span>
<span class="fc" id="L2395">            missingLeft[p].addAll(group.left[p]);</span>
          }
        }
      }
<span class="fc bfc" id="L2399" title="All 2 branches covered.">      if (group.hitRight != null) {</span>
<span class="fc bfc" id="L2400" title="All 2 branches covered.">        for (int p = 0; p &lt; Math.min(leftRangeLength,</span>
<span class="fc" id="L2401">            group.hitRight.length - dataHit.length); p++) {</span>
<span class="pc bpc" id="L2402" title="1 of 2 branches missed.">          if (group.hitRight[p + dataHit.length] != null) {</span>
<span class="fc" id="L2403">            missingLeft[p].addAll(group.hitRight[p + dataHit.length]);</span>
          }
        }
      }
<span class="fc bfc" id="L2407" title="All 2 branches covered.">      if (group.right != null) {</span>
<span class="fc bfc" id="L2408" title="All 2 branches covered.">        for (int p = 0; p &lt; Math.min(rightRangeLength,</span>
<span class="fc" id="L2409">            group.right.length); p++) {</span>
<span class="fc bfc" id="L2410" title="All 2 branches covered.">          if (group.right[p] != null) {</span>
<span class="fc" id="L2411">            missingRight[p].addAll(group.right[p]);</span>
          }
        }
      }
<span class="fc bfc" id="L2415" title="All 2 branches covered.">      if (group.hitLeft != null) {</span>
<span class="fc bfc" id="L2416" title="All 2 branches covered.">        for (int p = 0; p &lt; Math.min(rightRangeLength,</span>
<span class="fc" id="L2417">            group.hitLeft.length - dataHit.length); p++) {</span>
<span class="pc bpc" id="L2418" title="1 of 2 branches missed.">          if (group.hitLeft[p + dataHit.length] != null) {</span>
<span class="fc" id="L2419">            missingRight[p].addAll(group.hitLeft[p + dataHit.length]);</span>
          }
        }
      }

      // fill arrays and update missing administration
<span class="fc" id="L2425">      List&lt;MtasTreeHit&lt;String&gt;&gt; sortedList = sort(list);</span>
<span class="fc bfc" id="L2426" title="All 2 branches covered.">      for (MtasTreeHit&lt;String&gt; hit : sortedList) {</span>
        // inside hit
<span class="pc bpc" id="L2428" title="1 of 4 branches missed.">        if (group.hitInside != null &amp;&amp; hit.idData != null</span>
<span class="fc bfc" id="L2429" title="All 2 branches covered.">            &amp;&amp; group.hitInside.contains(hit.idData)) {</span>
<span class="fc bfc" id="L2430" title="All 2 branches covered.">          for (int p = Math.max(hitStart, hit.startPosition); p &lt;= Math</span>
<span class="fc" id="L2431">              .min(hitEnd, hit.endPosition); p++) {</span>
<span class="fc" id="L2432">            dataHit[p - hitStart].add(hit.refData);</span>
<span class="fc" id="L2433">            missingHit[p - hitStart]</span>
<span class="fc" id="L2434">                .remove(MtasToken.getPrefixFromValue(hit.refData));</span>
          }
<span class="fc bfc" id="L2436" title="All 4 branches covered.">        } else if ((group.hitInsideLeft != null || group.hitLeft != null</span>
<span class="fc bfc" id="L2437" title="All 4 branches covered.">            || group.hitInsideRight != null || group.hitRight != null)</span>
<span class="pc bpc" id="L2438" title="1 of 2 branches missed.">            &amp;&amp; hit.idData != null) {</span>
<span class="fc bfc" id="L2439" title="All 2 branches covered.">          for (int p = Math.max(hitStart, hit.startPosition); p &lt;= Math</span>
<span class="fc" id="L2440">              .min(hitEnd, hit.endPosition); p++) {</span>
<span class="fc" id="L2441">            int pHitLeft = p - hitStart;</span>
<span class="fc" id="L2442">            int pHitRight = hitEnd - p;</span>
<span class="fc bfc" id="L2443" title="All 2 branches covered.">            if (group.hitInsideLeft != null</span>
<span class="pc bpc" id="L2444" title="1 of 2 branches missed.">                &amp;&amp; pHitLeft &lt;= (group.hitInsideLeft.length - 1)</span>
<span class="pc bpc" id="L2445" title="1 of 2 branches missed.">                &amp;&amp; group.hitInsideLeft[pHitLeft] != null</span>
<span class="fc bfc" id="L2446" title="All 2 branches covered.">                &amp;&amp; group.hitInsideLeft[pHitLeft].contains(hit.idData)) {</span>
              // keyHit += hit.refData;
<span class="fc" id="L2448">              dataHit[p - hitStart].add(hit.refData);</span>
<span class="fc" id="L2449">              missingHit[p - hitStart]</span>
<span class="fc" id="L2450">                  .remove(MtasToken.getPrefixFromValue(hit.refData));</span>
<span class="fc bfc" id="L2451" title="All 2 branches covered.">            } else if (group.hitLeft != null</span>
<span class="pc bpc" id="L2452" title="1 of 2 branches missed.">                &amp;&amp; pHitLeft &lt;= (group.hitLeft.length - 1)</span>
<span class="pc bpc" id="L2453" title="1 of 2 branches missed.">                &amp;&amp; group.hitLeft[pHitLeft] != null</span>
<span class="fc bfc" id="L2454" title="All 2 branches covered.">                &amp;&amp; group.hitLeft[pHitLeft].contains(hit.idData)) {</span>
              // keyHit += hit.refData;
<span class="fc" id="L2456">              dataHit[p - hitStart].add(hit.refData);</span>
<span class="fc" id="L2457">              missingHit[p - hitStart]</span>
<span class="fc" id="L2458">                  .remove(MtasToken.getPrefixFromValue(hit.refData));</span>
<span class="fc bfc" id="L2459" title="All 2 branches covered.">            } else if (group.hitInsideRight != null</span>
<span class="pc bpc" id="L2460" title="1 of 2 branches missed.">                &amp;&amp; pHitRight &lt;= (group.hitInsideRight.length - 1)</span>
<span class="fc bfc" id="L2461" title="All 2 branches covered.">                &amp;&amp; group.hitInsideRight[pHitRight] != null</span>
<span class="fc bfc" id="L2462" title="All 2 branches covered.">                &amp;&amp; group.hitInsideRight[pHitRight].contains(hit.idData)) {</span>
<span class="fc" id="L2463">              dataHit[p - hitStart].add(hit.refData);</span>
<span class="fc" id="L2464">              missingHit[p - hitStart]</span>
<span class="fc" id="L2465">                  .remove(MtasToken.getPrefixFromValue(hit.refData));</span>
<span class="fc bfc" id="L2466" title="All 2 branches covered.">            } else if (group.hitRight != null</span>
<span class="pc bpc" id="L2467" title="1 of 2 branches missed.">                &amp;&amp; pHitRight &lt;= (group.hitRight.length - 1)</span>
<span class="fc bfc" id="L2468" title="All 2 branches covered.">                &amp;&amp; group.hitRight[pHitRight] != null</span>
<span class="fc bfc" id="L2469" title="All 2 branches covered.">                &amp;&amp; group.hitRight[pHitRight].contains(hit.idData)) {</span>
<span class="fc" id="L2470">              dataHit[p - hitStart].add(hit.refData);</span>
<span class="fc" id="L2471">              missingHit[p - hitStart]</span>
<span class="fc" id="L2472">                  .remove(MtasToken.getPrefixFromValue(hit.refData));</span>
            }
          }
        }
        // left
<span class="fc bfc" id="L2477" title="All 2 branches covered.">        if (hit.startPosition &lt; hitStart) {</span>
<span class="pc bpc" id="L2478" title="1 of 4 branches missed.">          if ((group.left != null || (group.hitRight != null</span>
<span class="pc bpc" id="L2479" title="1 of 2 branches missed.">              &amp;&amp; group.hitRight.length &gt; (1 + hitEnd - hitStart)))</span>
<span class="pc bpc" id="L2480" title="1 of 2 branches missed.">              &amp;&amp; hit.idData != null) {</span>
<span class="fc bfc" id="L2481" title="All 2 branches covered.">            for (int p = Math.min(hit.endPosition,</span>
<span class="fc" id="L2482">                hitStart - 1); p &gt;= hit.startPosition; p--) {</span>
<span class="fc" id="L2483">              int pLeft = hitStart - 1 - p;</span>
<span class="fc" id="L2484">              int pHitRight = hitEnd - p;</span>
<span class="fc bfc" id="L2485" title="All 4 branches covered.">              if (group.left != null &amp;&amp; pLeft &lt;= (group.left.length - 1)</span>
<span class="fc bfc" id="L2486" title="All 2 branches covered.">                  &amp;&amp; group.left[pLeft] != null</span>
<span class="fc bfc" id="L2487" title="All 2 branches covered.">                  &amp;&amp; group.left[pLeft].contains(hit.idData)) {</span>
<span class="fc" id="L2488">                dataLeft[hitStart - 1 - p].add(hit.refData);</span>
<span class="fc" id="L2489">                missingLeft[hitStart - 1 - p]</span>
<span class="fc" id="L2490">                    .remove(MtasToken.getPrefixFromValue(hit.refData));</span>
<span class="fc bfc" id="L2491" title="All 2 branches covered.">              } else if (group.hitRight != null</span>
<span class="fc bfc" id="L2492" title="All 2 branches covered.">                  &amp;&amp; pHitRight &lt;= (group.hitRight.length - 1)</span>
<span class="pc bpc" id="L2493" title="1 of 2 branches missed.">                  &amp;&amp; group.hitRight[pHitRight] != null</span>
<span class="fc bfc" id="L2494" title="All 2 branches covered.">                  &amp;&amp; group.hitRight[pHitRight].contains(hit.idData)) {</span>
<span class="fc" id="L2495">                dataLeft[hitStart - 1 - p].add(hit.refData);</span>
<span class="fc" id="L2496">                missingLeft[hitStart - 1 - p]</span>
<span class="fc" id="L2497">                    .remove(MtasToken.getPrefixFromValue(hit.refData));</span>
              }
            }
          }
        }
        // right
<span class="fc bfc" id="L2503" title="All 2 branches covered.">        if (hit.endPosition &gt; hitEnd) {</span>
<span class="pc bpc" id="L2504" title="1 of 4 branches missed.">          if ((group.right != null || (group.hitLeft != null</span>
<span class="pc bpc" id="L2505" title="1 of 2 branches missed.">              &amp;&amp; group.hitLeft.length &gt; (1 + hitEnd - hitStart)))</span>
<span class="pc bpc" id="L2506" title="1 of 2 branches missed.">              &amp;&amp; hit.idData != null) {</span>
<span class="fc bfc" id="L2507" title="All 2 branches covered.">            for (int p = Math.max(hit.startPosition,</span>
<span class="fc" id="L2508">                hitEnd + 1); p &lt;= hit.endPosition; p++) {</span>
<span class="fc" id="L2509">              int pRight = p - hitEnd - 1;</span>
<span class="fc" id="L2510">              int pHitLeft = p - hitStart;</span>
<span class="fc bfc" id="L2511" title="All 4 branches covered.">              if (group.right != null &amp;&amp; pRight &lt;= (group.right.length - 1)</span>
<span class="fc bfc" id="L2512" title="All 2 branches covered.">                  &amp;&amp; group.right[pRight] != null</span>
<span class="fc bfc" id="L2513" title="All 2 branches covered.">                  &amp;&amp; group.right[pRight].contains(hit.idData)) {</span>
<span class="fc" id="L2514">                dataRight[p - rightRangeStart].add(hit.refData);</span>
<span class="fc" id="L2515">                missingRight[p - rightRangeStart]</span>
<span class="fc" id="L2516">                    .remove(MtasToken.getPrefixFromValue(hit.refData));</span>
<span class="fc bfc" id="L2517" title="All 2 branches covered.">              } else if (group.hitLeft != null</span>
<span class="fc bfc" id="L2518" title="All 2 branches covered.">                  &amp;&amp; pHitLeft &lt;= (group.hitLeft.length - 1)</span>
<span class="pc bpc" id="L2519" title="1 of 2 branches missed.">                  &amp;&amp; group.hitLeft[pHitLeft] != null</span>
<span class="fc bfc" id="L2520" title="All 2 branches covered.">                  &amp;&amp; group.hitLeft[pHitLeft].contains(hit.idData)) {</span>
<span class="fc" id="L2521">                dataRight[p - rightRangeStart].add(hit.refData);</span>
<span class="fc" id="L2522">                missingRight[p - rightRangeStart]</span>
<span class="fc" id="L2523">                    .remove(MtasToken.getPrefixFromValue(hit.refData));</span>
              }
            }
          }
        }
      }
      // register unknown
<span class="fc bfc" id="L2530" title="All 2 branches covered.">      if (missingLeft != null) {</span>
<span class="fc bfc" id="L2531" title="All 2 branches covered.">        for (int i = 0; i &lt; missingLeft.length; i++) {</span>
<span class="fc bfc" id="L2532" title="All 2 branches covered.">          for (String prefix : missingLeft[i]) {</span>
<span class="pc bpc" id="L2533" title="1 of 2 branches missed.">            if (!knownPrefixes.contains(prefix)) {</span>
<span class="nc" id="L2534">              unknownLeft[i].add(prefix);</span>
            }
          }
        }
      }
<span class="pc bpc" id="L2539" title="1 of 2 branches missed.">      if (missingHit != null) {</span>
<span class="fc bfc" id="L2540" title="All 2 branches covered.">        for (int i = 0; i &lt; missingHit.length; i++) {</span>
<span class="fc bfc" id="L2541" title="All 2 branches covered.">          for (String prefix : missingHit[i]) {</span>
<span class="pc bpc" id="L2542" title="1 of 2 branches missed.">            if (!knownPrefixes.contains(prefix)) {</span>
<span class="nc" id="L2543">              unknownHit[i].add(prefix);</span>
            }
          }
        }
      }
<span class="fc bfc" id="L2548" title="All 2 branches covered.">      if (missingRight != null) {</span>
<span class="fc bfc" id="L2549" title="All 2 branches covered.">        for (int i = 0; i &lt; missingRight.length; i++) {</span>
<span class="pc bpc" id="L2550" title="1 of 2 branches missed.">          for (String prefix : missingRight[i]) {</span>
<span class="nc bnc" id="L2551" title="All 2 branches missed.">            if (!knownPrefixes.contains(prefix)) {</span>
<span class="nc" id="L2552">              unknownRight[i].add(prefix);</span>
            }
          }
        }
      }
      // construct keys
<span class="fc" id="L2558">      keyLeft = dataToString(dataLeft, missingLeft, true);</span>
<span class="fc" id="L2559">      keyHit = dataToString(dataHit, missingHit, false);</span>
<span class="fc" id="L2560">      keyRight = dataToString(dataRight, missingRight, false);</span>
<span class="fc" id="L2561">      key = KEY_START;</span>
<span class="fc bfc" id="L2562" title="All 2 branches covered.">      if (keyLeft != null) {</span>
<span class="fc" id="L2563">        key += keyLeft;</span>
<span class="fc" id="L2564">        hashLeft = keyLeft.hashCode();</span>
<span class="fc" id="L2565">      } else {</span>
<span class="fc" id="L2566">        hashLeft = 1;</span>
      }
<span class="fc" id="L2568">      key += &quot;|&quot;;</span>
<span class="pc bpc" id="L2569" title="1 of 2 branches missed.">      if (keyHit != null) {</span>
<span class="fc" id="L2570">        key += keyHit;</span>
<span class="fc" id="L2571">        hashHit = keyHit.hashCode();</span>
<span class="fc" id="L2572">      } else {</span>
<span class="nc" id="L2573">        hashHit = 1;</span>
      }
<span class="fc" id="L2575">      key += &quot;|&quot;;</span>
<span class="fc bfc" id="L2576" title="All 2 branches covered.">      if (keyRight != null) {</span>
<span class="fc" id="L2577">        key += keyRight;</span>
<span class="fc" id="L2578">        hashRight = keyRight.hashCode();</span>
<span class="fc" id="L2579">      } else {</span>
<span class="fc" id="L2580">        hashRight = 1;</span>
      }
      // compute hash
<span class="fc" id="L2583">      hash = hashHit * (hashLeft ^ 3) * (hashRight ^ 5);</span>
<span class="fc" id="L2584">    }</span>

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
<span class="fc" id="L2593">      return hash;</span>
    }

    /**
     * Data equals.
     *
     * @param d1 the d 1
     * @param d2 the d 2
     * @return true, if successful
     */
    private boolean dataEquals(List&lt;String&gt;[] d1, List&lt;String&gt;[] d2) {
      List&lt;String&gt; a1;
      List&lt;String&gt; a2;
<span class="pc bpc" id="L2606" title="1 of 4 branches missed.">      if (d1 == null &amp;&amp; d2 == null) {</span>
<span class="fc" id="L2607">        return true;</span>
<span class="pc bpc" id="L2608" title="2 of 4 branches missed.">      } else if (d1 == null || d2 == null) {</span>
<span class="nc" id="L2609">        return false;</span>
      } else {
<span class="pc bpc" id="L2611" title="1 of 2 branches missed.">        if (d1.length == d2.length) {</span>
<span class="fc bfc" id="L2612" title="All 2 branches covered.">          for (int i = 0; i &lt; d1.length; i++) {</span>
<span class="fc" id="L2613">            a1 = d1[i];</span>
<span class="fc" id="L2614">            a2 = d2[i];</span>
<span class="pc bpc" id="L2615" title="3 of 6 branches missed.">            if (a1 != null &amp;&amp; a2 != null &amp;&amp; a1.size() == a2.size()) {</span>
<span class="fc bfc" id="L2616" title="All 2 branches covered.">              for (int j = 0; j &lt; a1.size(); j++) {</span>
<span class="pc bpc" id="L2617" title="1 of 2 branches missed.">                if (!a1.get(j).equals(a2.get(j))) {</span>
<span class="nc" id="L2618">                  return false;</span>
                }
              }
<span class="fc" id="L2621">            } else {</span>
<span class="nc" id="L2622">              return false;</span>
            }
          }
<span class="fc" id="L2625">          return true;</span>
        } else {
<span class="nc" id="L2627">          return false;</span>
        }
      }
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
<span class="pc bpc" id="L2639" title="1 of 2 branches missed.">      if (this == obj) </span>
<span class="nc" id="L2640">        return true;</span>
<span class="pc bpc" id="L2641" title="1 of 2 branches missed.">      if (obj == null)</span>
<span class="nc" id="L2642">        return false;</span>
<span class="pc bpc" id="L2643" title="1 of 2 branches missed.">      if (getClass() != obj.getClass())</span>
<span class="nc" id="L2644">        return false;</span>
<span class="fc" id="L2645">      GroupHit other = (GroupHit) obj;</span>
<span class="fc bfc" id="L2646" title="All 2 branches covered.">      if (hashCode() != other.hashCode())</span>
<span class="fc" id="L2647">        return false;</span>
<span class="pc bpc" id="L2648" title="1 of 2 branches missed.">      if (!dataEquals(dataHit, other.dataHit))</span>
<span class="nc" id="L2649">        return false;</span>
<span class="pc bpc" id="L2650" title="1 of 2 branches missed.">      if (!dataEquals(dataLeft, other.dataLeft))</span>
<span class="nc" id="L2651">        return false;</span>
<span class="pc bpc" id="L2652" title="1 of 2 branches missed.">      if (!dataEquals(dataRight, other.dataRight))</span>
<span class="nc" id="L2653">        return false;</span>
<span class="fc" id="L2654">      return true;</span>
    }

    /**
     * Data to string.
     *
     * @param data the data
     * @param missing the missing
     * @return the string
     * @throws UnsupportedEncodingException the unsupported encoding exception
     */
    private String dataToString(List&lt;String&gt;[] data, Set&lt;String&gt;[] missing, boolean reverse)
        throws UnsupportedEncodingException {
<span class="fc" id="L2667">      StringBuilder text = null;</span>
<span class="fc" id="L2668">      Encoder encoder = Base64.getEncoder();</span>
      String prefix;
      String postfix;
      List&lt;String&gt; dataItem;
      Set&lt;String&gt; missingItem;
<span class="pc bpc" id="L2673" title="2 of 6 branches missed.">      if (data != null &amp;&amp; missing != null &amp;&amp; data.length == missing.length) {</span>
<span class="fc bfc" id="L2674" title="All 2 branches covered.">        for (int i = 0; i &lt; data.length; i++) {</span>
<span class="fc bfc" id="L2675" title="All 2 branches covered.">          if(reverse) {</span>
<span class="fc" id="L2676">            dataItem = data[(data.length-i-1)];</span>
<span class="fc" id="L2677">            missingItem = missing[(data.length-i-1)];</span>
<span class="fc" id="L2678">          } else {</span>
<span class="fc" id="L2679">            dataItem = data[i];</span>
<span class="fc" id="L2680">            missingItem = missing[i];</span>
          }
<span class="fc bfc" id="L2682" title="All 2 branches covered.">          if (i &gt; 0) {</span>
<span class="fc" id="L2683">            text.append(&quot;,&quot;);</span>
<span class="fc" id="L2684">          } else {</span>
<span class="fc" id="L2685">            text = new StringBuilder();</span>
          }
<span class="fc bfc" id="L2687" title="All 2 branches covered.">          for (int j = 0; j &lt; dataItem.size(); j++) {</span>
<span class="fc bfc" id="L2688" title="All 2 branches covered.">            if (j &gt; 0) {</span>
<span class="fc" id="L2689">              text.append(&quot;&amp;&quot;);</span>
            }
<span class="fc" id="L2691">            prefix = MtasToken.getPrefixFromValue(dataItem.get(j));</span>
<span class="fc" id="L2692">            postfix = MtasToken.getPostfixFromValue(dataItem.get(j));</span>
<span class="fc" id="L2693">            text.append(encoder</span>
<span class="fc" id="L2694">                .encodeToString(prefix.getBytes(StandardCharsets.UTF_8)));</span>
<span class="fc bfc" id="L2695" title="All 2 branches covered.">            if (!postfix.isEmpty()) {</span>
<span class="fc" id="L2696">              text.append(&quot;.&quot;);</span>
<span class="fc" id="L2697">              text.append(encoder</span>
<span class="fc" id="L2698">                  .encodeToString(postfix.getBytes(StandardCharsets.UTF_8)));</span>
            }
          }
<span class="pc bpc" id="L2701" title="1 of 2 branches missed.">          if (missingItem != null) {</span>
<span class="fc" id="L2702">            String[] tmpMissing = missingItem</span>
<span class="fc" id="L2703">                .toArray(new String[missingItem.size()]);</span>
<span class="fc bfc" id="L2704" title="All 2 branches covered.">            for (int j = 0; j &lt; tmpMissing.length; j++) {</span>
<span class="fc bfc" id="L2705" title="All 4 branches covered.">              if (j &gt; 0 || !dataItem.isEmpty()) {</span>
<span class="fc" id="L2706">                text.append(&quot;&amp;&quot;);</span>
              }
<span class="fc" id="L2708">              text.append(encoder.encodeToString(</span>
<span class="fc" id="L2709">                  (&quot;!&quot; + tmpMissing[j]).getBytes(StandardCharsets.UTF_8)));</span>
            }
          }
        }
      }
<span class="fc bfc" id="L2714" title="All 2 branches covered.">      return text != null ? text.toString() : null;</span>
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    public String toString() {
<span class="fc" id="L2723">      return key;</span>
    }

    /**
     * Key to sub sub object.
     *
     * @param key the key
     * @param newKey the new key
     * @return the map[]
     */
    private static Map&lt;String, String&gt;[] keyToSubSubObject(String key,
        StringBuilder newKey) {
<span class="fc bfc" id="L2735" title="All 2 branches covered.">      if (!key.isEmpty()) {</span>
<span class="fc" id="L2736">        newKey.append(&quot; [&quot;);</span>
        String prefix;
        String postfix;
<span class="fc" id="L2739">        String[] parts = key.split(Pattern.quote(&quot;&amp;&quot;));</span>
<span class="fc" id="L2740">        Map&lt;String, String&gt;[] result = new HashMap[parts.length];</span>
<span class="fc" id="L2741">        Pattern pattern = Pattern.compile(&quot;^([^\\.]*)\\.([^\\.]*)$&quot;);</span>
<span class="fc" id="L2742">        Decoder decoder = Base64.getDecoder();</span>
        Matcher matcher;
<span class="fc" id="L2744">        StringBuilder tmpNewKey = null;</span>
<span class="fc bfc" id="L2745" title="All 2 branches covered.">        for (int i = 0; i &lt; parts.length; i++) {</span>
<span class="pc bpc" id="L2746" title="1 of 2 branches missed.">          if (parts[i].isEmpty()) {</span>
<span class="nc" id="L2747">            result[i] = null;</span>
<span class="nc" id="L2748">          } else {</span>
<span class="fc" id="L2749">            HashMap&lt;String, String&gt; subResult = new HashMap&lt;&gt;();</span>
<span class="fc" id="L2750">            matcher = pattern.matcher(parts[i]);</span>
<span class="fc bfc" id="L2751" title="All 2 branches covered.">            if (tmpNewKey != null) {</span>
<span class="fc" id="L2752">              tmpNewKey.append(&quot; &amp; &quot;);</span>
<span class="fc" id="L2753">            } else {</span>
<span class="fc" id="L2754">              tmpNewKey = new StringBuilder();</span>
            }
<span class="fc bfc" id="L2756" title="All 2 branches covered.">            if (matcher.matches()) {</span>
<span class="fc" id="L2757">              prefix = new String(</span>
<span class="fc" id="L2758">                  decoder.decode(</span>
<span class="fc" id="L2759">                      matcher.group(1).getBytes(StandardCharsets.UTF_8)),</span>
<span class="fc" id="L2760">                  StandardCharsets.UTF_8);</span>
<span class="fc" id="L2761">              postfix = new String(</span>
<span class="fc" id="L2762">                  decoder.decode(</span>
<span class="fc" id="L2763">                      matcher.group(2).getBytes(StandardCharsets.UTF_8)),</span>
<span class="fc" id="L2764">                  StandardCharsets.UTF_8);</span>
<span class="fc" id="L2765">              tmpNewKey.append(prefix.replace(&quot;=&quot;, &quot;\\=&quot;));</span>
<span class="fc" id="L2766">              tmpNewKey.append(&quot;=\&quot;&quot; + postfix.replace(&quot;\&quot;&quot;, &quot;\\\&quot;&quot;) + &quot;\&quot;&quot;);</span>
<span class="fc" id="L2767">              subResult.put(&quot;prefix&quot;, prefix);</span>
<span class="fc" id="L2768">              subResult.put(&quot;value&quot;, postfix);</span>
<span class="fc" id="L2769">            } else {</span>
<span class="fc" id="L2770">              prefix = new String(</span>
<span class="fc" id="L2771">                  decoder.decode(parts[i].getBytes(StandardCharsets.UTF_8)),</span>
<span class="fc" id="L2772">                  StandardCharsets.UTF_8);</span>
<span class="fc" id="L2773">              tmpNewKey.append(prefix.replace(&quot;=&quot;, &quot;\\=&quot;));</span>
<span class="fc bfc" id="L2774" title="All 2 branches covered.">              if (prefix.startsWith(&quot;!&quot;)) {</span>
<span class="fc" id="L2775">                subResult.put(&quot;missing&quot;, prefix.substring(1));</span>
<span class="fc" id="L2776">              } else {</span>
<span class="fc" id="L2777">                subResult.put(&quot;prefix&quot;, prefix);</span>
              }
            }
<span class="fc" id="L2780">            result[i] = subResult;</span>
          }
        }
<span class="pc bpc" id="L2783" title="1 of 2 branches missed.">        if (tmpNewKey != null) {</span>
<span class="fc" id="L2784">          newKey.append(tmpNewKey);</span>
        }
<span class="fc" id="L2786">        newKey.append(&quot;]&quot;);</span>
<span class="fc" id="L2787">        return result;</span>
      } else {
<span class="fc" id="L2789">        newKey.append(&quot; []&quot;);</span>
<span class="fc" id="L2790">        return null;</span>
      }
    }

    /**
     * Key to sub object.
     *
     * @param key the key
     * @param newKey the new key
     * @return the map
     */
    private static Map&lt;Integer, Map&lt;String, String&gt;[]&gt; keyToSubObject(
        String key, StringBuilder newKey) {
<span class="fc" id="L2803">      Map&lt;Integer, Map&lt;String, String&gt;[]&gt; result = new HashMap&lt;&gt;();</span>
<span class="pc bpc" id="L2804" title="1 of 4 branches missed.">      if (key == null || key.trim().isEmpty()) {</span>
<span class="fc" id="L2805">        return null;</span>
      } else {
<span class="fc" id="L2807">        String[] parts = key.split(Pattern.quote(&quot;,&quot;), -1);</span>
<span class="pc bpc" id="L2808" title="1 of 2 branches missed.">        if (parts.length &gt; 0) {</span>
<span class="fc bfc" id="L2809" title="All 2 branches covered.">          for (int i = 0; i &lt; parts.length; i++) {</span>
<span class="fc" id="L2810">            result.put(i, keyToSubSubObject(parts[i].trim(), newKey));</span>
          }
<span class="fc" id="L2812">          return result;</span>
        } else {
<span class="nc" id="L2814">          return null;</span>
        }
      }
    }

    /**
     * Key to object.
     *
     * @param key the key
     * @param newKey the new key
     * @return the map
     */
    public static Map&lt;String, Map&lt;Integer, Map&lt;String, String&gt;[]&gt;&gt; keyToObject(
        String key, StringBuilder newKey) {
<span class="pc bpc" id="L2828" title="1 of 2 branches missed.">      if (key.startsWith(KEY_START)) {</span>
<span class="fc" id="L2829">        String content = key.substring(KEY_START.length());</span>
<span class="fc" id="L2830">        StringBuilder keyLeft = new StringBuilder(&quot;&quot;);</span>
<span class="fc" id="L2831">        StringBuilder keyHit = new StringBuilder(&quot;&quot;);</span>
<span class="fc" id="L2832">        StringBuilder keyRight = new StringBuilder(&quot;&quot;);</span>
<span class="fc" id="L2833">        Map&lt;String, Map&lt;Integer, Map&lt;String, String&gt;[]&gt;&gt; result = new HashMap&lt;&gt;();</span>
<span class="fc" id="L2834">        Map&lt;Integer, Map&lt;String, String&gt;[]&gt; resultLeft = null;</span>
<span class="fc" id="L2835">        Map&lt;Integer, Map&lt;String, String&gt;[]&gt; resultHit = null;</span>
<span class="fc" id="L2836">        Map&lt;Integer, Map&lt;String, String&gt;[]&gt; resultRight = null;</span>
<span class="fc" id="L2837">        String[] parts = content.split(Pattern.quote(&quot;|&quot;), -1);</span>
<span class="pc bpc" id="L2838" title="1 of 2 branches missed.">        if (parts.length == 3) {</span>
<span class="fc" id="L2839">          resultLeft = keyToSubObject(parts[0].trim(), keyLeft);</span>
<span class="fc" id="L2840">          resultHit = keyToSubObject(parts[1].trim(), keyHit);</span>
<span class="fc" id="L2841">          resultRight = keyToSubObject(parts[2].trim(), keyRight);</span>
<span class="pc bnc" id="L2842" title="All 2 branches missed.">        } else if (parts.length == 1) {</span>
<span class="nc" id="L2843">          resultHit = keyToSubObject(parts[0].trim(), keyHit);</span>
        }
<span class="fc bfc" id="L2845" title="All 2 branches covered.">        if (resultLeft != null) {</span>
<span class="fc" id="L2846">          result.put(&quot;left&quot;, resultLeft);</span>
        }
<span class="fc" id="L2848">        result.put(&quot;hit&quot;, resultHit);</span>
<span class="fc bfc" id="L2849" title="All 2 branches covered.">        if (resultRight != null) {</span>
<span class="fc" id="L2850">          result.put(&quot;right&quot;, resultRight);</span>
        }
<span class="fc" id="L2852">        newKey.append(keyLeft);</span>
<span class="fc" id="L2853">        newKey.append(&quot; |&quot;);</span>
<span class="fc" id="L2854">        newKey.append(keyHit);</span>
<span class="fc" id="L2855">        newKey.append(&quot; |&quot;);</span>
<span class="fc" id="L2856">        newKey.append(keyRight);</span>
<span class="fc" id="L2857">        return result;</span>
      } else {
<span class="nc" id="L2859">        return null;</span>
      }
    }

  }

  /**
   * The Class ListToken.
   */
  public static class ListToken {

    /** The doc id. */
    public Integer docId;

    /** The doc position. */
    public Integer docPosition;

    /** The start position. */
    public int startPosition;

    /** The end position. */
    public int endPosition;

    /** The tokens. */
    public List&lt;MtasTokenString&gt; tokens;

    /**
     * Instantiates a new list token.
     *
     * @param docId the doc id
     * @param docPosition the doc position
     * @param match the match
     * @param tokens the tokens
     */
<span class="nc" id="L2893">    public ListToken(Integer docId, Integer docPosition, Match match,</span>
        List&lt;MtasTokenString&gt; tokens) {
<span class="nc" id="L2895">      this.docId = docId;</span>
<span class="nc" id="L2896">      this.docPosition = docPosition;</span>
<span class="nc" id="L2897">      startPosition = match.startPosition;</span>
<span class="nc" id="L2898">      endPosition = match.endPosition - 1;</span>
<span class="nc" id="L2899">      this.tokens = tokens;</span>
<span class="nc" id="L2900">    }</span>
  }

  /**
   * The Class ListHit.
   */
  public static class ListHit {

    /** The doc id. */
    public Integer docId;

    /** The doc position. */
    public Integer docPosition;

    /** The start position. */
    public int startPosition;

    /** The end position. */
    public int endPosition;

    /** The hits. */
    public Map&lt;Integer, List&lt;String&gt;&gt; hits;

    /**
     * Instantiates a new list hit.
     *
     * @param docId the doc id
     * @param docPosition the doc position
     * @param match the match
     * @param hits the hits
     */
<span class="nc" id="L2931">    public ListHit(Integer docId, Integer docPosition, Match match,</span>
        Map&lt;Integer, List&lt;String&gt;&gt; hits) {
<span class="nc" id="L2933">      this.docId = docId;</span>
<span class="nc" id="L2934">      this.docPosition = docPosition;</span>
<span class="nc" id="L2935">      startPosition = match.startPosition;</span>
<span class="nc" id="L2936">      endPosition = match.endPosition - 1;</span>
<span class="nc" id="L2937">      this.hits = hits;</span>
<span class="nc" id="L2938">    }</span>
  }

  /**
   * The Class Match.
   */
  public static class Match {

    /** The start position. */
    public int startPosition;

    /** The end position. */
    public int endPosition;

    /**
     * Instantiates a new match.
     *
     * @param startPosition the start position
     * @param endPosition the end position
     */
<span class="fc" id="L2958">    public Match(int startPosition, int endPosition) {</span>
<span class="fc" id="L2959">      this.startPosition = startPosition;</span>
<span class="fc" id="L2960">      this.endPosition = endPosition;</span>
<span class="fc" id="L2961">    }</span>

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
<span class="nc bnc" id="L2970" title="All 2 branches missed.">      if (this == obj)</span>
<span class="nc" id="L2971">        return true;</span>
<span class="nc bnc" id="L2972" title="All 2 branches missed.">      if (obj == null)</span>
<span class="nc" id="L2973">        return false;</span>
<span class="nc bnc" id="L2974" title="All 2 branches missed.">      if (getClass() != obj.getClass())</span>
<span class="nc" id="L2975">        return false;</span>
<span class="nc" id="L2976">      final Match that = (Match) obj;</span>
<span class="nc bnc" id="L2977" title="All 2 branches missed.">      return startPosition == that.startPosition</span>
<span class="nc bnc" id="L2978" title="All 2 branches missed.">          &amp;&amp; endPosition == that.endPosition;</span>
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
<span class="nc" id="L2988">      int h = this.getClass().getSimpleName().hashCode();</span>
<span class="nc" id="L2989">      h = (h * 5) ^ startPosition;</span>
<span class="nc" id="L2990">      h = (h * 7) ^ endPosition;</span>
<span class="nc" id="L2991">      return h;</span>
    }

  }

}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>