pax_global_header00006660000000000000000000000064142276252420014520gustar00rootroot0000000000000052 comment=e84c4c6f15f94a78b316c00be772cd241aba82d8 jhighlight-jhighlight-1.1.0/000077500000000000000000000000001422762524200157575ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/.github/000077500000000000000000000000001422762524200173175ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/.github/workflows/000077500000000000000000000000001422762524200213545ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/.github/workflows/codeql-analysis.yml000066400000000000000000000050271422762524200251730ustar00rootroot00000000000000# For most projects, this workflow file will not need changing; you simply need # to commit it to your repository. # # You may wish to alter this file to override the set of languages analyzed, # or to provide custom queries or build logic. name: "CodeQL" on: push: branches: [master] pull_request: # The branches below must be a subset of the branches above branches: [master] schedule: - cron: '0 8 * * 3' jobs: analyze: name: Analyze runs-on: ubuntu-latest strategy: fail-fast: false matrix: # Override automatic language detection by changing the below list # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] language: ['java'] # Learn more... # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection steps: - name: Checkout repository uses: actions/checkout@v2 with: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. fetch-depth: 2 # If this run was triggered by a pull request event, then checkout # the head of the pull request instead of the merge commit. - run: git checkout HEAD^2 if: ${{ github.event_name == 'pull_request' }} # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v1 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. # By default, queries listed here will override any specified in a config file. # Prefix the list here with "+" to use these queries and those in the config file. # queries: ./path/to/local/query, your-org/your-repo/queries@main # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild uses: github/codeql-action/autobuild@v1 # ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines # and modify them (or add more) to build your code if your project # uses a compiled language #- run: | # make bootstrap # make release - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v1 jhighlight-jhighlight-1.1.0/.github/workflows/maven.yml000066400000000000000000000010741422762524200232070ustar00rootroot00000000000000# This workflow will build a Java project with Maven # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven name: Java CI with Maven on: push: branches: [ master ] pull_request: branches: [ master ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up JDK 11 uses: actions/setup-java@v2 with: java-version: '11' distribution: 'adopt' - name: Build with Maven run: mvn -B package --file pom.xml jhighlight-jhighlight-1.1.0/.gitignore000066400000000000000000000000671422762524200177520ustar00rootroot00000000000000/target /bin /work .settings .classpath .project .idea jhighlight-jhighlight-1.1.0/COPYING000066400000000000000000000005461422762524200170170ustar00rootroot00000000000000JHighlight is Copyright (C) 2000-2006 * Omnicore Software, Hans Kratz & Dennis Strein GbR, * Geert Bevin * Arnout Engelen It is distributed under the terms of either: - the common development and distribution license (CDDL), v1.0; or - the GNU Lesser General Public License, v2.1 or later jhighlight-jhighlight-1.1.0/LICENSE_CDDL.txt000066400000000000000000000473021422762524200203760ustar00rootroot00000000000000 COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 1. Definitions. 1.1. 'Contributor' means each individual or entity that creates or contributes to the creation of Modifications. 1.2. 'Contributor Version' means the combination of the Original Software, prior Modifications used by a Contributor (if any), and the Modifications made by that particular Contributor. 1.3. 'Covered Software' means (a) the Original Software, or (b) Modifications, or (c) the combination of files containing Original Software with files containing Modifications, in each case including portions thereof. 1.4. 'Executable' means the Covered Software in any form other than Source Code. 1.5. 'Initial Developer' means the individual or entity that first makes Original Software available under this License. 1.6. 'Larger Work' means a work which combines Covered Software or portions thereof with code not governed by the terms of this License. 1.7. 'License' means this document. 1.8. 'Licensable' means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently acquired, any and all of the rights conveyed herein. 1.9. 'Modifications' means the Source Code and Executable form of any of the following: A. Any file that results from an addition to, deletion from or modification of the contents of a file containing Original Software or previous Modifications; B. Any new file that contains any part of the Original Software or previous Modification; or C. Any new file that is contributed or otherwise made available under the terms of this License. 1.10. 'Original Software' means the Source Code and Executable form of computer software code that is originally released under this License. 1.11. 'Patent Claims' means any patent claim(s), now owned or hereafter acquired, including without limitation, method, process, and apparatus claims, in any patent Licensable by grantor. 1.12. 'Source Code' means (a) the common form of computer software code in which modifications are made and (b) associated documentation included in or with such code. 1.13. 'You' (or 'Your') means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, 'You' includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, 'control' means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. 2. License Grants. 2.1. The Initial Developer Grant. Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, the Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license: (a) under intellectual property rights (other than patent or trademark) Licensable by Initial Developer, to use, reproduce, modify, display, perform, sublicense and distribute the Original Software (or portions thereof), with or without Modifications, and/or as part of a Larger Work; and (b) under Patent Claims infringed by the making, using or selling of Original Software, to make, have made, use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Software (or portions thereof). (c) The licenses granted in Sections 2.1(a) and (b) are effective on the date Initial Developer first distributes or otherwise makes the Original Software available to a third party under the terms of this License. (d) Notwithstanding Section 2.1(b) above, no patent license is granted: (1) for code that You delete from the Original Software, or (2) for infringements caused by: (i) the modification of the Original Software, or (ii) the combination of the Original Software with other software or devices. 2.2. Contributor Grant. Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license: (a) under intellectual property rights (other than patent or trademark) Licensable by Contributor to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof), either on an unmodified basis, with other Modifications, as Covered Software and/or as part of a Larger Work; and (b) under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor either alone and/or in combination with its Contributor Version (or portions of such combination), to make, use, sell, offer for sale, have made, and/or otherwise dispose of: (1) Modifications made by that Contributor (or portions thereof); and (2) the combination of Modifications made by that Contributor with its Contributor Version (or portions of such combination). (c) The licenses granted in Sections 2.2(a) and 2.2(b) are effective on the date Contributor first distributes or otherwise makes the Modifications available to a third party. (d) Notwithstanding Section 2.2(b) above, no patent license is granted: (1) for any code that Contributor has deleted from the Contributor Version; (2) for infringements caused by: (i) third party modifications of Contributor Version, or (ii) the combination of Modifications made by that Contributor with other software (except as part of the Contributor Version) or other devices; or (3) under Patent Claims infringed by Covered Software in the absence of Modifications made by that Contributor. 3. Distribution Obligations. 3.1. Availability of Source Code. Any Covered Software that You distribute or otherwise make available in Executable form must also be made available in Source Code form and that Source Code form must be distributed only under the terms of this License. You must include a copy of this License with every copy of the Source Code form of the Covered Software You distribute or otherwise make available. You must inform recipients of any such Covered Software in Executable form as to how they can obtain such Covered Software in Source Code form in a reasonable manner on or through a medium customarily used for software exchange. 3.2. Modifications. The Modifications that You create or to which You contribute are governed by the terms of this License. You represent that You believe Your Modifications are Your original creation(s) and/or You have sufficient rights to grant the rights conveyed by this License. 3.3. Required Notices. You must include a notice in each of Your Modifications that identifies You as the Contributor of the Modification. You may not remove or alter any copyright, patent or trademark notices contained within the Covered Software, or any notices of licensing or any descriptive text giving attribution to any Contributor or the Initial Developer. 3.4. Application of Additional Terms. You may not offer or impose any terms on any Covered Software in Source Code form that alters or restricts the applicable version of this License or the recipients rights hereunder. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, you may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear that any such warranty, support, indemnity or liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability terms You offer. 3.5. Distribution of Executable Versions. You may distribute the Executable form of the Covered Software under the terms of this License or under the terms of a license of Your choice, which may contain terms different from this License, provided that You are in compliance with the terms of this License and that the license for the Executable form does not attempt to limit or alter the recipients rights in the Source Code form from the rights set forth in this License. If You distribute the Covered Software in Executable form under a different license, You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer. 3.6. Larger Works. You may create a Larger Work by combining Covered Software with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Software. 4. Versions of the License. 4.1. New Versions. Sun Microsystems, Inc. is the initial license steward and may publish revised and/or new versions of this License from time to time. Each version will be given a distinguishing version number. Except as provided in Section 4.3, no one other than the license steward has the right to modify this License. 4.2. Effect of New Versions. You may always continue to use, distribute or otherwise make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. If the Initial Developer includes a notice in the Original Software prohibiting it from being distributed or otherwise made available under any subsequent version of the License, You must distribute and make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. Otherwise, You may also choose to use, distribute or otherwise make the Covered Software available under the terms of any subsequent version of the License published by the license steward. 4.3. Modified Versions. When You are an Initial Developer and You want to create a new license for Your Original Software, You may create and use a modified version of this License if You: (a) rename the license and remove any references to the name of the license steward (except to note that the license differs from this License); and (b) otherwise make it clear that the license contains terms which differ from this License. 5. DISCLAIMER OF WARRANTY. COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN 'AS IS' BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. 6. TERMINATION. 6.1. This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive. 6.2. If You assert a patent infringement claim (excluding declaratory judgment actions) against Initial Developer or a Contributor (the Initial Developer or Contributor against whom You assert such claim is referred to as 'Participant') alleging that the Participant Software (meaning the Contributor Version where the Participant is a Contributor or the Original Software where the Participant is the Initial Developer) directly or indirectly infringes any patent, then any and all rights granted directly or indirectly to You by such Participant, the Initial Developer (if the Initial Developer is not the Participant) and all Contributors under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively and automatically at the expiration of such 60 day notice period, unless if within such 60 day period You withdraw Your claim with respect to the Participant Software against such Participant either unilaterally or pursuant to a written agreement with Participant. 6.3. In the event of termination under Sections 6.1 or 6.2 above, all end user licenses that have been validly granted by You or any distributor hereunder prior to termination (excluding licenses granted to You by any distributor) shall survive termination. 7. LIMITATION OF LIABILITY. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH PARTYS NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. 8. U.S. GOVERNMENT END USERS. The Covered Software is a 'commercial item,' as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of 'commercial computer software' (as that term is defined at 48 C.F.R. 252.227-7014(a)(1)) and 'commercial computer software documentation' as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Software with only those rights set forth herein. This U.S. Government Rights clause is in lieu of, and supersedes, any other FAR, DFAR, or other clause or provision that addresses Government rights in computer software under this License. 9. MISCELLANEOUS. This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by the law of the jurisdiction specified in a notice contained within the Original Software (except to the extent applicable law, if any, provides otherwise), excluding such jurisdictions conflict-of-law provisions. Any litigation relating to this License shall be subject to the jurisdiction of the courts located in the jurisdiction and venue specified in a notice contained within the Original Software, with the losing party responsible for costs, including, without limitation, court costs and reasonable attorneys fees and expenses. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License. You agree that You alone are responsible for compliance with the United States export administration regulations (and the export control laws and regulation of any other countries) when You use, distribute or otherwise make available any Covered Software. 10. RESPONSIBILITY FOR CLAIMS. As between Initial Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of its utilization of rights under this License and You agree to work with Initial Developer and Contributors to distribute such responsibility on an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability. jhighlight-jhighlight-1.1.0/LICENSE_LGPL.txt000066400000000000000000000016001422762524200204150ustar00rootroot00000000000000RIFE, Copyright 2001-2006 Geert Bevin , Distributed under the GNU Lesser General Public License v2.1. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Distributed under the GNU General Public License v2 or later. jhighlight-jhighlight-1.1.0/README.md000066400000000000000000000026021422762524200172360ustar00rootroot00000000000000JHighlight [![Java CI with Maven](https://github.com/codelibs/jhighlight/actions/workflows/maven.yml/badge.svg)](https://github.com/codelibs/jhighlight/actions/workflows/maven.yml) ================== ## Overview JHighlight is an embeddable pure Java syntax highlighting library that supports Java, HTML, XHTML, XML and LZX languages and outputs to XHTML. It also supports RIFE templates tags and highlights them clearly so that you can easily identify the difference between your RIFE markup and the actual marked up source. This project is forked from https://jhighlight.dev.java.net/ to fix several bugs. ## Reference The original jhighlight handles multi-byte characters as garbled one. To solve this problem, replace with CodeLibs jhighlight. ### Tika Tika uses jhighlight to parse source code files, such as .java. If a source code file has a multi-byte chracter, it becomes a garbled one. To avoid this problem, change your pom.xml to: org.apache.tika tika-parsers 1.6 com.uwyn jhighlight org.codelibs jhighlight 1.0.2 jhighlight-jhighlight-1.1.0/pom.xml000066400000000000000000000070441422762524200173010ustar00rootroot00000000000000 4.0.0 org.codelibs jhighlight 1.1.0 jar JHighlight JHighlight is an embeddable pure Java syntax highlighting library that supports Java, HTML, XHTML, XML and LZX languages and outputs to XHTML. It also supports RIFE templates tags and highlights them clearly so that you can easily identify the difference between your RIFE markup and the actual marked up source. 2011 https://github.com/codelibs/jhighlight CDDL, v1.0 http://www.opensource.org/licenses/cddl1.php repo LGPL, v2.1 or later http://www.opensource.org/licenses/lgpl-license.php repo scm:git:git@github.com:codelibs/jhighlight.git scm:git:git@github.com:codelibs/jhighlight.git git@github.com:codelibs/jhighlight.git org.sonatype.oss oss-parent 9 org.apache.maven.plugins maven-compiler-plugin 3.8.1 1.8 1.8 org.apache.maven.plugins maven-surefire-plugin 2.22.2 **/*Test.java false org.apache.maven.plugins maven-source-plugin 3.1.0 attach-sources jar org.apache.maven.plugins maven-javadoc-plugin 3.1.1 UTF-8 UTF-8 UTF-8 8 none maven-jar-plugin 3.2.2 org.codelibs.jhighlight commons-io commons-io 2.7 javax.servlet servlet-api 2.3 provided junit junit 4.13.1 test jhighlight-jhighlight-1.1.0/src/000077500000000000000000000000001422762524200165465ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/000077500000000000000000000000001422762524200174725ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/000077500000000000000000000000001422762524200204135ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/com/000077500000000000000000000000001422762524200211715ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/com/uwyn/000077500000000000000000000000001422762524200221735ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/com/uwyn/jhighlight/000077500000000000000000000000001422762524200243145ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/com/uwyn/jhighlight/renderer/000077500000000000000000000000001422762524200261225ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/com/uwyn/jhighlight/renderer/Renderer.java000066400000000000000000000011541422762524200305340ustar00rootroot00000000000000/* * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later */ package com.uwyn.jhighlight.renderer; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @Deprecated // for backward compatibility public interface Renderer { void highlight(String name, InputStream in, OutputStream out, String encoding, boolean fragment) throws IOException; String highlight(String name, String in, String encoding, boolean fragment) throws IOException; } jhighlight-jhighlight-1.1.0/src/main/java/com/uwyn/jhighlight/renderer/XhtmlRendererFactory.java000066400000000000000000000030321422762524200330760ustar00rootroot00000000000000/* * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later */ package com.uwyn.jhighlight.renderer; @Deprecated // for backward compatibility public class XhtmlRendererFactory { public static final String GROOVY = org.codelibs.jhighlight.renderer.XhtmlRendererFactory.GROOVY; public static final String JAVA = org.codelibs.jhighlight.renderer.XhtmlRendererFactory.JAVA; public static final String BEANSHELL = org.codelibs.jhighlight.renderer.XhtmlRendererFactory.BEANSHELL; public static final String BSH = org.codelibs.jhighlight.renderer.XhtmlRendererFactory.BSH; public static final String XML = org.codelibs.jhighlight.renderer.XhtmlRendererFactory.XML; public static final String XHTML = org.codelibs.jhighlight.renderer.XhtmlRendererFactory.XHTML; public static final String LZX = org.codelibs.jhighlight.renderer.XhtmlRendererFactory.LZX; public static final String HTML = org.codelibs.jhighlight.renderer.XhtmlRendererFactory.HTML; public static final String CPP = org.codelibs.jhighlight.renderer.XhtmlRendererFactory.CPP; public static final String CXX = org.codelibs.jhighlight.renderer.XhtmlRendererFactory.CXX; public static final String CPLUSPLUS = org.codelibs.jhighlight.renderer.XhtmlRendererFactory.CPP; public static Renderer getRenderer(String type) { return org.codelibs.jhighlight.renderer.XhtmlRendererFactory .getRenderer(type); } } jhighlight-jhighlight-1.1.0/src/main/java/org/000077500000000000000000000000001422762524200212025ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/000077500000000000000000000000001422762524200227665ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/000077500000000000000000000000001422762524200251075ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/JHighlight.java000066400000000000000000000162131422762524200277760ustar00rootroot00000000000000/* * Copyright 2004-2006 Geert Bevin * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: JHighlight.java 3429 2006-08-02 02:38:39Z gbevin $ */ package org.codelibs.jhighlight; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.Set; import java.util.regex.Pattern; import org.codelibs.jhighlight.renderer.XhtmlRendererFactory; import org.codelibs.jhighlight.tools.FileUtils; /** * Provides console access to the source code syntax highlighting for Java, * HTML, XHTML, XML and LZX files. The rendering will be done in HTML. *

The following file extensions will be processed: .java, * .html, .htm, .xhtml, * .xml and .lzx. *

Execute the highlighting with the following syntax: *

java org.codelibs.jhighlight.JHighlight [--verbose] [--fragment] [-d destdir] [-e encoding] file|dir ...
*

or *

java -jar jhighlight.jar [--verbose] [--fragment] [-d destdir] [-e encoding] file|dir ...
* * * * * * * * * * * * * * * * * *
--verboseOutput messages about what the parser is doing.
--fragmentOutput fragments instead of complete documents.
-dSpecify the destination directory
-eSpecify the encoding of the files
*

RIFE template tags are also * supported and will be clearly highlighted. * * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @version $Revision: 3429 $ * @since 1.0 */ public class JHighlight { public static void main(String[] arguments) throws Throwable { String destdir_name = null; boolean verbose = false; String encoding = null; boolean fragment = false; ArrayList names = new ArrayList(); boolean valid_arguments = true; if (arguments.length < 1) { valid_arguments = false; } else { boolean next_is_destdir = false; boolean next_is_encoding = false; String argument; for (int i = 0; i < arguments.length; i++) { argument = arguments[i]; if (next_is_destdir) { destdir_name = argument; next_is_destdir = false; continue; } if (next_is_encoding) { encoding = argument; next_is_encoding = false; continue; } if (argument.equals("-d")) { next_is_destdir = true; continue; } if (argument.equals("-e")) { next_is_encoding = true; continue; } if (argument.equals("--verbose")) { verbose = true; continue; } if (argument.equals("--fragment")) { fragment = true; continue; } names.add(argument); } } if (0 == names.size()) { valid_arguments = false; } if (!valid_arguments) { System.err.println("Usage :"); System.err.println(" java " + JHighlight.class.getName() + " [--verbose] [--fragment] [-d destdir] [-e encoding] file|dir ..."); System.err.println("or"); System.err.println(" java -jar jhighlight-" + JHighlightVersion.getVersion() + ".jar [--verbose] [--fragment] [-d destdir] [-e encoding] file|dir ..."); System.err.println("Generates highlighted XHTML files from all Java and XML source files"); System.err.println("in the specified directories."); System.err.println(" --verbose Output messages about what the parser is doing"); System.err.println(" --fragment Output fragments instead of complete documents"); System.err.println(" -d Specify the destination directory"); System.err.println(" -e Specify the encoding of the files"); System.exit(1); } File destdir = null; if (destdir_name != null) { destdir = new File(destdir_name); if (!destdir.exists()) { throw new IOException("The destination directory '" + destdir_name + "' doesn't exist."); } if (!destdir.canWrite()) { throw new IOException("The destination directory '" + destdir_name + "' is not writable."); } if (!destdir.isDirectory()) { throw new IOException("The destination directory '" + destdir_name + "' is not a directory."); } } Iterator names_it = names.iterator(); String name; while (names_it.hasNext()) { name = (String)names_it.next(); File location = new File(name); if (!location.exists()) { throw new IOException("The source location '" + name + "' doesn't exist."); } if (!location.canRead()) { throw new IOException("The source location '" + name + "' is not readable."); } if (!location.isDirectory()) { File out = null; if (null == destdir) { out = new File(location.getAbsolutePath() + ".html"); } else { out = new File(destdir, location.getName() + ".html"); } highlightFile(location.getName(), location, out, encoding, fragment, verbose); } else { Set supported_types = XhtmlRendererFactory.getSupportedTypes(); Pattern[] included = new Pattern[supported_types.size()]; Pattern[] excluded = new Pattern[supported_types.size()+5]; excluded[0] = Pattern.compile(".*SCCS.*"); excluded[0] = Pattern.compile(".*svn.*"); excluded[0] = Pattern.compile(".*CVS.*"); excluded[0] = Pattern.compile(".*jetty.*"); excluded[0] = Pattern.compile(".*tomcat.*"); Iterator types_it = supported_types.iterator(); String type; int counter = 0; while (types_it.hasNext()) { type = (String)types_it.next(); included[counter] = Pattern.compile(".*\\."+type+"$"); excluded[counter+5] = Pattern.compile(".*\\."+type+"\\.html\\.*"); counter++; } ArrayList file_names = FileUtils.getFileList(location, included, excluded); Iterator file_names_it = file_names.iterator(); String file_name; while (file_names_it.hasNext()) { file_name = (String)file_names_it.next(); File in = new File(location.getAbsolutePath() + File.separator + file_name); File out = null; if (null == destdir) { out = new File(location.getAbsolutePath() + File.separator + file_name + ".html"); } else { out = new File(destdir, location.getName() + File.separator + file_name + ".html"); } highlightFile(location.getName() + File.separator + file_name, in, out, encoding, fragment, verbose); } } } } private static void highlightFile(String name, File in, File out, String encoding, boolean fragment, boolean verbose) throws IOException { out.getParentFile().mkdirs(); if (verbose) { System.out.print(name + " ... "); } XhtmlRendererFactory.getRenderer(FileUtils.getExtension(name)) .highlight(name, in.toURL().openStream(), new FileOutputStream(out), encoding, fragment); if (verbose) { System.out.println("done."); } } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/JHighlightVersion.java000066400000000000000000000040701422762524200313420ustar00rootroot00000000000000/* * Copyright 2004-2006 Geert Bevin * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: JHighlightVersion.java 3108 2006-03-13 18:03:00Z gbevin $ */ package org.codelibs.jhighlight; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; import org.apache.commons.io.output.ByteArrayOutputStream; /** * Provides acces to the version number of this JHighlight release. * * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @version $Revision: 3108 $ * @since 1.0 */ public class JHighlightVersion { private String mVersion = null; JHighlightVersion() { URL version_url = getClass().getClassLoader().getResource("JHIGHLIGHT_VERSION"); if (version_url != null) { try { URLConnection connection = version_url.openConnection(); connection.setUseCaches(false); InputStream inputStream = connection.getInputStream(); byte[] buffer = new byte[64]; int return_value = -1; ByteArrayOutputStream output_stream = new ByteArrayOutputStream(buffer.length); try { return_value = inputStream.read(buffer); while (-1 != return_value) { output_stream.write(buffer, 0, return_value); return_value = inputStream.read(buffer); } } finally { output_stream.close(); inputStream.close(); } mVersion = output_stream.toString("UTF-8"); } catch (IOException e) { mVersion = null; } } if (mVersion != null) { mVersion = mVersion.trim(); } if (null == mVersion) { mVersion = "(unknown version)"; } } private String getVersionString() { return mVersion; } /** * Returns the version number of this JHighlight release. * * @return the version number * @since 1.0 */ public static String getVersion() { return JHighlightVersionSingleton.INSTANCE.getVersionString(); } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/JHighlightVersionSingleton.java000066400000000000000000000010641422762524200332250ustar00rootroot00000000000000/* * Copyright 2004-2006 Geert Bevin * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: JHighlightVersionSingleton.java 3108 2006-03-13 18:03:00Z gbevin $ */ package org.codelibs.jhighlight; /** * Helper class to avoid Double Check Locking * and still have a thread-safe singleton pattern */ class JHighlightVersionSingleton { static final JHighlightVersion INSTANCE = new JHighlightVersion(); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/000077500000000000000000000000001422762524200267425ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/Arrays.java000066400000000000000000000310151422762524200310460ustar00rootroot00000000000000package org.codelibs.jhighlight.fastutil; /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.ArrayList; import org.codelibs.jhighlight.fastutil.ints.IntComparator; /** A class providing static methods and objects that do useful things with arrays. * *

In addition to commodity methods, this class contains {@link Swapper}-based implementations * of {@linkplain #quickSort(int, int, IntComparator, Swapper) quicksort} and of * a stable, in-place {@linkplain #mergeSort(int, int, IntComparator, Swapper) mergesort}. These * generic sorting methods can be used to sort any kind of list, but they find their natural * usage, for instance, in sorting arrays in parallel. * * @see Arrays */ public class Arrays { private Arrays() {} /** This is a safe value used by {@link ArrayList} (as of Java 7) to avoid * throwing {@link OutOfMemoryError} on some JVMs. We adopt the same value. */ public static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; /** Ensures that a range given by its first (inclusive) and last (exclusive) elements fits an array of given length. * *

This method may be used whenever an array range check is needed. * * @param arrayLength an array length. * @param from a start index (inclusive). * @param to an end index (inclusive). * @throws IllegalArgumentException if from is greater than to. * @throws ArrayIndexOutOfBoundsException if from or to are greater than arrayLength or negative. */ public static void ensureFromTo( final int arrayLength, final int from, final int to ) { if ( from < 0 ) throw new ArrayIndexOutOfBoundsException( "Start index (" + from + ") is negative" ); if ( from > to ) throw new IllegalArgumentException( "Start index (" + from + ") is greater than end index (" + to + ")" ); if ( to > arrayLength ) throw new ArrayIndexOutOfBoundsException( "End index (" + to + ") is greater than array length (" + arrayLength + ")" ); } /** Ensures that a range given by an offset and a length fits an array of given length. * *

This method may be used whenever an array range check is needed. * * @param arrayLength an array length. * @param offset a start index for the fragment * @param length a length (the number of elements in the fragment). * @throws IllegalArgumentException if length is negative. * @throws ArrayIndexOutOfBoundsException if offset is negative or offset+length is greater than arrayLength. */ public static void ensureOffsetLength( final int arrayLength, final int offset, final int length ) { if ( offset < 0 ) throw new ArrayIndexOutOfBoundsException( "Offset (" + offset + ") is negative" ); if ( length < 0 ) throw new IllegalArgumentException( "Length (" + length + ") is negative" ); if ( offset + length > arrayLength ) throw new ArrayIndexOutOfBoundsException( "Last index (" + ( offset + length ) + ") is greater than array length (" + arrayLength + ")" ); } private static final int SMALL = 7; private static final int MEDIUM = 40; /** * Transforms two consecutive sorted ranges into a single sorted range. The initial ranges are * [first..middle) and [middle..last), and the resulting range is * [first..last). Elements in the first input range will precede equal elements in * the second. */ private static void inPlaceMerge( final int from, int mid, final int to, final IntComparator comp, final Swapper swapper ) { if ( from >= mid || mid >= to ) return; if ( to - from == 2 ) { if ( comp.compare( mid, from ) < 0 ) swapper.swap( from, mid ); return; } int firstCut; int secondCut; if ( mid - from > to - mid ) { firstCut = from + ( mid - from ) / 2; secondCut = lowerBound( mid, to, firstCut, comp ); } else { secondCut = mid + ( to - mid ) / 2; firstCut = upperBound( from, mid, secondCut, comp ); } int first2 = firstCut; int middle2 = mid; int last2 = secondCut; if ( middle2 != first2 && middle2 != last2 ) { int first1 = first2; int last1 = middle2; while ( first1 < --last1 ) swapper.swap( first1++, last1 ); first1 = middle2; last1 = last2; while ( first1 < --last1 ) swapper.swap( first1++, last1 ); first1 = first2; last1 = last2; while ( first1 < --last1 ) swapper.swap( first1++, last1 ); } mid = firstCut + ( secondCut - mid ); inPlaceMerge( from, firstCut, mid, comp, swapper ); inPlaceMerge( mid, secondCut, to, comp, swapper ); } /** * Performs a binary search on an already-sorted range: finds the first position where an * element can be inserted without violating the ordering. Sorting is by a user-supplied * comparison function. * * @param from the index of the first element (inclusive) to be included in the binary search. * @param to the index of the last element (exclusive) to be included in the binary search. * @param pos the position of the element to be searched for. * @param comp the comparison function. * @return the largest index i such that, for every j in the range [first..i), * comp.compare(j, pos) is true. */ private static int lowerBound( int from, final int to, final int pos, final IntComparator comp ) { // if (comp==null) throw new NullPointerException(); int len = to - from; while ( len > 0 ) { int half = len / 2; int middle = from + half; if ( comp.compare( middle, pos ) < 0 ) { from = middle + 1; len -= half + 1; } else { len = half; } } return from; } /** * Performs a binary search on an already sorted range: finds the last position where an element * can be inserted without violating the ordering. Sorting is by a user-supplied comparison * function. * * @param from the index of the first element (inclusive) to be included in the binary search. * @param to the index of the last element (exclusive) to be included in the binary search. * @param pos the position of the element to be searched for. * @param comp the comparison function. * @return The largest index i such that, for every j in the range [first..i), * comp.compare(pos, j) is false. */ private static int upperBound( int from, final int mid, final int pos, final IntComparator comp ) { // if (comp==null) throw new NullPointerException(); int len = mid - from; while ( len > 0 ) { int half = len / 2; int middle = from + half; if ( comp.compare( pos, middle ) < 0 ) { len = half; } else { from = middle + 1; len -= half + 1; } } return from; } /** * Returns the index of the median of the three indexed chars. */ private static int med3( final int a, final int b, final int c, final IntComparator comp ) { int ab = comp.compare( a, b ); int ac = comp.compare( a, c ); int bc = comp.compare( b, c ); return ( ab < 0 ? ( bc < 0 ? b : ac < 0 ? c : a ) : ( bc > 0 ? b : ac > 0 ? c : a ) ); } /** Sorts the specified range of elements using the specified swapper and according to the order induced by the specified * comparator using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. The sorting algorithm is an in-place mergesort that is significantly slower than a * standard mergesort, as its running time is O(n (log n)2), but it does not allocate additional memory; as a result, it can be * used as a generic sorting algorithm. * * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param c the comparator to determine the order of the generic data (arguments are positions). * @param swapper an object that knows how to swap the elements at any two positions. */ public static void mergeSort( final int from, final int to, final IntComparator c, final Swapper swapper ) { /* * We retain the same method signature as quickSort. Given only a comparator and swapper we * do not know how to copy and move elements from/to temporary arrays. Hence, in contrast to * the JDK mergesorts this is an "in-place" mergesort, i.e. does not allocate any temporary * arrays. A non-inplace mergesort would perhaps be faster in most cases, but would require * non-intuitive delegate objects... */ final int length = to - from; // Insertion sort on smallest arrays if ( length < SMALL ) { for ( int i = from; i < to; i++ ) { for ( int j = i; j > from && ( c.compare( j - 1, j ) > 0 ); j-- ) { swapper.swap( j, j - 1 ); } } return; } // Recursively sort halves int mid = ( from + to ) >>> 1; mergeSort( from, mid, c, swapper ); mergeSort( mid, to, c, swapper ); // If list is already sorted, nothing left to do. This is an // optimization that results in faster sorts for nearly ordered lists. if ( c.compare( mid - 1, mid ) <= 0 ) return; // Merge sorted halves inPlaceMerge( from, mid, to, c, swapper ); } /** Sorts the specified range of elements using the specified swapper and according to the order induced by the specified * comparator using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the order of the generic data. * @param swapper an object that knows how to swap the elements at any two positions. * */ public static void quickSort( final int from, final int to, final IntComparator comp, final Swapper swapper ) { final int len = to - from; // Insertion sort on smallest arrays if ( len < SMALL ) { for ( int i = from; i < to; i++ ) for ( int j = i; j > from && ( comp.compare( j - 1, j ) > 0 ); j-- ) { swapper.swap( j, j - 1 ); } return; } // Choose a partition element, v int m = from + len / 2; // Small arrays, middle element if ( len > SMALL ) { int l = from; int n = to - 1; if ( len > MEDIUM ) { // Big arrays, pseudomedian of 9 int s = len / 8; l = med3( l, l + s, l + 2 * s, comp ); m = med3( m - s, m, m + s, comp ); n = med3( n - 2 * s, n - s, n, comp ); } m = med3( l, m, n, comp ); // Mid-size, med of 3 } // int v = x[m]; int a = from; int b = a; int c = to - 1; // Establish Invariant: v* (v)* v* int d = c; while ( true ) { int comparison; while ( b <= c && ( ( comparison = comp.compare( b, m ) ) <= 0 ) ) { if ( comparison == 0 ) { if ( a == m ) m = b; // moving target; DELTA to JDK !!! else if ( b == m ) m = a; // moving target; DELTA to JDK !!! swapper.swap( a++, b ); } b++; } while ( c >= b && ( ( comparison = comp.compare( c, m ) ) >= 0 ) ) { if ( comparison == 0 ) { if ( c == m ) m = d; // moving target; DELTA to JDK !!! else if ( d == m ) m = c; // moving target; DELTA to JDK !!! swapper.swap( c, d-- ); } c--; } if ( b > c ) break; if ( b == m ) m = d; // moving target; DELTA to JDK !!! else if ( c == m ) m = c; // moving target; DELTA to JDK !!! swapper.swap( b++, c-- ); } // Swap partition elements back to middle int s; int n = to; s = Math.min( a - from, b - a ); vecSwap( swapper, from, b - s, s ); s = Math.min( d - c, n - d - 1 ); vecSwap( swapper, b, n - s, s ); // Recursively sort non-partition-elements if ( ( s = b - a ) > 1 ) quickSort( from, from + s, comp, swapper ); if ( ( s = d - c ) > 1 ) quickSort( n - s, n, comp, swapper ); } /** * Swaps x[a .. (a+n-1)] with x[b .. (b+n-1)]. */ private static void vecSwap( final Swapper swapper, int from, int l, final int s ) { for ( int i = 0; i < s; i++, from++, l++ ) swapper.swap( from, l ); } } BidirectionalIterator.java000066400000000000000000000032741422762524200340160ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutilpackage org.codelibs.jhighlight.fastutil; /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Iterator; import java.util.ListIterator; /** A bidirectional {@link Iterator}. * *

This kind of iterator is essentially a {@link ListIterator} that * does not support {@link ListIterator#previousIndex()} and {@link * ListIterator#nextIndex()}. It is useful for those maps that can easily * provide bidirectional iteration, but provide no index. * *

Note that iterators returned by fastutil classes are more * specific, and support skipping. This class serves the purpose of organising * in a cleaner way the relationships between various iterators. * * @see Iterator * @see ListIterator */ public interface BidirectionalIterator extends Iterator { /** Returns the previous element from the collection. * * @return the previous element from the collection. * @see java.util.ListIterator#previous() */ K previous(); /** Returns whether there is a previous element. * * @return whether there is a previous element. * @see java.util.ListIterator#hasPrevious() */ boolean hasPrevious(); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/Function.java000066400000000000000000000074661422762524200314070ustar00rootroot00000000000000package org.codelibs.jhighlight.fastutil; /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** A function mapping keys into values. * *

Instances of this class represent functions: the main difference with {@link java.util.Map} * is that functions do not in principle allow enumeration of their domain or range. The need for * this interface lies in the existence of several highly optimized implementations of * functions (e.g., minimal perfect hashes) which do not actually store their domain or range explicitly. * In case the domain is known, {@link #containsKey(Object)} can be used to perform membership queries. * *

The choice of naming all methods exactly as in {@link java.util.Map} makes it possible * for all type-specific maps to extend type-specific functions (e.g., {@link org.codelibs.jhighlight.fastutil.ints.Int2IntMap} * extends {@link org.codelibs.jhighlight.fastutil.ints.Int2IntFunction}). However, {@link #size()} is allowed to return -1 to denote * that the number of keys is not available (e.g., in the case of a string hash function). * *

Note that there is an {@link org.codelibs.jhighlight.fastutil.objects.Object2ObjectFunction} that * can also set its default return value. * *

Warning: Equality of functions is not specified * by contract, and it will usually be by reference, as there is no way to enumerate the keys * and establish whether two functions represent the same mathematical entity. * * @see java.util.Map */ public interface Function { /** Associates the specified value with the specified key in this function (optional operation). * * @param key the key. * @param value the value. * @return the old value, or null if no value was present for the given key. * @see java.util.Map#put(Object,Object) */ V put( K key, V value ); /** Returns the value associated by this function to the specified key. * * @param key the key. * @return the corresponding value, or null if no value was present for the given key. * @see java.util.Map#get(Object) */ V get( Object key ); /** Returns true if this function contains a mapping for the specified key. * *

Note that for some kind of functions (e.g., hashes) this method * will always return true. * * @param key the key. * @return true if this function associates a value to key. * @see java.util.Map#containsKey(Object) */ boolean containsKey( Object key ); /** Removes this key and the associated value from this function if it is present (optional operation). * * @param key * @return the old value, or null if no value was present for the given key. * @see java.util.Map#remove(Object) */ V remove( Object key ); /** Returns the intended number of keys in this function, or -1 if no such number exists. * *

Most function implementations will have some knowledge of the intended number of keys * in their domain. In some cases, however, this might not be possible. * * @return the intended number of keys in this function, or -1 if that number is not available. */ int size(); /** Removes all associations from this function (optional operation). * * @see java.util.Map#clear() */ void clear(); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/Hash.java000066400000000000000000000235441422762524200305000ustar00rootroot00000000000000package org.codelibs.jhighlight.fastutil; /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** Basic data for all hash-based classes. * *

Historical note

* *

Warning: the following comments are here for historical reasons, * and apply just to the double hash classes that can be optionally generated. * The standard fastutil distribution since 6.1.0 uses linear-probing hash * tables, and tables are always sized as powers of two. * *

The classes in fastutil are built around open-addressing hashing * implemented via double hashing. Following Knuth's suggestions in the third volume of The Art of Computer * Programming, we use for the table size a prime p such that * p-2 is also prime. In this way hashing is implemented with modulo p, * and secondary hashing with modulo p-2. * *

Entries in a table can be in three states: {@link #FREE}, {@link #OCCUPIED} or {@link #REMOVED}. * The naive handling of removed entries requires that you search for a free entry as if they were occupied. However, * fastutil implements two useful optimizations, based on the following invariant: *

* Let i0, i1, &hellip, ip-1 be * the permutation of the table indices induced by the key k, that is, i0 is the hash * of k and the following indices are obtained by adding (modulo p) the secondary hash plus one. * If there is a {@link #OCCUPIED} entry with key k, its index in the sequence above comes before * the indices of any {@link #REMOVED} entries with key k. *
* *

When we search for the key k we scan the entries in the * sequence i0, i1, &hellip, * ip-1 and stop when k is found, * when we finished the sequence or when we find a {@link #FREE} entry. Note * that the correctness of this procedure it is not completely trivial. Indeed, * when we stop at a {@link #REMOVED} entry with key k we must rely * on the invariant to be sure that no {@link #OCCUPIED} entry with the same * key can appear later. If we insert and remove frequently the same entries, * this optimization can be very effective (note, however, that when using * objects as keys or values deleted entries are set to a special fixed value to * optimize garbage collection). * *

Moreover, during the probe we keep the index of the first {@link #REMOVED} entry we meet. * If we actually have to insert a new element, we use that * entry if we can, thus avoiding to pollute another {@link #FREE} entry. Since this position comes * a fortiori before any {@link #REMOVED} entries with the same key, we are also keeping the invariant true. */ public interface Hash { /** The initial default size of a hash table. */ final public int DEFAULT_INITIAL_SIZE = 16; /** The default load factor of a hash table. */ final public float DEFAULT_LOAD_FACTOR = .75f; /** The load factor for a (usually small) table that is meant to be particularly fast. */ final public float FAST_LOAD_FACTOR = .5f; /** The load factor for a (usually very small) table that is meant to be extremely fast. */ final public float VERY_FAST_LOAD_FACTOR = .25f; /** A generic hash strategy. * *

Custom hash structures (e.g., {@link * org.codelibs.jhighlight.fastutil.objects.ObjectOpenCustomHashSet}) allow to hash objects * using arbitrary functions, a typical example being that of {@linkplain * org.codelibs.jhighlight.fastutil.ints.IntArrays#HASH_STRATEGY arrays}. Of course, * one has to compare objects for equality consistently with the chosen * function. A hash strategy, thus, specifies an {@linkplain * #equals(Object,Object) equality method} and a {@linkplain * #hashCode(Object) hash function}, with the obvious property that * equal objects must have the same hash code. * *

If your custom collection must be able to contain null, * then your strategy must be able to handle null, too. */ public interface Strategy { /** Returns the hash code of the specified object with respect to this hash strategy. * * @param o an object (or null). * @return the hash code of the given object with respect to this hash strategy. */ public int hashCode( K o ); /** Returns true if the given objects are equal with respect to this hash strategy. * * @param a an object (or null). * @param b another object (or null). * @return true if the two specified objects are equal with respect to this hash strategy. */ public boolean equals( K a, K b ); } /** The default growth factor of a hash table. */ final public int DEFAULT_GROWTH_FACTOR = 16; /** The state of a free hash table entry. */ final public byte FREE = 0; /** The state of a occupied hash table entry. */ final public byte OCCUPIED = -1; /** The state of a hash table entry freed by a deletion. */ final public byte REMOVED = 1; /** A list of primes to be used as table sizes. The i-th element is * the largest prime p smaller than 2(i+28)/16 * and such that p-2 is also prime (or 1, for the first few entries). */ final public int PRIMES[] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 13, 13, 13, 13, 13, 13, 13, 13, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 31, 31, 31, 31, 31, 31, 31, 43, 43, 43, 43, 43, 43, 43, 43, 61, 61, 61, 61, 61, 73, 73, 73, 73, 73, 73, 73, 103, 103, 109, 109, 109, 109, 109, 139, 139, 151, 151, 151, 151, 181, 181, 193, 199, 199, 199, 229, 241, 241, 241, 271, 283, 283, 313, 313, 313, 349, 349, 349, 349, 421, 433, 463, 463, 463, 523, 523, 571, 601, 619, 661, 661, 661, 661, 661, 823, 859, 883, 883, 883, 1021, 1063, 1093, 1153, 1153, 1231, 1321, 1321, 1429, 1489, 1489, 1621, 1699, 1789, 1873, 1951, 2029, 2131, 2143, 2311, 2383, 2383, 2593, 2731, 2803, 3001, 3121, 3259, 3391, 3583, 3673, 3919, 4093, 4273, 4423, 4651, 4801, 5023, 5281, 5521, 5743, 5881, 6301, 6571, 6871, 7129, 7489, 7759, 8089, 8539, 8863, 9283, 9721, 10141, 10531, 11071, 11551, 12073, 12613, 13009, 13759, 14323, 14869, 15649, 16363, 17029, 17839, 18541, 19471, 20233, 21193, 22159, 23059, 24181, 25171, 26263, 27541, 28753, 30013, 31321, 32719, 34213, 35731, 37309, 38923, 40639, 42463, 44281, 46309, 48313, 50461, 52711, 55051, 57529, 60091, 62299, 65521, 68281, 71413, 74611, 77713, 81373, 84979, 88663, 92671, 96739, 100801, 105529, 109849, 115021, 120079, 125509, 131011, 136861, 142873, 149251, 155863, 162751, 169891, 177433, 185071, 193381, 202129, 211063, 220021, 229981, 240349, 250969, 262111, 273643, 285841, 298411, 311713, 325543, 339841, 355009, 370663, 386989, 404269, 422113, 440809, 460081, 480463, 501829, 524221, 547399, 571603, 596929, 623353, 651019, 679909, 709741, 741343, 774133, 808441, 844201, 881539, 920743, 961531, 1004119, 1048573, 1094923, 1143283, 1193911, 1246963, 1302181, 1359733, 1420039, 1482853, 1548541, 1616899, 1688413, 1763431, 1841293, 1922773, 2008081, 2097133, 2189989, 2286883, 2388163, 2493853, 2604013, 2719669, 2840041, 2965603, 3097123, 3234241, 3377191, 3526933, 3682363, 3845983, 4016041, 4193803, 4379719, 4573873, 4776223, 4987891, 5208523, 5439223, 5680153, 5931313, 6194191, 6468463, 6754879, 7053331, 7366069, 7692343, 8032639, 8388451, 8759953, 9147661, 9552733, 9975193, 10417291, 10878619, 11360203, 11863153, 12387841, 12936529, 13509343, 14107801, 14732413, 15384673, 16065559, 16777141, 17519893, 18295633, 19105483, 19951231, 20834689, 21757291, 22720591, 23726449, 24776953, 25873963, 27018853, 28215619, 29464579, 30769093, 32131711, 33554011, 35039911, 36591211, 38211163, 39903121, 41669479, 43514521, 45441199, 47452879, 49553941, 51747991, 54039079, 56431513, 58930021, 61539091, 64263571, 67108669, 70079959, 73182409, 76422793, 79806229, 83339383, 87029053, 90881083, 94906249, 99108043, 103495879, 108077731, 112863013, 117860053, 123078019, 128526943, 134217439, 140159911, 146365159, 152845393, 159612601, 166679173, 174058849, 181765093, 189812341, 198216103, 206991601, 216156043, 225726379, 235720159, 246156271, 257054491, 268435009, 280319203, 292730833, 305691181, 319225021, 333358513, 348117151, 363529759, 379624279, 396432481, 413983771, 432312511, 451452613, 471440161, 492312523, 514109251, 536870839, 560640001, 585461743, 611382451, 638450569, 666717199, 696235363, 727060069, 759249643, 792864871, 827967631, 864625033, 902905501, 942880663, 984625531, 1028218189, 1073741719, 1121280091, 1170923713, 1222764841, 1276901371, 1333434301, 1392470281, 1454120779, 1518500173, 1585729993, 1655935399, 1729249999, 1805811253, 1885761133, 1969251079, 2056437379, 2147482951 }; } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/HashCommon.java000066400000000000000000000145521422762524200316500ustar00rootroot00000000000000package org.codelibs.jhighlight.fastutil; /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** Common code for all hash-based classes. */ public class HashCommon { protected HashCommon() {}; /** This reference is used to fill keys and values of removed entries (if they are objects). null cannot be used as it would confuse the search algorithm in the presence of an actual null key. */ public static final Object REMOVED = new Object(); /** Avalanches the bits of an integer by applying the finalisation step of MurmurHash3. * *

This method implements the finalisation step of Austin Appleby's MurmurHash3. * Its purpose is to avalanche the bits of the argument to within 0.25% bias. It is used, among other things, to scramble quickly (but deeply) the hash * values returned by {@link Object#hashCode()}. * * @param x an integer. * @return a hash value with good avalanching properties. */ public final static int murmurHash3( int x ) { x ^= x >>> 16; x *= 0x85ebca6b; x ^= x >>> 13; x *= 0xc2b2ae35; x ^= x >>> 16; return x; } /** Avalanches the bits of a long integer by applying the finalisation step of MurmurHash3. * *

This method implements the finalisation step of Austin Appleby's MurmurHash3. * Its purpose is to avalanche the bits of the argument to within 0.25% bias. It is used, among other things, to scramble quickly (but deeply) the hash * values returned by {@link Object#hashCode()}. * *

Incidentally, iterating this method starting from a nonzero value will generate a sequence of nonzero * values that passes strongest statistical tests. * * @param x a long integer. * @return a hash value with good avalanching properties. */ public final static long murmurHash3( long x ) { x ^= x >>> 33; x *= 0xff51afd7ed558ccdL; x ^= x >>> 33; x *= 0xc4ceb9fe1a85ec53L; x ^= x >>> 33; return x; } /** Returns the hash code that would be returned by {@link Float#hashCode()}. * * @return the same code as {@link Float#hashCode() new Float(f).hashCode()}. */ final public static int float2int( final float f ) { return Float.floatToRawIntBits( f ); } /** Returns the hash code that would be returned by {@link Double#hashCode()}. * * @return the same code as {@link Double#hashCode() new Double(f).hashCode()}. */ final public static int double2int( final double d ) { final long l = Double.doubleToRawLongBits( d ); return (int)( l ^ ( l >>> 32 ) ); } /** Returns the hash code that would be returned by {@link Long#hashCode()}. * * @return the same code as {@link Long#hashCode() new Long(f).hashCode()}. */ final public static int long2int( final long l ) { return (int)( l ^ ( l >>> 32 ) ); } /** Return the least power of two greater than or equal to the specified value. * *

Note that this function will return 1 when the argument is 0. * * @param x an integer smaller than or equal to 230. * @return the least power of two greater than or equal to the specified value. */ public static int nextPowerOfTwo( int x ) { if ( x == 0 ) return 1; x--; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; return ( x | x >> 16 ) + 1; } /** Return the least power of two greater than or equal to the specified value. * *

Note that this function will return 1 when the argument is 0. * * @param x a long integer smaller than or equal to 262. * @return the least power of two greater than or equal to the specified value. */ public static long nextPowerOfTwo( long x ) { if ( x == 0 ) return 1; x--; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return ( x | x >> 32 ) + 1; } /** Returns the maximum number of entries that can be filled before rehashing. * * @param n the size of the backing array. * @param f the load factor. * @return the maximum number of entries before rehashing. */ public static int maxFill( final int n, final float f ) { /* We must guarantee that there is always at least * one free entry (even with pathological load factors). */ return Math.min( (int)Math.ceil( n * f ), n - 1 ); } /** Returns the maximum number of entries that can be filled before rehashing. * * @param n the size of the backing array. * @param f the load factor. * @return the maximum number of entries before rehashing. */ public static long maxFill( final long n, final float f ) { /* We must guarantee that there is always at least * one free entry (even with pathological load factors). */ return Math.min( (long)Math.ceil( n * f ), n - 1 ); } /** Returns the least power of two smaller than or equal to 230 and larger than or equal to Math.ceil( expected / f ). * * @param expected the expected number of elements in a hash table. * @param f the load factor. * @return the minimum possible size for a backing array. * @throws IllegalArgumentException if the necessary size is larger than 230. */ public static int arraySize( final int expected, final float f ) { final long s = Math.max( 2, nextPowerOfTwo( (long)Math.ceil( expected / f ) ) ); if ( s > (1 << 30) ) throw new IllegalArgumentException( "Too large (" + expected + " expected elements with load factor " + f + ")" ); return (int)s; } /** Returns the least power of two larger than or equal to Math.ceil( expected / f ). * * @param expected the expected number of elements in a hash table. * @param f the load factor. * @return the minimum possible size for a backing big array. */ public static long bigArraySize( final long expected, final float f ) { return nextPowerOfTwo( (long)Math.ceil( expected / f ) ); } }jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/Stack.java000066400000000000000000000036001422762524200306510ustar00rootroot00000000000000package org.codelibs.jhighlight.fastutil; /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.NoSuchElementException; /** A stack. * *

A stack must provide the classical {@link #push(Object)} and * {@link #pop()} operations, but may be also peekable * to some extent: it may provide just the {@link #top()} function, * or even a more powerful {@link #peek(int)} method that provides * access to all elements on the stack (indexed from the top, which * has index 0). */ public interface Stack { /** Pushes the given object on the stack. * * @param o the object that will become the new top of the stack. */ void push( K o ); /** Pops the top off the stack. * * @return the top of the stack. * @throws NoSuchElementException if the stack is empty. */ K pop(); /** Checks whether the stack is empty. * * @return true if the stack is empty. */ boolean isEmpty(); /** Peeks at the top of the stack (optional operation). * * @return the top of the stack. * @throws NoSuchElementException if the stack is empty. */ K top(); /** Peeks at an element on the stack (optional operation). * * @return the i-th element on the stack; 0 represents the top. * @throws IndexOutOfBoundsException if the designated element does not exist.. */ K peek( int i ); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/Swapper.java000066400000000000000000000020131422762524200312220ustar00rootroot00000000000000package org.codelibs.jhighlight.fastutil; /* * Copyright (C) 2010-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** An object that can swap elements whose position is specified by integers * * @see Arrays#quickSort(int, int, org.codelibs.jhighlight.fastutil.ints.IntComparator, Swapper) */ public interface Swapper { /** Swaps the data at the given positions. * * @param a the first position to swap. * @param b the second position to swap. */ void swap( int a, int b ); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/booleans/000077500000000000000000000000001422762524200305445ustar00rootroot00000000000000BooleanArrays.java000066400000000000000000000716171422762524200341050ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/booleans/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * * * For the sorting and binary search code: * * Copyright (C) 1999 CERN - European Organization for Nuclear Research. * * Permission to use, copy, modify, distribute and sell this software and * its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation. CERN makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without expressed or implied warranty. */ package org.codelibs.jhighlight.fastutil.booleans; import java.util.Random; import org.codelibs.jhighlight.fastutil.Arrays; import org.codelibs.jhighlight.fastutil.Hash; /** A class providing static methods and objects that do useful things with type-specific arrays. * *

In particular, the ensureCapacity(), grow(), * trim() and setLength() methods allow to handle * arrays much like array lists. This can be very useful when efficiency (or * syntactic simplicity) reasons make array lists unsuitable. * *

Note that {@link org.codelibs.jhighlight.fastutil.io.BinIO} and {@link org.codelibs.jhighlight.fastutil.io.TextIO} * contain several methods make it possible to load and save arrays of primitive types as sequences * of elements in {@link java.io.DataInput} format (i.e., not as objects) or as sequences of lines of text. * * @see java.util.Arrays */ public class BooleanArrays { private BooleanArrays() {} /** A static, final, empty array. */ public final static boolean[] EMPTY_ARRAY = {}; /** Ensures that an array can contain the given number of entries. * *

If you cannot foresee whether this array will need again to be * enlarged, you should probably use grow() instead. * * @param array an array. * @param length the new minimum length for this array. * @return array, if it contains length entries or more; otherwise, * an array with length entries whose first array.length * entries are the same as those of array. */ public static boolean[] ensureCapacity( final boolean[] array, final int length ) { if ( length > array.length ) { final boolean t[] = new boolean[ length ]; System.arraycopy( array, 0, t, 0, array.length ); return t; } return array; } /** Ensures that an array can contain the given number of entries, preserving just a part of the array. * * @param array an array. * @param length the new minimum length for this array. * @param preserve the number of elements of the array that must be preserved in case a new allocation is necessary. * @return array, if it can contain length entries or more; otherwise, * an array with length entries whose first preserve * entries are the same as those of array. */ public static boolean[] ensureCapacity( final boolean[] array, final int length, final int preserve ) { if ( length > array.length ) { final boolean t[] = new boolean[ length ]; System.arraycopy( array, 0, t, 0, preserve ); return t; } return array; } /** Grows the given array to the maximum between the given length and * the current length multiplied by two, provided that the given * length is larger than the current length. * *

If you want complete control on the array growth, you * should probably use ensureCapacity() instead. * * @param array an array. * @param length the new minimum length for this array. * @return array, if it can contain length * entries; otherwise, an array with * max(length,array.length/φ) entries whose first * array.length entries are the same as those of array. * */ public static boolean[] grow( final boolean[] array, final int length ) { if ( length > array.length ) { final int newLength = (int)Math.max( Math.min( 2L * array.length, Arrays.MAX_ARRAY_SIZE ), length ); final boolean t[] = new boolean[ newLength ]; System.arraycopy( array, 0, t, 0, array.length ); return t; } return array; } /** Grows the given array to the maximum between the given length and * the current length multiplied by two, provided that the given * length is larger than the current length, preserving just a part of the array. * *

If you want complete control on the array growth, you * should probably use ensureCapacity() instead. * * @param array an array. * @param length the new minimum length for this array. * @param preserve the number of elements of the array that must be preserved in case a new allocation is necessary. * @return array, if it can contain length * entries; otherwise, an array with * max(length,array.length/φ) entries whose first * preserve entries are the same as those of array. * */ public static boolean[] grow( final boolean[] array, final int length, final int preserve ) { if ( length > array.length ) { final int newLength = (int)Math.max( Math.min( 2L * array.length, Arrays.MAX_ARRAY_SIZE ), length ); final boolean t[] = new boolean[ newLength ]; System.arraycopy( array, 0, t, 0, preserve ); return t; } return array; } /** Trims the given array to the given length. * * @param array an array. * @param length the new maximum length for the array. * @return array, if it contains length * entries or less; otherwise, an array with * length entries whose entries are the same as * the first length entries of array. * */ public static boolean[] trim( final boolean[] array, final int length ) { if ( length >= array.length ) return array; final boolean t[] = length == 0 ? EMPTY_ARRAY : new boolean[ length ]; System.arraycopy( array, 0, t, 0, length ); return t; } /** Sets the length of the given array. * * @param array an array. * @param length the new length for the array. * @return array, if it contains exactly length * entries; otherwise, if it contains more than * length entries, an array with length entries * whose entries are the same as the first length entries of * array; otherwise, an array with length entries * whose first array.length entries are the same as those of * array. * */ public static boolean[] setLength( final boolean[] array, final int length ) { if ( length == array.length ) return array; if ( length < array.length ) return trim( array, length ); return ensureCapacity( array, length ); } /** Returns a copy of a portion of an array. * * @param array an array. * @param offset the first element to copy. * @param length the number of elements to copy. * @return a new array containing length elements of array starting at offset. */ public static boolean[] copy( final boolean[] array, final int offset, final int length ) { ensureOffsetLength( array, offset, length ); final boolean[] a = length == 0 ? EMPTY_ARRAY : new boolean[ length ]; System.arraycopy( array, offset, a, 0, length ); return a; } /** Returns a copy of an array. * * @param array an array. * @return a copy of array. */ public static boolean[] copy( final boolean[] array ) { return array.clone(); } /** Fills the given array with the given value. * *

This method uses a backward loop. It is significantly faster than the corresponding * method in {@link java.util.Arrays}. * * @param array an array. * @param value the new value for all elements of the array. */ public static void fill( final boolean[] array, final boolean value ) { int i = array.length; while( i-- != 0 ) array[ i ] = value; } /** Fills a portion of the given array with the given value. * *

If possible (i.e., from is 0) this method uses a * backward loop. In this case, it is significantly faster than the * corresponding method in {@link java.util.Arrays}. * * @param array an array. * @param from the starting index of the portion to fill (inclusive). * @param to the end index of the portion to fill (exclusive). * @param value the new value for all elements of the specified portion of the array. */ public static void fill( final boolean[] array, final int from, int to, final boolean value ) { ensureFromTo( array, from, to ); if ( from == 0 ) while( to-- != 0 ) array[ to ] = value; else for( int i = from; i < to; i++ ) array[ i ] = value; } /** Returns true if the two arrays are elementwise equal. * * @param a1 an array. * @param a2 another array. * @return true if the two arrays are of the same length, and their elements are equal. * @deprecated Please use the corresponding {@link java.util.Arrays} method, which is intrinsified in recent JVMs. */ @Deprecated public static boolean equals( final boolean[] a1, final boolean a2[] ) { int i = a1.length; if ( i != a2.length ) return false; while( i-- != 0 ) if (! ( (a1[ i ]) == (a2[ i ]) ) ) return false; return true; } /** Ensures that a range given by its first (inclusive) and last (exclusive) elements fits an array. * *

This method may be used whenever an array range check is needed. * * @param a an array. * @param from a start index (inclusive). * @param to an end index (exclusive). * @throws IllegalArgumentException if from is greater than to. * @throws ArrayIndexOutOfBoundsException if from or to are greater than the array length or negative. */ public static void ensureFromTo( final boolean[] a, final int from, final int to ) { Arrays.ensureFromTo( a.length, from, to ); } /** Ensures that a range given by an offset and a length fits an array. * *

This method may be used whenever an array range check is needed. * * @param a an array. * @param offset a start index. * @param length a length (the number of elements in the range). * @throws IllegalArgumentException if length is negative. * @throws ArrayIndexOutOfBoundsException if offset is negative or offset+length is greater than the array length. */ public static void ensureOffsetLength( final boolean[] a, final int offset, final int length ) { Arrays.ensureOffsetLength( a.length, offset, length ); } private static final int SMALL = 7; private static final int MEDIUM = 50; private static void swap( final boolean x[], final int a, final int b ) { final boolean t = x[ a ]; x[ a ] = x[ b ]; x[ b ] = t; } private static void vecSwap( final boolean[] x, int a, int b, final int n ) { for( int i = 0; i < n; i++, a++, b++ ) swap( x, a, b ); } private static int med3( final boolean x[], final int a, final int b, final int c, BooleanComparator comp ) { int ab = comp.compare( x[ a ], x[ b ] ); int ac = comp.compare( x[ a ], x[ c ] ); int bc = comp.compare( x[ b ], x[ c ] ); return ( ab < 0 ? ( bc < 0 ? b : ac < 0 ? c : a ) : ( bc > 0 ? b : ac > 0 ? c : a ) ); } private static void selectionSort( final boolean[] a, final int from, final int to, final BooleanComparator comp ) { for( int i = from; i < to - 1; i++ ) { int m = i; for( int j = i + 1; j < to; j++ ) if ( comp.compare( a[ j ], a[ m ] ) < 0 ) m = j; if ( m != i ) { final boolean u = a[ i ]; a[ i ] = a[ m ]; a[ m ] = u; } } } private static void insertionSort( final boolean[] a, final int from, final int to, final BooleanComparator comp ) { for ( int i = from; ++i < to; ) { boolean t = a[ i ]; int j = i; for ( boolean u = a[ j - 1 ]; comp.compare( t, u ) < 0; u = a[ --j - 1 ] ) { a[ j ] = u; if ( from == j - 1 ) { --j; break; } } a[ j ] = t; } } @SuppressWarnings("unchecked") private static void selectionSort( final boolean[] a, final int from, final int to ) { for( int i = from; i < to - 1; i++ ) { int m = i; for( int j = i + 1; j < to; j++ ) if ( ( !(a[ j ]) && (a[ m ]) ) ) m = j; if ( m != i ) { final boolean u = a[ i ]; a[ i ] = a[ m ]; a[ m ] = u; } } } @SuppressWarnings("unchecked") private static void insertionSort( final boolean[] a, final int from, final int to ) { for ( int i = from; ++i < to; ) { boolean t = a[ i ]; int j = i; for ( boolean u = a[ j - 1 ]; ( !(t) && (u) ); u = a[ --j - 1 ] ) { a[ j ] = u; if ( from == j - 1 ) { --j; break; } } a[ j ] = t; } } /** Sorts the specified range of elements according to the order induced by the specified * comparator using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. * */ public static void quickSort( final boolean[] x, final int from, final int to, final BooleanComparator comp ) { final int len = to - from; // Selection sort on smallest arrays if ( len < SMALL ) { selectionSort( x, from, to, comp ); return; } // Choose a partition element, v int m = from + len / 2; // Small arrays, middle element if ( len > SMALL ) { int l = from; int n = to - 1; if ( len > MEDIUM ) { // Big arrays, pseudomedian of 9 int s = len / 8; l = med3( x, l, l + s, l + 2 * s, comp ); m = med3( x, m - s, m, m + s, comp ); n = med3( x, n - 2 * s, n - s, n, comp ); } m = med3( x, l, m, n, comp ); // Mid-size, med of 3 } final boolean v = x[ m ]; // Establish Invariant: v* (v)* v* int a = from, b = a, c = to - 1, d = c; while(true) { int comparison; while ( b <= c && ( comparison = comp.compare( x[ b ], v ) ) <= 0 ) { if ( comparison == 0 ) swap( x, a++, b ); b++; } while (c >= b && ( comparison = comp.compare( x[ c ], v ) ) >=0 ) { if ( comparison == 0 ) swap( x, c, d-- ); c--; } if ( b > c ) break; swap( x, b++, c-- ); } // Swap partition elements back to middle int s, n = to; s = Math.min( a - from, b - a ); vecSwap( x, from, b - s, s ); s = Math.min( d - c, n - d - 1 ); vecSwap( x, b, n - s, s ); // Recursively sort non-partition-elements if ( ( s = b - a ) > 1 ) quickSort( x, from, from + s, comp ); if ( ( s = d - c ) > 1 ) quickSort( x, n - s, n, comp ); } /** Sorts an array according to the order induced by the specified * comparator using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * @param comp the comparator to determine the sorting order. * */ public static void quickSort( final boolean[] x, final BooleanComparator comp ) { quickSort( x, 0, x.length, comp ); } @SuppressWarnings("unchecked") private static int med3( final boolean x[], final int a, final int b, final int c ) { int ab = ( !(x[ a ]) && (x[ b ]) ? -1 : ( (x[ a ]) == (x[ b ]) ? 0 : 1 ) ); int ac = ( !(x[ a ]) && (x[ c ]) ? -1 : ( (x[ a ]) == (x[ c ]) ? 0 : 1 ) ); int bc = ( !(x[ b ]) && (x[ c ]) ? -1 : ( (x[ b ]) == (x[ c ]) ? 0 : 1 ) ); return ( ab < 0 ? ( bc < 0 ? b : ac < 0 ? c : a ) : ( bc > 0 ? b : ac > 0 ? c : a ) ); } /** Sorts the specified range of elements according to the natural ascending order using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ @SuppressWarnings("unchecked") public static void quickSort( final boolean[] x, final int from, final int to ) { final int len = to - from; // Selection sort on smallest arrays if ( len < SMALL ) { selectionSort( x, from, to ); return; } // Choose a partition element, v int m = from + len / 2; // Small arrays, middle element if ( len > SMALL ) { int l = from; int n = to - 1; if ( len > MEDIUM ) { // Big arrays, pseudomedian of 9 int s = len / 8; l = med3( x, l, l + s, l + 2 * s ); m = med3( x, m - s, m, m + s ); n = med3( x, n - 2 * s, n - s, n ); } m = med3( x, l, m, n ); // Mid-size, med of 3 } final boolean v = x[ m ]; // Establish Invariant: v* (v)* v* int a = from, b = a, c = to - 1, d = c; while(true) { int comparison; while ( b <= c && ( comparison = ( !(x[ b ]) && (v) ? -1 : ( (x[ b ]) == (v) ? 0 : 1 ) ) ) <= 0 ) { if ( comparison == 0 ) swap( x, a++, b ); b++; } while (c >= b && ( comparison = ( !(x[ c ]) && (v) ? -1 : ( (x[ c ]) == (v) ? 0 : 1 ) ) ) >=0 ) { if ( comparison == 0 ) swap( x, c, d-- ); c--; } if ( b > c ) break; swap( x, b++, c-- ); } // Swap partition elements back to middle int s, n = to; s = Math.min( a - from, b - a ); vecSwap( x, from, b - s, s ); s = Math.min( d - c, n - d - 1 ); vecSwap( x, b, n - s, s ); // Recursively sort non-partition-elements if ( ( s = b - a ) > 1 ) quickSort( x, from, from + s ); if ( ( s = d - c ) > 1 ) quickSort( x, n - s, n ); } /** Sorts an array according to the natural ascending order using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * */ public static void quickSort( final boolean[] x ) { quickSort( x, 0, x.length ); } /** Sorts the specified range of elements according to the natural ascending order using mergesort, using a given pre-filled support array. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. Moreover, no support arrays will be allocated. * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param supp a support array containing at least to elements, and whose entries are identical to those * of {@code a} in the specified range. */ @SuppressWarnings("unchecked") public static void mergeSort( final boolean a[], final int from, final int to, final boolean supp[] ) { int len = to - from; // Insertion sort on smallest arrays if ( len < SMALL ) { insertionSort( a, from, to ); return; } // Recursively sort halves of a into supp final int mid = ( from + to ) >>> 1; mergeSort( supp, from, mid, a ); mergeSort( supp, mid, to, a ); // If list is already sorted, just copy from supp to a. This is an // optimization that results in faster sorts for nearly ordered lists. if ( ( !(supp[ mid - 1 ]) || (supp[ mid ]) ) ) { System.arraycopy( supp, from, a, from, len ); return; } // Merge sorted halves (now in supp) into a for( int i = from, p = from, q = mid; i < to; i++ ) { if ( q >= to || p < mid && ( !(supp[ p ]) || (supp[ q ]) ) ) a[ i ] = supp[ p++ ]; else a[ i ] = supp[ q++ ]; } } /** Sorts the specified range of elements according to the natural ascending order using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ public static void mergeSort( final boolean a[], final int from, final int to ) { mergeSort( a, from, to, a.clone() ); } /** Sorts an array according to the natural ascending order using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * @param a the array to be sorted. */ public static void mergeSort( final boolean a[] ) { mergeSort( a, 0, a.length ); } /** Sorts the specified range of elements according to the order induced by the specified * comparator using mergesort, using a given pre-filled support array. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. Moreover, no support arrays will be allocated. * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. * @param supp a support array containing at least to elements, and whose entries are identical to those * of {@code a} in the specified range. */ @SuppressWarnings("unchecked") public static void mergeSort( final boolean a[], final int from, final int to, BooleanComparator comp, final boolean supp[] ) { int len = to - from; // Insertion sort on smallest arrays if ( len < SMALL ) { insertionSort( a, from, to, comp ); return; } // Recursively sort halves of a into supp final int mid = ( from + to ) >>> 1; mergeSort( supp, from, mid, comp, a ); mergeSort( supp, mid, to, comp, a ); // If list is already sorted, just copy from supp to a. This is an // optimization that results in faster sorts for nearly ordered lists. if ( comp.compare( supp[ mid - 1 ], supp[ mid ] ) <= 0 ) { System.arraycopy( supp, from, a, from, len ); return; } // Merge sorted halves (now in supp) into a for( int i = from, p = from, q = mid; i < to; i++ ) { if ( q >= to || p < mid && comp.compare( supp[ p ], supp[ q ] ) <= 0 ) a[ i ] = supp[ p++ ]; else a[ i ] = supp[ q++ ]; } } /** Sorts the specified range of elements according to the order induced by the specified * comparator using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. */ public static void mergeSort( final boolean a[], final int from, final int to, BooleanComparator comp ) { mergeSort( a, from, to, comp, a.clone() ); } /** Sorts an array according to the order induced by the specified * comparator using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * @param a the array to be sorted. * @param comp the comparator to determine the sorting order. */ public static void mergeSort( final boolean a[], BooleanComparator comp ) { mergeSort( a, 0, a.length, comp ); } /** Shuffles the specified array fragment using the specified pseudorandom number generator. * * @param a the array to be shuffled. * @param from the index of the first element (inclusive) to be shuffled. * @param to the index of the last element (exclusive) to be shuffled. * @param random a pseudorandom number generator (please use a XorShift* generator). * @return a. */ public static boolean[] shuffle( final boolean[] a, final int from, final int to, final Random random ) { for( int i = to - from; i-- != 0; ) { final int p = random.nextInt( i + 1 ); final boolean t = a[ from + i ]; a[ from + i ] = a[ from + p ]; a[ from + p ] = t; } return a; } /** Shuffles the specified array using the specified pseudorandom number generator. * * @param a the array to be shuffled. * @param random a pseudorandom number generator (please use a XorShift* generator). * @return a. */ public static boolean[] shuffle( final boolean[] a, final Random random ) { for( int i = a.length; i-- != 0; ) { final int p = random.nextInt( i + 1 ); final boolean t = a[ i ]; a[ i ] = a[ p ]; a[ p ] = t; } return a; } /** Reverses the order of the elements in the specified array. * * @param a the array to be reversed. * @return a. */ public static boolean[] reverse( final boolean[] a ) { final int length = a.length; for( int i = length / 2; i-- != 0; ) { final boolean t = a[ length - i - 1 ]; a[ length - i - 1 ] = a[ i ]; a[ i ] = t; } return a; } /** Reverses the order of the elements in the specified array fragment. * * @param a the array to be reversed. * @param from the index of the first element (inclusive) to be reversed. * @param to the index of the last element (exclusive) to be reversed. * @return a. */ public static boolean[] reverse( final boolean[] a, final int from, final int to ) { final int length = to - from; for( int i = length / 2; i-- != 0; ) { final boolean t = a[ from + length - i - 1 ]; a[ from + length - i - 1 ] = a[ from + i ]; a[ from + i ] = t; } return a; } /** A type-specific content-based hash strategy for arrays. */ private static final class ArrayHashStrategy implements Hash.Strategy, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; public int hashCode( final boolean[] o ) { return java.util.Arrays.hashCode( o ); } public boolean equals( final boolean[] a, final boolean[] b ) { return java.util.Arrays.equals( a, b ); } } /** A type-specific content-based hash strategy for arrays. * *

This hash strategy may be used in custom hash collections whenever keys are * arrays, and they must be considered equal by content. This strategy * will handle null correctly, and it is serializable. */ public final static Hash.Strategy HASH_STRATEGY = new ArrayHashStrategy(); } BooleanComparator.java000066400000000000000000000041631422762524200347430ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/booleans/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.booleans; import java.util.Comparator; /** A type-specific {@link Comparator}; provides methods to compare two primitive types both as objects * and as primitive types. * *

Note that fastutil provides a corresponding abstract class that * can be used to implement this interface just by specifying the type-specific * comparator. * * @see Comparator */ public interface BooleanComparator extends Comparator { /** Compares the given primitive types. * * @see java.util.Comparator * @return A positive integer, zero, or a negative integer if the first * argument is greater than, equal to, or smaller than, respectively, the * second one. */ public int compare( boolean k1, boolean k2 ); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/000077500000000000000000000000001422762524200300425ustar00rootroot00000000000000AbstractChar2ObjectFunction.java000066400000000000000000000111741422762524200361120ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; /** An abstract class providing basic methods for functions implementing a type-specific interface. * *

Optional operations just throw an {@link * UnsupportedOperationException}. Generic versions of accessors delegate to * the corresponding type-specific counterparts following the interface rules * (they take care of returning null on a missing key). * *

This class handles directly a default return * value (including {@linkplain #defaultReturnValue() methods to access * it}). Instances of classes inheriting from this class have just to return * defRetValue to denote lack of a key in type-specific methods. The value * is serialized. * *

Implementing subclasses have just to provide type-specific get(), * type-specific containsKey(), and size() methods. * */ public abstract class AbstractChar2ObjectFunction implements Char2ObjectFunction , java.io.Serializable { private static final long serialVersionUID = -4940583368468432370L; protected AbstractChar2ObjectFunction() {} /** * The default return value for get(), put() and * remove(). */ protected V defRetValue; public void defaultReturnValue( final V rv ) { defRetValue = rv; } public V defaultReturnValue() { return defRetValue; } public V put( char key, V value ) { throw new UnsupportedOperationException(); } public V remove( char key ) { throw new UnsupportedOperationException(); } public void clear() { throw new UnsupportedOperationException(); } public boolean containsKey( final Object ok ) { return containsKey( ((((Character)(ok)).charValue())) ); } /** Delegates to the corresponding type-specific method, taking care of returning null on a missing key. * *

This method must check whether the provided key is in the map using containsKey(). Thus, * it probes the map twice. Implementors of subclasses should override it with a more efficient method. */ public V get( final Object ok ) { final char k = ((((Character)(ok)).charValue())); return containsKey( k ) ? (get( k )) : null; } /** Delegates to the corresponding type-specific method, taking care of returning null on a missing key. * *

This method must check whether the provided key is in the map using containsKey(). Thus, * it probes the map twice. Implementors of subclasses should override it with a more efficient method. */ public V put( final Character ok, final V ov ) { final char k = ((ok).charValue()); final boolean containsKey = containsKey( k ); final V v = put( k, (ov) ); return containsKey ? (v) : null; } /** Delegates to the corresponding type-specific method, taking care of returning null on a missing key. * *

This method must check whether the provided key is in the map using containsKey(). Thus, * it probes the map twice. Implementors of subclasses should override it with a more efficient method. */ public V remove( final Object ok ) { final char k = ((((Character)(ok)).charValue())); final boolean containsKey = containsKey( k ); final V v = remove( k ); return containsKey ? (v) : null; } } AbstractChar2ObjectMap.java000066400000000000000000000214051422762524200350400ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import java.util.Iterator; import java.util.Map; import org.codelibs.jhighlight.fastutil.objects.AbstractObjectCollection; import org.codelibs.jhighlight.fastutil.objects.AbstractObjectIterator; import org.codelibs.jhighlight.fastutil.objects.ObjectCollection; import org.codelibs.jhighlight.fastutil.objects.ObjectIterator; import org.codelibs.jhighlight.fastutil.objects.ObjectSet; /** An abstract class providing basic methods for maps implementing a type-specific interface. * *

Optional operations just throw an {@link * UnsupportedOperationException}. Generic versions of accessors delegate to * the corresponding type-specific counterparts following the interface rules * (they take care of returning null on a missing key). * *

As a further help, this class provides a {@link BasicEntry BasicEntry} inner class * that implements a type-specific version of {@link java.util.Map.Entry}; it * is particularly useful for those classes that do not implement their own * entries (e.g., most immutable maps). */ public abstract class AbstractChar2ObjectMap extends AbstractChar2ObjectFunction implements Char2ObjectMap , java.io.Serializable { private static final long serialVersionUID = -4940583368468432370L; protected AbstractChar2ObjectMap() {} /** Checks whether the given value is contained in {@link #values()}. */ public boolean containsValue( Object v ) { return values().contains( v ); } /** Checks whether the given value is contained in {@link #keySet()}. */ public boolean containsKey( char k ) { return keySet().contains( k ); } /** Puts all pairs in the given map. * If the map implements the interface of this map, * it uses the faster iterators. * * @param m a map. */ @SuppressWarnings("unchecked") public void putAll(Map m) { int n = m.size(); final Iterator> i = m.entrySet().iterator(); if (m instanceof Char2ObjectMap) { Char2ObjectMap.Entry e; while(n-- != 0) { e = (Char2ObjectMap.Entry )i.next(); put(e.getCharKey(), e.getValue()); } } else { Map.Entry e; while(n-- != 0) { e = i.next(); put(e.getKey(), e.getValue()); } } } public boolean isEmpty() { return size() == 0; } /** This class provides a basic but complete type-specific entry class for all those maps implementations * that do not have entries on their own (e.g., most immutable maps). * *

This class does not implement {@link java.util.Map.Entry#setValue(Object) setValue()}, as the modification * would not be reflected in the base map. */ public static class BasicEntry implements Char2ObjectMap.Entry { protected char key; protected V value; public BasicEntry( final Character key, final V value ) { this.key = ((key).charValue()); this.value = (value); } public BasicEntry( final char key, final V value ) { this.key = key; this.value = value; } public Character getKey() { return (Character.valueOf(key)); } public char getCharKey() { return key; } public V getValue() { return (value); } public V setValue( final V value ) { throw new UnsupportedOperationException(); } public boolean equals( final Object o ) { if (!(o instanceof Map.Entry)) return false; Map.Entry e = (Map.Entry)o; return ( (key) == (((((Character)(e.getKey())).charValue()))) ) && ( (value) == null ? ((e.getValue())) == null : (value).equals((e.getValue())) ); } public int hashCode() { return (key) ^ ( (value) == null ? 0 : (value).hashCode() ); } public String toString() { return key + "->" + value; } } /** Returns a type-specific-set view of the keys of this map. * *

The view is backed by the set returned by {@link #entrySet()}. Note that * no attempt is made at caching the result of this method, as this would * require adding some attributes that lightweight implementations would * not need. Subclasses may easily override this policy by calling * this method and caching the result, but implementors are encouraged to * write more efficient ad-hoc implementations. * * @return a set view of the keys of this map; it may be safely cast to a type-specific interface. */ public CharSet keySet() { return new AbstractCharSet () { public boolean contains( final char k ) { return containsKey( k ); } public int size() { return AbstractChar2ObjectMap.this.size(); } public void clear() { AbstractChar2ObjectMap.this.clear(); } public CharIterator iterator() { return new AbstractCharIterator () { final ObjectIterator> i = entrySet().iterator(); public char nextChar() { return ((Char2ObjectMap.Entry )i.next()).getCharKey(); }; public boolean hasNext() { return i.hasNext(); } }; } }; } /** Returns a type-specific-set view of the values of this map. * *

The view is backed by the set returned by {@link #entrySet()}. Note that * no attempt is made at caching the result of this method, as this would * require adding some attributes that lightweight implementations would * not need. Subclasses may easily override this policy by calling * this method and caching the result, but implementors are encouraged to * write more efficient ad-hoc implementations. * * @return a set view of the values of this map; it may be safely cast to a type-specific interface. */ public ObjectCollection values() { return new AbstractObjectCollection () { public boolean contains( final Object k ) { return containsValue( k ); } public int size() { return AbstractChar2ObjectMap.this.size(); } public void clear() { AbstractChar2ObjectMap.this.clear(); } public ObjectIterator iterator() { return new AbstractObjectIterator () { final ObjectIterator> i = entrySet().iterator(); public V next() { return ((Char2ObjectMap.Entry )i.next()).getValue(); }; public boolean hasNext() { return i.hasNext(); } }; } }; } @SuppressWarnings({ "unchecked", "rawtypes" }) public ObjectSet> entrySet() { return (ObjectSet)char2ObjectEntrySet(); } /** Returns a hash code for this map. * * The hash code of a map is computed by summing the hash codes of its entries. * * @return a hash code for this map. */ public int hashCode() { int h = 0, n = size(); final ObjectIterator> i = entrySet().iterator(); while( n-- != 0 ) h += i.next().hashCode(); return h; } public boolean equals(Object o) { if ( o == this ) return true; if ( ! ( o instanceof Map ) ) return false; Map m = (Map)o; if ( m.size() != size() ) return false; return entrySet().containsAll( m.entrySet() ); } public String toString() { final StringBuilder s = new StringBuilder(); final ObjectIterator> i = entrySet().iterator(); int n = size(); Char2ObjectMap.Entry e; boolean first = true; s.append("{"); while(n-- != 0) { if (first) first = false; else s.append(", "); e = (Char2ObjectMap.Entry )i.next(); s.append(String.valueOf(e.getCharKey())); s.append("=>"); if (this == e.getValue()) s.append("(this map)"); else s.append(String.valueOf(e.getValue())); } s.append("}"); return s.toString(); } } AbstractCharBidirectionalIterator.java000066400000000000000000000052701422762524200373760ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; /** An abstract class facilitating the creation of type-specific {@linkplain org.codelibs.jhighlight.fastutil.BidirectionalIterator bidirectional iterators}. * *

To create a type-specific bidirectional iterator, besides what is needed * for an iterator you need both a method returning the previous element as * primitive type and a method returning the previous element as an * object. However, if you inherit from this class you need just one (anyone). * *

This class implements also a trivial version of {@link #back(int)} that * uses type-specific methods. */ public abstract class AbstractCharBidirectionalIterator extends AbstractCharIterator implements CharBidirectionalIterator { protected AbstractCharBidirectionalIterator() {} /** Delegates to the corresponding generic method. */ public char previousChar() { return previous().charValue(); } /** Delegates to the corresponding type-specific method. */ public Character previous() { return Character.valueOf( previousChar() ); } /** This method just iterates the type-specific version of {@link #previous()} for * at most n times, stopping if {@link * #hasPrevious()} becomes false. */ public int back( final int n ) { int i = n; while( i-- != 0 && hasPrevious() ) previousChar(); return n - i - 1; } } AbstractCharCollection.java000066400000000000000000000173761422762524200352210ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import java.util.AbstractCollection; import java.util.Collection; import java.util.Iterator; /** An abstract class providing basic methods for collections implementing a type-specific interface. * *

In particular, this class provide {@link #iterator()}, add(), {@link #remove(Object)} and * {@link #contains(Object)} methods that just call the type-specific counterpart. */ public abstract class AbstractCharCollection extends AbstractCollection implements CharCollection { protected AbstractCharCollection() {} public char[] toArray( char a[] ) { return toCharArray( a ); } public char[] toCharArray() { return toCharArray( null ); } public char[] toCharArray( char a[] ) { if ( a == null || a.length < size() ) a = new char[ size() ]; CharIterators.unwrap( iterator(), a ); return a; } /** Adds all elements of the given type-specific collection to this collection. * * @param c a type-specific collection. * @return true if this collection changed as a result of the call. */ public boolean addAll( CharCollection c ) { boolean retVal = false; final CharIterator i = c.iterator(); int n = c.size(); while( n-- != 0 ) if ( add( i.nextChar() ) ) retVal = true; return retVal; } /** Checks whether this collection contains all elements from the given type-specific collection. * * @param c a type-specific collection. * @return true if this collection contains all elements of the argument. */ public boolean containsAll( CharCollection c ) { final CharIterator i = c.iterator(); int n = c.size(); while( n-- != 0 ) if ( ! contains( i.nextChar() ) ) return false; return true; } /** Retains in this collection only elements from the given type-specific collection. * * @param c a type-specific collection. * @return true if this collection changed as a result of the call. */ public boolean retainAll( CharCollection c ) { boolean retVal = false; int n = size(); final CharIterator i = iterator(); while( n-- != 0 ) { if ( ! c.contains( i.nextChar() ) ) { i.remove(); retVal = true; } } return retVal; } /** Remove from this collection all elements in the given type-specific collection. * * @param c a type-specific collection. * @return true if this collection changed as a result of the call. */ public boolean removeAll( CharCollection c ) { boolean retVal = false; int n = c.size(); final CharIterator i = c.iterator(); while( n-- != 0 ) if ( rem( i.nextChar() ) ) retVal = true; return retVal; } public Object[] toArray() { final Object[] a = new Object[ size() ]; org.codelibs.jhighlight.fastutil.objects.ObjectIterators.unwrap( iterator(), a ); return a; } @SuppressWarnings("unchecked") public T[] toArray( T[] a ) { if ( a.length < size() ) a = (T[])java.lang.reflect.Array.newInstance( a.getClass().getComponentType(), size() ); org.codelibs.jhighlight.fastutil.objects.ObjectIterators.unwrap( iterator(), a ); return a; } /** Adds all elements of the given collection to this collection. * * @param c a collection. * @return true if this collection changed as a result of the call. */ public boolean addAll( Collection c ) { boolean retVal = false; final Iterator i = c.iterator(); int n = c.size(); while( n-- != 0 ) if ( add( i.next() ) ) retVal = true; return retVal; } public boolean add( char k ) { throw new UnsupportedOperationException(); } /** Delegates to the new covariantly stronger generic method. */ @Deprecated public CharIterator charIterator() { return iterator(); } public abstract CharIterator iterator(); /** Delegates to the type-specific rem() method. */ public boolean remove( Object ok ) { return rem( ((((Character)(ok)).charValue())) ); } /** Delegates to the corresponding type-specific method. */ public boolean add( final Character o ) { return add( o.charValue() ); } /** Delegates to the corresponding type-specific method. */ public boolean rem( final Object o ) { return rem( ((((Character)(o)).charValue())) ); } /** Delegates to the corresponding type-specific method. */ public boolean contains( final Object o ) { return contains( ((((Character)(o)).charValue())) ); } public boolean contains( final char k ) { final CharIterator iterator = iterator(); while ( iterator.hasNext() ) if ( k == iterator.nextChar() ) return true; return false; } public boolean rem( final char k ) { final CharIterator iterator = iterator(); while ( iterator.hasNext() ) if ( k == iterator.nextChar() ) { iterator.remove(); return true; } return false; } /** Checks whether this collection contains all elements from the given collection. * * @param c a collection. * @return true if this collection contains all elements of the argument. */ public boolean containsAll( Collection c ) { int n = c.size(); final Iterator i = c.iterator(); while( n-- != 0 ) if ( ! contains( i.next() ) ) return false; return true; } /** Retains in this collection only elements from the given collection. * * @param c a collection. * @return true if this collection changed as a result of the call. */ public boolean retainAll( Collection c ) { boolean retVal = false; int n = size(); final Iterator i = iterator(); while( n-- != 0 ) { if ( ! c.contains( i.next() ) ) { i.remove(); retVal = true; } } return retVal; } /** Remove from this collection all elements in the given collection. * If the collection is an instance of this class, it uses faster iterators. * * @param c a collection. * @return true if this collection changed as a result of the call. */ public boolean removeAll( Collection c ) { boolean retVal = false; int n = c.size(); final Iterator i = c.iterator(); while( n-- != 0 ) if ( remove( i.next() ) ) retVal = true; return retVal; } public boolean isEmpty() { return size() == 0; } public String toString() { final StringBuilder s = new StringBuilder(); final CharIterator i = iterator(); int n = size(); char k; boolean first = true; s.append("{"); while(n-- != 0) { if (first) first = false; else s.append(", "); k = i.nextChar(); s.append(String.valueOf(k)); } s.append("}"); return s.toString(); } } AbstractCharIterator.java000066400000000000000000000052761422762524200347130ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; /** An abstract class facilitating the creation of type-specific iterators. * *

To create a type-specific iterator you need both a method returning the * next element as primitive type and a method returning the next element as an * object. However, if you inherit from this class you need just one (anyone). * *

This class implements also a trivial version of {@link #skip(int)} that uses * type-specific methods; moreover, {@link #remove()} will throw an {@link * UnsupportedOperationException}. * * @see java.util.Iterator */ public abstract class AbstractCharIterator implements CharIterator { protected AbstractCharIterator() {} /** Delegates to the corresponding generic method. */ public char nextChar() { return next().charValue(); } /** Delegates to the corresponding type-specific method. */ public Character next() { return Character.valueOf( nextChar() ); } /** This method just throws an {@link UnsupportedOperationException}. */ public void remove() { throw new UnsupportedOperationException(); } /** This method just iterates the type-specific version of {@link #next()} for at most * n times, stopping if {@link #hasNext()} becomes false.*/ public int skip( final int n ) { int i = n; while( i-- != 0 && hasNext() ) nextChar(); return n - i - 1; } } AbstractCharList.java000066400000000000000000000462511422762524200340330ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; /** An abstract class providing basic methods for lists implementing a type-specific list interface. * *

As an additional bonus, this class implements on top of the list operations a type-specific stack. */ public abstract class AbstractCharList extends AbstractCharCollection implements CharList , CharStack { protected AbstractCharList() {} /** Ensures that the given index is nonnegative and not greater than the list size. * * @param index an index. * @throws IndexOutOfBoundsException if the given index is negative or greater than the list size. */ protected void ensureIndex( final int index ) { if ( index < 0 ) throw new IndexOutOfBoundsException( "Index (" + index + ") is negative" ); if ( index > size() ) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than list size (" + ( size() ) + ")" ); } /** Ensures that the given index is nonnegative and smaller than the list size. * * @param index an index. * @throws IndexOutOfBoundsException if the given index is negative or not smaller than the list size. */ protected void ensureRestrictedIndex( final int index ) { if ( index < 0 ) throw new IndexOutOfBoundsException( "Index (" + index + ") is negative" ); if ( index >= size() ) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + ( size() ) + ")" ); } public void add( final int index, final char k ) { throw new UnsupportedOperationException(); } public boolean add( final char k ) { add( size(), k ); return true; } public char removeChar( int i ) { throw new UnsupportedOperationException(); } public char set( final int index, final char k ) { throw new UnsupportedOperationException(); } public boolean addAll( int index, final Collection c ) { ensureIndex( index ); int n = c.size(); if ( n == 0 ) return false; Iterator i = c.iterator(); while( n-- != 0 ) add( index++, i.next() ); return true; } /** Delegates to a more generic method. */ public boolean addAll( final Collection c ) { return addAll( size(), c ); } /** Delegates to the new covariantly stronger generic method. */ @Deprecated public CharListIterator charListIterator() { return listIterator(); } /** Delegates to the new covariantly stronger generic method. */ @Deprecated public CharListIterator charListIterator( final int index ) { return listIterator( index ); } public CharListIterator iterator() { return listIterator(); } public CharListIterator listIterator() { return listIterator( 0 ); } public CharListIterator listIterator( final int index ) { return new AbstractCharListIterator () { int pos = index, last = -1; public boolean hasNext() { return pos < AbstractCharList.this.size(); } public boolean hasPrevious() { return pos > 0; } public char nextChar() { if ( ! hasNext() ) throw new NoSuchElementException(); return AbstractCharList.this.getChar( last = pos++ ); } public char previousChar() { if ( ! hasPrevious() ) throw new NoSuchElementException(); return AbstractCharList.this.getChar( last = --pos ); } public int nextIndex() { return pos; } public int previousIndex() { return pos - 1; } public void add( char k ) { if ( last == -1 ) throw new IllegalStateException(); AbstractCharList.this.add( pos++, k ); last = -1; } public void set( char k ) { if ( last == -1 ) throw new IllegalStateException(); AbstractCharList.this.set( last, k ); } public void remove() { if ( last == -1 ) throw new IllegalStateException(); AbstractCharList.this.removeChar( last ); /* If the last operation was a next(), we are removing an element *before* us, and we must decrease pos correspondingly. */ if ( last < pos ) pos--; last = -1; } }; } public boolean contains( final char k ) { return indexOf( k ) >= 0; } public int indexOf( final char k ) { final CharListIterator i = listIterator(); char e; while( i.hasNext() ) { e = i.nextChar(); if ( ( (k) == (e) ) ) return i.previousIndex(); } return -1; } public int lastIndexOf( final char k ) { CharListIterator i = listIterator( size() ); char e; while( i.hasPrevious() ) { e = i.previousChar(); if ( ( (k) == (e) ) ) return i.nextIndex(); } return -1; } public void size( final int size ) { int i = size(); if ( size > i ) while( i++ < size ) add( ((char)0) ); else while( i-- != size ) remove( i ); } public CharList subList( final int from, final int to ) { ensureIndex( from ); ensureIndex( to ); if ( from > to ) throw new IndexOutOfBoundsException( "Start index (" + from + ") is greater than end index (" + to + ")" ); return new CharSubList ( this, from, to ); } /** Delegates to the new covariantly stronger generic method. */ @Deprecated public CharList charSubList( final int from, final int to ) { return subList( from, to ); } /** Removes elements of this type-specific list one-by-one. * *

This is a trivial iterator-based implementation. It is expected that * implementations will override this method with a more optimized version. * * * @param from the start index (inclusive). * @param to the end index (exclusive). */ public void removeElements( final int from, final int to ) { ensureIndex( to ); CharListIterator i = listIterator( from ); int n = to - from; if ( n < 0 ) throw new IllegalArgumentException( "Start index (" + from + ") is greater than end index (" + to + ")" ); while( n-- != 0 ) { i.nextChar(); i.remove(); } } /** Adds elements to this type-specific list one-by-one. * *

This is a trivial iterator-based implementation. It is expected that * implementations will override this method with a more optimized version. * * @param index the index at which to add elements. * @param a the array containing the elements. * @param offset the offset of the first element to add. * @param length the number of elements to add. */ public void addElements( int index, final char a[], int offset, int length ) { ensureIndex( index ); if ( offset < 0 ) throw new ArrayIndexOutOfBoundsException( "Offset (" + offset + ") is negative" ); if ( offset + length > a.length ) throw new ArrayIndexOutOfBoundsException( "End index (" + ( offset + length ) + ") is greater than array length (" + a.length + ")" ); while( length-- != 0 ) add( index++, a[ offset++ ] ); } public void addElements( final int index, final char a[] ) { addElements( index, a, 0, a.length ); } /** Copies element of this type-specific list into the given array one-by-one. * *

This is a trivial iterator-based implementation. It is expected that * implementations will override this method with a more optimized version. * * @param from the start index (inclusive). * @param a the destination array. * @param offset the offset into the destination array where to store the first element copied. * @param length the number of elements to be copied. */ public void getElements( final int from, final char a[], int offset, int length ) { CharListIterator i = listIterator( from ); if ( offset < 0 ) throw new ArrayIndexOutOfBoundsException( "Offset (" + offset + ") is negative" ); if ( offset + length > a.length ) throw new ArrayIndexOutOfBoundsException( "End index (" + ( offset + length ) + ") is greater than array length (" + a.length + ")" ); if ( from + length > size() ) throw new IndexOutOfBoundsException( "End index (" + ( from + length ) + ") is greater than list size (" + size() + ")" ); while( length-- != 0 ) a[ offset++ ] = i.nextChar(); } private boolean valEquals( final Object a, final Object b ) { return a == null ? b == null : a.equals( b ); } public boolean equals( final Object o ) { if ( o == this ) return true; if ( ! ( o instanceof List ) ) return false; final List l = (List)o; int s = size(); if ( s != l.size() ) return false; if ( l instanceof CharList ) { final CharListIterator i1 = listIterator(), i2 = ((CharList )l).listIterator(); while( s-- != 0 ) if ( i1.nextChar() != i2.nextChar() ) return false; return true; } final ListIterator i1 = listIterator(), i2 = l.listIterator(); while( s-- != 0 ) if ( ! valEquals( i1.next(), i2.next() ) ) return false; return true; } /** Compares this list to another object. If the * argument is a {@link java.util.List}, this method performs a lexicographical comparison; otherwise, * it throws a ClassCastException. * * @param l a list. * @return if the argument is a {@link java.util.List}, a negative integer, * zero, or a positive integer as this list is lexicographically less than, equal * to, or greater than the argument. * @throws ClassCastException if the argument is not a list. */ @SuppressWarnings("unchecked") public int compareTo( final List l ) { if ( l == this ) return 0; if ( l instanceof CharList ) { final CharListIterator i1 = listIterator(), i2 = ((CharList )l).listIterator(); int r; char e1, e2; while( i1.hasNext() && i2.hasNext() ) { e1 = i1.nextChar(); e2 = i2.nextChar(); if ( ( r = ( (e1) < (e2) ? -1 : ( (e1) == (e2) ? 0 : 1 ) ) ) != 0 ) return r; } return i2.hasNext() ? -1 : ( i1.hasNext() ? 1 : 0 ); } ListIterator i1 = listIterator(), i2 = l.listIterator(); int r; while( i1.hasNext() && i2.hasNext() ) { if ( ( r = ((Comparable)i1.next()).compareTo( i2.next() ) ) != 0 ) return r; } return i2.hasNext() ? -1 : ( i1.hasNext() ? 1 : 0 ); } /** Returns the hash code for this list, which is identical to {@link java.util.List#hashCode()}. * * @return the hash code for this list. */ public int hashCode() { CharIterator i = iterator(); int h = 1, s = size(); while ( s-- != 0 ) { char k = i.nextChar(); h = 31 * h + (k); } return h; } public void push( char o ) { add( o ); } public char popChar() { if ( isEmpty() ) throw new NoSuchElementException(); return removeChar( size() - 1 ); } public char topChar() { if ( isEmpty() ) throw new NoSuchElementException(); return getChar( size() - 1 ); } public char peekChar( int i ) { return getChar( size() - 1 - i ); } public boolean rem( char k ) { int index = indexOf( k ); if ( index == -1 ) return false; removeChar( index ); return true; } /** Delegates to rem(). */ public boolean remove( final Object o ) { return rem( ((((Character)(o)).charValue())) ); } /** Delegates to a more generic method. */ public boolean addAll( final int index, final CharCollection c ) { return addAll( index, (Collection)c ); } /** Delegates to a more generic method. */ public boolean addAll( final int index, final CharList l ) { return addAll( index, (CharCollection)l ); } public boolean addAll( final CharCollection c ) { return addAll( size(), c ); } public boolean addAll( final CharList l ) { return addAll( size(), l ); } /** Delegates to the corresponding type-specific method. */ public void add( final int index, final Character ok ) { add( index, ok.charValue() ); } /** Delegates to the corresponding type-specific method. */ public Character set( final int index, final Character ok ) { return (Character.valueOf(set( index, ok.charValue() ))); } /** Delegates to the corresponding type-specific method. */ public Character get( final int index ) { return (Character.valueOf(getChar( index ))); } /** Delegates to the corresponding type-specific method. */ public int indexOf( final Object ok) { return indexOf( ((((Character)(ok)).charValue())) ); } /** Delegates to the corresponding type-specific method. */ public int lastIndexOf( final Object ok ) { return lastIndexOf( ((((Character)(ok)).charValue())) ); } /** Delegates to the corresponding type-specific method. */ public Character remove( final int index ) { return (Character.valueOf(removeChar( index ))); } /** Delegates to the corresponding type-specific method. */ public void push( Character o ) { push( o.charValue() ); } /** Delegates to the corresponding type-specific method. */ public Character pop() { return Character.valueOf( popChar() ); } /** Delegates to the corresponding type-specific method. */ public Character top() { return Character.valueOf( topChar() ); } /** Delegates to the corresponding type-specific method. */ public Character peek( int i ) { return Character.valueOf( peekChar( i ) ); } public String toString() { final StringBuilder s = new StringBuilder(); final CharIterator i = iterator(); int n = size(); char k; boolean first = true; s.append("["); while( n-- != 0 ) { if (first) first = false; else s.append(", "); k = i.nextChar(); s.append( String.valueOf( k ) ); } s.append("]"); return s.toString(); } public static class CharSubList extends AbstractCharList implements java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; /** The list this sublist restricts. */ protected final CharList l; /** Initial (inclusive) index of this sublist. */ protected final int from; /** Final (exclusive) index of this sublist. */ protected int to; private static final boolean ASSERTS = false; public CharSubList( final CharList l, final int from, final int to ) { this.l = l; this.from = from; this.to = to; } private void assertRange() { if ( ASSERTS ) { assert from <= l.size(); assert to <= l.size(); assert to >= from; } } public boolean add( final char k ) { l.add( to, k ); to++; if ( ASSERTS ) assertRange(); return true; } public void add( final int index, final char k ) { ensureIndex( index ); l.add( from + index, k ); to++; if ( ASSERTS ) assertRange(); } public boolean addAll( final int index, final Collection c ) { ensureIndex( index ); to += c.size(); if ( ASSERTS ) { boolean retVal = l.addAll( from + index, c ); assertRange(); return retVal; } return l.addAll( from + index, c ); } public char getChar( int index ) { ensureRestrictedIndex( index ); return l.getChar( from + index ); } public char removeChar( int index ) { ensureRestrictedIndex( index ); to--; return l.removeChar( from + index ); } public char set( int index, char k ) { ensureRestrictedIndex( index ); return l.set( from + index, k ); } public void clear() { removeElements( 0, size() ); if ( ASSERTS ) assertRange(); } public int size() { return to - from; } public void getElements( final int from, final char[] a, final int offset, final int length ) { ensureIndex( from ); if ( from + length > size() ) throw new IndexOutOfBoundsException( "End index (" + from + length + ") is greater than list size (" + size() + ")" ); l.getElements( this.from + from, a, offset, length ); } public void removeElements( final int from, final int to ) { ensureIndex( from ); ensureIndex( to ); l.removeElements( this.from + from, this.from + to ); this.to -= ( to - from ); if ( ASSERTS ) assertRange(); } public void addElements( int index, final char a[], int offset, int length ) { ensureIndex( index ); l.addElements( this.from + index, a, offset, length ); this.to += length; if ( ASSERTS ) assertRange(); } public CharListIterator listIterator( final int index ) { ensureIndex( index ); return new AbstractCharListIterator () { int pos = index, last = -1; public boolean hasNext() { return pos < size(); } public boolean hasPrevious() { return pos > 0; } public char nextChar() { if ( ! hasNext() ) throw new NoSuchElementException(); return l.getChar( from + ( last = pos++ ) ); } public char previousChar() { if ( ! hasPrevious() ) throw new NoSuchElementException(); return l.getChar( from + ( last = --pos ) ); } public int nextIndex() { return pos; } public int previousIndex() { return pos - 1; } public void add( char k ) { if ( last == -1 ) throw new IllegalStateException(); CharSubList.this.add( pos++, k ); last = -1; if ( ASSERTS ) assertRange(); } public void set( char k ) { if ( last == -1 ) throw new IllegalStateException(); CharSubList.this.set( last, k ); } public void remove() { if ( last == -1 ) throw new IllegalStateException(); CharSubList.this.removeChar( last ); /* If the last operation was a next(), we are removing an element *before* us, and we must decrease pos correspondingly. */ if ( last < pos ) pos--; last = -1; if ( ASSERTS ) assertRange(); } }; } public CharList subList( final int from, final int to ) { ensureIndex( from ); ensureIndex( to ); if ( from > to ) throw new IllegalArgumentException( "Start index (" + from + ") is greater than end index (" + to + ")" ); return new CharSubList ( this, from, to ); } public boolean rem( char k ) { int index = indexOf( k ); if ( index == -1 ) return false; to--; l.removeChar( from + index ); if ( ASSERTS ) assertRange(); return true; } public boolean remove( final Object o ) { return rem( ((((Character)(o)).charValue())) ); } public boolean addAll( final int index, final CharCollection c ) { ensureIndex( index ); to += c.size(); if ( ASSERTS ) { boolean retVal = l.addAll( from + index, c ); assertRange(); return retVal; } return l.addAll( from + index, c ); } public boolean addAll( final int index, final CharList l ) { ensureIndex( index ); to += l.size(); if ( ASSERTS ) { boolean retVal = this.l.addAll( from + index, l ); assertRange(); return retVal; } return this.l.addAll( from + index, l ); } } } AbstractCharListIterator.java000066400000000000000000000052671422762524200355470ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; /** An abstract class facilitating the creation of type-specific {@linkplain java.util.ListIterator list iterators}. * *

This class provides trivial type-specific implementations of {@link * java.util.ListIterator#set(Object) set()} and {@link java.util.ListIterator#add(Object) add()} which * throw an {@link UnsupportedOperationException}. For primitive types, it also * provides a trivial implementation of {@link java.util.ListIterator#set(Object) set()} and {@link * java.util.ListIterator#add(Object) add()} that just invokes the type-specific one. * * * @see java.util.ListIterator */ public abstract class AbstractCharListIterator extends AbstractCharBidirectionalIterator implements CharListIterator { protected AbstractCharListIterator() {} /** Delegates to the corresponding type-specific method. */ public void set( Character ok ) { set( ok.charValue() ); } /** Delegates to the corresponding type-specific method. */ public void add( Character ok ) { add( ok.charValue() ); } /** This method just throws an {@link UnsupportedOperationException}. */ public void set( char k ) { throw new UnsupportedOperationException(); } /** This method just throws an {@link UnsupportedOperationException}. */ public void add( char k ) { throw new UnsupportedOperationException(); } } AbstractCharSet.java000066400000000000000000000053521422762524200336500ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import java.util.Set; /** An abstract class providing basic methods for sets implementing a type-specific interface. */ public abstract class AbstractCharSet extends AbstractCharCollection implements Cloneable, CharSet { protected AbstractCharSet() {} public abstract CharIterator iterator(); public boolean equals( final Object o ) { if ( o == this ) return true; if ( !( o instanceof Set ) ) return false; Set s = (Set) o; if ( s.size() != size() ) return false; return containsAll(s); } /** Returns a hash code for this set. * * The hash code of a set is computed by summing the hash codes of * its elements. * * @return a hash code for this set. */ public int hashCode() { int h = 0, n = size(); CharIterator i = iterator(); char k; while( n-- != 0 ) { k = i.nextChar(); // We need k because KEY2JAVAHASH() is a macro with repeated evaluation. h += (k); } return h; } public boolean remove( char k ) { throw new UnsupportedOperationException(); } /** Delegates to remove(). * * @param k the element to be removed. * @return true if the set was modified. */ public boolean rem( char k ) { return remove( k ); } /** Delegates to the corresponding type-specific method. */ public boolean remove( final Object o ) { return remove( ((((Character)(o)).charValue())) ); } } Char2ObjectFunction.java000066400000000000000000000102641422762524200344250ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars /* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2010 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import org.codelibs.jhighlight.fastutil.Function; /** A type-specific {@link Function}; provides some additional methods that use polymorphism to avoid (un)boxing. * *

Type-specific versions of get(), put() and * remove() cannot rely on null to denote absence of * a key. Rather, they return a {@linkplain #defaultReturnValue() default * return value}, which is set to 0 cast to the return type (false * for booleans) at creation, but can be changed using the * defaultReturnValue() method. * *

For uniformity reasons, even maps returning objects implement the default * return value (of course, in this case the default return value is * initialized to null). * *

Warning: to fall in line as much as possible with the * {@linkplain java.util.Map standard map interface}, it is strongly suggested * that standard versions of get(), put() and * remove() for maps with primitive-type values return * null to denote missing keys rather than wrap the default * return value in an object (of course, for maps with object keys and values * this is not possible, as there is no type-specific version). * * @see Function */ public interface Char2ObjectFunction extends Function { /** Adds a pair to the map. * * @param key the key. * @param value the value. * @return the old value, or the {@linkplain #defaultReturnValue() default return value} if no value was present for the given key. * @see Function#put(Object,Object) */ V put( char key, V value ); /** Returns the value to which the given key is mapped. * * @param key the key. * @return the corresponding value, or the {@linkplain #defaultReturnValue() default return value} if no value was present for the given key. * @see Function#get(Object) */ V get( char key ); /** Removes the mapping with the given key. * @param key * @return the old value, or the {@linkplain #defaultReturnValue() default return value} if no value was present for the given key. * @see Function#remove(Object) */ V remove( char key ); /** * @see Function#containsKey(Object) */ boolean containsKey( char key ); /** Sets the default return value. * * This value must be returned by type-specific versions of * get(), put() and remove() to * denote that the map does not contain the specified key. It must be * 0/false/null by default. * * @param rv the new default return value. * @see #defaultReturnValue() */ void defaultReturnValue( V rv ); /** Gets the default return value. * * @return the current default return value. */ V defaultReturnValue(); } Char2ObjectFunctions.java000066400000000000000000000224301422762524200346060ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; /** A class providing static methods and objects that do useful things with type-specific functions. * * @see org.codelibs.jhighlight.fastutil.Function * @see java.util.Collections */ public class Char2ObjectFunctions { private Char2ObjectFunctions() {} /** An immutable class representing an empty type-specific function. * *

This class may be useful to implement your own in case you subclass * a type-specific function. */ public static class EmptyFunction extends AbstractChar2ObjectFunction implements java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; protected EmptyFunction() {} public V get( final char k ) { return (null); } public boolean containsKey( final char k ) { return false; } public V defaultReturnValue() { return (null); } public void defaultReturnValue( final V defRetValue ) { throw new UnsupportedOperationException(); } public V get( final Object k ) { return null; } public int size() { return 0; } public void clear() {} private Object readResolve() { return EMPTY_FUNCTION; } public Object clone() { return EMPTY_FUNCTION; } } /** An empty type-specific function (immutable). It is serializable and cloneable. */ @SuppressWarnings("rawtypes") public static final EmptyFunction EMPTY_FUNCTION = new EmptyFunction(); /** An immutable class representing a type-specific singleton function. * *

This class may be useful to implement your own in case you subclass * a type-specific function. */ public static class Singleton extends AbstractChar2ObjectFunction implements java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; protected final char key; protected final V value; protected Singleton( final char key, final V value ) { this.key = key; this.value = value; } public boolean containsKey( final char k ) { return ( (key) == (k) ); } public V get( final char k ) { if ( ( (key) == (k) ) ) return value; return defRetValue; } public int size() { return 1; } public Object clone() { return this; } } /** Returns a type-specific immutable function containing only the specified pair. The returned function is serializable and cloneable. * *

Note that albeit the returned function is immutable, its default return value may be changed. * * @param key the only key of the returned function. * @param value the only value of the returned function. * @return a type-specific immutable function containing just the pair <key,value>. */ public static Char2ObjectFunction singleton( final char key, V value ) { return new Singleton ( key, value ); } /** Returns a type-specific immutable function containing only the specified pair. The returned function is serializable and cloneable. * *

Note that albeit the returned function is immutable, its default return value may be changed. * * @param key the only key of the returned function. * @param value the only value of the returned function. * @return a type-specific immutable function containing just the pair <key,value>. */ public static Char2ObjectFunction singleton( final Character key, final V value ) { return new Singleton ( ((key).charValue()), (value) ); } /** A synchronized wrapper class for functions. */ public static class SynchronizedFunction extends AbstractChar2ObjectFunction implements java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; protected final Char2ObjectFunction function; protected final Object sync; protected SynchronizedFunction( final Char2ObjectFunction f, final Object sync ) { if ( f == null ) throw new NullPointerException(); this.function = f; this.sync = sync; } protected SynchronizedFunction( final Char2ObjectFunction f ) { if ( f == null ) throw new NullPointerException(); this.function = f; this.sync = this; } public int size() { synchronized( sync ) { return function.size(); } } public boolean containsKey( final char k ) { synchronized( sync ) { return function.containsKey( k ); } } public V defaultReturnValue() { synchronized( sync ) { return function.defaultReturnValue(); } } public void defaultReturnValue( final V defRetValue ) { synchronized( sync ) { function.defaultReturnValue( defRetValue ); } } public V put( final char k, final V v ) { synchronized( sync ) { return function.put( k, v ); } } public void clear() { synchronized( sync ) { function.clear(); } } public String toString() { synchronized( sync ) { return function.toString(); } } public V put( final Character k, final V v ) { synchronized( sync ) { return function.put( k, v ); } } public V get( final Object k ) { synchronized( sync ) { return function.get( k ); } } public V remove( final Object k ) { synchronized( sync ) { return function.remove( k ); } } public V remove( final char k ) { synchronized( sync ) { return function.remove( k ); } } public V get( final char k ) { synchronized( sync ) { return function.get( k ); } } public boolean containsKey( final Object ok ) { synchronized( sync ) { return function.containsKey( ok ); } } } /** Returns a synchronized type-specific function backed by the given type-specific function. * * @param f the function to be wrapped in a synchronized function. * @return a synchronized view of the specified function. * @see java.util.Collections#synchronizedMap(java.util.Map) */ public static Char2ObjectFunction synchronize( final Char2ObjectFunction f ) { return new SynchronizedFunction ( f ); } /** Returns a synchronized type-specific function backed by the given type-specific function, using an assigned object to synchronize. * * @param f the function to be wrapped in a synchronized function. * @param sync an object that will be used to synchronize the access to the function. * @return a synchronized view of the specified function. * @see java.util.Collections#synchronizedMap(java.util.Map) */ public static Char2ObjectFunction synchronize( final Char2ObjectFunction f, final Object sync ) { return new SynchronizedFunction ( f, sync ); } /** An unmodifiable wrapper class for functions. */ public static class UnmodifiableFunction extends AbstractChar2ObjectFunction implements java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; protected final Char2ObjectFunction function; protected UnmodifiableFunction( final Char2ObjectFunction f ) { if ( f == null ) throw new NullPointerException(); this.function = f; } public int size() { return function.size(); } public boolean containsKey( final char k ) { return function.containsKey( k ); } public V defaultReturnValue() { return function.defaultReturnValue(); } public void defaultReturnValue( final V defRetValue ) { throw new UnsupportedOperationException(); } public V put( final char k, final V v ) { throw new UnsupportedOperationException(); } public void clear() { throw new UnsupportedOperationException(); } public String toString() { return function.toString(); } public V remove( final char k ) { throw new UnsupportedOperationException(); } public V get( final char k ) { return function.get( k ); } public boolean containsKey( final Object ok ) { return function.containsKey( ok ); } public V remove( final Object k ) { throw new UnsupportedOperationException(); } public V get( final Object k ) { return function.get( k ); } } /** Returns an unmodifiable type-specific function backed by the given type-specific function. * * @param f the function to be wrapped in an unmodifiable function. * @return an unmodifiable view of the specified function. * @see java.util.Collections#unmodifiableMap(java.util.Map) */ public static Char2ObjectFunction unmodifiable( final Char2ObjectFunction f ) { return new UnmodifiableFunction ( f ); } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/Char2ObjectMap.java000066400000000000000000000117721422762524200334410ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import java.util.Map; import org.codelibs.jhighlight.fastutil.objects.ObjectCollection; import org.codelibs.jhighlight.fastutil.objects.ObjectIterator; import org.codelibs.jhighlight.fastutil.objects.ObjectSet; /** A type-specific {@link Map}; provides some additional methods that use polymorphism to avoid (un)boxing, and handling of a default return value. * *

Besides extending the corresponding type-specific {@linkplain org.codelibs.jhighlight.fastutil.Function function}, this interface strengthens {@link #entrySet()}, * {@link #keySet()} and {@link #values()}. Maps returning entry sets of type {@link FastEntrySet} support also fast iteration. * *

A submap or subset may or may not have an * independent default return value (which however must be initialized to the * default return value of the originator). * * @see Map */ public interface Char2ObjectMap extends Char2ObjectFunction , Map { /** An entry set providing fast iteration. * *

In some cases (e.g., hash-based classes) iteration over an entry set requires the creation * of a large number of {@link java.util.Map.Entry} objects. Some fastutil * maps might return {@linkplain #entrySet() entry set} objects of type FastEntrySet: in this case, {@link #fastIterator() fastIterator()} * will return an iterator that is guaranteed not to create a large number of objects, possibly * by returning always the same entry (of course, mutated). */ public interface FastEntrySet extends ObjectSet > { /** Returns a fast iterator over this entry set; the iterator might return always the same entry object, suitably mutated. * * @return a fast iterator over this entry set; the iterator might return always the same {@link java.util.Map.Entry} object, suitably mutated. */ public ObjectIterator > fastIterator(); } /** Returns a set view of the mappings contained in this map. *

Note that this specification strengthens the one given in {@link Map#entrySet()}. * * @return a set view of the mappings contained in this map. * @see Map#entrySet() */ ObjectSet> entrySet(); /** Returns a type-specific set view of the mappings contained in this map. * *

This method is necessary because there is no inheritance along * type parameters: it is thus impossible to strengthen {@link #entrySet()} * so that it returns an {@link org.codelibs.jhighlight.fastutil.objects.ObjectSet} * of objects of type {@link java.util.Map.Entry} (the latter makes it possible to * access keys and values with type-specific methods). * * @return a type-specific set view of the mappings contained in this map. * @see #entrySet() */ ObjectSet > char2ObjectEntrySet(); /** Returns a set view of the keys contained in this map. *

Note that this specification strengthens the one given in {@link Map#keySet()}. * * @return a set view of the keys contained in this map. * @see Map#keySet() */ CharSet keySet(); /** Returns a set view of the values contained in this map. *

Note that this specification strengthens the one given in {@link Map#values()}. * * @return a set view of the values contained in this map. * @see Map#values() */ ObjectCollection values(); /** A type-specific {@link java.util.Map.Entry}; provides some additional methods * that use polymorphism to avoid (un)boxing. * * @see java.util.Map.Entry */ interface Entry extends Map.Entry { /** * @see java.util.Map.Entry#getKey() */ char getCharKey(); } } Char2ObjectOpenHashMap.java000066400000000000000000000663521422762524200350140ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import static org.codelibs.jhighlight.fastutil.HashCommon.arraySize; import static org.codelibs.jhighlight.fastutil.HashCommon.maxFill; import java.util.Map; import java.util.NoSuchElementException; import org.codelibs.jhighlight.fastutil.Hash; import org.codelibs.jhighlight.fastutil.HashCommon; import org.codelibs.jhighlight.fastutil.booleans.BooleanArrays; import org.codelibs.jhighlight.fastutil.objects.AbstractObjectCollection; import org.codelibs.jhighlight.fastutil.objects.AbstractObjectSet; import org.codelibs.jhighlight.fastutil.objects.ObjectArrays; import org.codelibs.jhighlight.fastutil.objects.ObjectCollection; import org.codelibs.jhighlight.fastutil.objects.ObjectIterator; /** A type-specific hash map with a fast, small-footprint implementation. * *

Instances of this class use a hash table to represent a map. The table is * enlarged as needed by doubling its size when new entries are created, but it is never made * smaller (even on a {@link #clear()}). A family of {@linkplain #trim() trimming * methods} lets you control the size of the table; this is particularly useful * if you reuse instances of this class. * *

Warning: The implementation of this class has significantly * changed in fastutil 6.1.0. Please read the * comments about this issue in the section “Faster Hash Tables” of the overview. * * @see Hash * @see HashCommon */ public class Char2ObjectOpenHashMap extends AbstractChar2ObjectMap implements java.io.Serializable, Cloneable, Hash { private static final long serialVersionUID = 0L; private static final boolean ASSERTS = false; /** The array of keys. */ protected transient char key[]; /** The array of values. */ protected transient V value[]; /** The array telling whether a position is used. */ protected transient boolean used[]; /** The acceptable load factor. */ protected final float f; /** The current table size. */ protected transient int n; /** Threshold after which we rehash. It must be the table size times {@link #f}. */ protected transient int maxFill; /** The mask for wrapping a position counter. */ protected transient int mask; /** Number of entries in the set. */ protected int size; /** Cached set of entries. */ protected transient volatile FastEntrySet entries; /** Cached set of keys. */ protected transient volatile CharSet keys; /** Cached collection of values. */ protected transient volatile ObjectCollection values; /** Creates a new hash map. * *

The actual table size will be the least power of two greater than expected/f. * * @param expected the expected number of elements in the hash set. * @param f the load factor. */ @SuppressWarnings("unchecked") public Char2ObjectOpenHashMap( final int expected, final float f ) { if ( f <= 0 || f > 1 ) throw new IllegalArgumentException( "Load factor must be greater than 0 and smaller than or equal to 1" ); if ( expected < 0 ) throw new IllegalArgumentException( "The expected number of elements must be nonnegative" ); this.f = f; n = arraySize( expected, f ); mask = n - 1; maxFill = maxFill( n, f ); key = new char[ n ]; value = (V[]) new Object[ n ]; used = new boolean[ n ]; } /** Creates a new hash map with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor. * * @param expected the expected number of elements in the hash map. */ public Char2ObjectOpenHashMap( final int expected ) { this( expected, DEFAULT_LOAD_FACTOR ); } /** Creates a new hash map with initial expected {@link Hash#DEFAULT_INITIAL_SIZE} entries * and {@link Hash#DEFAULT_LOAD_FACTOR} as load factor. */ public Char2ObjectOpenHashMap() { this( DEFAULT_INITIAL_SIZE, DEFAULT_LOAD_FACTOR ); } /** Creates a new hash map copying a given one. * * @param m a {@link Map} to be copied into the new hash map. * @param f the load factor. */ public Char2ObjectOpenHashMap( final Map m, final float f ) { this( m.size(), f ); putAll( m ); } /** Creates a new hash map with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor copying a given one. * * @param m a {@link Map} to be copied into the new hash map. */ public Char2ObjectOpenHashMap( final Map m ) { this( m, DEFAULT_LOAD_FACTOR ); } /** Creates a new hash map copying a given type-specific one. * * @param m a type-specific map to be copied into the new hash map. * @param f the load factor. */ public Char2ObjectOpenHashMap( final Char2ObjectMap m, final float f ) { this( m.size(), f ); putAll( m ); } /** Creates a new hash map with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor copying a given type-specific one. * * @param m a type-specific map to be copied into the new hash map. */ public Char2ObjectOpenHashMap( final Char2ObjectMap m ) { this( m, DEFAULT_LOAD_FACTOR ); } /** Creates a new hash map using the elements of two parallel arrays. * * @param k the array of keys of the new hash map. * @param v the array of corresponding values in the new hash map. * @param f the load factor. * @throws IllegalArgumentException if k and v have different lengths. */ public Char2ObjectOpenHashMap( final char[] k, final V v[], final float f ) { this( k.length, f ); if ( k.length != v.length ) throw new IllegalArgumentException( "The key array and the value array have different lengths (" + k.length + " and " + v.length + ")" ); for( int i = 0; i < k.length; i++ ) this.put( k[ i ], v[ i ] ); } /** Creates a new hash map with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor using the elements of two parallel arrays. * * @param k the array of keys of the new hash map. * @param v the array of corresponding values in the new hash map. * @throws IllegalArgumentException if k and v have different lengths. */ public Char2ObjectOpenHashMap( final char[] k, final V v[] ) { this( k, v, DEFAULT_LOAD_FACTOR ); } /* * The following methods implements some basic building blocks used by * all accessors. They are (and should be maintained) identical to those used in OpenHashSet.drv. */ public V put(final char k, final V v) { // The starting point. int pos = ( org.codelibs.jhighlight.fastutil.HashCommon.murmurHash3( (k) ^ mask ) ) & mask; // There's always an unused entry. while( used[ pos ] ) { if ( ( (key[ pos ]) == (k) ) ) { final V oldValue = value[ pos ]; value[ pos ] = v; return oldValue; } pos = ( pos + 1 ) & mask; } used[ pos ] = true; key[ pos ] = k; value[ pos ] = v; if ( size++ >= maxFill ) rehash( arraySize( size + 1, f ) ); if ( ASSERTS ) checkTable(); return defRetValue; } public V put( final Character ok, final V ov ) { final V v = (ov); final char k = ((ok).charValue()); // The starting point. int pos = ( org.codelibs.jhighlight.fastutil.HashCommon.murmurHash3( (k) ^ mask ) ) & mask; // There's always an unused entry. while( used[ pos ] ) { if ( ( (key[ pos ]) == (k) ) ) { final V oldValue = (value[ pos ]); value[ pos ] = v; return oldValue; } pos = ( pos + 1 ) & mask; } used[ pos ] = true; key[ pos ] = k; value[ pos ] = v; if ( size++ >= maxFill ) rehash( arraySize( size + 1, f ) ); if ( ASSERTS ) checkTable(); return (this.defRetValue); } /** Shifts left entries with the specified hash code, starting at the specified position, * and empties the resulting free entry. * * @param pos a starting position. * @return the position cleared by the shifting process. */ protected final int shiftKeys( int pos ) { // Shift entries with the same hash. int last, slot; for(;;) { pos = ( ( last = pos ) + 1 ) & mask; while( used[ pos ] ) { slot = ( org.codelibs.jhighlight.fastutil.HashCommon.murmurHash3( (key[ pos ]) ^ mask ) ) & mask; if ( last <= pos ? last >= slot || slot > pos : last >= slot && slot > pos ) break; pos = ( pos + 1 ) & mask; } if ( ! used[ pos ] ) break; key[ last ] = key[ pos ]; value[ last ] = value[ pos ]; } used[ last ] = false; value[ last ] = null; return last; } @SuppressWarnings("unchecked") public V remove( final char k ) { // The starting point. int pos = ( org.codelibs.jhighlight.fastutil.HashCommon.murmurHash3( (k) ^ mask ) ) & mask; // There's always an unused entry. while( used[ pos ] ) { if ( ( (key[ pos ]) == (k) ) ) { size--; final V v = value[ pos ]; shiftKeys( pos ); return v; } pos = ( pos + 1 ) & mask; } return defRetValue; } @SuppressWarnings("unchecked") public V remove( final Object ok ) { final char k = ((((Character)(ok)).charValue())); // The starting point. int pos = ( org.codelibs.jhighlight.fastutil.HashCommon.murmurHash3( (k) ^ mask ) ) & mask; // There's always an unused entry. while( used[ pos ] ) { if ( ( (key[ pos ]) == (k) ) ) { size--; final V v = value[ pos ]; shiftKeys( pos ); return (v); } pos = ( pos + 1 ) & mask; } return (this.defRetValue); } public V get( final Character ok ) { final char k = ((ok).charValue()); // The starting point. int pos = ( org.codelibs.jhighlight.fastutil.HashCommon.murmurHash3( ( k) ^ mask ) ) & mask; // There's always an unused entry. while( used[ pos ] ) { if ( ( (key[ pos ]) == ( k) ) ) return (value[ pos ]); pos = ( pos + 1 ) & mask; } return (this.defRetValue); } @SuppressWarnings("unchecked") public V get( final char k ) { // The starting point. int pos = ( org.codelibs.jhighlight.fastutil.HashCommon.murmurHash3( (k) ^ mask ) ) & mask; // There's always an unused entry. while( used[ pos ] ) { if ( ( (key[ pos ]) == (k) ) ) return value[ pos ]; pos = ( pos + 1 ) & mask; } return defRetValue; } @SuppressWarnings("unchecked") public boolean containsKey( final char k ) { // The starting point. int pos = ( org.codelibs.jhighlight.fastutil.HashCommon.murmurHash3( (k) ^ mask ) ) & mask; // There's always an unused entry. while( used[ pos ] ) { if ( ( (key[ pos ]) == (k) ) ) return true; pos = ( pos + 1 ) & mask; } return false; } public boolean containsValue( final Object v ) { final V value[] = this.value; final boolean used[] = this.used; for( int i = n; i-- != 0; ) if ( used[ i ] && ( (value[ i ]) == null ? (v) == null : (value[ i ]).equals(v) ) ) return true; return false; } /* Removes all elements from this map. * *

To increase object reuse, this method does not change the table size. * If you want to reduce the table size, you must use {@link #trim()}. * */ public void clear() { if ( size == 0 ) return; size = 0; BooleanArrays.fill( used, false ); // We null all object entries so that the garbage collector can do its work. ObjectArrays.fill( value, null ); } public int size() { return size; } public boolean isEmpty() { return size == 0; } /** A no-op for backward compatibility. * * @param growthFactor unused. * @deprecated Since fastutil 6.1.0, hash tables are doubled when they are too full. */ @Deprecated public void growthFactor( int growthFactor ) {} /** Gets the growth factor (2). * * @return the growth factor of this set, which is fixed (2). * @see #growthFactor(int) * @deprecated Since fastutil 6.1.0, hash tables are doubled when they are too full. */ @Deprecated public int growthFactor() { return 16; } /** The entry class for a hash map does not record key and value, but * rather the position in the hash table of the corresponding entry. This * is necessary so that calls to {@link java.util.Map.Entry#setValue(Object)} are reflected in * the map */ private final class MapEntry implements Char2ObjectMap.Entry , Map.Entry { // The table index this entry refers to, or -1 if this entry has been deleted. private int index; MapEntry( final int index ) { this.index = index; } public Character getKey() { return (Character.valueOf(key[ index ])); } public char getCharKey() { return key[ index ]; } public V getValue() { return (value[ index ]); } public V setValue( final V v ) { final V oldValue = value[ index ]; value[ index ] = v; return oldValue; } @SuppressWarnings("unchecked") public boolean equals( final Object o ) { if (!(o instanceof Map.Entry)) return false; Map.Entry e = (Map.Entry)o; return ( (key[ index ]) == (((e.getKey()).charValue())) ) && ( (value[ index ]) == null ? ((e.getValue())) == null : (value[ index ]).equals((e.getValue())) ); } public int hashCode() { return (key[ index ]) ^ ( (value[ index ]) == null ? 0 : (value[ index ]).hashCode() ); } public String toString() { return key[ index ] + "=>" + value[ index ]; } } /** An iterator over a hash map. */ private class MapIterator { /** The index of the next entry to be returned, if positive or zero. If negative, the next entry to be returned, if any, is that of index -pos -2 from the {@link #wrapped} list. */ int pos = Char2ObjectOpenHashMap.this.n; /** The index of the last entry that has been returned. It is -1 if either we did not return an entry yet, or the last returned entry has been removed. */ int last = -1; /** A downward counter measuring how many entries must still be returned. */ int c = size; /** A lazily allocated list containing the keys of elements that have wrapped around the table because of removals; such elements would not be enumerated (other elements would be usually enumerated twice in their place). */ CharArrayList wrapped; { final boolean used[] = Char2ObjectOpenHashMap.this.used; if ( c != 0 ) while( ! used[ --pos ] ); } public boolean hasNext() { return c != 0; } public int nextEntry() { if ( ! hasNext() ) throw new NoSuchElementException(); c--; // We are just enumerating elements from the wrapped list. if ( pos < 0 ) { final char k = wrapped.getChar( - ( last = --pos ) - 2 ); // The starting point. int pos = ( org.codelibs.jhighlight.fastutil.HashCommon.murmurHash3( (k) ^ mask ) ) & mask; // There's always an unused entry. while( used[ pos ] ) { if ( ( (key[ pos ]) == (k) ) ) return pos; pos = ( pos + 1 ) & mask; } } last = pos; //System.err.println( "Count: " + c ); if ( c != 0 ) { final boolean used[] = Char2ObjectOpenHashMap.this.used; while ( pos-- != 0 && !used[ pos ] ); // When here pos < 0 there are no more elements to be enumerated by scanning, but wrapped might be nonempty. } return last; } /** Shifts left entries with the specified hash code, starting at the specified position, * and empties the resulting free entry. If any entry wraps around the table, instantiates * lazily {@link #wrapped} and stores the entry key. * * @param pos a starting position. * @return the position cleared by the shifting process. */ protected final int shiftKeys( int pos ) { // Shift entries with the same hash. int last, slot; for(;;) { pos = ( ( last = pos ) + 1 ) & mask; while( used[ pos ] ) { slot = ( org.codelibs.jhighlight.fastutil.HashCommon.murmurHash3( (key[ pos ]) ^ mask ) ) & mask; if ( last <= pos ? last >= slot || slot > pos : last >= slot && slot > pos ) break; pos = ( pos + 1 ) & mask; } if ( ! used[ pos ] ) break; if ( pos < last ) { // Wrapped entry. if ( wrapped == null ) wrapped = new CharArrayList (); wrapped.add( key[ pos ] ); } key[ last ] = key[ pos ]; value[ last ] = value[ pos ]; } used[ last ] = false; value[ last ] = null; return last; } @SuppressWarnings("unchecked") public void remove() { if ( last == -1 ) throw new IllegalStateException(); if ( pos < -1 ) { // We're removing wrapped entries. Char2ObjectOpenHashMap.this.remove( wrapped.getChar( - pos - 2 ) ); last = -1; return; } size--; if ( shiftKeys( last ) == pos && c > 0 ) { c++; nextEntry(); } last = -1; // You can no longer remove this entry. if ( ASSERTS ) checkTable(); } public int skip( final int n ) { int i = n; while( i-- != 0 && hasNext() ) nextEntry(); return n - i - 1; } } private class EntryIterator extends MapIterator implements ObjectIterator > { private MapEntry entry; public Char2ObjectMap.Entry next() { return entry = new MapEntry( nextEntry() ); } @Override public void remove() { super.remove(); entry.index = -1; // You cannot use a deleted entry. } } private class FastEntryIterator extends MapIterator implements ObjectIterator > { final BasicEntry entry = new BasicEntry ( ((char)0), (null) ); public BasicEntry next() { final int e = nextEntry(); entry.key = key[ e ]; entry.value = value[ e ]; return entry; } } private final class MapEntrySet extends AbstractObjectSet > implements FastEntrySet { public ObjectIterator > iterator() { return new EntryIterator(); } public ObjectIterator > fastIterator() { return new FastEntryIterator(); } @SuppressWarnings("unchecked") public boolean contains( final Object o ) { if ( !( o instanceof Map.Entry ) ) return false; final Map.Entry e = (Map.Entry)o; final char k = ((e.getKey()).charValue()); // The starting point. int pos = ( org.codelibs.jhighlight.fastutil.HashCommon.murmurHash3( (k) ^ mask ) ) & mask; // There's always an unused entry. while( used[ pos ] ) { if ( ( (key[ pos ]) == (k) ) ) return ( (value[ pos ]) == null ? ((e.getValue())) == null : (value[ pos ]).equals((e.getValue())) ); pos = ( pos + 1 ) & mask; } return false; } @SuppressWarnings("unchecked") public boolean remove( final Object o ) { if ( !( o instanceof Map.Entry ) ) return false; final Map.Entry e = (Map.Entry)o; final char k = ((e.getKey()).charValue()); // The starting point. int pos = ( org.codelibs.jhighlight.fastutil.HashCommon.murmurHash3( (k) ^ mask ) ) & mask; // There's always an unused entry. while( used[ pos ] ) { if ( ( (key[ pos ]) == (k) ) ) { Char2ObjectOpenHashMap.this.remove( e.getKey() ); return true; } pos = ( pos + 1 ) & mask; } return false; } public int size() { return size; } public void clear() { Char2ObjectOpenHashMap.this.clear(); } } public FastEntrySet char2ObjectEntrySet() { if ( entries == null ) entries = new MapEntrySet(); return entries; } /** An iterator on keys. * *

We simply override the {@link java.util.ListIterator#next()}/{@link java.util.ListIterator#previous()} methods * (and possibly their type-specific counterparts) so that they return keys * instead of entries. */ private final class KeyIterator extends MapIterator implements CharIterator { public KeyIterator() { super(); } public char nextChar() { return key[ nextEntry() ]; } public Character next() { return (Character.valueOf(key[ nextEntry() ])); } } private final class KeySet extends AbstractCharSet { public CharIterator iterator() { return new KeyIterator(); } public int size() { return size; } public boolean contains( char k ) { return containsKey( k ); } public boolean remove( char k ) { final int oldSize = size; Char2ObjectOpenHashMap.this.remove( k ); return size != oldSize; } public void clear() { Char2ObjectOpenHashMap.this.clear(); } } public CharSet keySet() { if ( keys == null ) keys = new KeySet(); return keys; } /** An iterator on values. * *

We simply override the {@link java.util.ListIterator#next()}/{@link java.util.ListIterator#previous()} methods * (and possibly their type-specific counterparts) so that they return values * instead of entries. */ private final class ValueIterator extends MapIterator implements ObjectIterator { public ValueIterator() { super(); } public V next() { return value[ nextEntry() ]; } } public ObjectCollection values() { if ( values == null ) values = new AbstractObjectCollection () { public ObjectIterator iterator() { return new ValueIterator(); } public int size() { return size; } public boolean contains( Object v ) { return containsValue( v ); } public void clear() { Char2ObjectOpenHashMap.this.clear(); } }; return values; } /** A no-op for backward compatibility. The kind of tables implemented by * this class never need rehashing. * *

If you need to reduce the table size to fit exactly * this set, use {@link #trim()}. * * @return true. * @see #trim() * @deprecated A no-op. */ @Deprecated public boolean rehash() { return true; } /** Rehashes the map, making the table as small as possible. * *

This method rehashes the table to the smallest size satisfying the * load factor. It can be used when the set will not be changed anymore, so * to optimize access speed and size. * *

If the table size is already the minimum possible, this method * does nothing. * * @return true if there was enough memory to trim the map. * @see #trim(int) */ public boolean trim() { final int l = arraySize( size, f ); if ( l >= n ) return true; try { rehash( l ); } catch(OutOfMemoryError cantDoIt) { return false; } return true; } /** Rehashes this map if the table is too large. * *

Let N be the smallest table size that can hold * max(n,{@link #size()}) entries, still satisfying the load factor. If the current * table size is smaller than or equal to N, this method does * nothing. Otherwise, it rehashes this map in a table of size * N. * *

This method is useful when reusing maps. {@linkplain #clear() Clearing a * map} leaves the table size untouched. If you are reusing a map * many times, you can call this method with a typical * size to avoid keeping around a very large table just * because of a few large transient maps. * * @param n the threshold for the trimming. * @return true if there was enough memory to trim the map. * @see #trim() */ public boolean trim( final int n ) { final int l = HashCommon.nextPowerOfTwo( (int)Math.ceil( n / f ) ); if ( this.n <= l ) return true; try { rehash( l ); } catch( OutOfMemoryError cantDoIt ) { return false; } return true; } /** Rehashes the map. * *

This method implements the basic rehashing strategy, and may be * overriden by subclasses implementing different rehashing strategies (e.g., * disk-based rehashing). However, you should not override this method * unless you understand the internal workings of this class. * * @param newN the new size */ @SuppressWarnings("unchecked") protected void rehash( final int newN ) { int i = 0, pos; final boolean used[] = this.used; char k; final char key[] = this.key; final V value[] = this.value; final int mask = newN - 1; // Note that this is used by the hashing macro final char newKey[] = new char[ newN ]; final V newValue[] = (V[]) new Object[newN]; final boolean newUsed[] = new boolean[ newN ]; for( int j = size; j-- != 0; ) { while( ! used[ i ] ) i++; k = key[ i ]; pos = ( org.codelibs.jhighlight.fastutil.HashCommon.murmurHash3( (k) ^ mask ) ) & mask; while ( newUsed[ pos ] ) pos = ( pos + 1 ) & mask; newUsed[ pos ] = true; newKey[ pos ] = k; newValue[ pos ] = value[ i ]; i++; } n = newN; this.mask = mask; maxFill = maxFill( n, f ); this.key = newKey; this.value = newValue; this.used = newUsed; } /** Returns a deep copy of this map. * *

This method performs a deep copy of this hash map; the data stored in the * map, however, is not cloned. Note that this makes a difference only for object keys. * * @return a deep copy of this map. */ @SuppressWarnings("unchecked") public Char2ObjectOpenHashMap clone() { Char2ObjectOpenHashMap c; try { c = (Char2ObjectOpenHashMap )super.clone(); } catch(CloneNotSupportedException cantHappen) { throw new InternalError(); } c.keys = null; c.values = null; c.entries = null; c.key = key.clone(); c.value = value.clone(); c.used = used.clone(); return c; } /** Returns a hash code for this map. * * This method overrides the generic method provided by the superclass. * Since equals() is not overriden, it is important * that the value returned by this method is the same value as * the one returned by the overriden method. * * @return a hash code for this map. */ public int hashCode() { int h = 0; for( int j = size, i = 0, t = 0; j-- != 0; ) { while( ! used[ i ] ) i++; t = (key[ i ]); if ( this != value[ i ] ) t ^= ( (value[ i ]) == null ? 0 : (value[ i ]).hashCode() ); h += t; i++; } return h; } private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { final char key[] = this.key; final V value[] = this.value; final MapIterator i = new MapIterator(); s.defaultWriteObject(); for( int j = size, e; j-- != 0; ) { e = i.nextEntry(); s.writeChar( key[ e ] ); s.writeObject( value[ e ] ); } } @SuppressWarnings("unchecked") private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); n = arraySize( size, f ); maxFill = maxFill( n, f ); mask = n - 1; final char key[] = this.key = new char[ n ]; final V value[] = this.value = (V[]) new Object[ n ]; final boolean used[] = this.used = new boolean[ n ]; char k; V v; for( int i = size, pos = 0; i-- != 0; ) { k = s.readChar(); v = (V) s.readObject(); pos = ( org.codelibs.jhighlight.fastutil.HashCommon.murmurHash3( (k) ^ mask ) ) & mask; while ( used[ pos ] ) pos = ( pos + 1 ) & mask; used[ pos ] = true; key[ pos ] = k; value[ pos ] = v; } if ( ASSERTS ) checkTable(); } private void checkTable() {} } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/CharArrayList.java000066400000000000000000000404311422762524200334170ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.RandomAccess; import org.codelibs.jhighlight.fastutil.Arrays; /** A type-specific array-based list; provides some additional methods that use polymorphism to avoid (un)boxing. * *

This class implements a lightweight, fast, open, optimized, * reuse-oriented version of array-based lists. Instances of this class * represent a list with an array that is enlarged as needed when new entries * are created (by doubling its current length), but is * never made smaller (even on a {@link #clear()}). A family of * {@linkplain #trim() trimming methods} lets you control the size of the * backing array; this is particularly useful if you reuse instances of this class. * Range checks are equivalent to those of {@link java.util}'s classes, but * they are delayed as much as possible. The backing array is exposed by the * {@link #elements()} method. * *

This class implements the bulk methods removeElements(), * addElements() and getElements() using * high-performance system calls (e.g., {@link * System#arraycopy(Object,int,Object,int,int) System.arraycopy()} instead of * expensive loops. * * @see java.util.ArrayList */ public class CharArrayList extends AbstractCharList implements RandomAccess, Cloneable, java.io.Serializable { private static final long serialVersionUID = -7046029254386353130L; /** The initial default capacity of an array list. */ public final static int DEFAULT_INITIAL_CAPACITY = 16; /** The backing array. */ protected transient char a[]; /** The current actual size of the list (never greater than the backing-array length). */ protected int size; private static final boolean ASSERTS = false; /** Creates a new array list using a given array. * *

This constructor is only meant to be used by the wrapping methods. * * @param a the array that will be used to back this array list. */ @SuppressWarnings("unused") protected CharArrayList( final char a[], boolean dummy ) { this.a = a; } /** Creates a new array list with given capacity. * * @param capacity the initial capacity of the array list (may be 0). */ @SuppressWarnings("unchecked") public CharArrayList( final int capacity ) { if ( capacity < 0 ) throw new IllegalArgumentException( "Initial capacity (" + capacity + ") is negative" ); a = new char[ capacity ]; } /** Creates a new array list with {@link #DEFAULT_INITIAL_CAPACITY} capacity. */ public CharArrayList() { this( DEFAULT_INITIAL_CAPACITY ); } /** Creates a new array list and fills it with a given collection. * * @param c a collection that will be used to fill the array list. */ public CharArrayList( final Collection c ) { this( c.size() ); size = CharIterators.unwrap( CharIterators.asCharIterator( c.iterator() ), a ); } /** Creates a new array list and fills it with a given type-specific collection. * * @param c a type-specific collection that will be used to fill the array list. */ public CharArrayList( final CharCollection c ) { this( c.size() ); size = CharIterators.unwrap( c.iterator(), a ); } /** Creates a new array list and fills it with a given type-specific list. * * @param l a type-specific list that will be used to fill the array list. */ public CharArrayList( final CharList l ) { this( l.size() ); l.getElements( 0, a, 0, size = l.size() ); } /** Creates a new array list and fills it with the elements of a given array. * * @param a an array whose elements will be used to fill the array list. */ public CharArrayList( final char a[] ) { this( a, 0, a.length ); } /** Creates a new array list and fills it with the elements of a given array. * * @param a an array whose elements will be used to fill the array list. * @param offset the first element to use. * @param length the number of elements to use. */ public CharArrayList( final char a[], final int offset, final int length ) { this( length ); System.arraycopy( a, offset, this.a, 0, length ); size = length; } /** Creates a new array list and fills it with the elements returned by an iterator.. * * @param i an iterator whose returned elements will fill the array list. */ public CharArrayList( final Iterator i ) { this(); while( i.hasNext() ) this.add( i.next() ); } /** Creates a new array list and fills it with the elements returned by a type-specific iterator.. * * @param i a type-specific iterator whose returned elements will fill the array list. */ public CharArrayList( final CharIterator i ) { this(); while( i.hasNext() ) this.add( i.nextChar() ); } /** Returns the backing array of this list. * * @return the backing array. */ public char[] elements() { return a; } /** Wraps a given array into an array list of given size. * * @param a an array to wrap. * @param length the length of the resulting array list. * @return a new array list of the given size, wrapping the given array. */ public static CharArrayList wrap( final char a[], final int length ) { if ( length > a.length ) throw new IllegalArgumentException( "The specified length (" + length + ") is greater than the array size (" + a.length + ")" ); final CharArrayList l = new CharArrayList ( a, false ); l.size = length; return l; } /** Wraps a given array into an array list. * * @param a an array to wrap. * @return a new array list wrapping the given array. */ public static CharArrayList wrap( final char a[] ) { return wrap( a, a.length ); } /** Ensures that this array list can contain the given number of entries without resizing. * * @param capacity the new minimum capacity for this array list. */ @SuppressWarnings("unchecked") public void ensureCapacity( final int capacity ) { a = CharArrays.ensureCapacity( a, capacity, size ); if ( ASSERTS ) assert size <= a.length; } /** Grows this array list, ensuring that it can contain the given number of entries without resizing, * and in case enlarging it at least by a factor of two. * * @param capacity the new minimum capacity for this array list. */ @SuppressWarnings("unchecked") private void grow( final int capacity ) { a = CharArrays.grow( a, capacity, size ); if ( ASSERTS ) assert size <= a.length; } public void add( final int index, final char k ) { ensureIndex( index ); grow( size + 1 ); if ( index != size ) System.arraycopy( a, index, a, index + 1, size - index ); a[ index ] = k; size++; if ( ASSERTS ) assert size <= a.length; } public boolean add( final char k ) { grow( size + 1 ); a[ size++ ] = k; if ( ASSERTS ) assert size <= a.length; return true; } public char getChar( final int index ) { if ( index >= size ) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + size + ")" ); return a[ index ]; } public int indexOf( final char k ) { for( int i = 0; i < size; i++ ) if ( ( (k) == (a[ i ]) ) ) return i; return -1; } public int lastIndexOf( final char k ) { for( int i = size; i-- != 0; ) if ( ( (k) == (a[ i ]) ) ) return i; return -1; } public char removeChar( final int index ) { if ( index >= size ) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + size + ")" ); final char old = a[ index ]; size--; if ( index != size ) System.arraycopy( a, index + 1, a, index, size - index ); if ( ASSERTS ) assert size <= a.length; return old; } public boolean rem( final char k ) { int index = indexOf( k ); if ( index == -1 ) return false; removeChar( index ); if ( ASSERTS ) assert size <= a.length; return true; } public char set( final int index, final char k ) { if ( index >= size ) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + size + ")" ); char old = a[ index ]; a[ index ] = k; return old; } public void clear() { size = 0; if ( ASSERTS ) assert size <= a.length; } public int size() { return size; } public void size( final int size ) { if ( size > a.length ) ensureCapacity( size ); if ( size > this.size ) CharArrays.fill( a, this.size, size, ((char)0) ); this.size = size; } public boolean isEmpty() { return size == 0; } /** Trims this array list so that the capacity is equal to the size. * * @see java.util.ArrayList#trimToSize() */ public void trim() { trim( 0 ); } /** Trims the backing array if it is too large. * * If the current array length is smaller than or equal to * n, this method does nothing. Otherwise, it trims the * array length to the maximum between n and {@link #size()}. * *

This method is useful when reusing lists. {@linkplain #clear() Clearing a * list} leaves the array length untouched. If you are reusing a list * many times, you can call this method with a typical * size to avoid keeping around a very large array just * because of a few large transient lists. * * @param n the threshold for the trimming. */ @SuppressWarnings("unchecked") public void trim( final int n ) { // TODO: use Arrays.trim() and preserve type only if necessary if ( n >= a.length || size == a.length ) return; final char t[] = new char[ Math.max( n, size ) ]; System.arraycopy( a, 0, t, 0, size ); a = t; if ( ASSERTS ) assert size <= a.length; } /** Copies element of this type-specific list into the given array using optimized system calls. * * @param from the start index (inclusive). * @param a the destination array. * @param offset the offset into the destination array where to store the first element copied. * @param length the number of elements to be copied. */ public void getElements( final int from, final char[] a, final int offset, final int length ) { CharArrays.ensureOffsetLength( a, offset, length ); System.arraycopy( this.a, from, a, offset, length ); } /** Removes elements of this type-specific list using optimized system calls. * * @param from the start index (inclusive). * @param to the end index (exclusive). */ public void removeElements( final int from, final int to ) { Arrays.ensureFromTo( size, from, to ); System.arraycopy( a, to, a, from, size - to ); size -= ( to - from ); } /** Adds elements to this type-specific list using optimized system calls. * * @param index the index at which to add elements. * @param a the array containing the elements. * @param offset the offset of the first element to add. * @param length the number of elements to add. */ public void addElements( final int index, final char a[], final int offset, final int length ) { ensureIndex( index ); CharArrays.ensureOffsetLength( a, offset, length ); grow( size + length ); System.arraycopy( this.a, index, this.a, index + length, size - index ); System.arraycopy( a, offset, this.a, index, length ); size += length; } public char[] toCharArray( char a[] ) { if ( a == null || a.length < size ) a = new char[ size ]; System.arraycopy( this.a, 0, a, 0, size ); return a; } public boolean addAll( int index, final CharCollection c ) { ensureIndex( index ); int n = c.size(); if ( n == 0 ) return false; grow( size + n ); if ( index != size ) System.arraycopy( a, index, a, index + n, size - index ); final CharIterator i = c.iterator(); size += n; while( n-- != 0 ) a[ index++ ] = i.nextChar(); if ( ASSERTS ) assert size <= a.length; return true; } public boolean addAll( final int index, final CharList l ) { ensureIndex( index ); final int n = l.size(); if ( n == 0 ) return false; grow( size + n ); if ( index != size ) System.arraycopy( a, index, a, index + n, size - index ); l.getElements( 0, a, index, n ); size += n; if ( ASSERTS ) assert size <= a.length; return true; } public CharListIterator listIterator( final int index ) { ensureIndex( index ); return new AbstractCharListIterator () { int pos = index, last = -1; public boolean hasNext() { return pos < size; } public boolean hasPrevious() { return pos > 0; } public char nextChar() { if ( ! hasNext() ) throw new NoSuchElementException(); return a[ last = pos++ ]; } public char previousChar() { if ( ! hasPrevious() ) throw new NoSuchElementException(); return a[ last = --pos ]; } public int nextIndex() { return pos; } public int previousIndex() { return pos - 1; } public void add( char k ) { if ( last == -1 ) throw new IllegalStateException(); CharArrayList.this.add( pos++, k ); last = -1; } public void set( char k ) { if ( last == -1 ) throw new IllegalStateException(); CharArrayList.this.set( last, k ); } public void remove() { if ( last == -1 ) throw new IllegalStateException(); CharArrayList.this.removeChar( last ); /* If the last operation was a next(), we are removing an element *before* us, and we must decrease pos correspondingly. */ if ( last < pos ) pos--; last = -1; } }; } @SuppressWarnings("unchecked") public CharArrayList clone() { CharArrayList c = new CharArrayList ( size ); System.arraycopy( a, 0, c.a, 0, size ); c.size = size; return c; } /** Compares this type-specific array list to another one. * *

This method exists only for sake of efficiency. The implementation * inherited from the abstract implementation would already work. * * @param l a type-specific array list. * @return true if the argument contains the same elements of this type-specific array list. */ public boolean equals( final CharArrayList l ) { if ( l == this ) return true; int s = size(); if ( s != l.size() ) return false; final char[] a1 = a; final char[] a2 = l.a; while( s-- != 0 ) if ( a1[ s ] != a2[ s ] ) return false; return true; } /** Compares this array list to another array list. * *

This method exists only for sake of efficiency. The implementation * inherited from the abstract implementation would already work. * * @param l an array list. * @return a negative integer, * zero, or a positive integer as this list is lexicographically less than, equal * to, or greater than the argument. */ @SuppressWarnings("unchecked") public int compareTo( final CharArrayList l ) { final int s1 = size(), s2 = l.size(); final char a1[] = a, a2[] = l.a; char e1, e2; int r, i; for( i = 0; i < s1 && i < s2; i++ ) { e1 = a1[ i ]; e2 = a2[ i ]; if ( ( r = ( (e1) < (e2) ? -1 : ( (e1) == (e2) ? 0 : 1 ) ) ) != 0 ) return r; } return i < s2 ? -1 : ( i < s1 ? 1 : 0 ); } private void writeObject( java.io.ObjectOutputStream s ) throws java.io.IOException { s.defaultWriteObject(); for( int i = 0; i < size; i++ ) s.writeChar( a[ i ] ); } @SuppressWarnings("unchecked") private void readObject( java.io.ObjectInputStream s ) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); a = new char[ size ]; for( int i = 0; i < size; i++ ) a[ i ] = s.readChar(); } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/CharArrays.java000066400000000000000000002001651422762524200327500ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * * * For the sorting and binary search code: * * Copyright (C) 1999 CERN - European Organization for Nuclear Research. * * Permission to use, copy, modify, distribute and sell this software and * its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation. CERN makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without expressed or implied warranty. */ package org.codelibs.jhighlight.fastutil.chars; import java.util.Random; import org.codelibs.jhighlight.fastutil.Arrays; import org.codelibs.jhighlight.fastutil.Hash; /** A class providing static methods and objects that do useful things with type-specific arrays. * *

In particular, the ensureCapacity(), grow(), * trim() and setLength() methods allow to handle * arrays much like array lists. This can be very useful when efficiency (or * syntactic simplicity) reasons make array lists unsuitable. * *

Note that {@link org.codelibs.jhighlight.fastutil.io.BinIO} and {@link org.codelibs.jhighlight.fastutil.io.TextIO} * contain several methods make it possible to load and save arrays of primitive types as sequences * of elements in {@link java.io.DataInput} format (i.e., not as objects) or as sequences of lines of text. * * @see java.util.Arrays */ public class CharArrays { private CharArrays() {} /** A static, final, empty array. */ public final static char[] EMPTY_ARRAY = {}; /** Ensures that an array can contain the given number of entries. * *

If you cannot foresee whether this array will need again to be * enlarged, you should probably use grow() instead. * * @param array an array. * @param length the new minimum length for this array. * @return array, if it contains length entries or more; otherwise, * an array with length entries whose first array.length * entries are the same as those of array. */ public static char[] ensureCapacity( final char[] array, final int length ) { if ( length > array.length ) { final char t[] = new char[ length ]; System.arraycopy( array, 0, t, 0, array.length ); return t; } return array; } /** Ensures that an array can contain the given number of entries, preserving just a part of the array. * * @param array an array. * @param length the new minimum length for this array. * @param preserve the number of elements of the array that must be preserved in case a new allocation is necessary. * @return array, if it can contain length entries or more; otherwise, * an array with length entries whose first preserve * entries are the same as those of array. */ public static char[] ensureCapacity( final char[] array, final int length, final int preserve ) { if ( length > array.length ) { final char t[] = new char[ length ]; System.arraycopy( array, 0, t, 0, preserve ); return t; } return array; } /** Grows the given array to the maximum between the given length and * the current length multiplied by two, provided that the given * length is larger than the current length. * *

If you want complete control on the array growth, you * should probably use ensureCapacity() instead. * * @param array an array. * @param length the new minimum length for this array. * @return array, if it can contain length * entries; otherwise, an array with * max(length,array.length/φ) entries whose first * array.length entries are the same as those of array. * */ public static char[] grow( final char[] array, final int length ) { if ( length > array.length ) { final int newLength = (int)Math.max( Math.min( 2L * array.length, Arrays.MAX_ARRAY_SIZE ), length ); final char t[] = new char[ newLength ]; System.arraycopy( array, 0, t, 0, array.length ); return t; } return array; } /** Grows the given array to the maximum between the given length and * the current length multiplied by two, provided that the given * length is larger than the current length, preserving just a part of the array. * *

If you want complete control on the array growth, you * should probably use ensureCapacity() instead. * * @param array an array. * @param length the new minimum length for this array. * @param preserve the number of elements of the array that must be preserved in case a new allocation is necessary. * @return array, if it can contain length * entries; otherwise, an array with * max(length,array.length/φ) entries whose first * preserve entries are the same as those of array. * */ public static char[] grow( final char[] array, final int length, final int preserve ) { if ( length > array.length ) { final int newLength = (int)Math.max( Math.min( 2L * array.length, Arrays.MAX_ARRAY_SIZE ), length ); final char t[] = new char[ newLength ]; System.arraycopy( array, 0, t, 0, preserve ); return t; } return array; } /** Trims the given array to the given length. * * @param array an array. * @param length the new maximum length for the array. * @return array, if it contains length * entries or less; otherwise, an array with * length entries whose entries are the same as * the first length entries of array. * */ public static char[] trim( final char[] array, final int length ) { if ( length >= array.length ) return array; final char t[] = length == 0 ? EMPTY_ARRAY : new char[ length ]; System.arraycopy( array, 0, t, 0, length ); return t; } /** Sets the length of the given array. * * @param array an array. * @param length the new length for the array. * @return array, if it contains exactly length * entries; otherwise, if it contains more than * length entries, an array with length entries * whose entries are the same as the first length entries of * array; otherwise, an array with length entries * whose first array.length entries are the same as those of * array. * */ public static char[] setLength( final char[] array, final int length ) { if ( length == array.length ) return array; if ( length < array.length ) return trim( array, length ); return ensureCapacity( array, length ); } /** Returns a copy of a portion of an array. * * @param array an array. * @param offset the first element to copy. * @param length the number of elements to copy. * @return a new array containing length elements of array starting at offset. */ public static char[] copy( final char[] array, final int offset, final int length ) { ensureOffsetLength( array, offset, length ); final char[] a = length == 0 ? EMPTY_ARRAY : new char[ length ]; System.arraycopy( array, offset, a, 0, length ); return a; } /** Returns a copy of an array. * * @param array an array. * @return a copy of array. */ public static char[] copy( final char[] array ) { return array.clone(); } /** Fills the given array with the given value. * *

This method uses a backward loop. It is significantly faster than the corresponding * method in {@link java.util.Arrays}. * * @param array an array. * @param value the new value for all elements of the array. */ public static void fill( final char[] array, final char value ) { int i = array.length; while( i-- != 0 ) array[ i ] = value; } /** Fills a portion of the given array with the given value. * *

If possible (i.e., from is 0) this method uses a * backward loop. In this case, it is significantly faster than the * corresponding method in {@link java.util.Arrays}. * * @param array an array. * @param from the starting index of the portion to fill (inclusive). * @param to the end index of the portion to fill (exclusive). * @param value the new value for all elements of the specified portion of the array. */ public static void fill( final char[] array, final int from, int to, final char value ) { ensureFromTo( array, from, to ); if ( from == 0 ) while( to-- != 0 ) array[ to ] = value; else for( int i = from; i < to; i++ ) array[ i ] = value; } /** Returns true if the two arrays are elementwise equal. * * @param a1 an array. * @param a2 another array. * @return true if the two arrays are of the same length, and their elements are equal. * @deprecated Please use the corresponding {@link java.util.Arrays} method, which is intrinsified in recent JVMs. */ @Deprecated public static boolean equals( final char[] a1, final char a2[] ) { int i = a1.length; if ( i != a2.length ) return false; while( i-- != 0 ) if (! ( (a1[ i ]) == (a2[ i ]) ) ) return false; return true; } /** Ensures that a range given by its first (inclusive) and last (exclusive) elements fits an array. * *

This method may be used whenever an array range check is needed. * * @param a an array. * @param from a start index (inclusive). * @param to an end index (exclusive). * @throws IllegalArgumentException if from is greater than to. * @throws ArrayIndexOutOfBoundsException if from or to are greater than the array length or negative. */ public static void ensureFromTo( final char[] a, final int from, final int to ) { Arrays.ensureFromTo( a.length, from, to ); } /** Ensures that a range given by an offset and a length fits an array. * *

This method may be used whenever an array range check is needed. * * @param a an array. * @param offset a start index. * @param length a length (the number of elements in the range). * @throws IllegalArgumentException if length is negative. * @throws ArrayIndexOutOfBoundsException if offset is negative or offset+length is greater than the array length. */ public static void ensureOffsetLength( final char[] a, final int offset, final int length ) { Arrays.ensureOffsetLength( a.length, offset, length ); } private static final int SMALL = 7; private static final int MEDIUM = 50; private static void swap( final char x[], final int a, final int b ) { final char t = x[ a ]; x[ a ] = x[ b ]; x[ b ] = t; } private static void vecSwap( final char[] x, int a, int b, final int n ) { for( int i = 0; i < n; i++, a++, b++ ) swap( x, a, b ); } private static int med3( final char x[], final int a, final int b, final int c, CharComparator comp ) { int ab = comp.compare( x[ a ], x[ b ] ); int ac = comp.compare( x[ a ], x[ c ] ); int bc = comp.compare( x[ b ], x[ c ] ); return ( ab < 0 ? ( bc < 0 ? b : ac < 0 ? c : a ) : ( bc > 0 ? b : ac > 0 ? c : a ) ); } private static void selectionSort( final char[] a, final int from, final int to, final CharComparator comp ) { for( int i = from; i < to - 1; i++ ) { int m = i; for( int j = i + 1; j < to; j++ ) if ( comp.compare( a[ j ], a[ m ] ) < 0 ) m = j; if ( m != i ) { final char u = a[ i ]; a[ i ] = a[ m ]; a[ m ] = u; } } } private static void insertionSort( final char[] a, final int from, final int to, final CharComparator comp ) { for ( int i = from; ++i < to; ) { char t = a[ i ]; int j = i; for ( char u = a[ j - 1 ]; comp.compare( t, u ) < 0; u = a[ --j - 1 ] ) { a[ j ] = u; if ( from == j - 1 ) { --j; break; } } a[ j ] = t; } } @SuppressWarnings("unchecked") private static void selectionSort( final char[] a, final int from, final int to ) { for( int i = from; i < to - 1; i++ ) { int m = i; for( int j = i + 1; j < to; j++ ) if ( ( (a[ j ]) < (a[ m ]) ) ) m = j; if ( m != i ) { final char u = a[ i ]; a[ i ] = a[ m ]; a[ m ] = u; } } } @SuppressWarnings("unchecked") private static void insertionSort( final char[] a, final int from, final int to ) { for ( int i = from; ++i < to; ) { char t = a[ i ]; int j = i; for ( char u = a[ j - 1 ]; ( (t) < (u) ); u = a[ --j - 1 ] ) { a[ j ] = u; if ( from == j - 1 ) { --j; break; } } a[ j ] = t; } } /** Sorts the specified range of elements according to the order induced by the specified * comparator using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. * */ public static void quickSort( final char[] x, final int from, final int to, final CharComparator comp ) { final int len = to - from; // Selection sort on smallest arrays if ( len < SMALL ) { selectionSort( x, from, to, comp ); return; } // Choose a partition element, v int m = from + len / 2; // Small arrays, middle element if ( len > SMALL ) { int l = from; int n = to - 1; if ( len > MEDIUM ) { // Big arrays, pseudomedian of 9 int s = len / 8; l = med3( x, l, l + s, l + 2 * s, comp ); m = med3( x, m - s, m, m + s, comp ); n = med3( x, n - 2 * s, n - s, n, comp ); } m = med3( x, l, m, n, comp ); // Mid-size, med of 3 } final char v = x[ m ]; // Establish Invariant: v* (v)* v* int a = from, b = a, c = to - 1, d = c; while(true) { int comparison; while ( b <= c && ( comparison = comp.compare( x[ b ], v ) ) <= 0 ) { if ( comparison == 0 ) swap( x, a++, b ); b++; } while (c >= b && ( comparison = comp.compare( x[ c ], v ) ) >=0 ) { if ( comparison == 0 ) swap( x, c, d-- ); c--; } if ( b > c ) break; swap( x, b++, c-- ); } // Swap partition elements back to middle int s, n = to; s = Math.min( a - from, b - a ); vecSwap( x, from, b - s, s ); s = Math.min( d - c, n - d - 1 ); vecSwap( x, b, n - s, s ); // Recursively sort non-partition-elements if ( ( s = b - a ) > 1 ) quickSort( x, from, from + s, comp ); if ( ( s = d - c ) > 1 ) quickSort( x, n - s, n, comp ); } /** Sorts an array according to the order induced by the specified * comparator using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * @param comp the comparator to determine the sorting order. * */ public static void quickSort( final char[] x, final CharComparator comp ) { quickSort( x, 0, x.length, comp ); } @SuppressWarnings("unchecked") private static int med3( final char x[], final int a, final int b, final int c ) { int ab = ( (x[ a ]) < (x[ b ]) ? -1 : ( (x[ a ]) == (x[ b ]) ? 0 : 1 ) ); int ac = ( (x[ a ]) < (x[ c ]) ? -1 : ( (x[ a ]) == (x[ c ]) ? 0 : 1 ) ); int bc = ( (x[ b ]) < (x[ c ]) ? -1 : ( (x[ b ]) == (x[ c ]) ? 0 : 1 ) ); return ( ab < 0 ? ( bc < 0 ? b : ac < 0 ? c : a ) : ( bc > 0 ? b : ac > 0 ? c : a ) ); } /** Sorts the specified range of elements according to the natural ascending order using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ @SuppressWarnings("unchecked") public static void quickSort( final char[] x, final int from, final int to ) { final int len = to - from; // Selection sort on smallest arrays if ( len < SMALL ) { selectionSort( x, from, to ); return; } // Choose a partition element, v int m = from + len / 2; // Small arrays, middle element if ( len > SMALL ) { int l = from; int n = to - 1; if ( len > MEDIUM ) { // Big arrays, pseudomedian of 9 int s = len / 8; l = med3( x, l, l + s, l + 2 * s ); m = med3( x, m - s, m, m + s ); n = med3( x, n - 2 * s, n - s, n ); } m = med3( x, l, m, n ); // Mid-size, med of 3 } final char v = x[ m ]; // Establish Invariant: v* (v)* v* int a = from, b = a, c = to - 1, d = c; while(true) { int comparison; while ( b <= c && ( comparison = ( (x[ b ]) < (v) ? -1 : ( (x[ b ]) == (v) ? 0 : 1 ) ) ) <= 0 ) { if ( comparison == 0 ) swap( x, a++, b ); b++; } while (c >= b && ( comparison = ( (x[ c ]) < (v) ? -1 : ( (x[ c ]) == (v) ? 0 : 1 ) ) ) >=0 ) { if ( comparison == 0 ) swap( x, c, d-- ); c--; } if ( b > c ) break; swap( x, b++, c-- ); } // Swap partition elements back to middle int s, n = to; s = Math.min( a - from, b - a ); vecSwap( x, from, b - s, s ); s = Math.min( d - c, n - d - 1 ); vecSwap( x, b, n - s, s ); // Recursively sort non-partition-elements if ( ( s = b - a ) > 1 ) quickSort( x, from, from + s ); if ( ( s = d - c ) > 1 ) quickSort( x, n - s, n ); } /** Sorts an array according to the natural ascending order using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * */ public static void quickSort( final char[] x ) { quickSort( x, 0, x.length ); } /** Sorts the specified range of elements according to the natural ascending order using mergesort, using a given pre-filled support array. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. Moreover, no support arrays will be allocated. * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param supp a support array containing at least to elements, and whose entries are identical to those * of {@code a} in the specified range. */ @SuppressWarnings("unchecked") public static void mergeSort( final char a[], final int from, final int to, final char supp[] ) { int len = to - from; // Insertion sort on smallest arrays if ( len < SMALL ) { insertionSort( a, from, to ); return; } // Recursively sort halves of a into supp final int mid = ( from + to ) >>> 1; mergeSort( supp, from, mid, a ); mergeSort( supp, mid, to, a ); // If list is already sorted, just copy from supp to a. This is an // optimization that results in faster sorts for nearly ordered lists. if ( ( (supp[ mid - 1 ]) <= (supp[ mid ]) ) ) { System.arraycopy( supp, from, a, from, len ); return; } // Merge sorted halves (now in supp) into a for( int i = from, p = from, q = mid; i < to; i++ ) { if ( q >= to || p < mid && ( (supp[ p ]) <= (supp[ q ]) ) ) a[ i ] = supp[ p++ ]; else a[ i ] = supp[ q++ ]; } } /** Sorts the specified range of elements according to the natural ascending order using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ public static void mergeSort( final char a[], final int from, final int to ) { mergeSort( a, from, to, a.clone() ); } /** Sorts an array according to the natural ascending order using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * @param a the array to be sorted. */ public static void mergeSort( final char a[] ) { mergeSort( a, 0, a.length ); } /** Sorts the specified range of elements according to the order induced by the specified * comparator using mergesort, using a given pre-filled support array. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. Moreover, no support arrays will be allocated. * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. * @param supp a support array containing at least to elements, and whose entries are identical to those * of {@code a} in the specified range. */ @SuppressWarnings("unchecked") public static void mergeSort( final char a[], final int from, final int to, CharComparator comp, final char supp[] ) { int len = to - from; // Insertion sort on smallest arrays if ( len < SMALL ) { insertionSort( a, from, to, comp ); return; } // Recursively sort halves of a into supp final int mid = ( from + to ) >>> 1; mergeSort( supp, from, mid, comp, a ); mergeSort( supp, mid, to, comp, a ); // If list is already sorted, just copy from supp to a. This is an // optimization that results in faster sorts for nearly ordered lists. if ( comp.compare( supp[ mid - 1 ], supp[ mid ] ) <= 0 ) { System.arraycopy( supp, from, a, from, len ); return; } // Merge sorted halves (now in supp) into a for( int i = from, p = from, q = mid; i < to; i++ ) { if ( q >= to || p < mid && comp.compare( supp[ p ], supp[ q ] ) <= 0 ) a[ i ] = supp[ p++ ]; else a[ i ] = supp[ q++ ]; } } /** Sorts the specified range of elements according to the order induced by the specified * comparator using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. */ public static void mergeSort( final char a[], final int from, final int to, CharComparator comp ) { mergeSort( a, from, to, comp, a.clone() ); } /** Sorts an array according to the order induced by the specified * comparator using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * @param a the array to be sorted. * @param comp the comparator to determine the sorting order. */ public static void mergeSort( final char a[], CharComparator comp ) { mergeSort( a, 0, a.length, comp ); } /** * Searches a range of the specified array for the specified value using * the binary search algorithm. The range must be sorted prior to making this call. * If it is not sorted, the results are undefined. If the range contains multiple elements with * the specified value, there is no guarantee which one will be found. * * @param a the array to be searched. * @param from the index of the first element (inclusive) to be searched. * @param to the index of the last element (exclusive) to be searched. * @param key the value to be searched for. * @return index of the search key, if it is contained in the array; * otherwise, (-(insertion point) - 1). The insertion * point is defined as the the point at which the value would * be inserted into the array: the index of the first * element greater than the key, or the length of the array, if all * elements in the array are less than the specified key. Note * that this guarantees that the return value will be >= 0 if * and only if the key is found. * @see java.util.Arrays */ @SuppressWarnings({"unchecked","rawtypes"}) public static int binarySearch( final char[] a, int from, int to, final char key ) { char midVal; to--; while (from <= to) { final int mid = (from + to) >>> 1; midVal = a[ mid ]; if (midVal < key) from = mid + 1; else if (midVal > key) to = mid - 1; else return mid; } return -( from + 1 ); } /** * Searches an array for the specified value using * the binary search algorithm. The range must be sorted prior to making this call. * If it is not sorted, the results are undefined. If the range contains multiple elements with * the specified value, there is no guarantee which one will be found. * * @param a the array to be searched. * @param key the value to be searched for. * @return index of the search key, if it is contained in the array; * otherwise, (-(insertion point) - 1). The insertion * point is defined as the the point at which the value would * be inserted into the array: the index of the first * element greater than the key, or the length of the array, if all * elements in the array are less than the specified key. Note * that this guarantees that the return value will be >= 0 if * and only if the key is found. * @see java.util.Arrays */ public static int binarySearch( final char[] a, final char key ) { return binarySearch( a, 0, a.length, key ); } /** * Searches a range of the specified array for the specified value using * the binary search algorithm and a specified comparator. The range must be sorted following the comparator prior to making this call. * If it is not sorted, the results are undefined. If the range contains multiple elements with * the specified value, there is no guarantee which one will be found. * * @param a the array to be searched. * @param from the index of the first element (inclusive) to be searched. * @param to the index of the last element (exclusive) to be searched. * @param key the value to be searched for. * @param c a comparator. * @return index of the search key, if it is contained in the array; * otherwise, (-(insertion point) - 1). The insertion * point is defined as the the point at which the value would * be inserted into the array: the index of the first * element greater than the key, or the length of the array, if all * elements in the array are less than the specified key. Note * that this guarantees that the return value will be >= 0 if * and only if the key is found. * @see java.util.Arrays */ public static int binarySearch( final char[] a, int from, int to, final char key, final CharComparator c ) { char midVal; to--; while (from <= to) { final int mid = (from + to) >>> 1; midVal = a[ mid ]; final int cmp = c.compare( midVal, key ); if ( cmp < 0 ) from = mid + 1; else if (cmp > 0) to = mid - 1; else return mid; // key found } return -( from + 1 ); } /** * Searches an array for the specified value using * the binary search algorithm and a specified comparator. The range must be sorted following the comparator prior to making this call. * If it is not sorted, the results are undefined. If the range contains multiple elements with * the specified value, there is no guarantee which one will be found. * * @param a the array to be searched. * @param key the value to be searched for. * @param c a comparator. * @return index of the search key, if it is contained in the array; * otherwise, (-(insertion point) - 1). The insertion * point is defined as the the point at which the value would * be inserted into the array: the index of the first * element greater than the key, or the length of the array, if all * elements in the array are less than the specified key. Note * that this guarantees that the return value will be >= 0 if * and only if the key is found. * @see java.util.Arrays */ public static int binarySearch( final char[] a, final char key, final CharComparator c ) { return binarySearch( a, 0, a.length, key, c ); } /** The size of a digit used during radix sort (must be a power of 2). */ private static final int DIGIT_BITS = 8; /** The mask to extract a digit of {@link #DIGIT_BITS} bits. */ private static final int DIGIT_MASK = ( 1 << DIGIT_BITS ) - 1; /** The number of digits per element. */ private static final int DIGITS_PER_ELEMENT = Character.SIZE / DIGIT_BITS; /** This method fixes negative numbers so that the combination exponent/significand is lexicographically sorted. */ /** Sorts the specified array using radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This implementation is significantly faster than quicksort * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. * It will allocate a support array of bytes with the same number of elements as the array to be sorted. * * @param a the array to be sorted. */ public static void radixSort( final char[] a ) { radixSort( a, 0, a.length ); } /** Sorts the specified array using radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This implementation is significantly faster than quicksort * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. * It will allocate a support array of bytes with the same number of elements as the array to be sorted. * * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ public static void radixSort( final char[] a, final int from, final int to ) { final int maxLevel = DIGITS_PER_ELEMENT - 1; final int stackSize = ( ( 1 << DIGIT_BITS ) - 1 ) * ( DIGITS_PER_ELEMENT - 1 ) + 1; final int[] offsetStack = new int[ stackSize ]; int offsetPos = 0; final int[] lengthStack = new int[ stackSize ]; int lengthPos = 0; final int[] levelStack = new int[ stackSize ]; int levelPos = 0; offsetStack[ offsetPos++ ] = from; lengthStack[ lengthPos++ ] = to - from; levelStack[ levelPos++ ] = 0; final int[] count = new int[ 1 << DIGIT_BITS ]; final int[] pos = new int[ 1 << DIGIT_BITS ]; final byte[] digit = new byte[ to - from ]; while( offsetPos > 0 ) { final int first = offsetStack[ --offsetPos ]; final int length = lengthStack[ --lengthPos ]; final int level = levelStack[ --levelPos ]; final int signMask = 0; if ( length < MEDIUM ) { selectionSort( a, first, first + length ); continue; } final int shift = ( DIGITS_PER_ELEMENT - 1 - level % DIGITS_PER_ELEMENT ) * DIGIT_BITS; // This is the shift that extract the right byte from a key // Count keys. for( int i = length; i-- != 0; ) digit[ i ] = (byte)( ( ( (a[ first + i ]) >>> shift ) & DIGIT_MASK ) ^ signMask ); for( int i = length; i-- != 0; ) count[ digit[ i ] & 0xFF ]++; // Compute cumulative distribution and push non-singleton keys on stack. int lastUsed = -1; for( int i = 0, p = 0; i < 1 << DIGIT_BITS; i++ ) { if ( count[ i ] != 0 ) { lastUsed = i; if ( level < maxLevel && count[ i ] > 1 ){ //System.err.println( " Pushing " + new StackEntry( first + pos[ i - 1 ], first + pos[ i ], level + 1 ) ); offsetStack[ offsetPos++ ] = p + first; lengthStack[ lengthPos++ ] = count[ i ]; levelStack[ levelPos++ ] = level + 1; } } pos[ i ] = ( p += count[ i ] ); } // When all slots are OK, the last slot is necessarily OK. final int end = length - count[ lastUsed ]; count[ lastUsed ] = 0; // i moves through the start of each block for( int i = 0, c = -1, d; i < end; i += count[ c ], count[ c ] = 0 ) { char t = a[ i + first ]; c = digit[ i ] & 0xFF; while( ( d = --pos[ c ] ) > i ) { final char z = t; final int zz = c; t = a[ d + first ]; c = digit[ d ] & 0xFF; a[ d + first ] = z; digit[ d ] = (byte)zz; } a[ i + first ] = t; } } } private static void insertionSortIndirect( final int[] perm, final char[] a, final int from, final int to ) { for ( int i = from; ++i < to; ) { int t = perm[ i ]; int j = i; for ( int u = perm[ j - 1 ]; ( (a[ t ]) < (a[ u ]) ); u = perm[ --j - 1 ] ) { perm[ j ] = u; if ( from == j - 1 ) { --j; break; } } perm[ j ] = t; } } /** Sorts the specified array using indirect radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implement an indirect sort. The elements of perm (which must * be exactly the numbers in the interval [0..perm.length)) will be permuted so that * a[ perm[ i ] ] <= a[ perm[ i + 1 ] ]. * *

This implementation is significantly faster than quicksort (unstable) or mergesort (stable) * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. * It will allocate a support array of bytes with the same number of elements as the array to be sorted, * and, in the stable case, a further support array as large as perm (note that the stable * version is slightly faster). * * @param perm a permutation array indexing a. * @param a the array to be sorted. * @param stable whether the sorting algorithm should be stable. */ public static void radixSortIndirect( final int[] perm, final char[] a, final boolean stable ) { radixSortIndirect( perm, a, 0, perm.length, stable ); } /** Sorts the specified array using indirect radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implement an indirect sort. The elements of perm (which must * be exactly the numbers in the interval [0..perm.length)) will be permuted so that * a[ perm[ i ] ] <= a[ perm[ i + 1 ] ]. * *

This implementation is significantly faster than quicksort (unstable) or mergesort (stable) * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. * It will allocate a support array of bytes with the same number of elements as the array to be sorted, * and, in the stable case, a further support array as large as perm (note that the stable * version is slightly faster). * * @param perm a permutation array indexing a. * @param a the array to be sorted. * @param from the index of the first element of perm (inclusive) to be permuted. * @param to the index of the last element of perm (exclusive) to be permuted. * @param stable whether the sorting algorithm should be stable. */ public static void radixSortIndirect( final int[] perm, final char[] a, final int from, final int to, final boolean stable ) { final int maxLevel = DIGITS_PER_ELEMENT - 1; final int stackSize = ( ( 1 << DIGIT_BITS ) - 1 ) * ( DIGITS_PER_ELEMENT - 1 ) + 1; final int[] offsetStack = new int[ stackSize ]; int offsetPos = 0; final int[] lengthStack = new int[ stackSize ]; int lengthPos = 0; final int[] levelStack = new int[ stackSize ]; int levelPos = 0; offsetStack[ offsetPos++ ] = from; lengthStack[ lengthPos++ ] = to - from; levelStack[ levelPos++ ] = 0; final int[] count = new int[ 1 << DIGIT_BITS ]; final int[] pos = stable ? null : new int[ 1 << DIGIT_BITS ]; final int[] support = stable ? new int[ perm.length ] : null; final byte[] digit = new byte[ to - from ]; while( offsetPos > 0 ) { final int first = offsetStack[ --offsetPos ]; final int length = lengthStack[ --lengthPos ]; final int level = levelStack[ --levelPos ]; final int signMask = 0; if ( length < MEDIUM ) { insertionSortIndirect( perm, a, first, first + length ); continue; } final int shift = ( DIGITS_PER_ELEMENT - 1 - level % DIGITS_PER_ELEMENT ) * DIGIT_BITS; // This is the shift that extract the right byte from a key // Count keys. for( int i = length; i-- != 0; ) digit[ i ] = (byte)( ( ( (a[ perm[ first + i ] ]) >>> shift ) & DIGIT_MASK ) ^ signMask ); for( int i = length; i-- != 0; ) count[ digit[ i ] & 0xFF ]++; // Compute cumulative distribution and push non-singleton keys on stack. int lastUsed = -1; for( int i = 0, p = 0; i < 1 << DIGIT_BITS; i++ ) { if ( count[ i ] != 0 ) { lastUsed = i; if ( level < maxLevel && count[ i ] > 1 ){ offsetStack[ offsetPos++ ] = p + first; lengthStack[ lengthPos++ ] = count[ i ]; levelStack[ levelPos++ ] = level + 1; } } if ( stable ) count[ i ] = p += count[ i ]; else pos[ i ] = ( p += count[ i ] ); } if ( stable ) { for( int i = length; i-- != 0; ) support[ --count[ digit[ i ] & 0xFF ] ] = perm[ first + i ]; System.arraycopy( support, 0, perm, first, length ); org.codelibs.jhighlight.fastutil.ints.IntArrays.fill( count, 0 ); } else { // When all slots are OK, the last slot is necessarily OK. final int end = length - count[ lastUsed ]; count[ lastUsed ] = 0; // i moves through the start of each block for( int i = 0, c = -1, d; i < end; i += count[ c ], count[ c ] = 0 ) { int t = perm[ i + first ]; c = digit[ i ] & 0xFF; while( ( d = --pos[ c ] ) > i ) { final int z = t; final int zz = c; t = perm[ d + first ]; c = digit[ d ] & 0xFF; perm[ d + first ] = z; digit[ d ] = (byte)zz; } perm[ i + first ] = t; } } } } private static void selectionSort( final char[] a, final char[] b, final int from, final int to ) { for( int i = from; i < to - 1; i++ ) { int m = i; for( int j = i + 1; j < to; j++ ) if ( a[ j ] < a[ m ] || a[ j ] == a[ m ] && b[ j ] < b[ m ] ) m = j; if ( m != i ) { char t = a[ i ]; a[ i ] = a[ m ]; a[ m ] = t; t = b[ i ]; b[ i ] = b[ m ]; b[ m ] = t; } } } /** Sorts the specified pair of arrays lexicographically using radix sort. *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implements a lexicographical sorting of the arguments. Pairs of elements * in the same position in the two provided arrays will be considered a single key, and permuted * accordingly. In the end, either a[ i ] < a[ i + 1 ] or a[ i ] == a[ i + 1 ] and b[ i ] <= b[ i + 1 ]. * *

This implementation is significantly faster than quicksort * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. It will allocate a support array of bytes with the same number of elements as the arrays to be sorted. * * @param a the first array to be sorted. * @param b the second array to be sorted. */ public static void radixSort( final char[] a, final char[] b ) { radixSort( a, b, 0, a.length ); } /** Sorts the specified pair of arrays lexicographically using radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implements a lexicographical sorting of the arguments. Pairs of elements * in the same position in the two provided arrays will be considered a single key, and permuted * accordingly. In the end, either a[ i ] < a[ i + 1 ] or a[ i ] == a[ i + 1 ] and b[ i ] <= b[ i + 1 ]. * *

This implementation is significantly faster than quicksort * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. It will allocate a support array of bytes with the same number of elements as the arrays to be sorted. * * @param a the first array to be sorted. * @param b the second array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ public static void radixSort( final char[] a, final char[] b, final int from, final int to ) { final int layers = 2; if ( a.length != b.length ) throw new IllegalArgumentException( "Array size mismatch." ); final int maxLevel = DIGITS_PER_ELEMENT * layers - 1; final int stackSize = ( ( 1 << DIGIT_BITS ) - 1 ) * ( layers * DIGITS_PER_ELEMENT - 1 ) + 1; final int[] offsetStack = new int[ stackSize ]; int offsetPos = 0; final int[] lengthStack = new int[ stackSize ]; int lengthPos = 0; final int[] levelStack = new int[ stackSize ]; int levelPos = 0; offsetStack[ offsetPos++ ] = from; lengthStack[ lengthPos++ ] = to - from; levelStack[ levelPos++ ] = 0; final int[] count = new int[ 1 << DIGIT_BITS ]; final int[] pos = new int[ 1 << DIGIT_BITS ]; final byte[] digit = new byte[ to - from ]; while( offsetPos > 0 ) { final int first = offsetStack[ --offsetPos ]; final int length = lengthStack[ --lengthPos ]; final int level = levelStack[ --levelPos ]; final int signMask = 0; if ( length < MEDIUM ) { selectionSort( a, b, first, first + length ); continue; } final char[] k = level < DIGITS_PER_ELEMENT ? a : b; // This is the key array final int shift = ( DIGITS_PER_ELEMENT - 1 - level % DIGITS_PER_ELEMENT ) * DIGIT_BITS; // This is the shift that extract the right byte from a key // Count keys. for( int i = length; i-- != 0; ) digit[ i ] = (byte)( ( ( (k[ first + i ]) >>> shift ) & DIGIT_MASK ) ^ signMask ); for( int i = length; i-- != 0; ) count[ digit[ i ] & 0xFF ]++; // Compute cumulative distribution and push non-singleton keys on stack. int lastUsed = -1; for( int i = 0, p = 0; i < 1 << DIGIT_BITS; i++ ) { if ( count[ i ] != 0 ) { lastUsed = i; if ( level < maxLevel && count[ i ] > 1 ){ offsetStack[ offsetPos++ ] = p + first; lengthStack[ lengthPos++ ] = count[ i ]; levelStack[ levelPos++ ] = level + 1; } } pos[ i ] = ( p += count[ i ] ); } // When all slots are OK, the last slot is necessarily OK. final int end = length - count[ lastUsed ]; count[ lastUsed ] = 0; // i moves through the start of each block for( int i = 0, c = -1, d; i < end; i += count[ c ], count[ c ] = 0 ) { char t = a[ i + first ]; char u = b[ i + first ]; c = digit[ i ] & 0xFF; while( ( d = --pos[ c ] ) > i ) { char z = t; final int zz = c; t = a[ d + first ]; a[ d + first ] = z; z = u; u = b[ d + first ]; b[ d + first ] = z; c = digit[ d ] & 0xFF; digit[ d ] = (byte)zz; } a[ i + first ] = t; b[ i + first ] = u; } } } private static void insertionSortIndirect( final int[] perm, final char[] a, final char[] b, final int from, final int to ) { for ( int i = from; ++i < to; ) { int t = perm[ i ]; int j = i; for ( int u = perm[ j - 1 ]; ( (a[ t ]) < (a[ u ]) ) || ( (a[ t ]) == (a[ u ]) ) && ( (b[ t ]) < (b[ u ]) ); u = perm[ --j - 1 ] ) { perm[ j ] = u; if ( from == j - 1 ) { --j; break; } } perm[ j ] = t; } } /** Sorts the specified pair of arrays lexicographically using indirect radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implement an indirect sort. The elements of perm (which must * be exactly the numbers in the interval [0..perm.length)) will be permuted so that * a[ perm[ i ] ] <= a[ perm[ i + 1 ] ]. * *

This implementation is significantly faster than quicksort (unstable) or mergesort (stable) * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. * It will allocate a support array of bytes with the same number of elements as the array to be sorted, * and, in the stable case, a further support array as large as perm (note that the stable * version is slightly faster). * * @param perm a permutation array indexing a. * @param a the array to be sorted. * @param b the second array to be sorted. * @param stable whether the sorting algorithm should be stable. */ public static void radixSortIndirect( final int[] perm, final char[] a, final char[] b, final boolean stable ) { radixSortIndirect( perm, a, b, 0, perm.length, stable ); } /** Sorts the specified pair of arrays lexicographically using indirect radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implement an indirect sort. The elements of perm (which must * be exactly the numbers in the interval [0..perm.length)) will be permuted so that * a[ perm[ i ] ] <= a[ perm[ i + 1 ] ]. * *

This implementation is significantly faster than quicksort (unstable) or mergesort (stable) * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. * It will allocate a support array of bytes with the same number of elements as the array to be sorted, * and, in the stable case, a further support array as large as perm (note that the stable * version is slightly faster). * * @param perm a permutation array indexing a. * @param a the array to be sorted. * @param b the second array to be sorted. * @param from the index of the first element of perm (inclusive) to be permuted. * @param to the index of the last element of perm (exclusive) to be permuted. * @param stable whether the sorting algorithm should be stable. */ public static void radixSortIndirect( final int[] perm, final char[] a, final char[] b, final int from, final int to, final boolean stable ) { final int layers = 2; if ( a.length != b.length ) throw new IllegalArgumentException( "Array size mismatch." ); final int maxLevel = DIGITS_PER_ELEMENT * layers - 1; final int stackSize = ( ( 1 << DIGIT_BITS ) - 1 ) * ( layers * DIGITS_PER_ELEMENT - 1 ) + 1; final int[] offsetStack = new int[ stackSize ]; int offsetPos = 0; final int[] lengthStack = new int[ stackSize ]; int lengthPos = 0; final int[] levelStack = new int[ stackSize ]; int levelPos = 0; offsetStack[ offsetPos++ ] = from; lengthStack[ lengthPos++ ] = to - from; levelStack[ levelPos++ ] = 0; final int[] count = new int[ 1 << DIGIT_BITS ]; final int[] pos = stable ? null : new int[ 1 << DIGIT_BITS ]; final int[] support = stable ? new int[ perm.length ] : null; final byte[] digit = new byte[ to - from ]; while( offsetPos > 0 ) { final int first = offsetStack[ --offsetPos ]; final int length = lengthStack[ --lengthPos ]; final int level = levelStack[ --levelPos ]; final int signMask = 0; if ( length < MEDIUM ) { insertionSortIndirect( perm, a, b, first, first + length ); continue; } final char[] k = level < DIGITS_PER_ELEMENT ? a : b; // This is the key array final int shift = ( DIGITS_PER_ELEMENT - 1 - level % DIGITS_PER_ELEMENT ) * DIGIT_BITS; // This is the shift that extract the right byte from a key // Count keys. for( int i = length; i-- != 0; ) digit[ i ] = (byte)( ( ( (k[ perm[ first + i ] ]) >>> shift ) & DIGIT_MASK ) ^ signMask ); for( int i = length; i-- != 0; ) count[ digit[ i ] & 0xFF ]++; // Compute cumulative distribution and push non-singleton keys on stack. int lastUsed = -1; for( int i = 0, p = 0; i < 1 << DIGIT_BITS; i++ ) { if ( count[ i ] != 0 ) { lastUsed = i; if ( level < maxLevel && count[ i ] > 1 ){ offsetStack[ offsetPos++ ] = p + first; lengthStack[ lengthPos++ ] = count[ i ]; levelStack[ levelPos++ ] = level + 1; } } if ( stable ) count[ i ] = p += count[ i ]; else pos[ i ] = ( p += count[ i ] ); } if ( stable ) { for( int i = length; i-- != 0; ) support[ --count[ digit[ i ] & 0xFF ] ] = perm[ first + i ]; System.arraycopy( support, 0, perm, first, length ); org.codelibs.jhighlight.fastutil.ints.IntArrays.fill( count, 0 ); } else { // When all slots are OK, the last slot is necessarily OK. final int end = length - count[ lastUsed ]; count[ lastUsed ] = 0; // i moves through the start of each block for( int i = 0, c = -1, d; i < end; i += count[ c ], count[ c ] = 0 ) { int t = perm[ i + first ]; c = digit[ i ] & 0xFF; while( ( d = --pos[ c ] ) > i ) { final int z = t; final int zz = c; t = perm[ d + first ]; c = digit[ d ] & 0xFF; perm[ d + first ] = z; digit[ d ] = (byte)zz; } perm[ i + first ] = t; } } } } private static void selectionSort( final char[][] a, final int from, final int to, final int level ) { final int layers = a.length; final int firstLayer = level / DIGITS_PER_ELEMENT; for( int i = from; i < to - 1; i++ ) { int m = i; for( int j = i + 1; j < to; j++ ) { for( int p = firstLayer; p < layers; p++ ) { if ( a[ p ][ j ] < a[ p ][ m ] ) { m = j; break; } else if ( a[ p ][ j ] > a[ p ][ m ] ) break; } } if ( m != i ) { for( int p = layers; p-- != 0; ) { final char u = a[ p ][ i ]; a[ p ][ i ] = a[ p ][ m ]; a[ p ][ m ] = u; } } } } /** Sorts the specified array of arrays lexicographically using radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implements a lexicographical sorting of the provided arrays. Tuples of elements * in the same position will be considered a single key, and permuted * accordingly. * *

This implementation is significantly faster than quicksort * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. It will allocate a support array of bytes with the same number of elements as the arrays to be sorted. * * @param a an array containing arrays of equal length to be sorted lexicographically in parallel. */ public static void radixSort( final char[][] a ) { radixSort( a, 0, a[ 0 ].length ); } /** Sorts the specified array of arrays lexicographically using radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implements a lexicographical sorting of the provided arrays. Tuples of elements * in the same position will be considered a single key, and permuted * accordingly. * *

This implementation is significantly faster than quicksort * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. It will allocate a support array of bytes with the same number of elements as the arrays to be sorted. * * @param a an array containing arrays of equal length to be sorted lexicographically in parallel. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ public static void radixSort( final char[][] a, final int from, final int to ) { final int layers = a.length; final int maxLevel = DIGITS_PER_ELEMENT * layers - 1; for( int p = layers, l = a[ 0 ].length; p-- != 0; ) if ( a[ p ].length != l ) throw new IllegalArgumentException( "The array of index " + p + " has not the same length of the array of index 0." ); final int stackSize = ( ( 1 << DIGIT_BITS ) - 1 ) * ( layers * DIGITS_PER_ELEMENT - 1 ) + 1; final int[] offsetStack = new int[ stackSize ]; int offsetPos = 0; final int[] lengthStack = new int[ stackSize ]; int lengthPos = 0; final int[] levelStack = new int[ stackSize ]; int levelPos = 0; offsetStack[ offsetPos++ ] = from; lengthStack[ lengthPos++ ] = to - from; levelStack[ levelPos++ ] = 0; final int[] count = new int[ 1 << DIGIT_BITS ]; final int[] pos = new int[ 1 << DIGIT_BITS ]; final byte[] digit = new byte[ to - from ]; final char[] t = new char[ layers ]; while( offsetPos > 0 ) { final int first = offsetStack[ --offsetPos ]; final int length = lengthStack[ --lengthPos ]; final int level = levelStack[ --levelPos ]; final int signMask = 0; if ( length < MEDIUM ) { selectionSort( a, first, first + length, level ); continue; } final char[] k = a[ level / DIGITS_PER_ELEMENT ]; // This is the key array final int shift = ( DIGITS_PER_ELEMENT - 1 - level % DIGITS_PER_ELEMENT ) * DIGIT_BITS; // This is the shift that extract the right byte from a key // Count keys. for( int i = length; i-- != 0; ) digit[ i ] = (byte)( ( (k[ first + i ]) >>> shift & DIGIT_MASK ) ^ signMask ); for( int i = length; i-- != 0; ) count[ digit[ i ] & 0xFF ]++; // Compute cumulative distribution and push non-singleton keys on stack. int lastUsed = -1; for( int i = 0, p = 0; i < 1 << DIGIT_BITS; i++ ) { if ( count[ i ] != 0 ) { lastUsed = i; if ( level < maxLevel && count[ i ] > 1 ){ offsetStack[ offsetPos++ ] = p + first; lengthStack[ lengthPos++ ] = count[ i ]; levelStack[ levelPos++ ] = level + 1; } } pos[ i ] = ( p += count[ i ] ); } // When all slots are OK, the last slot is necessarily OK. final int end = length - count[ lastUsed ]; count[ lastUsed ] = 0; // i moves through the start of each block for( int i = 0, c = -1, d; i < end; i += count[ c ], count[ c ] = 0 ) { for( int p = layers; p-- != 0; ) t[ p ] = a[ p ][ i + first ]; c = digit[ i ] & 0xFF; while( ( d = --pos[ c ] ) > i ) { for( int p = layers; p-- != 0; ) { final char u = t[ p ]; t[ p ] = a[ p ][ d + first ]; a[ p ][ d + first ] = u; } final int zz = c; c = digit[ d ] & 0xFF; digit[ d ] = (byte)zz; } for( int p = layers; p-- != 0; ) a[ p ][ i + first ] = t[ p ]; } } } /** Shuffles the specified array fragment using the specified pseudorandom number generator. * * @param a the array to be shuffled. * @param from the index of the first element (inclusive) to be shuffled. * @param to the index of the last element (exclusive) to be shuffled. * @param random a pseudorandom number generator (please use a XorShift* generator). * @return a. */ public static char[] shuffle( final char[] a, final int from, final int to, final Random random ) { for( int i = to - from; i-- != 0; ) { final int p = random.nextInt( i + 1 ); final char t = a[ from + i ]; a[ from + i ] = a[ from + p ]; a[ from + p ] = t; } return a; } /** Shuffles the specified array using the specified pseudorandom number generator. * * @param a the array to be shuffled. * @param random a pseudorandom number generator (please use a XorShift* generator). * @return a. */ public static char[] shuffle( final char[] a, final Random random ) { for( int i = a.length; i-- != 0; ) { final int p = random.nextInt( i + 1 ); final char t = a[ i ]; a[ i ] = a[ p ]; a[ p ] = t; } return a; } /** Reverses the order of the elements in the specified array. * * @param a the array to be reversed. * @return a. */ public static char[] reverse( final char[] a ) { final int length = a.length; for( int i = length / 2; i-- != 0; ) { final char t = a[ length - i - 1 ]; a[ length - i - 1 ] = a[ i ]; a[ i ] = t; } return a; } /** Reverses the order of the elements in the specified array fragment. * * @param a the array to be reversed. * @param from the index of the first element (inclusive) to be reversed. * @param to the index of the last element (exclusive) to be reversed. * @return a. */ public static char[] reverse( final char[] a, final int from, final int to ) { final int length = to - from; for( int i = length / 2; i-- != 0; ) { final char t = a[ from + length - i - 1 ]; a[ from + length - i - 1 ] = a[ from + i ]; a[ from + i ] = t; } return a; } /** A type-specific content-based hash strategy for arrays. */ private static final class ArrayHashStrategy implements Hash.Strategy, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; public int hashCode( final char[] o ) { return java.util.Arrays.hashCode( o ); } public boolean equals( final char[] a, final char[] b ) { return java.util.Arrays.equals( a, b ); } } /** A type-specific content-based hash strategy for arrays. * *

This hash strategy may be used in custom hash collections whenever keys are * arrays, and they must be considered equal by content. This strategy * will handle null correctly, and it is serializable. */ public final static Hash.Strategy HASH_STRATEGY = new ArrayHashStrategy(); } CharBidirectionalIterator.java000066400000000000000000000046271422762524200357170ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import org.codelibs.jhighlight.fastutil.BidirectionalIterator; import org.codelibs.jhighlight.fastutil.objects.ObjectBidirectionalIterator; /** A type-specific bidirectional iterator; provides an additional method to avoid (un)boxing, * and the possibility to skip elements backwards. * * @see BidirectionalIterator */ public interface CharBidirectionalIterator extends CharIterator , ObjectBidirectionalIterator { /** * Returns the previous element as a primitive type. * * @return the previous element in the iteration. * @see java.util.ListIterator#previous() */ char previousChar(); /** Moves back for the given number of elements. * *

The effect of this call is exactly the same as that of * calling {@link #previous()} for n times (possibly stopping * if {@link #hasPrevious()} becomes false). * * @param n the number of elements to skip back. * @return the number of elements actually skipped. * @see java.util.Iterator#next() */ int back( int n ); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/CharCollection.java000066400000000000000000000121661422762524200336040ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import java.util.Collection; /** A type-specific {@link Collection}; provides some additional methods * that use polymorphism to avoid (un)boxing. * *

Additionally, this class defines strengthens (again) {@link #iterator()} and defines * a slightly different semantics for {@link #toArray(Object[])}. * * @see Collection */ public interface CharCollection extends Collection, CharIterable { /** Returns a type-specific iterator on the elements of this collection. * *

Note that this specification strengthens the one given in * {@link java.lang.Iterable#iterator()}, which was already * strengthened in the corresponding type-specific class, * but was weakened by the fact that this interface extends {@link Collection}. * * @return a type-specific iterator on the elements of this collection. */ CharIterator iterator(); /** Returns a type-specific iterator on this elements of this collection. * * @see #iterator() * @deprecated As of fastutil 5, replaced by {@link #iterator()}. */ @Deprecated CharIterator charIterator(); /** Returns an containing the items of this collection; * the runtime type of the returned array is that of the specified array. * *

Warning: Note that, contrarily to {@link Collection#toArray(Object[])}, this * methods just writes all elements of this collection: no special * value will be added after the last one. * * @param a if this array is big enough, it will be used to store this collection. * @return a primitive type array containing the items of this collection. * @see Collection#toArray(Object[]) */ T[] toArray(T[] a); /** * @see Collection#contains(Object) */ boolean contains( char key ); /** Returns a primitive type array containing the items of this collection. * @return a primitive type array containing the items of this collection. * @see Collection#toArray() */ char[] toCharArray(); /** Returns a primitive type array containing the items of this collection. * *

Note that, contrarily to {@link Collection#toArray(Object[])}, this * methods just writes all elements of this collection: no special * value will be added after the last one. * * @param a if this array is big enough, it will be used to store this collection. * @return a primitive type array containing the items of this collection. * @see Collection#toArray(Object[]) */ char[] toCharArray( char a[] ); /** Returns a primitive type array containing the items of this collection. * *

Note that, contrarily to {@link Collection#toArray(Object[])}, this * methods just writes all elements of this collection: no special * value will be added after the last one. * * @param a if this array is big enough, it will be used to store this collection. * @return a primitive type array containing the items of this collection. * @see Collection#toArray(Object[]) */ char[] toArray( char a[] ); /** * @see Collection#add(Object) */ boolean add( char key ); /** Note that this method should be called {@link java.util.Collection#remove(Object) remove()}, but the clash * with the similarly named index-based method in the {@link java.util.List} interface * forces us to use a distinguished name. For simplicity, the set interfaces reinstates * remove(). * * @see Collection#remove(Object) */ boolean rem( char key ); /** * @see Collection#addAll(Collection) */ boolean addAll( CharCollection c ); /** * @see Collection#containsAll(Collection) */ boolean containsAll( CharCollection c ); /** * @see Collection#removeAll(Collection) */ boolean removeAll( CharCollection c ); /** * @see Collection#retainAll(Collection) */ boolean retainAll( CharCollection c ); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/CharComparator.java000066400000000000000000000041511422762524200336130ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import java.util.Comparator; /** A type-specific {@link Comparator}; provides methods to compare two primitive types both as objects * and as primitive types. * *

Note that fastutil provides a corresponding abstract class that * can be used to implement this interface just by specifying the type-specific * comparator. * * @see Comparator */ public interface CharComparator extends Comparator { /** Compares the given primitive types. * * @see java.util.Comparator * @return A positive integer, zero, or a negative integer if the first * argument is greater than, equal to, or smaller than, respectively, the * second one. */ public int compare( char k1, char k2 ); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/CharIterable.java000066400000000000000000000042101422762524200332270ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; /** A type-specific {@link Iterable} that strengthens that specification of {@link Iterable#iterator()}. * *

Warning: Java will let you write “colon” for statements with primitive-type * loop variables; however, what is (unfortunately) really happening is that at each iteration an * unboxing (and, in the case of fastutil type-specific data structures, a boxing) will be performed. Watch out. * * @see Iterable */ public interface CharIterable extends Iterable { /** Returns a type-specific iterator. * * Note that this specification strengthens the one given in {@link Iterable#iterator()}. * * @return a type-specific iterator. */ CharIterator iterator(); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/CharIterator.java000066400000000000000000000042341422762524200332770ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import java.util.Iterator; /** A type-specific {@link Iterator}; provides an additional method to avoid (un)boxing, and * the possibility to skip elements. * * @see Iterator */ public interface CharIterator extends Iterator { /** * Returns the next element as a primitive type. * * @return the next element in the iteration. * @see Iterator#next() */ char nextChar(); /** Skips the given number of elements. * *

The effect of this call is exactly the same as that of * calling {@link #next()} for n times (possibly stopping * if {@link #hasNext()} becomes false). * * @param n the number of elements to skip. * @return the number of elements actually skipped. * @see Iterator#next() */ int skip( int n ); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/CharIterators.java000066400000000000000000000561651422762524200334740ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import java.util.Iterator; import java.util.ListIterator; import java.util.NoSuchElementException; /** A class providing static methods and objects that do useful things with type-specific iterators. * * @see Iterator */ public class CharIterators { private CharIterators() {} /** A class returning no elements and a type-specific iterator interface. * *

This class may be useful to implement your own in case you subclass * a type-specific iterator. */ public static class EmptyIterator extends AbstractCharListIterator implements java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; protected EmptyIterator() {} public boolean hasNext() { return false; } public boolean hasPrevious() { return false; } public char nextChar() { throw new NoSuchElementException(); } public char previousChar() { throw new NoSuchElementException(); } public int nextIndex() { return 0; } public int previousIndex() { return -1; } public int skip( int n ) { return 0; }; public int back( int n ) { return 0; }; public Object clone() { return EMPTY_ITERATOR; } private Object readResolve() { return EMPTY_ITERATOR; } } /** An empty iterator (immutable). It is serializable and cloneable. * *

The class of this objects represent an abstract empty iterator * that can iterate as a type-specific (list) iterator. */ @SuppressWarnings("rawtypes") public final static EmptyIterator EMPTY_ITERATOR = new EmptyIterator(); /** An iterator returning a single element. */ private static class SingletonIterator extends AbstractCharListIterator { private final char element; private int curr; public SingletonIterator( final char element ) { this.element = element; } public boolean hasNext() { return curr == 0; } public boolean hasPrevious() { return curr == 1; } public char nextChar() { if ( ! hasNext() ) throw new NoSuchElementException(); curr = 1; return element; } public char previousChar() { if ( ! hasPrevious() ) throw new NoSuchElementException(); curr = 0; return element; } public int nextIndex() { return curr; } public int previousIndex() { return curr - 1; } } /** Returns an iterator that iterates just over the given element. * * @param element the only element to be returned by a type-specific list iterator. * @return an iterator that iterates just over element. */ public static CharListIterator singleton( final char element ) { return new SingletonIterator ( element ); } /** A class to wrap arrays in iterators. */ private static class ArrayIterator extends AbstractCharListIterator { private final char[] array; private final int offset, length; private int curr; public ArrayIterator( final char[] array, final int offset, final int length ) { this.array = array; this.offset = offset; this.length = length; } public boolean hasNext() { return curr < length; } public boolean hasPrevious() { return curr > 0; } public char nextChar() { if ( ! hasNext() ) throw new NoSuchElementException(); return array[ offset + curr++ ]; } public char previousChar() { if ( ! hasPrevious() ) throw new NoSuchElementException(); return array[ offset + --curr ]; } public int skip( int n ) { if ( n <= length - curr ) { curr += n; return n; } n = length - curr; curr = length; return n; } public int back( int n ) { if ( n <= curr ) { curr -= n; return n; } n = curr; curr = 0; return n; } public int nextIndex() { return curr; } public int previousIndex() { return curr - 1; } } /** Wraps the given part of an array into a type-specific list iterator. * *

The type-specific list iterator returned by this method will iterate * length times, returning consecutive elements of the given * array starting from the one with index offset. * * @param array an array to wrap into a type-specific list iterator. * @param offset the first element of the array to be returned. * @param length the number of elements to return. */ public static CharListIterator wrap( final char[] array, final int offset, final int length ) { CharArrays.ensureOffsetLength( array, offset, length ); return new ArrayIterator ( array, offset, length ); } /** Wraps the given array into a type-specific list iterator. * *

The type-specific list iterator returned by this method will return * all elements of the given array. * * @param array an array to wrap into a type-specific list iterator. */ public static CharListIterator wrap( final char[] array ) { return new ArrayIterator ( array, 0, array.length ); } /** Unwraps an iterator into an array starting at a given offset for a given number of elements. * *

This method iterates over the given type-specific iterator and stores the elements * returned, up to a maximum of length, in the given array starting at offset. * The number of actually unwrapped elements is returned (it may be less than max if * the iterator emits less than max elements). * * @param i a type-specific iterator. * @param array an array to contain the output of the iterator. * @param offset the first element of the array to be returned. * @param max the maximum number of elements to unwrap. * @return the number of elements unwrapped. */ public static int unwrap( final CharIterator i, final char array[], int offset, final int max ) { if ( max < 0 ) throw new IllegalArgumentException( "The maximum number of elements (" + max + ") is negative" ); if ( offset < 0 || offset + max > array.length ) throw new IllegalArgumentException(); int j = max; while( j-- != 0 && i.hasNext() ) array[ offset++ ] = i.nextChar(); return max - j - 1; } /** Unwraps an iterator into an array. * *

This method iterates over the given type-specific iterator and stores the * elements returned in the given array. The iteration will stop when the * iterator has no more elements or when the end of the array has been reached. * * @param i a type-specific iterator. * @param array an array to contain the output of the iterator. * @return the number of elements unwrapped. */ public static int unwrap( final CharIterator i, final char array[] ) { return unwrap( i, array, 0, array.length ); } /** Unwraps an iterator, returning an array, with a limit on the number of elements. * *

This method iterates over the given type-specific iterator and returns an array * containing the elements returned by the iterator. At most max elements * will be returned. * * @param i a type-specific iterator. * @param max the maximum number of elements to be unwrapped. * @return an array containing the elements returned by the iterator (at most max). */ @SuppressWarnings("unchecked") public static char[] unwrap( final CharIterator i, int max ) { if ( max < 0 ) throw new IllegalArgumentException( "The maximum number of elements (" + max + ") is negative" ); char array[] = new char[ 16 ]; int j = 0; while( max-- != 0 && i.hasNext() ) { if ( j == array.length ) array = CharArrays.grow( array, j + 1 ); array[ j++ ] = i.nextChar(); } return CharArrays.trim( array, j ); } /** Unwraps an iterator, returning an array. * *

This method iterates over the given type-specific iterator and returns an array * containing the elements returned by the iterator. * * @param i a type-specific iterator. * @return an array containing the elements returned by the iterator. */ public static char[] unwrap( final CharIterator i ) { return unwrap( i, Integer.MAX_VALUE ); } /** Unwraps an iterator into a type-specific collection, with a limit on the number of elements. * *

This method iterates over the given type-specific iterator and stores the elements * returned, up to a maximum of max, in the given type-specific collection. * The number of actually unwrapped elements is returned (it may be less than max if * the iterator emits less than max elements). * * @param i a type-specific iterator. * @param c a type-specific collection array to contain the output of the iterator. * @param max the maximum number of elements to unwrap. * @return the number of elements unwrapped. Note that * this is the number of elements returned by the iterator, which is not necessarily the number * of elements that have been added to the collection (because of duplicates). */ public static int unwrap( final CharIterator i, final CharCollection c, final int max ) { if ( max < 0 ) throw new IllegalArgumentException( "The maximum number of elements (" + max + ") is negative" ); int j = max; while( j-- != 0 && i.hasNext() ) c.add( i.nextChar() ); return max - j - 1; } /** Unwraps an iterator into a type-specific collection. * *

This method iterates over the given type-specific iterator and stores the * elements returned in the given type-specific collection. The returned count on the number * unwrapped elements is a long, so that it will work also with very large collections. * * @param i a type-specific iterator. * @param c a type-specific collection to contain the output of the iterator. * @return the number of elements unwrapped. Note that * this is the number of elements returned by the iterator, which is not necessarily the number * of elements that have been added to the collection (because of duplicates). */ public static long unwrap( final CharIterator i, final CharCollection c ) { long n = 0; while( i.hasNext() ) { c.add( i.nextChar() ); n++; } return n; } /** Pours an iterator into a type-specific collection, with a limit on the number of elements. * *

This method iterates over the given type-specific iterator and adds * the returned elements to the given collection (up to max). * * @param i a type-specific iterator. * @param s a type-specific collection. * @param max the maximum number of elements to be poured. * @return the number of elements poured. Note that * this is the number of elements returned by the iterator, which is not necessarily the number * of elements that have been added to the collection (because of duplicates). */ public static int pour( final CharIterator i, final CharCollection s, final int max ) { if ( max < 0 ) throw new IllegalArgumentException( "The maximum number of elements (" + max + ") is negative" ); int j = max; while( j-- != 0 && i.hasNext() ) s.add( i.nextChar() ); return max - j - 1; } /** Pours an iterator into a type-specific collection. * *

This method iterates over the given type-specific iterator and adds * the returned elements to the given collection. * * @param i a type-specific iterator. * @param s a type-specific collection. * @return the number of elements poured. Note that * this is the number of elements returned by the iterator, which is not necessarily the number * of elements that have been added to the collection (because of duplicates). */ public static int pour( final CharIterator i, final CharCollection s ) { return pour( i, s, Integer.MAX_VALUE ); } /** Pours an iterator, returning a type-specific list, with a limit on the number of elements. * *

This method iterates over the given type-specific iterator and returns * a type-specific list containing the returned elements (up to max). Iteration * on the returned list is guaranteed to produce the elements in the same order * in which they appeared in the iterator. * * * @param i a type-specific iterator. * @param max the maximum number of elements to be poured. * @return a type-specific list containing the returned elements, up to max. */ public static CharList pour( final CharIterator i, int max ) { final CharArrayList l = new CharArrayList (); pour( i, l, max ); l.trim(); return l; } /** Pours an iterator, returning a type-specific list. * *

This method iterates over the given type-specific iterator and returns * a list containing the returned elements. Iteration * on the returned list is guaranteed to produce the elements in the same order * in which they appeared in the iterator. * * @param i a type-specific iterator. * @return a type-specific list containing the returned elements. */ public static CharList pour( final CharIterator i ) { return pour( i, Integer.MAX_VALUE ); } private static class IteratorWrapper extends AbstractCharIterator { final Iterator i; public IteratorWrapper( final Iterator i ) { this.i = i; } public boolean hasNext() { return i.hasNext(); } public void remove() { i.remove(); } public char nextChar() { return ((i.next()).charValue()); } } /** Wraps a standard iterator into a type-specific iterator. * *

This method wraps a standard iterator into a type-specific one which will handle the * type conversions for you. Of course, any attempt to wrap an iterator returning the * instances of the wrong class will generate a {@link ClassCastException}. The * returned iterator is backed by i: changes to one of the iterators * will affect the other, too. * *

If i is already type-specific, it will returned and no new object * will be generated. * * @param i an iterator. * @return a type-specific iterator backed by i. */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static CharIterator asCharIterator( final Iterator i ) { if ( i instanceof CharIterator ) return (CharIterator )i; return new IteratorWrapper ( i ); } private static class ListIteratorWrapper extends AbstractCharListIterator { final ListIterator i; public ListIteratorWrapper( final ListIterator i ) { this.i = i; } public boolean hasNext() { return i.hasNext(); } public boolean hasPrevious() { return i.hasPrevious(); } public int nextIndex() { return i.nextIndex(); } public int previousIndex() { return i.previousIndex(); } @SuppressWarnings("unchecked") public void set( char k ) { i.set( (Character.valueOf(k)) ); } @SuppressWarnings("unchecked") public void add( char k ) { i.add( (Character.valueOf(k)) ); } public void remove() { i.remove(); } public char nextChar() { return ((i.next()).charValue()); } public char previousChar() { return ((i.previous()).charValue()); } } /** Wraps a standard list iterator into a type-specific list iterator. * *

This method wraps a standard list iterator into a type-specific one * which will handle the type conversions for you. Of course, any attempt * to wrap an iterator returning the instances of the wrong class will * generate a {@link ClassCastException}. The * returned iterator is backed by i: changes to one of the iterators * will affect the other, too. * *

If i is already type-specific, it will returned and no new object * will be generated. * * @param i a list iterator. * @return a type-specific list iterator backed by i. */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static CharListIterator asCharIterator( final ListIterator i ) { if ( i instanceof CharListIterator ) return (CharListIterator )i; return new ListIteratorWrapper ( i ); } private static class IntervalIterator extends AbstractCharListIterator { private final char from, to; char curr; public IntervalIterator( final char from, final char to ) { this.from = this.curr = from; this.to = to; } public boolean hasNext() { return curr < to; } public boolean hasPrevious() { return curr > from; } public char nextChar() { if ( ! hasNext() ) throw new NoSuchElementException(); return curr++; } public char previousChar() { if ( ! hasPrevious() ) throw new NoSuchElementException(); return --curr; } public int nextIndex() { return curr - from; } public int previousIndex() { return curr - from - 1; } public int skip( int n ) { if ( curr + n <= to ) { curr += n; return n; } n = to - curr; curr = to; return n; } public int back( int n ) { if ( curr - n >= from ) { curr -= n; return n; } n = curr - from ; curr = from; return n; } } /** Creates a type-specific list iterator over an interval. * *

The type-specific list iterator returned by this method will return the * elements from, from+1,…, to-1. * * @param from the starting element (inclusive). * @param to the ending element (exclusive). * @return a type-specific list iterator enumerating the elements from from to to. */ public static CharListIterator fromTo( final char from, final char to ) { return new IntervalIterator( from, to ); } private static class IteratorConcatenator extends AbstractCharIterator { final CharIterator a[]; int offset, length, lastOffset = -1; public IteratorConcatenator( final CharIterator a[], int offset, int length ) { this.a = a; this.offset = offset; this.length = length; advance(); } private void advance() { while( length != 0 ) { if ( a[ offset ].hasNext() ) break; length--; offset++; } return; } public boolean hasNext() { return length > 0; } public char nextChar() { if ( ! hasNext() ) throw new NoSuchElementException(); char next = a[ lastOffset = offset ].nextChar(); advance(); return next; } public void remove() { if ( lastOffset == -1 ) throw new IllegalStateException(); a[ lastOffset ].remove(); } public int skip( int n ) { lastOffset = -1; int skipped = 0; while( skipped < n && length != 0 ) { skipped += a[ offset ].skip( n - skipped ); if ( a[ offset ].hasNext() ) break; length--; offset++; } return skipped; } } /** Concatenates all iterators contained in an array. * *

This method returns an iterator that will enumerate in order the elements returned * by all iterators contained in the given array. * * @param a an array of iterators. * @return an iterator obtained by concatenation. */ public static CharIterator concat( final CharIterator a[] ) { return concat( a, 0, a.length ); } /** Concatenates a sequence of iterators contained in an array. * *

This method returns an iterator that will enumerate in order the elements returned * by a[ offset ], then those returned * by a[ offset + 1 ], and so on up to * a[ offset + length - 1 ]. * * @param a an array of iterators. * @param offset the index of the first iterator to concatenate. * @param length the number of iterators to concatenate. * @return an iterator obtained by concatenation of length elements of a starting at offset. */ public static CharIterator concat( final CharIterator a[], final int offset, final int length ) { return new IteratorConcatenator ( a, offset, length ); } /** An unmodifiable wrapper class for iterators. */ public static class UnmodifiableIterator extends AbstractCharIterator { final protected CharIterator i; @SuppressWarnings("unchecked") public UnmodifiableIterator( final CharIterator i ) { this.i = i; } public boolean hasNext() { return i.hasNext(); } public char nextChar() { return i.nextChar(); } public Character next() { return i.next(); } } /** Returns an unmodifiable iterator backed by the specified iterator. * * @param i the iterator to be wrapped in an unmodifiable iterator. * @return an unmodifiable view of the specified iterator. */ public static CharIterator unmodifiable( final CharIterator i ) { return new UnmodifiableIterator ( i ); } /** An unmodifiable wrapper class for bidirectional iterators. */ public static class UnmodifiableBidirectionalIterator extends AbstractCharBidirectionalIterator { final protected CharBidirectionalIterator i; @SuppressWarnings("unchecked") public UnmodifiableBidirectionalIterator( final CharBidirectionalIterator i ) { this.i = i; } public boolean hasNext() { return i.hasNext(); } public boolean hasPrevious() { return i.hasPrevious(); } public char nextChar() { return i.nextChar(); } public char previousChar() { return i.previousChar(); } public Character next() { return i.next(); } public Character previous() { return i.previous(); } } /** Returns an unmodifiable bidirectional iterator backed by the specified bidirectional iterator. * * @param i the bidirectional iterator to be wrapped in an unmodifiable bidirectional iterator. * @return an unmodifiable view of the specified bidirectional iterator. */ public static CharBidirectionalIterator unmodifiable( final CharBidirectionalIterator i ) { return new UnmodifiableBidirectionalIterator ( i ); } /** An unmodifiable wrapper class for list iterators. */ public static class UnmodifiableListIterator extends AbstractCharListIterator { final protected CharListIterator i; @SuppressWarnings("unchecked") public UnmodifiableListIterator( final CharListIterator i ) { this.i = i; } public boolean hasNext() { return i.hasNext(); } public boolean hasPrevious() { return i.hasPrevious(); } public char nextChar() { return i.nextChar(); } public char previousChar() { return i.previousChar(); } public int nextIndex() { return i.nextIndex(); } public int previousIndex() { return i.previousIndex(); } public Character next() { return i.next(); } public Character previous() { return i.previous(); } } /** Returns an unmodifiable list iterator backed by the specified list iterator. * * @param i the list iterator to be wrapped in an unmodifiable list iterator. * @return an unmodifiable view of the specified list iterator. */ public static CharListIterator unmodifiable( final CharListIterator i ) { return new UnmodifiableListIterator ( i ); } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/CharList.java000066400000000000000000000145271422762524200324270ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import java.util.List; /** A type-specific {@link List}; provides some additional methods that use polymorphism to avoid (un)boxing. * *

Note that this type-specific interface extends {@link Comparable}: it is expected that implementing * classes perform a lexicographical comparison using the standard operator "less then" for primitive types, * and the usual {@link Comparable#compareTo(Object) compareTo()} method for objects. * *

Additionally, this interface strengthens {@link #listIterator()}, * {@link #listIterator(int)} and {@link #subList(int,int)}. * *

Besides polymorphic methods, this interfaces specifies methods to copy into an array or remove contiguous * sublists. Although the abstract implementation of this interface provides simple, one-by-one implementations * of these methods, it is expected that concrete implementation override them with optimized versions. * * @see List */ public interface CharList extends List, Comparable>, CharCollection { /** Returns a type-specific iterator on the elements of this list (in proper sequence). * * Note that this specification strengthens the one given in {@link List#iterator()}. * It would not be normally necessary, but {@link java.lang.Iterable#iterator()} is bizarrily re-specified * in {@link List}. * * @return an iterator on the elements of this list (in proper sequence). */ CharListIterator iterator(); /** Returns a type-specific list iterator on the list. * * @see #listIterator() * @deprecated As of fastutil 5, replaced by {@link #listIterator()}. */ @Deprecated CharListIterator charListIterator(); /** Returns a type-specific list iterator on the list starting at a given index. * * @see #listIterator(int) * @deprecated As of fastutil 5, replaced by {@link #listIterator(int)}. */ @Deprecated CharListIterator charListIterator( int index ); /** Returns a type-specific list iterator on the list. * * @see List#listIterator() */ CharListIterator listIterator(); /** Returns a type-specific list iterator on the list starting at a given index. * * @see List#listIterator(int) */ CharListIterator listIterator( int index ); /** Returns a type-specific view of the portion of this list from the index from, inclusive, to the index to, exclusive. * @see List#subList(int,int) * @deprecated As of fastutil 5, replaced by {@link #subList(int,int)}. */ @Deprecated CharList charSubList( int from, int to ); /** Returns a type-specific view of the portion of this list from the index from, inclusive, to the index to, exclusive. * *

Note that this specification strengthens the one given in {@link List#subList(int,int)}. * * @see List#subList(int,int) */ CharList subList(int from, int to); /** Sets the size of this list. * *

If the specified size is smaller than the current size, the last elements are * discarded. Otherwise, they are filled with 0/null/false. * * @param size the new size. */ void size( int size ); /** Copies (hopefully quickly) elements of this type-specific list into the given array. * * @param from the start index (inclusive). * @param a the destination array. * @param offset the offset into the destination array where to store the first element copied. * @param length the number of elements to be copied. */ void getElements( int from, char a[], int offset, int length ); /** Removes (hopefully quickly) elements of this type-specific list. * * @param from the start index (inclusive). * @param to the end index (exclusive). */ void removeElements( int from, int to ); /** Add (hopefully quickly) elements to this type-specific list. * * @param index the index at which to add elements. * @param a the array containing the elements. */ void addElements( int index, char a[] ); /** Add (hopefully quickly) elements to this type-specific list. * * @param index the index at which to add elements. * @param a the array containing the elements. * @param offset the offset of the first element to add. * @param length the number of elements to add. */ void addElements( int index, char a[], int offset, int length ); /** * @see List#add(Object) */ boolean add( char key ); /** * @see List#add(int,Object) */ void add( int index, char key ); /** * @see List#add(int,Object) */ boolean addAll( int index, CharCollection c ); /** * @see List#add(int,Object) */ boolean addAll( int index, CharList c ); /** * @see List#add(int,Object) */ boolean addAll( CharList c ); /** * @see List#get(int) */ char getChar( int index ); /** * @see List#indexOf(Object) */ int indexOf( char k ); /** * @see List#lastIndexOf(Object) */ int lastIndexOf( char k ); /** * @see List#remove(int) */ char removeChar( int index ); /** * @see List#set(int,Object) */ char set( int index, char k ); } CharListIterator.java000066400000000000000000000040731422762524200340550ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import java.util.ListIterator; /** A type-specific bidirectional iterator that is also a {@link ListIterator}. * *

This interface merges the methods provided by a {@link ListIterator} and * a type-specific {@link org.codelibs.jhighlight.fastutil.BidirectionalIterator}. Moreover, it provides * type-specific versions of {@link java.util.ListIterator#add(Object) add()} * and {@link java.util.ListIterator#set(Object) set()}. * * @see java.util.ListIterator * @see org.codelibs.jhighlight.fastutil.BidirectionalIterator */ public interface CharListIterator extends ListIterator, CharBidirectionalIterator { void set( char k ); void add( char k ); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/CharSet.java000066400000000000000000000047431422762524200322460ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import java.util.Set; /** A type-specific {@link Set}; provides some additional methods that use polymorphism to avoid (un)boxing. * *

Additionally, this interface strengthens (again) {@link #iterator()}. * * @see Set */ public interface CharSet extends CharCollection , Set { /** Returns a type-specific iterator on the elements of this set. * *

Note that this specification strengthens the one given in {@link java.lang.Iterable#iterator()}, * which was already strengthened in the corresponding type-specific class, * but was weakened by the fact that this interface extends {@link Set}. * * @return a type-specific iterator on the elements of this set. */ CharIterator iterator(); /** Removes an element from this set. * *

Note that the corresponding method of the type-specific collection is rem(). * This unfortunate situation is caused by the clash * with the similarly named index-based method in the {@link java.util.List} interface. * * @see java.util.Collection#remove(Object) */ public boolean remove( char k ); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/chars/CharStack.java000066400000000000000000000035161422762524200325550ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.chars; import org.codelibs.jhighlight.fastutil.Stack; /** A type-specific {@link Stack}; provides some additional methods that use polymorphism to avoid (un)boxing. */ public interface CharStack extends Stack { /** * @see Stack#push(Object) */ void push( char k ); /** * @see Stack#pop() */ char popChar(); /** * @see Stack#top() */ char topChar(); /** * @see Stack#peek(int) */ char peekChar( int i ); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/ints/000077500000000000000000000000001422762524200277175ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/ints/IntArrays.java000066400000000000000000002004001422762524200324720ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * * * For the sorting and binary search code: * * Copyright (C) 1999 CERN - European Organization for Nuclear Research. * * Permission to use, copy, modify, distribute and sell this software and * its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation. CERN makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without expressed or implied warranty. */ package org.codelibs.jhighlight.fastutil.ints; import java.util.Random; import org.codelibs.jhighlight.fastutil.Arrays; import org.codelibs.jhighlight.fastutil.Hash; /** A class providing static methods and objects that do useful things with type-specific arrays. * *

In particular, the ensureCapacity(), grow(), * trim() and setLength() methods allow to handle * arrays much like array lists. This can be very useful when efficiency (or * syntactic simplicity) reasons make array lists unsuitable. * *

Note that {@link org.codelibs.jhighlight.fastutil.io.BinIO} and {@link org.codelibs.jhighlight.fastutil.io.TextIO} * contain several methods make it possible to load and save arrays of primitive types as sequences * of elements in {@link java.io.DataInput} format (i.e., not as objects) or as sequences of lines of text. * * @see java.util.Arrays */ public class IntArrays { private IntArrays() {} /** A static, final, empty array. */ public final static int[] EMPTY_ARRAY = {}; /** Ensures that an array can contain the given number of entries. * *

If you cannot foresee whether this array will need again to be * enlarged, you should probably use grow() instead. * * @param array an array. * @param length the new minimum length for this array. * @return array, if it contains length entries or more; otherwise, * an array with length entries whose first array.length * entries are the same as those of array. */ public static int[] ensureCapacity( final int[] array, final int length ) { if ( length > array.length ) { final int t[] = new int[ length ]; System.arraycopy( array, 0, t, 0, array.length ); return t; } return array; } /** Ensures that an array can contain the given number of entries, preserving just a part of the array. * * @param array an array. * @param length the new minimum length for this array. * @param preserve the number of elements of the array that must be preserved in case a new allocation is necessary. * @return array, if it can contain length entries or more; otherwise, * an array with length entries whose first preserve * entries are the same as those of array. */ public static int[] ensureCapacity( final int[] array, final int length, final int preserve ) { if ( length > array.length ) { final int t[] = new int[ length ]; System.arraycopy( array, 0, t, 0, preserve ); return t; } return array; } /** Grows the given array to the maximum between the given length and * the current length multiplied by two, provided that the given * length is larger than the current length. * *

If you want complete control on the array growth, you * should probably use ensureCapacity() instead. * * @param array an array. * @param length the new minimum length for this array. * @return array, if it can contain length * entries; otherwise, an array with * max(length,array.length/φ) entries whose first * array.length entries are the same as those of array. * */ public static int[] grow( final int[] array, final int length ) { if ( length > array.length ) { final int newLength = (int)Math.max( Math.min( 2L * array.length, Arrays.MAX_ARRAY_SIZE ), length ); final int t[] = new int[ newLength ]; System.arraycopy( array, 0, t, 0, array.length ); return t; } return array; } /** Grows the given array to the maximum between the given length and * the current length multiplied by two, provided that the given * length is larger than the current length, preserving just a part of the array. * *

If you want complete control on the array growth, you * should probably use ensureCapacity() instead. * * @param array an array. * @param length the new minimum length for this array. * @param preserve the number of elements of the array that must be preserved in case a new allocation is necessary. * @return array, if it can contain length * entries; otherwise, an array with * max(length,array.length/φ) entries whose first * preserve entries are the same as those of array. * */ public static int[] grow( final int[] array, final int length, final int preserve ) { if ( length > array.length ) { final int newLength = (int)Math.max( Math.min( 2L * array.length, Arrays.MAX_ARRAY_SIZE ), length ); final int t[] = new int[ newLength ]; System.arraycopy( array, 0, t, 0, preserve ); return t; } return array; } /** Trims the given array to the given length. * * @param array an array. * @param length the new maximum length for the array. * @return array, if it contains length * entries or less; otherwise, an array with * length entries whose entries are the same as * the first length entries of array. * */ public static int[] trim( final int[] array, final int length ) { if ( length >= array.length ) return array; final int t[] = length == 0 ? EMPTY_ARRAY : new int[ length ]; System.arraycopy( array, 0, t, 0, length ); return t; } /** Sets the length of the given array. * * @param array an array. * @param length the new length for the array. * @return array, if it contains exactly length * entries; otherwise, if it contains more than * length entries, an array with length entries * whose entries are the same as the first length entries of * array; otherwise, an array with length entries * whose first array.length entries are the same as those of * array. * */ public static int[] setLength( final int[] array, final int length ) { if ( length == array.length ) return array; if ( length < array.length ) return trim( array, length ); return ensureCapacity( array, length ); } /** Returns a copy of a portion of an array. * * @param array an array. * @param offset the first element to copy. * @param length the number of elements to copy. * @return a new array containing length elements of array starting at offset. */ public static int[] copy( final int[] array, final int offset, final int length ) { ensureOffsetLength( array, offset, length ); final int[] a = length == 0 ? EMPTY_ARRAY : new int[ length ]; System.arraycopy( array, offset, a, 0, length ); return a; } /** Returns a copy of an array. * * @param array an array. * @return a copy of array. */ public static int[] copy( final int[] array ) { return array.clone(); } /** Fills the given array with the given value. * *

This method uses a backward loop. It is significantly faster than the corresponding * method in {@link java.util.Arrays}. * * @param array an array. * @param value the new value for all elements of the array. */ public static void fill( final int[] array, final int value ) { int i = array.length; while( i-- != 0 ) array[ i ] = value; } /** Fills a portion of the given array with the given value. * *

If possible (i.e., from is 0) this method uses a * backward loop. In this case, it is significantly faster than the * corresponding method in {@link java.util.Arrays}. * * @param array an array. * @param from the starting index of the portion to fill (inclusive). * @param to the end index of the portion to fill (exclusive). * @param value the new value for all elements of the specified portion of the array. */ public static void fill( final int[] array, final int from, int to, final int value ) { ensureFromTo( array, from, to ); if ( from == 0 ) while( to-- != 0 ) array[ to ] = value; else for( int i = from; i < to; i++ ) array[ i ] = value; } /** Returns true if the two arrays are elementwise equal. * * @param a1 an array. * @param a2 another array. * @return true if the two arrays are of the same length, and their elements are equal. * @deprecated Please use the corresponding {@link java.util.Arrays} method, which is intrinsified in recent JVMs. */ @Deprecated public static boolean equals( final int[] a1, final int a2[] ) { int i = a1.length; if ( i != a2.length ) return false; while( i-- != 0 ) if (! ( (a1[ i ]) == (a2[ i ]) ) ) return false; return true; } /** Ensures that a range given by its first (inclusive) and last (exclusive) elements fits an array. * *

This method may be used whenever an array range check is needed. * * @param a an array. * @param from a start index (inclusive). * @param to an end index (exclusive). * @throws IllegalArgumentException if from is greater than to. * @throws ArrayIndexOutOfBoundsException if from or to are greater than the array length or negative. */ public static void ensureFromTo( final int[] a, final int from, final int to ) { Arrays.ensureFromTo( a.length, from, to ); } /** Ensures that a range given by an offset and a length fits an array. * *

This method may be used whenever an array range check is needed. * * @param a an array. * @param offset a start index. * @param length a length (the number of elements in the range). * @throws IllegalArgumentException if length is negative. * @throws ArrayIndexOutOfBoundsException if offset is negative or offset+length is greater than the array length. */ public static void ensureOffsetLength( final int[] a, final int offset, final int length ) { Arrays.ensureOffsetLength( a.length, offset, length ); } private static final int SMALL = 7; private static final int MEDIUM = 50; private static void swap( final int x[], final int a, final int b ) { final int t = x[ a ]; x[ a ] = x[ b ]; x[ b ] = t; } private static void vecSwap( final int[] x, int a, int b, final int n ) { for( int i = 0; i < n; i++, a++, b++ ) swap( x, a, b ); } private static int med3( final int x[], final int a, final int b, final int c, IntComparator comp ) { int ab = comp.compare( x[ a ], x[ b ] ); int ac = comp.compare( x[ a ], x[ c ] ); int bc = comp.compare( x[ b ], x[ c ] ); return ( ab < 0 ? ( bc < 0 ? b : ac < 0 ? c : a ) : ( bc > 0 ? b : ac > 0 ? c : a ) ); } private static void selectionSort( final int[] a, final int from, final int to, final IntComparator comp ) { for( int i = from; i < to - 1; i++ ) { int m = i; for( int j = i + 1; j < to; j++ ) if ( comp.compare( a[ j ], a[ m ] ) < 0 ) m = j; if ( m != i ) { final int u = a[ i ]; a[ i ] = a[ m ]; a[ m ] = u; } } } private static void insertionSort( final int[] a, final int from, final int to, final IntComparator comp ) { for ( int i = from; ++i < to; ) { int t = a[ i ]; int j = i; for ( int u = a[ j - 1 ]; comp.compare( t, u ) < 0; u = a[ --j - 1 ] ) { a[ j ] = u; if ( from == j - 1 ) { --j; break; } } a[ j ] = t; } } @SuppressWarnings("unchecked") private static void selectionSort( final int[] a, final int from, final int to ) { for( int i = from; i < to - 1; i++ ) { int m = i; for( int j = i + 1; j < to; j++ ) if ( ( (a[ j ]) < (a[ m ]) ) ) m = j; if ( m != i ) { final int u = a[ i ]; a[ i ] = a[ m ]; a[ m ] = u; } } } @SuppressWarnings("unchecked") private static void insertionSort( final int[] a, final int from, final int to ) { for ( int i = from; ++i < to; ) { int t = a[ i ]; int j = i; for ( int u = a[ j - 1 ]; ( (t) < (u) ); u = a[ --j - 1 ] ) { a[ j ] = u; if ( from == j - 1 ) { --j; break; } } a[ j ] = t; } } /** Sorts the specified range of elements according to the order induced by the specified * comparator using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. * */ public static void quickSort( final int[] x, final int from, final int to, final IntComparator comp ) { final int len = to - from; // Selection sort on smallest arrays if ( len < SMALL ) { selectionSort( x, from, to, comp ); return; } // Choose a partition element, v int m = from + len / 2; // Small arrays, middle element if ( len > SMALL ) { int l = from; int n = to - 1; if ( len > MEDIUM ) { // Big arrays, pseudomedian of 9 int s = len / 8; l = med3( x, l, l + s, l + 2 * s, comp ); m = med3( x, m - s, m, m + s, comp ); n = med3( x, n - 2 * s, n - s, n, comp ); } m = med3( x, l, m, n, comp ); // Mid-size, med of 3 } final int v = x[ m ]; // Establish Invariant: v* (v)* v* int a = from, b = a, c = to - 1, d = c; while(true) { int comparison; while ( b <= c && ( comparison = comp.compare( x[ b ], v ) ) <= 0 ) { if ( comparison == 0 ) swap( x, a++, b ); b++; } while (c >= b && ( comparison = comp.compare( x[ c ], v ) ) >=0 ) { if ( comparison == 0 ) swap( x, c, d-- ); c--; } if ( b > c ) break; swap( x, b++, c-- ); } // Swap partition elements back to middle int s, n = to; s = Math.min( a - from, b - a ); vecSwap( x, from, b - s, s ); s = Math.min( d - c, n - d - 1 ); vecSwap( x, b, n - s, s ); // Recursively sort non-partition-elements if ( ( s = b - a ) > 1 ) quickSort( x, from, from + s, comp ); if ( ( s = d - c ) > 1 ) quickSort( x, n - s, n, comp ); } /** Sorts an array according to the order induced by the specified * comparator using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * @param comp the comparator to determine the sorting order. * */ public static void quickSort( final int[] x, final IntComparator comp ) { quickSort( x, 0, x.length, comp ); } @SuppressWarnings("unchecked") private static int med3( final int x[], final int a, final int b, final int c ) { int ab = ( (x[ a ]) < (x[ b ]) ? -1 : ( (x[ a ]) == (x[ b ]) ? 0 : 1 ) ); int ac = ( (x[ a ]) < (x[ c ]) ? -1 : ( (x[ a ]) == (x[ c ]) ? 0 : 1 ) ); int bc = ( (x[ b ]) < (x[ c ]) ? -1 : ( (x[ b ]) == (x[ c ]) ? 0 : 1 ) ); return ( ab < 0 ? ( bc < 0 ? b : ac < 0 ? c : a ) : ( bc > 0 ? b : ac > 0 ? c : a ) ); } /** Sorts the specified range of elements according to the natural ascending order using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ @SuppressWarnings("unchecked") public static void quickSort( final int[] x, final int from, final int to ) { final int len = to - from; // Selection sort on smallest arrays if ( len < SMALL ) { selectionSort( x, from, to ); return; } // Choose a partition element, v int m = from + len / 2; // Small arrays, middle element if ( len > SMALL ) { int l = from; int n = to - 1; if ( len > MEDIUM ) { // Big arrays, pseudomedian of 9 int s = len / 8; l = med3( x, l, l + s, l + 2 * s ); m = med3( x, m - s, m, m + s ); n = med3( x, n - 2 * s, n - s, n ); } m = med3( x, l, m, n ); // Mid-size, med of 3 } final int v = x[ m ]; // Establish Invariant: v* (v)* v* int a = from, b = a, c = to - 1, d = c; while(true) { int comparison; while ( b <= c && ( comparison = ( (x[ b ]) < (v) ? -1 : ( (x[ b ]) == (v) ? 0 : 1 ) ) ) <= 0 ) { if ( comparison == 0 ) swap( x, a++, b ); b++; } while (c >= b && ( comparison = ( (x[ c ]) < (v) ? -1 : ( (x[ c ]) == (v) ? 0 : 1 ) ) ) >=0 ) { if ( comparison == 0 ) swap( x, c, d-- ); c--; } if ( b > c ) break; swap( x, b++, c-- ); } // Swap partition elements back to middle int s, n = to; s = Math.min( a - from, b - a ); vecSwap( x, from, b - s, s ); s = Math.min( d - c, n - d - 1 ); vecSwap( x, b, n - s, s ); // Recursively sort non-partition-elements if ( ( s = b - a ) > 1 ) quickSort( x, from, from + s ); if ( ( s = d - c ) > 1 ) quickSort( x, n - s, n ); } /** Sorts an array according to the natural ascending order using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * */ public static void quickSort( final int[] x ) { quickSort( x, 0, x.length ); } /** Sorts the specified range of elements according to the natural ascending order using mergesort, using a given pre-filled support array. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. Moreover, no support arrays will be allocated. * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param supp a support array containing at least to elements, and whose entries are identical to those * of {@code a} in the specified range. */ @SuppressWarnings("unchecked") public static void mergeSort( final int a[], final int from, final int to, final int supp[] ) { int len = to - from; // Insertion sort on smallest arrays if ( len < SMALL ) { insertionSort( a, from, to ); return; } // Recursively sort halves of a into supp final int mid = ( from + to ) >>> 1; mergeSort( supp, from, mid, a ); mergeSort( supp, mid, to, a ); // If list is already sorted, just copy from supp to a. This is an // optimization that results in faster sorts for nearly ordered lists. if ( ( (supp[ mid - 1 ]) <= (supp[ mid ]) ) ) { System.arraycopy( supp, from, a, from, len ); return; } // Merge sorted halves (now in supp) into a for( int i = from, p = from, q = mid; i < to; i++ ) { if ( q >= to || p < mid && ( (supp[ p ]) <= (supp[ q ]) ) ) a[ i ] = supp[ p++ ]; else a[ i ] = supp[ q++ ]; } } /** Sorts the specified range of elements according to the natural ascending order using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ public static void mergeSort( final int a[], final int from, final int to ) { mergeSort( a, from, to, a.clone() ); } /** Sorts an array according to the natural ascending order using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * @param a the array to be sorted. */ public static void mergeSort( final int a[] ) { mergeSort( a, 0, a.length ); } /** Sorts the specified range of elements according to the order induced by the specified * comparator using mergesort, using a given pre-filled support array. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. Moreover, no support arrays will be allocated. * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. * @param supp a support array containing at least to elements, and whose entries are identical to those * of {@code a} in the specified range. */ @SuppressWarnings("unchecked") public static void mergeSort( final int a[], final int from, final int to, IntComparator comp, final int supp[] ) { int len = to - from; // Insertion sort on smallest arrays if ( len < SMALL ) { insertionSort( a, from, to, comp ); return; } // Recursively sort halves of a into supp final int mid = ( from + to ) >>> 1; mergeSort( supp, from, mid, comp, a ); mergeSort( supp, mid, to, comp, a ); // If list is already sorted, just copy from supp to a. This is an // optimization that results in faster sorts for nearly ordered lists. if ( comp.compare( supp[ mid - 1 ], supp[ mid ] ) <= 0 ) { System.arraycopy( supp, from, a, from, len ); return; } // Merge sorted halves (now in supp) into a for( int i = from, p = from, q = mid; i < to; i++ ) { if ( q >= to || p < mid && comp.compare( supp[ p ], supp[ q ] ) <= 0 ) a[ i ] = supp[ p++ ]; else a[ i ] = supp[ q++ ]; } } /** Sorts the specified range of elements according to the order induced by the specified * comparator using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. */ public static void mergeSort( final int a[], final int from, final int to, IntComparator comp ) { mergeSort( a, from, to, comp, a.clone() ); } /** Sorts an array according to the order induced by the specified * comparator using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * @param a the array to be sorted. * @param comp the comparator to determine the sorting order. */ public static void mergeSort( final int a[], IntComparator comp ) { mergeSort( a, 0, a.length, comp ); } /** * Searches a range of the specified array for the specified value using * the binary search algorithm. The range must be sorted prior to making this call. * If it is not sorted, the results are undefined. If the range contains multiple elements with * the specified value, there is no guarantee which one will be found. * * @param a the array to be searched. * @param from the index of the first element (inclusive) to be searched. * @param to the index of the last element (exclusive) to be searched. * @param key the value to be searched for. * @return index of the search key, if it is contained in the array; * otherwise, (-(insertion point) - 1). The insertion * point is defined as the the point at which the value would * be inserted into the array: the index of the first * element greater than the key, or the length of the array, if all * elements in the array are less than the specified key. Note * that this guarantees that the return value will be >= 0 if * and only if the key is found. * @see java.util.Arrays */ @SuppressWarnings({"unchecked","rawtypes"}) public static int binarySearch( final int[] a, int from, int to, final int key ) { int midVal; to--; while (from <= to) { final int mid = (from + to) >>> 1; midVal = a[ mid ]; if (midVal < key) from = mid + 1; else if (midVal > key) to = mid - 1; else return mid; } return -( from + 1 ); } /** * Searches an array for the specified value using * the binary search algorithm. The range must be sorted prior to making this call. * If it is not sorted, the results are undefined. If the range contains multiple elements with * the specified value, there is no guarantee which one will be found. * * @param a the array to be searched. * @param key the value to be searched for. * @return index of the search key, if it is contained in the array; * otherwise, (-(insertion point) - 1). The insertion * point is defined as the the point at which the value would * be inserted into the array: the index of the first * element greater than the key, or the length of the array, if all * elements in the array are less than the specified key. Note * that this guarantees that the return value will be >= 0 if * and only if the key is found. * @see java.util.Arrays */ public static int binarySearch( final int[] a, final int key ) { return binarySearch( a, 0, a.length, key ); } /** * Searches a range of the specified array for the specified value using * the binary search algorithm and a specified comparator. The range must be sorted following the comparator prior to making this call. * If it is not sorted, the results are undefined. If the range contains multiple elements with * the specified value, there is no guarantee which one will be found. * * @param a the array to be searched. * @param from the index of the first element (inclusive) to be searched. * @param to the index of the last element (exclusive) to be searched. * @param key the value to be searched for. * @param c a comparator. * @return index of the search key, if it is contained in the array; * otherwise, (-(insertion point) - 1). The insertion * point is defined as the the point at which the value would * be inserted into the array: the index of the first * element greater than the key, or the length of the array, if all * elements in the array are less than the specified key. Note * that this guarantees that the return value will be >= 0 if * and only if the key is found. * @see java.util.Arrays */ public static int binarySearch( final int[] a, int from, int to, final int key, final IntComparator c ) { int midVal; to--; while (from <= to) { final int mid = (from + to) >>> 1; midVal = a[ mid ]; final int cmp = c.compare( midVal, key ); if ( cmp < 0 ) from = mid + 1; else if (cmp > 0) to = mid - 1; else return mid; // key found } return -( from + 1 ); } /** * Searches an array for the specified value using * the binary search algorithm and a specified comparator. The range must be sorted following the comparator prior to making this call. * If it is not sorted, the results are undefined. If the range contains multiple elements with * the specified value, there is no guarantee which one will be found. * * @param a the array to be searched. * @param key the value to be searched for. * @param c a comparator. * @return index of the search key, if it is contained in the array; * otherwise, (-(insertion point) - 1). The insertion * point is defined as the the point at which the value would * be inserted into the array: the index of the first * element greater than the key, or the length of the array, if all * elements in the array are less than the specified key. Note * that this guarantees that the return value will be >= 0 if * and only if the key is found. * @see java.util.Arrays */ public static int binarySearch( final int[] a, final int key, final IntComparator c ) { return binarySearch( a, 0, a.length, key, c ); } /** The size of a digit used during radix sort (must be a power of 2). */ private static final int DIGIT_BITS = 8; /** The mask to extract a digit of {@link #DIGIT_BITS} bits. */ private static final int DIGIT_MASK = ( 1 << DIGIT_BITS ) - 1; /** The number of digits per element. */ private static final int DIGITS_PER_ELEMENT = Integer.SIZE / DIGIT_BITS; /** This method fixes negative numbers so that the combination exponent/significand is lexicographically sorted. */ /** Sorts the specified array using radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This implementation is significantly faster than quicksort * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. * It will allocate a support array of bytes with the same number of elements as the array to be sorted. * * @param a the array to be sorted. */ public static void radixSort( final int[] a ) { radixSort( a, 0, a.length ); } /** Sorts the specified array using radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This implementation is significantly faster than quicksort * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. * It will allocate a support array of bytes with the same number of elements as the array to be sorted. * * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ public static void radixSort( final int[] a, final int from, final int to ) { final int maxLevel = DIGITS_PER_ELEMENT - 1; final int stackSize = ( ( 1 << DIGIT_BITS ) - 1 ) * ( DIGITS_PER_ELEMENT - 1 ) + 1; final int[] offsetStack = new int[ stackSize ]; int offsetPos = 0; final int[] lengthStack = new int[ stackSize ]; int lengthPos = 0; final int[] levelStack = new int[ stackSize ]; int levelPos = 0; offsetStack[ offsetPos++ ] = from; lengthStack[ lengthPos++ ] = to - from; levelStack[ levelPos++ ] = 0; final int[] count = new int[ 1 << DIGIT_BITS ]; final int[] pos = new int[ 1 << DIGIT_BITS ]; final byte[] digit = new byte[ to - from ]; while( offsetPos > 0 ) { final int first = offsetStack[ --offsetPos ]; final int length = lengthStack[ --lengthPos ]; final int level = levelStack[ --levelPos ]; final int signMask = level % DIGITS_PER_ELEMENT == 0 ? 1 << DIGIT_BITS - 1 : 0; if ( length < MEDIUM ) { selectionSort( a, first, first + length ); continue; } final int shift = ( DIGITS_PER_ELEMENT - 1 - level % DIGITS_PER_ELEMENT ) * DIGIT_BITS; // This is the shift that extract the right byte from a key // Count keys. for( int i = length; i-- != 0; ) digit[ i ] = (byte)( ( ( (a[ first + i ]) >>> shift ) & DIGIT_MASK ) ^ signMask ); for( int i = length; i-- != 0; ) count[ digit[ i ] & 0xFF ]++; // Compute cumulative distribution and push non-singleton keys on stack. int lastUsed = -1; for( int i = 0, p = 0; i < 1 << DIGIT_BITS; i++ ) { if ( count[ i ] != 0 ) { lastUsed = i; if ( level < maxLevel && count[ i ] > 1 ){ //System.err.println( " Pushing " + new StackEntry( first + pos[ i - 1 ], first + pos[ i ], level + 1 ) ); offsetStack[ offsetPos++ ] = p + first; lengthStack[ lengthPos++ ] = count[ i ]; levelStack[ levelPos++ ] = level + 1; } } pos[ i ] = ( p += count[ i ] ); } // When all slots are OK, the last slot is necessarily OK. final int end = length - count[ lastUsed ]; count[ lastUsed ] = 0; // i moves through the start of each block for( int i = 0, c = -1, d; i < end; i += count[ c ], count[ c ] = 0 ) { int t = a[ i + first ]; c = digit[ i ] & 0xFF; while( ( d = --pos[ c ] ) > i ) { final int z = t; final int zz = c; t = a[ d + first ]; c = digit[ d ] & 0xFF; a[ d + first ] = z; digit[ d ] = (byte)zz; } a[ i + first ] = t; } } } private static void insertionSortIndirect( final int[] perm, final int[] a, final int from, final int to ) { for ( int i = from; ++i < to; ) { int t = perm[ i ]; int j = i; for ( int u = perm[ j - 1 ]; ( (a[ t ]) < (a[ u ]) ); u = perm[ --j - 1 ] ) { perm[ j ] = u; if ( from == j - 1 ) { --j; break; } } perm[ j ] = t; } } /** Sorts the specified array using indirect radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implement an indirect sort. The elements of perm (which must * be exactly the numbers in the interval [0..perm.length)) will be permuted so that * a[ perm[ i ] ] <= a[ perm[ i + 1 ] ]. * *

This implementation is significantly faster than quicksort (unstable) or mergesort (stable) * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. * It will allocate a support array of bytes with the same number of elements as the array to be sorted, * and, in the stable case, a further support array as large as perm (note that the stable * version is slightly faster). * * @param perm a permutation array indexing a. * @param a the array to be sorted. * @param stable whether the sorting algorithm should be stable. */ public static void radixSortIndirect( final int[] perm, final int[] a, final boolean stable ) { radixSortIndirect( perm, a, 0, perm.length, stable ); } /** Sorts the specified array using indirect radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implement an indirect sort. The elements of perm (which must * be exactly the numbers in the interval [0..perm.length)) will be permuted so that * a[ perm[ i ] ] <= a[ perm[ i + 1 ] ]. * *

This implementation is significantly faster than quicksort (unstable) or mergesort (stable) * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. * It will allocate a support array of bytes with the same number of elements as the array to be sorted, * and, in the stable case, a further support array as large as perm (note that the stable * version is slightly faster). * * @param perm a permutation array indexing a. * @param a the array to be sorted. * @param from the index of the first element of perm (inclusive) to be permuted. * @param to the index of the last element of perm (exclusive) to be permuted. * @param stable whether the sorting algorithm should be stable. */ public static void radixSortIndirect( final int[] perm, final int[] a, final int from, final int to, final boolean stable ) { final int maxLevel = DIGITS_PER_ELEMENT - 1; final int stackSize = ( ( 1 << DIGIT_BITS ) - 1 ) * ( DIGITS_PER_ELEMENT - 1 ) + 1; final int[] offsetStack = new int[ stackSize ]; int offsetPos = 0; final int[] lengthStack = new int[ stackSize ]; int lengthPos = 0; final int[] levelStack = new int[ stackSize ]; int levelPos = 0; offsetStack[ offsetPos++ ] = from; lengthStack[ lengthPos++ ] = to - from; levelStack[ levelPos++ ] = 0; final int[] count = new int[ 1 << DIGIT_BITS ]; final int[] pos = stable ? null : new int[ 1 << DIGIT_BITS ]; final int[] support = stable ? new int[ perm.length ] : null; final byte[] digit = new byte[ to - from ]; while( offsetPos > 0 ) { final int first = offsetStack[ --offsetPos ]; final int length = lengthStack[ --lengthPos ]; final int level = levelStack[ --levelPos ]; final int signMask = level % DIGITS_PER_ELEMENT == 0 ? 1 << DIGIT_BITS - 1 : 0; if ( length < MEDIUM ) { insertionSortIndirect( perm, a, first, first + length ); continue; } final int shift = ( DIGITS_PER_ELEMENT - 1 - level % DIGITS_PER_ELEMENT ) * DIGIT_BITS; // This is the shift that extract the right byte from a key // Count keys. for( int i = length; i-- != 0; ) digit[ i ] = (byte)( ( ( (a[ perm[ first + i ] ]) >>> shift ) & DIGIT_MASK ) ^ signMask ); for( int i = length; i-- != 0; ) count[ digit[ i ] & 0xFF ]++; // Compute cumulative distribution and push non-singleton keys on stack. int lastUsed = -1; for( int i = 0, p = 0; i < 1 << DIGIT_BITS; i++ ) { if ( count[ i ] != 0 ) { lastUsed = i; if ( level < maxLevel && count[ i ] > 1 ){ offsetStack[ offsetPos++ ] = p + first; lengthStack[ lengthPos++ ] = count[ i ]; levelStack[ levelPos++ ] = level + 1; } } if ( stable ) count[ i ] = p += count[ i ]; else pos[ i ] = ( p += count[ i ] ); } if ( stable ) { for( int i = length; i-- != 0; ) support[ --count[ digit[ i ] & 0xFF ] ] = perm[ first + i ]; System.arraycopy( support, 0, perm, first, length ); org.codelibs.jhighlight.fastutil.ints.IntArrays.fill( count, 0 ); } else { // When all slots are OK, the last slot is necessarily OK. final int end = length - count[ lastUsed ]; count[ lastUsed ] = 0; // i moves through the start of each block for( int i = 0, c = -1, d; i < end; i += count[ c ], count[ c ] = 0 ) { int t = perm[ i + first ]; c = digit[ i ] & 0xFF; while( ( d = --pos[ c ] ) > i ) { final int z = t; final int zz = c; t = perm[ d + first ]; c = digit[ d ] & 0xFF; perm[ d + first ] = z; digit[ d ] = (byte)zz; } perm[ i + first ] = t; } } } } private static void selectionSort( final int[] a, final int[] b, final int from, final int to ) { for( int i = from; i < to - 1; i++ ) { int m = i; for( int j = i + 1; j < to; j++ ) if ( a[ j ] < a[ m ] || a[ j ] == a[ m ] && b[ j ] < b[ m ] ) m = j; if ( m != i ) { int t = a[ i ]; a[ i ] = a[ m ]; a[ m ] = t; t = b[ i ]; b[ i ] = b[ m ]; b[ m ] = t; } } } /** Sorts the specified pair of arrays lexicographically using radix sort. *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implements a lexicographical sorting of the arguments. Pairs of elements * in the same position in the two provided arrays will be considered a single key, and permuted * accordingly. In the end, either a[ i ] < a[ i + 1 ] or a[ i ] == a[ i + 1 ] and b[ i ] <= b[ i + 1 ]. * *

This implementation is significantly faster than quicksort * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. It will allocate a support array of bytes with the same number of elements as the arrays to be sorted. * * @param a the first array to be sorted. * @param b the second array to be sorted. */ public static void radixSort( final int[] a, final int[] b ) { radixSort( a, b, 0, a.length ); } /** Sorts the specified pair of arrays lexicographically using radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implements a lexicographical sorting of the arguments. Pairs of elements * in the same position in the two provided arrays will be considered a single key, and permuted * accordingly. In the end, either a[ i ] < a[ i + 1 ] or a[ i ] == a[ i + 1 ] and b[ i ] <= b[ i + 1 ]. * *

This implementation is significantly faster than quicksort * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. It will allocate a support array of bytes with the same number of elements as the arrays to be sorted. * * @param a the first array to be sorted. * @param b the second array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ public static void radixSort( final int[] a, final int[] b, final int from, final int to ) { final int layers = 2; if ( a.length != b.length ) throw new IllegalArgumentException( "Array size mismatch." ); final int maxLevel = DIGITS_PER_ELEMENT * layers - 1; final int stackSize = ( ( 1 << DIGIT_BITS ) - 1 ) * ( layers * DIGITS_PER_ELEMENT - 1 ) + 1; final int[] offsetStack = new int[ stackSize ]; int offsetPos = 0; final int[] lengthStack = new int[ stackSize ]; int lengthPos = 0; final int[] levelStack = new int[ stackSize ]; int levelPos = 0; offsetStack[ offsetPos++ ] = from; lengthStack[ lengthPos++ ] = to - from; levelStack[ levelPos++ ] = 0; final int[] count = new int[ 1 << DIGIT_BITS ]; final int[] pos = new int[ 1 << DIGIT_BITS ]; final byte[] digit = new byte[ to - from ]; while( offsetPos > 0 ) { final int first = offsetStack[ --offsetPos ]; final int length = lengthStack[ --lengthPos ]; final int level = levelStack[ --levelPos ]; final int signMask = level % DIGITS_PER_ELEMENT == 0 ? 1 << DIGIT_BITS - 1 : 0; if ( length < MEDIUM ) { selectionSort( a, b, first, first + length ); continue; } final int[] k = level < DIGITS_PER_ELEMENT ? a : b; // This is the key array final int shift = ( DIGITS_PER_ELEMENT - 1 - level % DIGITS_PER_ELEMENT ) * DIGIT_BITS; // This is the shift that extract the right byte from a key // Count keys. for( int i = length; i-- != 0; ) digit[ i ] = (byte)( ( ( (k[ first + i ]) >>> shift ) & DIGIT_MASK ) ^ signMask ); for( int i = length; i-- != 0; ) count[ digit[ i ] & 0xFF ]++; // Compute cumulative distribution and push non-singleton keys on stack. int lastUsed = -1; for( int i = 0, p = 0; i < 1 << DIGIT_BITS; i++ ) { if ( count[ i ] != 0 ) { lastUsed = i; if ( level < maxLevel && count[ i ] > 1 ){ offsetStack[ offsetPos++ ] = p + first; lengthStack[ lengthPos++ ] = count[ i ]; levelStack[ levelPos++ ] = level + 1; } } pos[ i ] = ( p += count[ i ] ); } // When all slots are OK, the last slot is necessarily OK. final int end = length - count[ lastUsed ]; count[ lastUsed ] = 0; // i moves through the start of each block for( int i = 0, c = -1, d; i < end; i += count[ c ], count[ c ] = 0 ) { int t = a[ i + first ]; int u = b[ i + first ]; c = digit[ i ] & 0xFF; while( ( d = --pos[ c ] ) > i ) { int z = t; final int zz = c; t = a[ d + first ]; a[ d + first ] = z; z = u; u = b[ d + first ]; b[ d + first ] = z; c = digit[ d ] & 0xFF; digit[ d ] = (byte)zz; } a[ i + first ] = t; b[ i + first ] = u; } } } private static void insertionSortIndirect( final int[] perm, final int[] a, final int[] b, final int from, final int to ) { for ( int i = from; ++i < to; ) { int t = perm[ i ]; int j = i; for ( int u = perm[ j - 1 ]; ( (a[ t ]) < (a[ u ]) ) || ( (a[ t ]) == (a[ u ]) ) && ( (b[ t ]) < (b[ u ]) ); u = perm[ --j - 1 ] ) { perm[ j ] = u; if ( from == j - 1 ) { --j; break; } } perm[ j ] = t; } } /** Sorts the specified pair of arrays lexicographically using indirect radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implement an indirect sort. The elements of perm (which must * be exactly the numbers in the interval [0..perm.length)) will be permuted so that * a[ perm[ i ] ] <= a[ perm[ i + 1 ] ]. * *

This implementation is significantly faster than quicksort (unstable) or mergesort (stable) * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. * It will allocate a support array of bytes with the same number of elements as the array to be sorted, * and, in the stable case, a further support array as large as perm (note that the stable * version is slightly faster). * * @param perm a permutation array indexing a. * @param a the array to be sorted. * @param b the second array to be sorted. * @param stable whether the sorting algorithm should be stable. */ public static void radixSortIndirect( final int[] perm, final int[] a, final int[] b, final boolean stable ) { radixSortIndirect( perm, a, b, 0, perm.length, stable ); } /** Sorts the specified pair of arrays lexicographically using indirect radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implement an indirect sort. The elements of perm (which must * be exactly the numbers in the interval [0..perm.length)) will be permuted so that * a[ perm[ i ] ] <= a[ perm[ i + 1 ] ]. * *

This implementation is significantly faster than quicksort (unstable) or mergesort (stable) * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. * It will allocate a support array of bytes with the same number of elements as the array to be sorted, * and, in the stable case, a further support array as large as perm (note that the stable * version is slightly faster). * * @param perm a permutation array indexing a. * @param a the array to be sorted. * @param b the second array to be sorted. * @param from the index of the first element of perm (inclusive) to be permuted. * @param to the index of the last element of perm (exclusive) to be permuted. * @param stable whether the sorting algorithm should be stable. */ public static void radixSortIndirect( final int[] perm, final int[] a, final int[] b, final int from, final int to, final boolean stable ) { final int layers = 2; if ( a.length != b.length ) throw new IllegalArgumentException( "Array size mismatch." ); final int maxLevel = DIGITS_PER_ELEMENT * layers - 1; final int stackSize = ( ( 1 << DIGIT_BITS ) - 1 ) * ( layers * DIGITS_PER_ELEMENT - 1 ) + 1; final int[] offsetStack = new int[ stackSize ]; int offsetPos = 0; final int[] lengthStack = new int[ stackSize ]; int lengthPos = 0; final int[] levelStack = new int[ stackSize ]; int levelPos = 0; offsetStack[ offsetPos++ ] = from; lengthStack[ lengthPos++ ] = to - from; levelStack[ levelPos++ ] = 0; final int[] count = new int[ 1 << DIGIT_BITS ]; final int[] pos = stable ? null : new int[ 1 << DIGIT_BITS ]; final int[] support = stable ? new int[ perm.length ] : null; final byte[] digit = new byte[ to - from ]; while( offsetPos > 0 ) { final int first = offsetStack[ --offsetPos ]; final int length = lengthStack[ --lengthPos ]; final int level = levelStack[ --levelPos ]; final int signMask = level % DIGITS_PER_ELEMENT == 0 ? 1 << DIGIT_BITS - 1 : 0; if ( length < MEDIUM ) { insertionSortIndirect( perm, a, b, first, first + length ); continue; } final int[] k = level < DIGITS_PER_ELEMENT ? a : b; // This is the key array final int shift = ( DIGITS_PER_ELEMENT - 1 - level % DIGITS_PER_ELEMENT ) * DIGIT_BITS; // This is the shift that extract the right byte from a key // Count keys. for( int i = length; i-- != 0; ) digit[ i ] = (byte)( ( ( (k[ perm[ first + i ] ]) >>> shift ) & DIGIT_MASK ) ^ signMask ); for( int i = length; i-- != 0; ) count[ digit[ i ] & 0xFF ]++; // Compute cumulative distribution and push non-singleton keys on stack. int lastUsed = -1; for( int i = 0, p = 0; i < 1 << DIGIT_BITS; i++ ) { if ( count[ i ] != 0 ) { lastUsed = i; if ( level < maxLevel && count[ i ] > 1 ){ offsetStack[ offsetPos++ ] = p + first; lengthStack[ lengthPos++ ] = count[ i ]; levelStack[ levelPos++ ] = level + 1; } } if ( stable ) count[ i ] = p += count[ i ]; else pos[ i ] = ( p += count[ i ] ); } if ( stable ) { for( int i = length; i-- != 0; ) support[ --count[ digit[ i ] & 0xFF ] ] = perm[ first + i ]; System.arraycopy( support, 0, perm, first, length ); org.codelibs.jhighlight.fastutil.ints.IntArrays.fill( count, 0 ); } else { // When all slots are OK, the last slot is necessarily OK. final int end = length - count[ lastUsed ]; count[ lastUsed ] = 0; // i moves through the start of each block for( int i = 0, c = -1, d; i < end; i += count[ c ], count[ c ] = 0 ) { int t = perm[ i + first ]; c = digit[ i ] & 0xFF; while( ( d = --pos[ c ] ) > i ) { final int z = t; final int zz = c; t = perm[ d + first ]; c = digit[ d ] & 0xFF; perm[ d + first ] = z; digit[ d ] = (byte)zz; } perm[ i + first ] = t; } } } } private static void selectionSort( final int[][] a, final int from, final int to, final int level ) { final int layers = a.length; final int firstLayer = level / DIGITS_PER_ELEMENT; for( int i = from; i < to - 1; i++ ) { int m = i; for( int j = i + 1; j < to; j++ ) { for( int p = firstLayer; p < layers; p++ ) { if ( a[ p ][ j ] < a[ p ][ m ] ) { m = j; break; } else if ( a[ p ][ j ] > a[ p ][ m ] ) break; } } if ( m != i ) { for( int p = layers; p-- != 0; ) { final int u = a[ p ][ i ]; a[ p ][ i ] = a[ p ][ m ]; a[ p ][ m ] = u; } } } } /** Sorts the specified array of arrays lexicographically using radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implements a lexicographical sorting of the provided arrays. Tuples of elements * in the same position will be considered a single key, and permuted * accordingly. * *

This implementation is significantly faster than quicksort * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. It will allocate a support array of bytes with the same number of elements as the arrays to be sorted. * * @param a an array containing arrays of equal length to be sorted lexicographically in parallel. */ public static void radixSort( final int[][] a ) { radixSort( a, 0, a[ 0 ].length ); } /** Sorts the specified array of arrays lexicographically using radix sort. * *

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas * McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), * and further improved using the digit-oracle idea described by * Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, * String Processing and Information Retrieval, 15th International Symposium, volume 5280 of * Lecture Notes in Computer Science, pages 3−14, Springer (2008). * *

This method implements a lexicographical sorting of the provided arrays. Tuples of elements * in the same position will be considered a single key, and permuted * accordingly. * *

This implementation is significantly faster than quicksort * already at small sizes (say, more than 10000 elements), but it can only * sort in ascending order. It will allocate a support array of bytes with the same number of elements as the arrays to be sorted. * * @param a an array containing arrays of equal length to be sorted lexicographically in parallel. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ public static void radixSort( final int[][] a, final int from, final int to ) { final int layers = a.length; final int maxLevel = DIGITS_PER_ELEMENT * layers - 1; for( int p = layers, l = a[ 0 ].length; p-- != 0; ) if ( a[ p ].length != l ) throw new IllegalArgumentException( "The array of index " + p + " has not the same length of the array of index 0." ); final int stackSize = ( ( 1 << DIGIT_BITS ) - 1 ) * ( layers * DIGITS_PER_ELEMENT - 1 ) + 1; final int[] offsetStack = new int[ stackSize ]; int offsetPos = 0; final int[] lengthStack = new int[ stackSize ]; int lengthPos = 0; final int[] levelStack = new int[ stackSize ]; int levelPos = 0; offsetStack[ offsetPos++ ] = from; lengthStack[ lengthPos++ ] = to - from; levelStack[ levelPos++ ] = 0; final int[] count = new int[ 1 << DIGIT_BITS ]; final int[] pos = new int[ 1 << DIGIT_BITS ]; final byte[] digit = new byte[ to - from ]; final int[] t = new int[ layers ]; while( offsetPos > 0 ) { final int first = offsetStack[ --offsetPos ]; final int length = lengthStack[ --lengthPos ]; final int level = levelStack[ --levelPos ]; final int signMask = level % DIGITS_PER_ELEMENT == 0 ? 1 << DIGIT_BITS - 1 : 0; if ( length < MEDIUM ) { selectionSort( a, first, first + length, level ); continue; } final int[] k = a[ level / DIGITS_PER_ELEMENT ]; // This is the key array final int shift = ( DIGITS_PER_ELEMENT - 1 - level % DIGITS_PER_ELEMENT ) * DIGIT_BITS; // This is the shift that extract the right byte from a key // Count keys. for( int i = length; i-- != 0; ) digit[ i ] = (byte)( ( (k[ first + i ]) >>> shift & DIGIT_MASK ) ^ signMask ); for( int i = length; i-- != 0; ) count[ digit[ i ] & 0xFF ]++; // Compute cumulative distribution and push non-singleton keys on stack. int lastUsed = -1; for( int i = 0, p = 0; i < 1 << DIGIT_BITS; i++ ) { if ( count[ i ] != 0 ) { lastUsed = i; if ( level < maxLevel && count[ i ] > 1 ){ offsetStack[ offsetPos++ ] = p + first; lengthStack[ lengthPos++ ] = count[ i ]; levelStack[ levelPos++ ] = level + 1; } } pos[ i ] = ( p += count[ i ] ); } // When all slots are OK, the last slot is necessarily OK. final int end = length - count[ lastUsed ]; count[ lastUsed ] = 0; // i moves through the start of each block for( int i = 0, c = -1, d; i < end; i += count[ c ], count[ c ] = 0 ) { for( int p = layers; p-- != 0; ) t[ p ] = a[ p ][ i + first ]; c = digit[ i ] & 0xFF; while( ( d = --pos[ c ] ) > i ) { for( int p = layers; p-- != 0; ) { final int u = t[ p ]; t[ p ] = a[ p ][ d + first ]; a[ p ][ d + first ] = u; } final int zz = c; c = digit[ d ] & 0xFF; digit[ d ] = (byte)zz; } for( int p = layers; p-- != 0; ) a[ p ][ i + first ] = t[ p ]; } } } /** Shuffles the specified array fragment using the specified pseudorandom number generator. * * @param a the array to be shuffled. * @param from the index of the first element (inclusive) to be shuffled. * @param to the index of the last element (exclusive) to be shuffled. * @param random a pseudorandom number generator (please use a XorShift* generator). * @return a. */ public static int[] shuffle( final int[] a, final int from, final int to, final Random random ) { for( int i = to - from; i-- != 0; ) { final int p = random.nextInt( i + 1 ); final int t = a[ from + i ]; a[ from + i ] = a[ from + p ]; a[ from + p ] = t; } return a; } /** Shuffles the specified array using the specified pseudorandom number generator. * * @param a the array to be shuffled. * @param random a pseudorandom number generator (please use a XorShift* generator). * @return a. */ public static int[] shuffle( final int[] a, final Random random ) { for( int i = a.length; i-- != 0; ) { final int p = random.nextInt( i + 1 ); final int t = a[ i ]; a[ i ] = a[ p ]; a[ p ] = t; } return a; } /** Reverses the order of the elements in the specified array. * * @param a the array to be reversed. * @return a. */ public static int[] reverse( final int[] a ) { final int length = a.length; for( int i = length / 2; i-- != 0; ) { final int t = a[ length - i - 1 ]; a[ length - i - 1 ] = a[ i ]; a[ i ] = t; } return a; } /** Reverses the order of the elements in the specified array fragment. * * @param a the array to be reversed. * @param from the index of the first element (inclusive) to be reversed. * @param to the index of the last element (exclusive) to be reversed. * @return a. */ public static int[] reverse( final int[] a, final int from, final int to ) { final int length = to - from; for( int i = length / 2; i-- != 0; ) { final int t = a[ from + length - i - 1 ]; a[ from + length - i - 1 ] = a[ from + i ]; a[ from + i ] = t; } return a; } /** A type-specific content-based hash strategy for arrays. */ private static final class ArrayHashStrategy implements Hash.Strategy, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; public int hashCode( final int[] o ) { return java.util.Arrays.hashCode( o ); } public boolean equals( final int[] a, final int[] b ) { return java.util.Arrays.equals( a, b ); } } /** A type-specific content-based hash strategy for arrays. * *

This hash strategy may be used in custom hash collections whenever keys are * arrays, and they must be considered equal by content. This strategy * will handle null correctly, and it is serializable. */ public final static Hash.Strategy HASH_STRATEGY = new ArrayHashStrategy(); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/ints/IntComparator.java000066400000000000000000000041431422762524200333460ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Primitive-type-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.ints; import java.util.Comparator; /** A type-specific {@link Comparator}; provides methods to compare two primitive types both as objects * and as primitive types. * *

Note that fastutil provides a corresponding abstract class that * can be used to implement this interface just by specifying the type-specific * comparator. * * @see Comparator */ public interface IntComparator extends Comparator { /** Compares the given primitive types. * * @see java.util.Comparator * @return A positive integer, zero, or a negative integer if the first * argument is greater than, equal to, or smaller than, respectively, the * second one. */ public int compare( int k1, int k2 ); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/000077500000000000000000000000001422762524200303735ustar00rootroot00000000000000AbstractObjectBidirectionalIterator.java000066400000000000000000000046351422762524200402640ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.objects; /** An abstract class facilitating the creation of type-specific {@linkplain org.codelibs.jhighlight.fastutil.BidirectionalIterator bidirectional iterators}. * *

To create a type-specific bidirectional iterator, besides what is needed * for an iterator you need both a method returning the previous element as * primitive type and a method returning the previous element as an * object. However, if you inherit from this class you need just one (anyone). * *

This class implements also a trivial version of {@link #back(int)} that * uses type-specific methods. */ public abstract class AbstractObjectBidirectionalIterator extends AbstractObjectIterator implements ObjectBidirectionalIterator { protected AbstractObjectBidirectionalIterator() {} /** This method just iterates the type-specific version of {@link #previous()} for * at most n times, stopping if {@link * #hasPrevious()} becomes false. */ public int back( final int n ) { int i = n; while( i-- != 0 && hasPrevious() ) previous(); return n - i - 1; } } AbstractObjectCollection.java000066400000000000000000000114021422762524200360630ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.objects; import java.util.AbstractCollection; import java.util.Collection; import java.util.Iterator; /** An abstract class providing basic methods for collections implementing a type-specific interface. * *

In particular, this class provide {@link #iterator()}, add(), {@link #remove(Object)} and * {@link #contains(Object)} methods that just call the type-specific counterpart. */ public abstract class AbstractObjectCollection extends AbstractCollection implements ObjectCollection { protected AbstractObjectCollection() {} public Object[] toArray() { final Object[] a = new Object[ size() ]; org.codelibs.jhighlight.fastutil.objects.ObjectIterators.unwrap( iterator(), a ); return a; } @SuppressWarnings("unchecked") public T[] toArray( T[] a ) { if ( a.length < size() ) a = (T[])java.lang.reflect.Array.newInstance( a.getClass().getComponentType(), size() ); org.codelibs.jhighlight.fastutil.objects.ObjectIterators.unwrap( iterator(), a ); return a; } /** Adds all elements of the given collection to this collection. * * @param c a collection. * @return true if this collection changed as a result of the call. */ public boolean addAll( Collection c ) { boolean retVal = false; final Iterator i = c.iterator(); int n = c.size(); while( n-- != 0 ) if ( add( i.next() ) ) retVal = true; return retVal; } public boolean add( K k ) { throw new UnsupportedOperationException(); } /** Delegates to the new covariantly stronger generic method. */ @Deprecated public ObjectIterator objectIterator() { return iterator(); } public abstract ObjectIterator iterator(); /** Checks whether this collection contains all elements from the given collection. * * @param c a collection. * @return true if this collection contains all elements of the argument. */ public boolean containsAll( Collection c ) { int n = c.size(); final Iterator i = c.iterator(); while( n-- != 0 ) if ( ! contains( i.next() ) ) return false; return true; } /** Retains in this collection only elements from the given collection. * * @param c a collection. * @return true if this collection changed as a result of the call. */ public boolean retainAll( Collection c ) { boolean retVal = false; int n = size(); final Iterator i = iterator(); while( n-- != 0 ) { if ( ! c.contains( i.next() ) ) { i.remove(); retVal = true; } } return retVal; } /** Remove from this collection all elements in the given collection. * If the collection is an instance of this class, it uses faster iterators. * * @param c a collection. * @return true if this collection changed as a result of the call. */ public boolean removeAll( Collection c ) { boolean retVal = false; int n = c.size(); final Iterator i = c.iterator(); while( n-- != 0 ) if ( remove( i.next() ) ) retVal = true; return retVal; } public boolean isEmpty() { return size() == 0; } public String toString() { final StringBuilder s = new StringBuilder(); final ObjectIterator i = iterator(); int n = size(); Object k; boolean first = true; s.append("{"); while(n-- != 0) { if (first) first = false; else s.append(", "); k = i.next(); if (this == k) s.append("(this collection)"); else s.append(String.valueOf(k)); } s.append("}"); return s.toString(); } } AbstractObjectIterator.java000066400000000000000000000046551422762524200355750ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.objects; /** An abstract class facilitating the creation of type-specific iterators. * *

To create a type-specific iterator you need both a method returning the * next element as primitive type and a method returning the next element as an * object. However, if you inherit from this class you need just one (anyone). * *

This class implements also a trivial version of {@link #skip(int)} that uses * type-specific methods; moreover, {@link #remove()} will throw an {@link * UnsupportedOperationException}. * * @see java.util.Iterator */ public abstract class AbstractObjectIterator implements ObjectIterator { protected AbstractObjectIterator() {} /** This method just throws an {@link UnsupportedOperationException}. */ public void remove() { throw new UnsupportedOperationException(); } /** This method just iterates the type-specific version of {@link #next()} for at most * n times, stopping if {@link #hasNext()} becomes false.*/ public int skip( final int n ) { int i = n; while( i-- != 0 && hasNext() ) next(); return n - i - 1; } } AbstractObjectList.java000066400000000000000000000402571422762524200347150ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.objects; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; import org.codelibs.jhighlight.fastutil.Stack; /** An abstract class providing basic methods for lists implementing a type-specific list interface. * *

As an additional bonus, this class implements on top of the list operations a type-specific stack. */ public abstract class AbstractObjectList extends AbstractObjectCollection implements ObjectList , Stack { protected AbstractObjectList() {} /** Ensures that the given index is nonnegative and not greater than the list size. * * @param index an index. * @throws IndexOutOfBoundsException if the given index is negative or greater than the list size. */ protected void ensureIndex( final int index ) { if ( index < 0 ) throw new IndexOutOfBoundsException( "Index (" + index + ") is negative" ); if ( index > size() ) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than list size (" + ( size() ) + ")" ); } /** Ensures that the given index is nonnegative and smaller than the list size. * * @param index an index. * @throws IndexOutOfBoundsException if the given index is negative or not smaller than the list size. */ protected void ensureRestrictedIndex( final int index ) { if ( index < 0 ) throw new IndexOutOfBoundsException( "Index (" + index + ") is negative" ); if ( index >= size() ) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + ( size() ) + ")" ); } public void add( final int index, final K k ) { throw new UnsupportedOperationException(); } public boolean add( final K k ) { add( size(), k ); return true; } public K remove( int i ) { throw new UnsupportedOperationException(); } public K set( final int index, final K k ) { throw new UnsupportedOperationException(); } public boolean addAll( int index, final Collection c ) { ensureIndex( index ); int n = c.size(); if ( n == 0 ) return false; Iterator i = c.iterator(); while( n-- != 0 ) add( index++, i.next() ); return true; } /** Delegates to a more generic method. */ public boolean addAll( final Collection c ) { return addAll( size(), c ); } /** Delegates to the new covariantly stronger generic method. */ @Deprecated public ObjectListIterator objectListIterator() { return listIterator(); } /** Delegates to the new covariantly stronger generic method. */ @Deprecated public ObjectListIterator objectListIterator( final int index ) { return listIterator( index ); } public ObjectListIterator iterator() { return listIterator(); } public ObjectListIterator listIterator() { return listIterator( 0 ); } public ObjectListIterator listIterator( final int index ) { return new AbstractObjectListIterator () { int pos = index, last = -1; public boolean hasNext() { return pos < AbstractObjectList.this.size(); } public boolean hasPrevious() { return pos > 0; } public K next() { if ( ! hasNext() ) throw new NoSuchElementException(); return AbstractObjectList.this.get( last = pos++ ); } public K previous() { if ( ! hasPrevious() ) throw new NoSuchElementException(); return AbstractObjectList.this.get( last = --pos ); } public int nextIndex() { return pos; } public int previousIndex() { return pos - 1; } public void add( K k ) { if ( last == -1 ) throw new IllegalStateException(); AbstractObjectList.this.add( pos++, k ); last = -1; } public void set( K k ) { if ( last == -1 ) throw new IllegalStateException(); AbstractObjectList.this.set( last, k ); } public void remove() { if ( last == -1 ) throw new IllegalStateException(); AbstractObjectList.this.remove( last ); /* If the last operation was a next(), we are removing an element *before* us, and we must decrease pos correspondingly. */ if ( last < pos ) pos--; last = -1; } }; } public boolean contains( final Object k ) { return indexOf( k ) >= 0; } public int indexOf( final Object k ) { final ObjectListIterator i = listIterator(); K e; while( i.hasNext() ) { e = i.next(); if ( ( (k) == null ? (e) == null : (k).equals(e) ) ) return i.previousIndex(); } return -1; } public int lastIndexOf( final Object k ) { ObjectListIterator i = listIterator( size() ); K e; while( i.hasPrevious() ) { e = i.previous(); if ( ( (k) == null ? (e) == null : (k).equals(e) ) ) return i.nextIndex(); } return -1; } public void size( final int size ) { int i = size(); if ( size > i ) while( i++ < size ) add( (null) ); else while( i-- != size ) remove( i ); } public ObjectList subList( final int from, final int to ) { ensureIndex( from ); ensureIndex( to ); if ( from > to ) throw new IndexOutOfBoundsException( "Start index (" + from + ") is greater than end index (" + to + ")" ); return new ObjectSubList ( this, from, to ); } /** Delegates to the new covariantly stronger generic method. */ @Deprecated public ObjectList objectSubList( final int from, final int to ) { return subList( from, to ); } /** Removes elements of this type-specific list one-by-one. * *

This is a trivial iterator-based implementation. It is expected that * implementations will override this method with a more optimized version. * * * @param from the start index (inclusive). * @param to the end index (exclusive). */ public void removeElements( final int from, final int to ) { ensureIndex( to ); ObjectListIterator i = listIterator( from ); int n = to - from; if ( n < 0 ) throw new IllegalArgumentException( "Start index (" + from + ") is greater than end index (" + to + ")" ); while( n-- != 0 ) { i.next(); i.remove(); } } /** Adds elements to this type-specific list one-by-one. * *

This is a trivial iterator-based implementation. It is expected that * implementations will override this method with a more optimized version. * * @param index the index at which to add elements. * @param a the array containing the elements. * @param offset the offset of the first element to add. * @param length the number of elements to add. */ public void addElements( int index, final K a[], int offset, int length ) { ensureIndex( index ); if ( offset < 0 ) throw new ArrayIndexOutOfBoundsException( "Offset (" + offset + ") is negative" ); if ( offset + length > a.length ) throw new ArrayIndexOutOfBoundsException( "End index (" + ( offset + length ) + ") is greater than array length (" + a.length + ")" ); while( length-- != 0 ) add( index++, a[ offset++ ] ); } public void addElements( final int index, final K a[] ) { addElements( index, a, 0, a.length ); } /** Copies element of this type-specific list into the given array one-by-one. * *

This is a trivial iterator-based implementation. It is expected that * implementations will override this method with a more optimized version. * * @param from the start index (inclusive). * @param a the destination array. * @param offset the offset into the destination array where to store the first element copied. * @param length the number of elements to be copied. */ public void getElements( final int from, final Object a[], int offset, int length ) { ObjectListIterator i = listIterator( from ); if ( offset < 0 ) throw new ArrayIndexOutOfBoundsException( "Offset (" + offset + ") is negative" ); if ( offset + length > a.length ) throw new ArrayIndexOutOfBoundsException( "End index (" + ( offset + length ) + ") is greater than array length (" + a.length + ")" ); if ( from + length > size() ) throw new IndexOutOfBoundsException( "End index (" + ( from + length ) + ") is greater than list size (" + size() + ")" ); while( length-- != 0 ) a[ offset++ ] = i.next(); } private boolean valEquals( final Object a, final Object b ) { return a == null ? b == null : a.equals( b ); } public boolean equals( final Object o ) { if ( o == this ) return true; if ( ! ( o instanceof List ) ) return false; final List l = (List)o; int s = size(); if ( s != l.size() ) return false; final ListIterator i1 = listIterator(), i2 = l.listIterator(); while( s-- != 0 ) if ( ! valEquals( i1.next(), i2.next() ) ) return false; return true; } /** Compares this list to another object. If the * argument is a {@link java.util.List}, this method performs a lexicographical comparison; otherwise, * it throws a ClassCastException. * * @param l a list. * @return if the argument is a {@link java.util.List}, a negative integer, * zero, or a positive integer as this list is lexicographically less than, equal * to, or greater than the argument. * @throws ClassCastException if the argument is not a list. */ @SuppressWarnings("unchecked") public int compareTo( final List l ) { if ( l == this ) return 0; if ( l instanceof ObjectList ) { final ObjectListIterator i1 = listIterator(), i2 = ((ObjectList )l).listIterator(); int r; K e1, e2; while( i1.hasNext() && i2.hasNext() ) { e1 = i1.next(); e2 = i2.next(); if ( ( r = ( ((Comparable)(e1)).compareTo(e2) ) ) != 0 ) return r; } return i2.hasNext() ? -1 : ( i1.hasNext() ? 1 : 0 ); } ListIterator i1 = listIterator(), i2 = l.listIterator(); int r; while( i1.hasNext() && i2.hasNext() ) { if ( ( r = ((Comparable)i1.next()).compareTo( i2.next() ) ) != 0 ) return r; } return i2.hasNext() ? -1 : ( i1.hasNext() ? 1 : 0 ); } /** Returns the hash code for this list, which is identical to {@link java.util.List#hashCode()}. * * @return the hash code for this list. */ public int hashCode() { ObjectIterator i = iterator(); int h = 1, s = size(); while ( s-- != 0 ) { K k = i.next(); h = 31 * h + ( (k) == null ? 0 : (k).hashCode() ); } return h; } public void push( K o ) { add( o ); } public K pop() { if ( isEmpty() ) throw new NoSuchElementException(); return remove( size() - 1 ); } public K top() { if ( isEmpty() ) throw new NoSuchElementException(); return get( size() - 1 ); } public K peek( int i ) { return get( size() - 1 - i ); } public String toString() { final StringBuilder s = new StringBuilder(); final ObjectIterator i = iterator(); int n = size(); K k; boolean first = true; s.append("["); while( n-- != 0 ) { if (first) first = false; else s.append(", "); k = i.next(); if (this == k) s.append("(this list)"); else s.append( String.valueOf( k ) ); } s.append("]"); return s.toString(); } public static class ObjectSubList extends AbstractObjectList implements java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; /** The list this sublist restricts. */ protected final ObjectList l; /** Initial (inclusive) index of this sublist. */ protected final int from; /** Final (exclusive) index of this sublist. */ protected int to; private static final boolean ASSERTS = false; public ObjectSubList( final ObjectList l, final int from, final int to ) { this.l = l; this.from = from; this.to = to; } private void assertRange() { if ( ASSERTS ) { assert from <= l.size(); assert to <= l.size(); assert to >= from; } } public boolean add( final K k ) { l.add( to, k ); to++; if ( ASSERTS ) assertRange(); return true; } public void add( final int index, final K k ) { ensureIndex( index ); l.add( from + index, k ); to++; if ( ASSERTS ) assertRange(); } public boolean addAll( final int index, final Collection c ) { ensureIndex( index ); to += c.size(); if ( ASSERTS ) { boolean retVal = l.addAll( from + index, c ); assertRange(); return retVal; } return l.addAll( from + index, c ); } public K get( int index ) { ensureRestrictedIndex( index ); return l.get( from + index ); } public K remove( int index ) { ensureRestrictedIndex( index ); to--; return l.remove( from + index ); } public K set( int index, K k ) { ensureRestrictedIndex( index ); return l.set( from + index, k ); } public void clear() { removeElements( 0, size() ); if ( ASSERTS ) assertRange(); } public int size() { return to - from; } public void getElements( final int from, final Object[] a, final int offset, final int length ) { ensureIndex( from ); if ( from + length > size() ) throw new IndexOutOfBoundsException( "End index (" + from + length + ") is greater than list size (" + size() + ")" ); l.getElements( this.from + from, a, offset, length ); } public void removeElements( final int from, final int to ) { ensureIndex( from ); ensureIndex( to ); l.removeElements( this.from + from, this.from + to ); this.to -= ( to - from ); if ( ASSERTS ) assertRange(); } public void addElements( int index, final K a[], int offset, int length ) { ensureIndex( index ); l.addElements( this.from + index, a, offset, length ); this.to += length; if ( ASSERTS ) assertRange(); } public ObjectListIterator listIterator( final int index ) { ensureIndex( index ); return new AbstractObjectListIterator () { int pos = index, last = -1; public boolean hasNext() { return pos < size(); } public boolean hasPrevious() { return pos > 0; } public K next() { if ( ! hasNext() ) throw new NoSuchElementException(); return l.get( from + ( last = pos++ ) ); } public K previous() { if ( ! hasPrevious() ) throw new NoSuchElementException(); return l.get( from + ( last = --pos ) ); } public int nextIndex() { return pos; } public int previousIndex() { return pos - 1; } public void add( K k ) { if ( last == -1 ) throw new IllegalStateException(); ObjectSubList.this.add( pos++, k ); last = -1; if ( ASSERTS ) assertRange(); } public void set( K k ) { if ( last == -1 ) throw new IllegalStateException(); ObjectSubList.this.set( last, k ); } public void remove() { if ( last == -1 ) throw new IllegalStateException(); ObjectSubList.this.remove( last ); /* If the last operation was a next(), we are removing an element *before* us, and we must decrease pos correspondingly. */ if ( last < pos ) pos--; last = -1; if ( ASSERTS ) assertRange(); } }; } public ObjectList subList( final int from, final int to ) { ensureIndex( from ); ensureIndex( to ); if ( from > to ) throw new IllegalArgumentException( "Start index (" + from + ") is greater than end index (" + to + ")" ); return new ObjectSubList ( this, from, to ); } @SuppressWarnings("unchecked") public boolean remove( final Object o ) { int index = indexOf( o ); if ( index == -1 ) return false; remove( index ); return true; } } } AbstractObjectListIterator.java000066400000000000000000000046501422762524200364240ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.objects; /** An abstract class facilitating the creation of type-specific {@linkplain java.util.ListIterator list iterators}. * *

This class provides trivial type-specific implementations of {@link * java.util.ListIterator#set(Object) set()} and {@link java.util.ListIterator#add(Object) add()} which * throw an {@link UnsupportedOperationException}. For primitive types, it also * provides a trivial implementation of {@link java.util.ListIterator#set(Object) set()} and {@link * java.util.ListIterator#add(Object) add()} that just invokes the type-specific one. * * * @see java.util.ListIterator */ public abstract class AbstractObjectListIterator extends AbstractObjectBidirectionalIterator implements ObjectListIterator { protected AbstractObjectListIterator() {} /** This method just throws an {@link UnsupportedOperationException}. */ public void set( K k ) { throw new UnsupportedOperationException(); } /** This method just throws an {@link UnsupportedOperationException}. */ public void add( K k ) { throw new UnsupportedOperationException(); } } AbstractObjectSet.java000066400000000000000000000046361422762524200345360ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.objects; import java.util.Set; /** An abstract class providing basic methods for sets implementing a type-specific interface. */ public abstract class AbstractObjectSet extends AbstractObjectCollection implements Cloneable, ObjectSet { protected AbstractObjectSet() {} public abstract ObjectIterator iterator(); public boolean equals( final Object o ) { if ( o == this ) return true; if ( !( o instanceof Set ) ) return false; Set s = (Set) o; if ( s.size() != size() ) return false; return containsAll(s); } /** Returns a hash code for this set. * * The hash code of a set is computed by summing the hash codes of * its elements. * * @return a hash code for this set. */ public int hashCode() { int h = 0, n = size(); ObjectIterator i = iterator(); K k; while( n-- != 0 ) { k = i.next(); // We need k because KEY2JAVAHASH() is a macro with repeated evaluation. h += ( (k) == null ? 0 : (k).hashCode() ); } return h; } public boolean remove( Object k ) { throw new UnsupportedOperationException(); } } ObjectArrayList.java000066400000000000000000000424741422762524200342330ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.objects; import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.RandomAccess; import org.codelibs.jhighlight.fastutil.Arrays; /** A type-specific array-based list; provides some additional methods that use polymorphism to avoid (un)boxing. * *

This class implements a lightweight, fast, open, optimized, * reuse-oriented version of array-based lists. Instances of this class * represent a list with an array that is enlarged as needed when new entries * are created (by doubling the current length), but is * never made smaller (even on a {@link #clear()}). A family of * {@linkplain #trim() trimming methods} lets you control the size of the * backing array; this is particularly useful if you reuse instances of this class. * Range checks are equivalent to those of {@link java.util}'s classes, but * they are delayed as much as possible. * *

The backing array is exposed by the {@link #elements()} method. If an instance * of this class was created {@linkplain #wrap(Object[],int) by wrapping}, * backing-array reallocations will be performed using reflection, so that * {@link #elements()} can return an array of the same type of the original array; the comments * about efficiency made in {@link org.codelibs.jhighlight.fastutil.objects.ObjectArrays} apply here. * *

This class implements the bulk methods removeElements(), * addElements() and getElements() using * high-performance system calls (e.g., {@link * System#arraycopy(Object,int,Object,int,int) System.arraycopy()} instead of * expensive loops. * * @see java.util.ArrayList */ public class ObjectArrayList extends AbstractObjectList implements RandomAccess, Cloneable, java.io.Serializable { private static final long serialVersionUID = -7046029254386353131L; /** The initial default capacity of an array list. */ public final static int DEFAULT_INITIAL_CAPACITY = 16; /** Whether the backing array was passed to wrap(). In * this case, we must reallocate with the same type of array. */ protected final boolean wrapped; /** The backing array. */ protected transient K a[]; /** The current actual size of the list (never greater than the backing-array length). */ protected int size; private static final boolean ASSERTS = false; /** Creates a new array list using a given array. * *

This constructor is only meant to be used by the wrapping methods. * * @param a the array that will be used to back this array list. */ @SuppressWarnings("unused") protected ObjectArrayList( final K a[], boolean dummy ) { this.a = a; this.wrapped = true; } /** Creates a new array list with given capacity. * * @param capacity the initial capacity of the array list (may be 0). */ @SuppressWarnings("unchecked") public ObjectArrayList( final int capacity ) { if ( capacity < 0 ) throw new IllegalArgumentException( "Initial capacity (" + capacity + ") is negative" ); a = (K[]) new Object[ capacity ]; wrapped = false; } /** Creates a new array list with {@link #DEFAULT_INITIAL_CAPACITY} capacity. */ public ObjectArrayList() { this( DEFAULT_INITIAL_CAPACITY ); } /** Creates a new array list and fills it with a given collection. * * @param c a collection that will be used to fill the array list. */ public ObjectArrayList( final Collection c ) { this( c.size() ); size = ObjectIterators.unwrap( c.iterator(), a ); } /** Creates a new array list and fills it with a given type-specific collection. * * @param c a type-specific collection that will be used to fill the array list. */ public ObjectArrayList( final ObjectCollection c ) { this( c.size() ); size = ObjectIterators.unwrap( c.iterator(), a ); } /** Creates a new array list and fills it with a given type-specific list. * * @param l a type-specific list that will be used to fill the array list. */ public ObjectArrayList( final ObjectList l ) { this( l.size() ); l.getElements( 0, a, 0, size = l.size() ); } /** Creates a new array list and fills it with the elements of a given array. * * @param a an array whose elements will be used to fill the array list. */ public ObjectArrayList( final K a[] ) { this( a, 0, a.length ); } /** Creates a new array list and fills it with the elements of a given array. * * @param a an array whose elements will be used to fill the array list. * @param offset the first element to use. * @param length the number of elements to use. */ public ObjectArrayList( final K a[], final int offset, final int length ) { this( length ); System.arraycopy( a, offset, this.a, 0, length ); size = length; } /** Creates a new array list and fills it with the elements returned by an iterator.. * * @param i an iterator whose returned elements will fill the array list. */ public ObjectArrayList( final Iterator i ) { this(); while( i.hasNext() ) this.add( i.next() ); } /** Creates a new array list and fills it with the elements returned by a type-specific iterator.. * * @param i a type-specific iterator whose returned elements will fill the array list. */ public ObjectArrayList( final ObjectIterator i ) { this(); while( i.hasNext() ) this.add( i.next() ); } /** Returns the backing array of this list. * *

If this array list was created by wrapping a given array, it is guaranteed * that the type of the returned array will be the same. Otherwise, the returned * array will be of type {@link Object Object[]} (in spite of the declared return type). * * Warning: This behaviour may cause (unfathomable) * run-time errors if a method expects an array * actually of type K[], but this methods returns an array * of type {@link Object Object[]}. * * @return the backing array. */ public K[] elements() { return a; } /** Wraps a given array into an array list of given size. * * @param a an array to wrap. * @param length the length of the resulting array list. * @return a new array list of the given size, wrapping the given array. */ public static ObjectArrayList wrap( final K a[], final int length ) { if ( length > a.length ) throw new IllegalArgumentException( "The specified length (" + length + ") is greater than the array size (" + a.length + ")" ); final ObjectArrayList l = new ObjectArrayList ( a, false ); l.size = length; return l; } /** Wraps a given array into an array list. * * @param a an array to wrap. * @return a new array list wrapping the given array. */ public static ObjectArrayList wrap( final K a[] ) { return wrap( a, a.length ); } /** Ensures that this array list can contain the given number of entries without resizing. * * @param capacity the new minimum capacity for this array list. */ @SuppressWarnings("unchecked") public void ensureCapacity( final int capacity ) { if ( wrapped ) a = ObjectArrays.ensureCapacity( a, capacity, size ); else { if ( capacity > a.length ) { final Object t[] = new Object[ capacity ]; System.arraycopy( a, 0, t, 0, size ); a = (K[])t; } } if ( ASSERTS ) assert size <= a.length; } /** Grows this array list, ensuring that it can contain the given number of entries without resizing, * and in case enlarging it at least by a factor of two. * * @param capacity the new minimum capacity for this array list. */ @SuppressWarnings("unchecked") private void grow( final int capacity ) { if ( wrapped ) a = ObjectArrays.grow( a, capacity, size ); else { if ( capacity > a.length ) { final int newLength = (int)Math.max( Math.min( 2L * a.length, Arrays.MAX_ARRAY_SIZE ), capacity ); final Object t[] = new Object[ newLength ]; System.arraycopy( a, 0, t, 0, size ); a = (K[])t; } } if ( ASSERTS ) assert size <= a.length; } public void add( final int index, final K k ) { ensureIndex( index ); grow( size + 1 ); if ( index != size ) System.arraycopy( a, index, a, index + 1, size - index ); a[ index ] = k; size++; if ( ASSERTS ) assert size <= a.length; } public boolean add( final K k ) { grow( size + 1 ); a[ size++ ] = k; if ( ASSERTS ) assert size <= a.length; return true; } public K get( final int index ) { if ( index >= size ) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + size + ")" ); return a[ index ]; } public int indexOf( final Object k ) { for( int i = 0; i < size; i++ ) if ( ( (k) == null ? (a[ i ]) == null : (k).equals(a[ i ]) ) ) return i; return -1; } public int lastIndexOf( final Object k ) { for( int i = size; i-- != 0; ) if ( ( (k) == null ? (a[ i ]) == null : (k).equals(a[ i ]) ) ) return i; return -1; } public K remove( final int index ) { if ( index >= size ) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + size + ")" ); final K old = a[ index ]; size--; if ( index != size ) System.arraycopy( a, index + 1, a, index, size - index ); a[ size ] = null; if ( ASSERTS ) assert size <= a.length; return old; } public boolean rem( final Object k ) { int index = indexOf( k ); if ( index == -1 ) return false; remove( index ); if ( ASSERTS ) assert size <= a.length; return true; } public boolean remove( final Object o ) { return rem( o ); } public K set( final int index, final K k ) { if ( index >= size ) throw new IndexOutOfBoundsException( "Index (" + index + ") is greater than or equal to list size (" + size + ")" ); K old = a[ index ]; a[ index ] = k; return old; } public void clear() { ObjectArrays.fill( a, 0, size, null ); size = 0; if ( ASSERTS ) assert size <= a.length; } public int size() { return size; } public void size( final int size ) { if ( size > a.length ) ensureCapacity( size ); if ( size > this.size ) ObjectArrays.fill( a, this.size, size, (null) ); else ObjectArrays.fill( a, size, this.size, (null) ); this.size = size; } public boolean isEmpty() { return size == 0; } /** Trims this array list so that the capacity is equal to the size. * * @see java.util.ArrayList#trimToSize() */ public void trim() { trim( 0 ); } /** Trims the backing array if it is too large. * * If the current array length is smaller than or equal to * n, this method does nothing. Otherwise, it trims the * array length to the maximum between n and {@link #size()}. * *

This method is useful when reusing lists. {@linkplain #clear() Clearing a * list} leaves the array length untouched. If you are reusing a list * many times, you can call this method with a typical * size to avoid keeping around a very large array just * because of a few large transient lists. * * @param n the threshold for the trimming. */ @SuppressWarnings("unchecked") public void trim( final int n ) { // TODO: use Arrays.trim() and preserve type only if necessary if ( n >= a.length || size == a.length ) return; final K t[] = (K[]) new Object[ Math.max( n, size ) ]; System.arraycopy( a, 0, t, 0, size ); a = t; if ( ASSERTS ) assert size <= a.length; } /** Copies element of this type-specific list into the given array using optimized system calls. * * @param from the start index (inclusive). * @param a the destination array. * @param offset the offset into the destination array where to store the first element copied. * @param length the number of elements to be copied. */ public void getElements( final int from, final Object[] a, final int offset, final int length ) { ObjectArrays.ensureOffsetLength( a, offset, length ); System.arraycopy( this.a, from, a, offset, length ); } /** Removes elements of this type-specific list using optimized system calls. * * @param from the start index (inclusive). * @param to the end index (exclusive). */ public void removeElements( final int from, final int to ) { Arrays.ensureFromTo( size, from, to ); System.arraycopy( a, to, a, from, size - to ); size -= ( to - from ); int i = to - from; while( i-- != 0 ) a[ size + i ] = null; } /** Adds elements to this type-specific list using optimized system calls. * * @param index the index at which to add elements. * @param a the array containing the elements. * @param offset the offset of the first element to add. * @param length the number of elements to add. */ public void addElements( final int index, final K a[], final int offset, final int length ) { ensureIndex( index ); ObjectArrays.ensureOffsetLength( a, offset, length ); grow( size + length ); System.arraycopy( this.a, index, this.a, index + length, size - index ); System.arraycopy( a, offset, this.a, index, length ); size += length; } public ObjectListIterator listIterator( final int index ) { ensureIndex( index ); return new AbstractObjectListIterator () { int pos = index, last = -1; public boolean hasNext() { return pos < size; } public boolean hasPrevious() { return pos > 0; } public K next() { if ( ! hasNext() ) throw new NoSuchElementException(); return a[ last = pos++ ]; } public K previous() { if ( ! hasPrevious() ) throw new NoSuchElementException(); return a[ last = --pos ]; } public int nextIndex() { return pos; } public int previousIndex() { return pos - 1; } public void add( K k ) { if ( last == -1 ) throw new IllegalStateException(); ObjectArrayList.this.add( pos++, k ); last = -1; } public void set( K k ) { if ( last == -1 ) throw new IllegalStateException(); ObjectArrayList.this.set( last, k ); } public void remove() { if ( last == -1 ) throw new IllegalStateException(); ObjectArrayList.this.remove( last ); /* If the last operation was a next(), we are removing an element *before* us, and we must decrease pos correspondingly. */ if ( last < pos ) pos--; last = -1; } }; } @SuppressWarnings("unchecked") public ObjectArrayList clone() { ObjectArrayList c = new ObjectArrayList ( size ); System.arraycopy( a, 0, c.a, 0, size ); c.size = size; return c; } private boolean valEquals( final K a, final K b ) { return a == null ? b == null : a.equals( b ); } /** Compares this type-specific array list to another one. * *

This method exists only for sake of efficiency. The implementation * inherited from the abstract implementation would already work. * * @param l a type-specific array list. * @return true if the argument contains the same elements of this type-specific array list. */ public boolean equals( final ObjectArrayList l ) { if ( l == this ) return true; int s = size(); if ( s != l.size() ) return false; final K[] a1 = a; final K[] a2 = l.a; while( s-- != 0 ) if ( ! valEquals( a1[ s ], a2[ s ] ) ) return false; return true; } /** Compares this array list to another array list. * *

This method exists only for sake of efficiency. The implementation * inherited from the abstract implementation would already work. * * @param l an array list. * @return a negative integer, * zero, or a positive integer as this list is lexicographically less than, equal * to, or greater than the argument. */ @SuppressWarnings("unchecked") public int compareTo( final ObjectArrayList l ) { final int s1 = size(), s2 = l.size(); final K a1[] = a, a2[] = l.a; K e1, e2; int r, i; for( i = 0; i < s1 && i < s2; i++ ) { e1 = a1[ i ]; e2 = a2[ i ]; if ( ( r = ( ((Comparable)(e1)).compareTo(e2) ) ) != 0 ) return r; } return i < s2 ? -1 : ( i < s1 ? 1 : 0 ); } private void writeObject( java.io.ObjectOutputStream s ) throws java.io.IOException { s.defaultWriteObject(); for( int i = 0; i < size; i++ ) s.writeObject( a[ i ] ); } @SuppressWarnings("unchecked") private void readObject( java.io.ObjectInputStream s ) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); a = (K[]) new Object[ size ]; for( int i = 0; i < size; i++ ) a[ i ] = (K) s.readObject(); } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/ObjectArrays.java000066400000000000000000001060261422762524200336330ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * * * For the sorting and binary search code: * * Copyright (C) 1999 CERN - European Organization for Nuclear Research. * * Permission to use, copy, modify, distribute and sell this software and * its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation. CERN makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without expressed or implied warranty. */ package org.codelibs.jhighlight.fastutil.objects; import java.util.Comparator; import java.util.Random; import org.codelibs.jhighlight.fastutil.Arrays; import org.codelibs.jhighlight.fastutil.Hash; /** A class providing static methods and objects that do useful things with type-specific arrays. * * In particular, the ensureCapacity(), grow(), * trim() and setLength() methods allow to handle * arrays much like array lists. This can be very useful when efficiency (or * syntactic simplicity) reasons make array lists unsuitable. * *

Warning: creating arrays * using {@linkplain java.lang.reflect.Array#newInstance(Class,int) reflection}, as it * happens in {@link #ensureCapacity(Object[],int,int)} and {@link #grow(Object[],int,int)}, * is significantly slower than using new. This phenomenon is particularly * evident in the first growth phases of an array reallocated with doubling (or similar) logic. * * @see java.util.Arrays */ public class ObjectArrays { private ObjectArrays() {} /** A static, final, empty array. */ public final static Object[] EMPTY_ARRAY = {}; /** Creates a new array using a the given one as prototype. * *

This method returns a new array of the given length whose element * are of the same class as of those of prototype. In case * of an empty array, it tries to return {@link #EMPTY_ARRAY}, if possible. * * @param prototype an array that will be used to type the new one. * @param length the length of the new array. * @return a new array of given type and length. */ @SuppressWarnings("unchecked") private static K[] newArray( final K[] prototype, final int length ) { final Class componentType = prototype.getClass().getComponentType(); if ( length == 0 && componentType == Object.class ) return (K[])EMPTY_ARRAY; return (K[])java.lang.reflect.Array.newInstance( prototype.getClass().getComponentType(), length ); } /** Ensures that an array can contain the given number of entries. * *

If you cannot foresee whether this array will need again to be * enlarged, you should probably use grow() instead. * * @param array an array. * @param length the new minimum length for this array. * @return array, if it contains length entries or more; otherwise, * an array with length entries whose first array.length * entries are the same as those of array. */ public static K[] ensureCapacity( final K[] array, final int length ) { if ( length > array.length ) { final K t[] = newArray( array, length ); System.arraycopy( array, 0, t, 0, array.length ); return t; } return array; } /** Ensures that an array can contain the given number of entries, preserving just a part of the array. * * @param array an array. * @param length the new minimum length for this array. * @param preserve the number of elements of the array that must be preserved in case a new allocation is necessary. * @return array, if it can contain length entries or more; otherwise, * an array with length entries whose first preserve * entries are the same as those of array. */ public static K[] ensureCapacity( final K[] array, final int length, final int preserve ) { if ( length > array.length ) { final K t[] = newArray( array, length ); System.arraycopy( array, 0, t, 0, preserve ); return t; } return array; } /** Grows the given array to the maximum between the given length and * the current length multiplied by two, provided that the given * length is larger than the current length. * *

If you want complete control on the array growth, you * should probably use ensureCapacity() instead. * * @param array an array. * @param length the new minimum length for this array. * @return array, if it can contain length * entries; otherwise, an array with * max(length,array.length/φ) entries whose first * array.length entries are the same as those of array. * */ public static K[] grow( final K[] array, final int length ) { if ( length > array.length ) { final int newLength = (int)Math.max( Math.min( 2L * array.length, Arrays.MAX_ARRAY_SIZE ), length ); final K t[] = newArray( array, newLength ); System.arraycopy( array, 0, t, 0, array.length ); return t; } return array; } /** Grows the given array to the maximum between the given length and * the current length multiplied by two, provided that the given * length is larger than the current length, preserving just a part of the array. * *

If you want complete control on the array growth, you * should probably use ensureCapacity() instead. * * @param array an array. * @param length the new minimum length for this array. * @param preserve the number of elements of the array that must be preserved in case a new allocation is necessary. * @return array, if it can contain length * entries; otherwise, an array with * max(length,array.length/φ) entries whose first * preserve entries are the same as those of array. * */ public static K[] grow( final K[] array, final int length, final int preserve ) { if ( length > array.length ) { final int newLength = (int)Math.max( Math.min( 2L * array.length, Arrays.MAX_ARRAY_SIZE ), length ); final K t[] = newArray( array, newLength ); System.arraycopy( array, 0, t, 0, preserve ); return t; } return array; } /** Trims the given array to the given length. * * @param array an array. * @param length the new maximum length for the array. * @return array, if it contains length * entries or less; otherwise, an array with * length entries whose entries are the same as * the first length entries of array. * */ public static K[] trim( final K[] array, final int length ) { if ( length >= array.length ) return array; final K t[] = newArray( array, length ); System.arraycopy( array, 0, t, 0, length ); return t; } /** Sets the length of the given array. * * @param array an array. * @param length the new length for the array. * @return array, if it contains exactly length * entries; otherwise, if it contains more than * length entries, an array with length entries * whose entries are the same as the first length entries of * array; otherwise, an array with length entries * whose first array.length entries are the same as those of * array. * */ public static K[] setLength( final K[] array, final int length ) { if ( length == array.length ) return array; if ( length < array.length ) return trim( array, length ); return ensureCapacity( array, length ); } /** Returns a copy of a portion of an array. * * @param array an array. * @param offset the first element to copy. * @param length the number of elements to copy. * @return a new array containing length elements of array starting at offset. */ public static K[] copy( final K[] array, final int offset, final int length ) { ensureOffsetLength( array, offset, length ); final K[] a = newArray( array, length ); System.arraycopy( array, offset, a, 0, length ); return a; } /** Returns a copy of an array. * * @param array an array. * @return a copy of array. */ public static K[] copy( final K[] array ) { return array.clone(); } /** Fills the given array with the given value. * *

This method uses a backward loop. It is significantly faster than the corresponding * method in {@link java.util.Arrays}. * * @param array an array. * @param value the new value for all elements of the array. */ public static void fill( final K[] array, final K value ) { int i = array.length; while( i-- != 0 ) array[ i ] = value; } /** Fills a portion of the given array with the given value. * *

If possible (i.e., from is 0) this method uses a * backward loop. In this case, it is significantly faster than the * corresponding method in {@link java.util.Arrays}. * * @param array an array. * @param from the starting index of the portion to fill (inclusive). * @param to the end index of the portion to fill (exclusive). * @param value the new value for all elements of the specified portion of the array. */ public static void fill( final K[] array, final int from, int to, final K value ) { ensureFromTo( array, from, to ); if ( from == 0 ) while( to-- != 0 ) array[ to ] = value; else for( int i = from; i < to; i++ ) array[ i ] = value; } /** Returns true if the two arrays are elementwise equal. * * @param a1 an array. * @param a2 another array. * @return true if the two arrays are of the same length, and their elements are equal. * @deprecated Please use the corresponding {@link java.util.Arrays} method, which is intrinsified in recent JVMs. */ @Deprecated public static boolean equals( final K[] a1, final K a2[] ) { int i = a1.length; if ( i != a2.length ) return false; while( i-- != 0 ) if (! ( (a1[ i ]) == null ? (a2[ i ]) == null : (a1[ i ]).equals(a2[ i ]) ) ) return false; return true; } /** Ensures that a range given by its first (inclusive) and last (exclusive) elements fits an array. * *

This method may be used whenever an array range check is needed. * * @param a an array. * @param from a start index (inclusive). * @param to an end index (exclusive). * @throws IllegalArgumentException if from is greater than to. * @throws ArrayIndexOutOfBoundsException if from or to are greater than the array length or negative. */ public static void ensureFromTo( final K[] a, final int from, final int to ) { Arrays.ensureFromTo( a.length, from, to ); } /** Ensures that a range given by an offset and a length fits an array. * *

This method may be used whenever an array range check is needed. * * @param a an array. * @param offset a start index. * @param length a length (the number of elements in the range). * @throws IllegalArgumentException if length is negative. * @throws ArrayIndexOutOfBoundsException if offset is negative or offset+length is greater than the array length. */ public static void ensureOffsetLength( final K[] a, final int offset, final int length ) { Arrays.ensureOffsetLength( a.length, offset, length ); } private static final int SMALL = 7; private static final int MEDIUM = 50; private static void swap( final K x[], final int a, final int b ) { final K t = x[ a ]; x[ a ] = x[ b ]; x[ b ] = t; } private static void vecSwap( final K[] x, int a, int b, final int n ) { for( int i = 0; i < n; i++, a++, b++ ) swap( x, a, b ); } private static int med3( final K x[], final int a, final int b, final int c, Comparator comp ) { int ab = comp.compare( x[ a ], x[ b ] ); int ac = comp.compare( x[ a ], x[ c ] ); int bc = comp.compare( x[ b ], x[ c ] ); return ( ab < 0 ? ( bc < 0 ? b : ac < 0 ? c : a ) : ( bc > 0 ? b : ac > 0 ? c : a ) ); } private static void selectionSort( final K[] a, final int from, final int to, final Comparator comp ) { for( int i = from; i < to - 1; i++ ) { int m = i; for( int j = i + 1; j < to; j++ ) if ( comp.compare( a[ j ], a[ m ] ) < 0 ) m = j; if ( m != i ) { final K u = a[ i ]; a[ i ] = a[ m ]; a[ m ] = u; } } } private static void insertionSort( final K[] a, final int from, final int to, final Comparator comp ) { for ( int i = from; ++i < to; ) { K t = a[ i ]; int j = i; for ( K u = a[ j - 1 ]; comp.compare( t, u ) < 0; u = a[ --j - 1 ] ) { a[ j ] = u; if ( from == j - 1 ) { --j; break; } } a[ j ] = t; } } @SuppressWarnings("unchecked") private static void selectionSort( final K[] a, final int from, final int to ) { for( int i = from; i < to - 1; i++ ) { int m = i; for( int j = i + 1; j < to; j++ ) if ( ( ((Comparable)(a[ j ])).compareTo(a[ m ]) < 0 ) ) m = j; if ( m != i ) { final K u = a[ i ]; a[ i ] = a[ m ]; a[ m ] = u; } } } @SuppressWarnings("unchecked") private static void insertionSort( final K[] a, final int from, final int to ) { for ( int i = from; ++i < to; ) { K t = a[ i ]; int j = i; for ( K u = a[ j - 1 ]; ( ((Comparable)(t)).compareTo(u) < 0 ); u = a[ --j - 1 ] ) { a[ j ] = u; if ( from == j - 1 ) { --j; break; } } a[ j ] = t; } } /** Sorts the specified range of elements according to the order induced by the specified * comparator using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. * */ public static void quickSort( final K[] x, final int from, final int to, final Comparator comp ) { final int len = to - from; // Selection sort on smallest arrays if ( len < SMALL ) { selectionSort( x, from, to, comp ); return; } // Choose a partition element, v int m = from + len / 2; // Small arrays, middle element if ( len > SMALL ) { int l = from; int n = to - 1; if ( len > MEDIUM ) { // Big arrays, pseudomedian of 9 int s = len / 8; l = med3( x, l, l + s, l + 2 * s, comp ); m = med3( x, m - s, m, m + s, comp ); n = med3( x, n - 2 * s, n - s, n, comp ); } m = med3( x, l, m, n, comp ); // Mid-size, med of 3 } final K v = x[ m ]; // Establish Invariant: v* (v)* v* int a = from, b = a, c = to - 1, d = c; while(true) { int comparison; while ( b <= c && ( comparison = comp.compare( x[ b ], v ) ) <= 0 ) { if ( comparison == 0 ) swap( x, a++, b ); b++; } while (c >= b && ( comparison = comp.compare( x[ c ], v ) ) >=0 ) { if ( comparison == 0 ) swap( x, c, d-- ); c--; } if ( b > c ) break; swap( x, b++, c-- ); } // Swap partition elements back to middle int s, n = to; s = Math.min( a - from, b - a ); vecSwap( x, from, b - s, s ); s = Math.min( d - c, n - d - 1 ); vecSwap( x, b, n - s, s ); // Recursively sort non-partition-elements if ( ( s = b - a ) > 1 ) quickSort( x, from, from + s, comp ); if ( ( s = d - c ) > 1 ) quickSort( x, n - s, n, comp ); } /** Sorts an array according to the order induced by the specified * comparator using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * @param comp the comparator to determine the sorting order. * */ public static void quickSort( final K[] x, final Comparator comp ) { quickSort( x, 0, x.length, comp ); } @SuppressWarnings("unchecked") private static int med3( final K x[], final int a, final int b, final int c ) { int ab = ( ((Comparable)(x[ a ])).compareTo(x[ b ]) ); int ac = ( ((Comparable)(x[ a ])).compareTo(x[ c ]) ); int bc = ( ((Comparable)(x[ b ])).compareTo(x[ c ]) ); return ( ab < 0 ? ( bc < 0 ? b : ac < 0 ? c : a ) : ( bc > 0 ? b : ac > 0 ? c : a ) ); } /** Sorts the specified range of elements according to the natural ascending order using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ @SuppressWarnings("unchecked") public static void quickSort( final K[] x, final int from, final int to ) { final int len = to - from; // Selection sort on smallest arrays if ( len < SMALL ) { selectionSort( x, from, to ); return; } // Choose a partition element, v int m = from + len / 2; // Small arrays, middle element if ( len > SMALL ) { int l = from; int n = to - 1; if ( len > MEDIUM ) { // Big arrays, pseudomedian of 9 int s = len / 8; l = med3( x, l, l + s, l + 2 * s ); m = med3( x, m - s, m, m + s ); n = med3( x, n - 2 * s, n - s, n ); } m = med3( x, l, m, n ); // Mid-size, med of 3 } final K v = x[ m ]; // Establish Invariant: v* (v)* v* int a = from, b = a, c = to - 1, d = c; while(true) { int comparison; while ( b <= c && ( comparison = ( ((Comparable)(x[ b ])).compareTo(v) ) ) <= 0 ) { if ( comparison == 0 ) swap( x, a++, b ); b++; } while (c >= b && ( comparison = ( ((Comparable)(x[ c ])).compareTo(v) ) ) >=0 ) { if ( comparison == 0 ) swap( x, c, d-- ); c--; } if ( b > c ) break; swap( x, b++, c-- ); } // Swap partition elements back to middle int s, n = to; s = Math.min( a - from, b - a ); vecSwap( x, from, b - s, s ); s = Math.min( d - c, n - d - 1 ); vecSwap( x, b, n - s, s ); // Recursively sort non-partition-elements if ( ( s = b - a ) > 1 ) quickSort( x, from, from + s ); if ( ( s = d - c ) > 1 ) quickSort( x, n - s, n ); } /** Sorts an array according to the natural ascending order using quicksort. * *

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas * McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages * 1249−1265, 1993. * *

Note that this implementation does not allocate any object, contrarily to the implementation * used to sort primitive types in {@link java.util.Arrays}, which switches to mergesort on large inputs. * * @param x the array to be sorted. * */ public static void quickSort( final K[] x ) { quickSort( x, 0, x.length ); } /** Sorts the specified range of elements according to the natural ascending order using mergesort, using a given pre-filled support array. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. Moreover, no support arrays will be allocated. * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param supp a support array containing at least to elements, and whose entries are identical to those * of {@code a} in the specified range. */ @SuppressWarnings("unchecked") public static void mergeSort( final K a[], final int from, final int to, final K supp[] ) { int len = to - from; // Insertion sort on smallest arrays if ( len < SMALL ) { insertionSort( a, from, to ); return; } // Recursively sort halves of a into supp final int mid = ( from + to ) >>> 1; mergeSort( supp, from, mid, a ); mergeSort( supp, mid, to, a ); // If list is already sorted, just copy from supp to a. This is an // optimization that results in faster sorts for nearly ordered lists. if ( ( ((Comparable)(supp[ mid - 1 ])).compareTo(supp[ mid ]) <= 0 ) ) { System.arraycopy( supp, from, a, from, len ); return; } // Merge sorted halves (now in supp) into a for( int i = from, p = from, q = mid; i < to; i++ ) { if ( q >= to || p < mid && ( ((Comparable)(supp[ p ])).compareTo(supp[ q ]) <= 0 ) ) a[ i ] = supp[ p++ ]; else a[ i ] = supp[ q++ ]; } } /** Sorts the specified range of elements according to the natural ascending order using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. */ public static void mergeSort( final K a[], final int from, final int to ) { mergeSort( a, from, to, a.clone() ); } /** Sorts an array according to the natural ascending order using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * @param a the array to be sorted. */ public static void mergeSort( final K a[] ) { mergeSort( a, 0, a.length ); } /** Sorts the specified range of elements according to the order induced by the specified * comparator using mergesort, using a given pre-filled support array. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. Moreover, no support arrays will be allocated. * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. * @param supp a support array containing at least to elements, and whose entries are identical to those * of {@code a} in the specified range. */ @SuppressWarnings("unchecked") public static void mergeSort( final K a[], final int from, final int to, Comparator comp, final K supp[] ) { int len = to - from; // Insertion sort on smallest arrays if ( len < SMALL ) { insertionSort( a, from, to, comp ); return; } // Recursively sort halves of a into supp final int mid = ( from + to ) >>> 1; mergeSort( supp, from, mid, comp, a ); mergeSort( supp, mid, to, comp, a ); // If list is already sorted, just copy from supp to a. This is an // optimization that results in faster sorts for nearly ordered lists. if ( comp.compare( supp[ mid - 1 ], supp[ mid ] ) <= 0 ) { System.arraycopy( supp, from, a, from, len ); return; } // Merge sorted halves (now in supp) into a for( int i = from, p = from, q = mid; i < to; i++ ) { if ( q >= to || p < mid && comp.compare( supp[ p ], supp[ q ] ) <= 0 ) a[ i ] = supp[ p++ ]; else a[ i ] = supp[ q++ ]; } } /** Sorts the specified range of elements according to the order induced by the specified * comparator using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * * @param a the array to be sorted. * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (exclusive) to be sorted. * @param comp the comparator to determine the sorting order. */ public static void mergeSort( final K a[], final int from, final int to, Comparator comp ) { mergeSort( a, from, to, comp, a.clone() ); } /** Sorts an array according to the order induced by the specified * comparator using mergesort. * *

This sort is guaranteed to be stable: equal elements will not be reordered as a result * of the sort. An array as large as a will be allocated by this method. * @param a the array to be sorted. * @param comp the comparator to determine the sorting order. */ public static void mergeSort( final K a[], Comparator comp ) { mergeSort( a, 0, a.length, comp ); } /** * Searches a range of the specified array for the specified value using * the binary search algorithm. The range must be sorted prior to making this call. * If it is not sorted, the results are undefined. If the range contains multiple elements with * the specified value, there is no guarantee which one will be found. * * @param a the array to be searched. * @param from the index of the first element (inclusive) to be searched. * @param to the index of the last element (exclusive) to be searched. * @param key the value to be searched for. * @return index of the search key, if it is contained in the array; * otherwise, (-(insertion point) - 1). The insertion * point is defined as the the point at which the value would * be inserted into the array: the index of the first * element greater than the key, or the length of the array, if all * elements in the array are less than the specified key. Note * that this guarantees that the return value will be >= 0 if * and only if the key is found. * @see java.util.Arrays */ @SuppressWarnings({"unchecked","rawtypes"}) public static int binarySearch( final K[] a, int from, int to, final K key ) { K midVal; to--; while (from <= to) { final int mid = (from + to) >>> 1; midVal = a[ mid ]; final int cmp = ((Comparable)midVal).compareTo( key ); if ( cmp < 0 ) from = mid + 1; else if (cmp > 0) to = mid - 1; else return mid; } return -( from + 1 ); } /** * Searches an array for the specified value using * the binary search algorithm. The range must be sorted prior to making this call. * If it is not sorted, the results are undefined. If the range contains multiple elements with * the specified value, there is no guarantee which one will be found. * * @param a the array to be searched. * @param key the value to be searched for. * @return index of the search key, if it is contained in the array; * otherwise, (-(insertion point) - 1). The insertion * point is defined as the the point at which the value would * be inserted into the array: the index of the first * element greater than the key, or the length of the array, if all * elements in the array are less than the specified key. Note * that this guarantees that the return value will be >= 0 if * and only if the key is found. * @see java.util.Arrays */ public static int binarySearch( final K[] a, final K key ) { return binarySearch( a, 0, a.length, key ); } /** * Searches a range of the specified array for the specified value using * the binary search algorithm and a specified comparator. The range must be sorted following the comparator prior to making this call. * If it is not sorted, the results are undefined. If the range contains multiple elements with * the specified value, there is no guarantee which one will be found. * * @param a the array to be searched. * @param from the index of the first element (inclusive) to be searched. * @param to the index of the last element (exclusive) to be searched. * @param key the value to be searched for. * @param c a comparator. * @return index of the search key, if it is contained in the array; * otherwise, (-(insertion point) - 1). The insertion * point is defined as the the point at which the value would * be inserted into the array: the index of the first * element greater than the key, or the length of the array, if all * elements in the array are less than the specified key. Note * that this guarantees that the return value will be >= 0 if * and only if the key is found. * @see java.util.Arrays */ public static int binarySearch( final K[] a, int from, int to, final K key, final Comparator c ) { K midVal; to--; while (from <= to) { final int mid = (from + to) >>> 1; midVal = a[ mid ]; final int cmp = c.compare( midVal, key ); if ( cmp < 0 ) from = mid + 1; else if (cmp > 0) to = mid - 1; else return mid; // key found } return -( from + 1 ); } /** * Searches an array for the specified value using * the binary search algorithm and a specified comparator. The range must be sorted following the comparator prior to making this call. * If it is not sorted, the results are undefined. If the range contains multiple elements with * the specified value, there is no guarantee which one will be found. * * @param a the array to be searched. * @param key the value to be searched for. * @param c a comparator. * @return index of the search key, if it is contained in the array; * otherwise, (-(insertion point) - 1). The insertion * point is defined as the the point at which the value would * be inserted into the array: the index of the first * element greater than the key, or the length of the array, if all * elements in the array are less than the specified key. Note * that this guarantees that the return value will be >= 0 if * and only if the key is found. * @see java.util.Arrays */ public static int binarySearch( final K[] a, final K key, final Comparator c ) { return binarySearch( a, 0, a.length, key, c ); } /** Shuffles the specified array fragment using the specified pseudorandom number generator. * * @param a the array to be shuffled. * @param from the index of the first element (inclusive) to be shuffled. * @param to the index of the last element (exclusive) to be shuffled. * @param random a pseudorandom number generator (please use a XorShift* generator). * @return a. */ public static K[] shuffle( final K[] a, final int from, final int to, final Random random ) { for( int i = to - from; i-- != 0; ) { final int p = random.nextInt( i + 1 ); final K t = a[ from + i ]; a[ from + i ] = a[ from + p ]; a[ from + p ] = t; } return a; } /** Shuffles the specified array using the specified pseudorandom number generator. * * @param a the array to be shuffled. * @param random a pseudorandom number generator (please use a XorShift* generator). * @return a. */ public static K[] shuffle( final K[] a, final Random random ) { for( int i = a.length; i-- != 0; ) { final int p = random.nextInt( i + 1 ); final K t = a[ i ]; a[ i ] = a[ p ]; a[ p ] = t; } return a; } /** Reverses the order of the elements in the specified array. * * @param a the array to be reversed. * @return a. */ public static K[] reverse( final K[] a ) { final int length = a.length; for( int i = length / 2; i-- != 0; ) { final K t = a[ length - i - 1 ]; a[ length - i - 1 ] = a[ i ]; a[ i ] = t; } return a; } /** Reverses the order of the elements in the specified array fragment. * * @param a the array to be reversed. * @param from the index of the first element (inclusive) to be reversed. * @param to the index of the last element (exclusive) to be reversed. * @return a. */ public static K[] reverse( final K[] a, final int from, final int to ) { final int length = to - from; for( int i = length / 2; i-- != 0; ) { final K t = a[ from + length - i - 1 ]; a[ from + length - i - 1 ] = a[ from + i ]; a[ from + i ] = t; } return a; } /** A type-specific content-based hash strategy for arrays. */ private static final class ArrayHashStrategy implements Hash.Strategy, java.io.Serializable { private static final long serialVersionUID = -7046029254386353129L; public int hashCode( final K[] o ) { return java.util.Arrays.hashCode( o ); } public boolean equals( final K[] a, final K[] b ) { return java.util.Arrays.equals( a, b ); } } /** A type-specific content-based hash strategy for arrays. * *

This hash strategy may be used in custom hash collections whenever keys are * arrays, and they must be considered equal by content. This strategy * will handle null correctly, and it is serializable. */ @SuppressWarnings({"rawtypes"}) public final static Hash.Strategy HASH_STRATEGY = new ArrayHashStrategy(); } ObjectBidirectionalIterator.java000066400000000000000000000041441422762524200365730ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.objects; import org.codelibs.jhighlight.fastutil.BidirectionalIterator; /** A type-specific bidirectional iterator; provides an additional method to avoid (un)boxing, * and the possibility to skip elements backwards. * * @see BidirectionalIterator */ public interface ObjectBidirectionalIterator extends ObjectIterator , BidirectionalIterator { /** Moves back for the given number of elements. * *

The effect of this call is exactly the same as that of * calling {@link #previous()} for n times (possibly stopping * if {@link #hasPrevious()} becomes false). * * @param n the number of elements to skip back. * @return the number of elements actually skipped. * @see java.util.Iterator#next() */ int back( int n ); } ObjectCollection.java000066400000000000000000000060201422762524200343770ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.objects; import java.util.Collection; /** A type-specific {@link Collection}; provides some additional methods * that use polymorphism to avoid (un)boxing. * *

Additionally, this class defines strengthens (again) {@link #iterator()} and defines * a slightly different semantics for {@link #toArray(Object[])}. * * @see Collection */ public interface ObjectCollection extends Collection, ObjectIterable { /** Returns a type-specific iterator on the elements of this collection. * *

Note that this specification strengthens the one given in * {@link java.lang.Iterable#iterator()}, which was already * strengthened in the corresponding type-specific class, * but was weakened by the fact that this interface extends {@link Collection}. * * @return a type-specific iterator on the elements of this collection. */ ObjectIterator iterator(); /** Returns a type-specific iterator on this elements of this collection. * * @see #iterator() * @deprecated As of fastutil 5, replaced by {@link #iterator()}. */ @Deprecated ObjectIterator objectIterator(); /** Returns an containing the items of this collection; * the runtime type of the returned array is that of the specified array. * *

Warning: Note that, contrarily to {@link Collection#toArray(Object[])}, this * methods just writes all elements of this collection: no special * value will be added after the last one. * * @param a if this array is big enough, it will be used to store this collection. * @return a primitive type array containing the items of this collection. * @see Collection#toArray(Object[]) */ T[] toArray(T[] a); } ObjectIterable.java000066400000000000000000000041411422762524200340350ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.objects; /** A type-specific {@link Iterable} that strengthens that specification of {@link Iterable#iterator()}. * *

Warning: Java will let you write “colon” for statements with primitive-type * loop variables; however, what is (unfortunately) really happening is that at each iteration an * unboxing (and, in the case of fastutil type-specific data structures, a boxing) will be performed. Watch out. * * @see Iterable */ public interface ObjectIterable extends Iterable { /** Returns a type-specific iterator. * * Note that this specification strengthens the one given in {@link Iterable#iterator()}. * * @return a type-specific iterator. */ ObjectIterator iterator(); } ObjectIterator.java000066400000000000000000000037251422762524200341060ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.objects; import java.util.Iterator; /** A type-specific {@link Iterator}; provides an additional method to avoid (un)boxing, and * the possibility to skip elements. * * @see Iterator */ public interface ObjectIterator extends Iterator { /** Skips the given number of elements. * *

The effect of this call is exactly the same as that of * calling {@link #next()} for n times (possibly stopping * if {@link #hasNext()} becomes false). * * @param n the number of elements to skip. * @return the number of elements actually skipped. * @see Iterator#next() */ int skip( int n ); } ObjectIterators.java000066400000000000000000000531141422762524200342660ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.objects; import java.util.Iterator; import java.util.ListIterator; import java.util.NoSuchElementException; /** A class providing static methods and objects that do useful things with type-specific iterators. * * @see Iterator */ public class ObjectIterators { private ObjectIterators() {} /** A class returning no elements and a type-specific iterator interface. * *

This class may be useful to implement your own in case you subclass * a type-specific iterator. */ public static class EmptyIterator extends AbstractObjectListIterator implements java.io.Serializable, Cloneable { private static final long serialVersionUID = -7046029254386353129L; protected EmptyIterator() {} public boolean hasNext() { return false; } public boolean hasPrevious() { return false; } public K next() { throw new NoSuchElementException(); } public K previous() { throw new NoSuchElementException(); } public int nextIndex() { return 0; } public int previousIndex() { return -1; } public int skip( int n ) { return 0; }; public int back( int n ) { return 0; }; public Object clone() { return EMPTY_ITERATOR; } private Object readResolve() { return EMPTY_ITERATOR; } } /** An empty iterator (immutable). It is serializable and cloneable. * *

The class of this objects represent an abstract empty iterator * that can iterate as a type-specific (list) iterator. */ @SuppressWarnings("rawtypes") public final static EmptyIterator EMPTY_ITERATOR = new EmptyIterator(); /** An iterator returning a single element. */ private static class SingletonIterator extends AbstractObjectListIterator { private final K element; private int curr; public SingletonIterator( final K element ) { this.element = element; } public boolean hasNext() { return curr == 0; } public boolean hasPrevious() { return curr == 1; } public K next() { if ( ! hasNext() ) throw new NoSuchElementException(); curr = 1; return element; } public K previous() { if ( ! hasPrevious() ) throw new NoSuchElementException(); curr = 0; return element; } public int nextIndex() { return curr; } public int previousIndex() { return curr - 1; } } /** Returns an iterator that iterates just over the given element. * * @param element the only element to be returned by a type-specific list iterator. * @return an iterator that iterates just over element. */ public static ObjectListIterator singleton( final K element ) { return new SingletonIterator ( element ); } /** A class to wrap arrays in iterators. */ private static class ArrayIterator extends AbstractObjectListIterator { private final K[] array; private final int offset, length; private int curr; public ArrayIterator( final K[] array, final int offset, final int length ) { this.array = array; this.offset = offset; this.length = length; } public boolean hasNext() { return curr < length; } public boolean hasPrevious() { return curr > 0; } public K next() { if ( ! hasNext() ) throw new NoSuchElementException(); return array[ offset + curr++ ]; } public K previous() { if ( ! hasPrevious() ) throw new NoSuchElementException(); return array[ offset + --curr ]; } public int skip( int n ) { if ( n <= length - curr ) { curr += n; return n; } n = length - curr; curr = length; return n; } public int back( int n ) { if ( n <= curr ) { curr -= n; return n; } n = curr; curr = 0; return n; } public int nextIndex() { return curr; } public int previousIndex() { return curr - 1; } } /** Wraps the given part of an array into a type-specific list iterator. * *

The type-specific list iterator returned by this method will iterate * length times, returning consecutive elements of the given * array starting from the one with index offset. * * @param array an array to wrap into a type-specific list iterator. * @param offset the first element of the array to be returned. * @param length the number of elements to return. */ public static ObjectListIterator wrap( final K[] array, final int offset, final int length ) { ObjectArrays.ensureOffsetLength( array, offset, length ); return new ArrayIterator ( array, offset, length ); } /** Wraps the given array into a type-specific list iterator. * *

The type-specific list iterator returned by this method will return * all elements of the given array. * * @param array an array to wrap into a type-specific list iterator. */ public static ObjectListIterator wrap( final K[] array ) { return new ArrayIterator ( array, 0, array.length ); } /** Unwraps an iterator into an array starting at a given offset for a given number of elements. * *

This method iterates over the given type-specific iterator and stores the elements * returned, up to a maximum of length, in the given array starting at offset. * The number of actually unwrapped elements is returned (it may be less than max if * the iterator emits less than max elements). * * @param i a type-specific iterator. * @param array an array to contain the output of the iterator. * @param offset the first element of the array to be returned. * @param max the maximum number of elements to unwrap. * @return the number of elements unwrapped. */ public static int unwrap( final Iterator i, final K array[], int offset, final int max ) { if ( max < 0 ) throw new IllegalArgumentException( "The maximum number of elements (" + max + ") is negative" ); if ( offset < 0 || offset + max > array.length ) throw new IllegalArgumentException(); int j = max; while( j-- != 0 && i.hasNext() ) array[ offset++ ] = i.next(); return max - j - 1; } /** Unwraps an iterator into an array. * *

This method iterates over the given type-specific iterator and stores the * elements returned in the given array. The iteration will stop when the * iterator has no more elements or when the end of the array has been reached. * * @param i a type-specific iterator. * @param array an array to contain the output of the iterator. * @return the number of elements unwrapped. */ public static int unwrap( final Iterator i, final K array[] ) { return unwrap( i, array, 0, array.length ); } /** Unwraps an iterator, returning an array, with a limit on the number of elements. * *

This method iterates over the given type-specific iterator and returns an array * containing the elements returned by the iterator. At most max elements * will be returned. * * @param i a type-specific iterator. * @param max the maximum number of elements to be unwrapped. * @return an array containing the elements returned by the iterator (at most max). */ @SuppressWarnings("unchecked") public static K[] unwrap( final Iterator i, int max ) { if ( max < 0 ) throw new IllegalArgumentException( "The maximum number of elements (" + max + ") is negative" ); K array[] = (K[]) new Object[ 16 ]; int j = 0; while( max-- != 0 && i.hasNext() ) { if ( j == array.length ) array = ObjectArrays.grow( array, j + 1 ); array[ j++ ] = i.next(); } return ObjectArrays.trim( array, j ); } /** Unwraps an iterator, returning an array. * *

This method iterates over the given type-specific iterator and returns an array * containing the elements returned by the iterator. * * @param i a type-specific iterator. * @return an array containing the elements returned by the iterator. */ public static K[] unwrap( final Iterator i ) { return unwrap( i, Integer.MAX_VALUE ); } /** Unwraps an iterator into a type-specific collection, with a limit on the number of elements. * *

This method iterates over the given type-specific iterator and stores the elements * returned, up to a maximum of max, in the given type-specific collection. * The number of actually unwrapped elements is returned (it may be less than max if * the iterator emits less than max elements). * * @param i a type-specific iterator. * @param c a type-specific collection array to contain the output of the iterator. * @param max the maximum number of elements to unwrap. * @return the number of elements unwrapped. Note that * this is the number of elements returned by the iterator, which is not necessarily the number * of elements that have been added to the collection (because of duplicates). */ public static int unwrap( final Iterator i, final ObjectCollection c, final int max ) { if ( max < 0 ) throw new IllegalArgumentException( "The maximum number of elements (" + max + ") is negative" ); int j = max; while( j-- != 0 && i.hasNext() ) c.add( i.next() ); return max - j - 1; } /** Unwraps an iterator into a type-specific collection. * *

This method iterates over the given type-specific iterator and stores the * elements returned in the given type-specific collection. The returned count on the number * unwrapped elements is a long, so that it will work also with very large collections. * * @param i a type-specific iterator. * @param c a type-specific collection to contain the output of the iterator. * @return the number of elements unwrapped. Note that * this is the number of elements returned by the iterator, which is not necessarily the number * of elements that have been added to the collection (because of duplicates). */ public static long unwrap( final Iterator i, final ObjectCollection c ) { long n = 0; while( i.hasNext() ) { c.add( i.next() ); n++; } return n; } /** Pours an iterator into a type-specific collection, with a limit on the number of elements. * *

This method iterates over the given type-specific iterator and adds * the returned elements to the given collection (up to max). * * @param i a type-specific iterator. * @param s a type-specific collection. * @param max the maximum number of elements to be poured. * @return the number of elements poured. Note that * this is the number of elements returned by the iterator, which is not necessarily the number * of elements that have been added to the collection (because of duplicates). */ public static int pour( final Iterator i, final ObjectCollection s, final int max ) { if ( max < 0 ) throw new IllegalArgumentException( "The maximum number of elements (" + max + ") is negative" ); int j = max; while( j-- != 0 && i.hasNext() ) s.add( i.next() ); return max - j - 1; } /** Pours an iterator into a type-specific collection. * *

This method iterates over the given type-specific iterator and adds * the returned elements to the given collection. * * @param i a type-specific iterator. * @param s a type-specific collection. * @return the number of elements poured. Note that * this is the number of elements returned by the iterator, which is not necessarily the number * of elements that have been added to the collection (because of duplicates). */ public static int pour( final Iterator i, final ObjectCollection s ) { return pour( i, s, Integer.MAX_VALUE ); } /** Pours an iterator, returning a type-specific list, with a limit on the number of elements. * *

This method iterates over the given type-specific iterator and returns * a type-specific list containing the returned elements (up to max). Iteration * on the returned list is guaranteed to produce the elements in the same order * in which they appeared in the iterator. * * * @param i a type-specific iterator. * @param max the maximum number of elements to be poured. * @return a type-specific list containing the returned elements, up to max. */ public static ObjectList pour( final Iterator i, int max ) { final ObjectArrayList l = new ObjectArrayList (); pour( i, l, max ); l.trim(); return l; } /** Pours an iterator, returning a type-specific list. * *

This method iterates over the given type-specific iterator and returns * a list containing the returned elements. Iteration * on the returned list is guaranteed to produce the elements in the same order * in which they appeared in the iterator. * * @param i a type-specific iterator. * @return a type-specific list containing the returned elements. */ public static ObjectList pour( final Iterator i ) { return pour( i, Integer.MAX_VALUE ); } private static class IteratorWrapper extends AbstractObjectIterator { final Iterator i; public IteratorWrapper( final Iterator i ) { this.i = i; } public boolean hasNext() { return i.hasNext(); } public void remove() { i.remove(); } public K next() { return (i.next()); } } /** Wraps a standard iterator into a type-specific iterator. * *

This method wraps a standard iterator into a type-specific one which will handle the * type conversions for you. Of course, any attempt to wrap an iterator returning the * instances of the wrong class will generate a {@link ClassCastException}. The * returned iterator is backed by i: changes to one of the iterators * will affect the other, too. * *

If i is already type-specific, it will returned and no new object * will be generated. * * @param i an iterator. * @return a type-specific iterator backed by i. */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static ObjectIterator asObjectIterator( final Iterator i ) { if ( i instanceof ObjectIterator ) return (ObjectIterator )i; return new IteratorWrapper ( i ); } private static class ListIteratorWrapper extends AbstractObjectListIterator { final ListIterator i; public ListIteratorWrapper( final ListIterator i ) { this.i = i; } public boolean hasNext() { return i.hasNext(); } public boolean hasPrevious() { return i.hasPrevious(); } public int nextIndex() { return i.nextIndex(); } public int previousIndex() { return i.previousIndex(); } @SuppressWarnings("unchecked") public void set( K k ) { i.set( (k) ); } @SuppressWarnings("unchecked") public void add( K k ) { i.add( (k) ); } public void remove() { i.remove(); } public K next() { return (i.next()); } public K previous() { return (i.previous()); } } /** Wraps a standard list iterator into a type-specific list iterator. * *

This method wraps a standard list iterator into a type-specific one * which will handle the type conversions for you. Of course, any attempt * to wrap an iterator returning the instances of the wrong class will * generate a {@link ClassCastException}. The * returned iterator is backed by i: changes to one of the iterators * will affect the other, too. * *

If i is already type-specific, it will returned and no new object * will be generated. * * @param i a list iterator. * @return a type-specific list iterator backed by i. */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static ObjectListIterator asObjectIterator( final ListIterator i ) { if ( i instanceof ObjectListIterator ) return (ObjectListIterator )i; return new ListIteratorWrapper ( i ); } private static class IteratorConcatenator extends AbstractObjectIterator { final ObjectIterator a[]; int offset, length, lastOffset = -1; public IteratorConcatenator( final ObjectIterator a[], int offset, int length ) { this.a = a; this.offset = offset; this.length = length; advance(); } private void advance() { while( length != 0 ) { if ( a[ offset ].hasNext() ) break; length--; offset++; } return; } public boolean hasNext() { return length > 0; } public K next() { if ( ! hasNext() ) throw new NoSuchElementException(); K next = a[ lastOffset = offset ].next(); advance(); return next; } public void remove() { if ( lastOffset == -1 ) throw new IllegalStateException(); a[ lastOffset ].remove(); } public int skip( int n ) { lastOffset = -1; int skipped = 0; while( skipped < n && length != 0 ) { skipped += a[ offset ].skip( n - skipped ); if ( a[ offset ].hasNext() ) break; length--; offset++; } return skipped; } } /** Concatenates all iterators contained in an array. * *

This method returns an iterator that will enumerate in order the elements returned * by all iterators contained in the given array. * * @param a an array of iterators. * @return an iterator obtained by concatenation. */ public static ObjectIterator concat( final ObjectIterator a[] ) { return concat( a, 0, a.length ); } /** Concatenates a sequence of iterators contained in an array. * *

This method returns an iterator that will enumerate in order the elements returned * by a[ offset ], then those returned * by a[ offset + 1 ], and so on up to * a[ offset + length - 1 ]. * * @param a an array of iterators. * @param offset the index of the first iterator to concatenate. * @param length the number of iterators to concatenate. * @return an iterator obtained by concatenation of length elements of a starting at offset. */ public static ObjectIterator concat( final ObjectIterator a[], final int offset, final int length ) { return new IteratorConcatenator ( a, offset, length ); } /** An unmodifiable wrapper class for iterators. */ public static class UnmodifiableIterator extends AbstractObjectIterator { final protected ObjectIterator i; @SuppressWarnings("unchecked") public UnmodifiableIterator( final ObjectIterator i ) { this.i = i; } public boolean hasNext() { return i.hasNext(); } public K next() { return i.next(); } } /** Returns an unmodifiable iterator backed by the specified iterator. * * @param i the iterator to be wrapped in an unmodifiable iterator. * @return an unmodifiable view of the specified iterator. */ public static ObjectIterator unmodifiable( final ObjectIterator i ) { return new UnmodifiableIterator ( i ); } /** An unmodifiable wrapper class for bidirectional iterators. */ public static class UnmodifiableBidirectionalIterator extends AbstractObjectBidirectionalIterator { final protected ObjectBidirectionalIterator i; @SuppressWarnings("unchecked") public UnmodifiableBidirectionalIterator( final ObjectBidirectionalIterator i ) { this.i = i; } public boolean hasNext() { return i.hasNext(); } public boolean hasPrevious() { return i.hasPrevious(); } public K next() { return i.next(); } public K previous() { return i.previous(); } } /** Returns an unmodifiable bidirectional iterator backed by the specified bidirectional iterator. * * @param i the bidirectional iterator to be wrapped in an unmodifiable bidirectional iterator. * @return an unmodifiable view of the specified bidirectional iterator. */ public static ObjectBidirectionalIterator unmodifiable( final ObjectBidirectionalIterator i ) { return new UnmodifiableBidirectionalIterator ( i ); } /** An unmodifiable wrapper class for list iterators. */ public static class UnmodifiableListIterator extends AbstractObjectListIterator { final protected ObjectListIterator i; @SuppressWarnings("unchecked") public UnmodifiableListIterator( final ObjectListIterator i ) { this.i = i; } public boolean hasNext() { return i.hasNext(); } public boolean hasPrevious() { return i.hasPrevious(); } public K next() { return i.next(); } public K previous() { return i.previous(); } public int nextIndex() { return i.nextIndex(); } public int previousIndex() { return i.previousIndex(); } } /** Returns an unmodifiable list iterator backed by the specified list iterator. * * @param i the list iterator to be wrapped in an unmodifiable list iterator. * @return an unmodifiable view of the specified list iterator. */ public static ObjectListIterator unmodifiable( final ObjectListIterator i ) { return new UnmodifiableListIterator ( i ); } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/ObjectList.java000066400000000000000000000132131422762524200333000ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.objects; import java.util.List; /** A type-specific {@link List}; provides some additional methods that use polymorphism to avoid (un)boxing. * *

Note that this type-specific interface extends {@link Comparable}: it is expected that implementing * classes perform a lexicographical comparison using the standard operator "less then" for primitive types, * and the usual {@link Comparable#compareTo(Object) compareTo()} method for objects. * *

Additionally, this interface strengthens {@link #listIterator()}, * {@link #listIterator(int)} and {@link #subList(int,int)}. * *

Besides polymorphic methods, this interfaces specifies methods to copy into an array or remove contiguous * sublists. Although the abstract implementation of this interface provides simple, one-by-one implementations * of these methods, it is expected that concrete implementation override them with optimized versions. * * @see List */ public interface ObjectList extends List, Comparable>, ObjectCollection { /** Returns a type-specific iterator on the elements of this list (in proper sequence). * * Note that this specification strengthens the one given in {@link List#iterator()}. * It would not be normally necessary, but {@link java.lang.Iterable#iterator()} is bizarrily re-specified * in {@link List}. * * @return an iterator on the elements of this list (in proper sequence). */ ObjectListIterator iterator(); /** Returns a type-specific list iterator on the list. * * @see #listIterator() * @deprecated As of fastutil 5, replaced by {@link #listIterator()}. */ @Deprecated ObjectListIterator objectListIterator(); /** Returns a type-specific list iterator on the list starting at a given index. * * @see #listIterator(int) * @deprecated As of fastutil 5, replaced by {@link #listIterator(int)}. */ @Deprecated ObjectListIterator objectListIterator( int index ); /** Returns a type-specific list iterator on the list. * * @see List#listIterator() */ ObjectListIterator listIterator(); /** Returns a type-specific list iterator on the list starting at a given index. * * @see List#listIterator(int) */ ObjectListIterator listIterator( int index ); /** Returns a type-specific view of the portion of this list from the index from, inclusive, to the index to, exclusive. * @see List#subList(int,int) * @deprecated As of fastutil 5, replaced by {@link #subList(int,int)}. */ @Deprecated ObjectList objectSubList( int from, int to ); /** Returns a type-specific view of the portion of this list from the index from, inclusive, to the index to, exclusive. * *

Note that this specification strengthens the one given in {@link List#subList(int,int)}. * * @see List#subList(int,int) */ ObjectList subList(int from, int to); /** Sets the size of this list. * *

If the specified size is smaller than the current size, the last elements are * discarded. Otherwise, they are filled with 0/null/false. * * @param size the new size. */ void size( int size ); /** Copies (hopefully quickly) elements of this type-specific list into the given array. * * @param from the start index (inclusive). * @param a the destination array. * @param offset the offset into the destination array where to store the first element copied. * @param length the number of elements to be copied. */ void getElements( int from, Object a[], int offset, int length ); /** Removes (hopefully quickly) elements of this type-specific list. * * @param from the start index (inclusive). * @param to the end index (exclusive). */ void removeElements( int from, int to ); /** Add (hopefully quickly) elements to this type-specific list. * * @param index the index at which to add elements. * @param a the array containing the elements. */ void addElements( int index, K a[] ); /** Add (hopefully quickly) elements to this type-specific list. * * @param index the index at which to add elements. * @param a the array containing the elements. * @param offset the offset of the first element to add. * @param length the number of elements to add. */ void addElements( int index, K a[], int offset, int length ); } ObjectListIterator.java000066400000000000000000000037521422762524200347420ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.objects; import java.util.ListIterator; /** A type-specific bidirectional iterator that is also a {@link ListIterator}. * *

This interface merges the methods provided by a {@link ListIterator} and * a type-specific {@link org.codelibs.jhighlight.fastutil.BidirectionalIterator}. Moreover, it provides * type-specific versions of {@link java.util.ListIterator#add(Object) add()} * and {@link java.util.ListIterator#set(Object) set()}. * * @see java.util.ListIterator * @see org.codelibs.jhighlight.fastutil.BidirectionalIterator */ public interface ObjectListIterator extends ListIterator, ObjectBidirectionalIterator { } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/fastutil/objects/ObjectSet.java000066400000000000000000000047031422762524200331240ustar00rootroot00000000000000/* Generic definitions */ /* Assertions (useful to generate conditional code) */ /* Current type and class (and size, if applicable) */ /* Value methods */ /* Interfaces (keys) */ /* Interfaces (values) */ /* Abstract implementations (keys) */ /* Abstract implementations (values) */ /* Static containers (keys) */ /* Static containers (values) */ /* Implementations */ /* Synchronized wrappers */ /* Unmodifiable wrappers */ /* Other wrappers */ /* Methods (keys) */ /* Methods (values) */ /* Methods (keys/values) */ /* Methods that have special names depending on keys (but the special names depend on values) */ /* Equality */ /* Object/Reference-only definitions (keys) */ /* Object/Reference-only definitions (values) */ /* * Copyright (C) 2002-2014 Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codelibs.jhighlight.fastutil.objects; import java.util.Set; /** A type-specific {@link Set}; provides some additional methods that use polymorphism to avoid (un)boxing. * *

Additionally, this interface strengthens (again) {@link #iterator()}. * * @see Set */ public interface ObjectSet extends ObjectCollection , Set { /** Returns a type-specific iterator on the elements of this set. * *

Note that this specification strengthens the one given in {@link java.lang.Iterable#iterator()}, * which was already strengthened in the corresponding type-specific class, * but was weakened by the fact that this interface extends {@link Set}. * * @return a type-specific iterator on the elements of this set. */ ObjectIterator iterator(); /** Removes an element from this set. * *

Note that the corresponding method of the type-specific collection is rem(). * This unfortunate situation is caused by the clash * with the similarly named index-based method in the {@link java.util.List} interface. * * @see java.util.Collection#remove(Object) */ public boolean remove( Object k ); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/highlighter/000077500000000000000000000000001422762524200274055ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/highlighter/CppHighlighter.flex000066400000000000000000000144201422762524200331670ustar00rootroot00000000000000/* * Copyright 2006 Arnout Engelen . * Copyright 2000-2006 Omnicore Software, Hans Kratz & Dennis Strein GbR, * Geert Bevin . * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id$ */ package org.codelibs.jhighlight.highlighter; import java.io.Reader; import java.io.IOException; %% %class CppHighlighter %implements ExplicitStateHighlighter %unicode %pack %buffer 128 %public %int %{ /* styles */ public static final byte PLAIN_STYLE = 1; public static final byte KEYWORD_STYLE = 2; public static final byte TYPE_STYLE = 3; public static final byte OPERATOR_STYLE = 4; public static final byte SEPARATOR_STYLE = 5; public static final byte LITERAL_STYLE = 6; public static final byte CPP_COMMENT_STYLE = 7; public static final byte DOXYGEN_COMMENT_STYLE = 8; public static final byte DOXYGEN_TAG_STYLE = 9; public static final byte PREPROC_STYLE = 10; /* Highlighter implementation */ public int getStyleCount() { return 10; } public byte getStartState() { return YYINITIAL+1; } public byte getCurrentState() { return (byte) (yystate()+1); } public void setState(byte newState) { yybegin(newState-1); } public byte getNextToken() throws IOException { return (byte) yylex(); } public int getTokenLength() { return yylength(); } public void setReader(Reader r) { this.zzReader = r; } public CppHighlighter() { } %} /* main character classes */ WhiteSpace = [ \t\f] /* identifiers */ ConstantIdentifier = {SimpleConstantIdentifier} SimpleConstantIdentifier = [#A-Z0-9_]+ Identifier = [:jletter:][:jletterdigit:]* TypeIdentifier = {SimpleTypeIdentifier} SimpleTypeIdentifier = [A-Z][:jletterdigit:]* /* int literals */ DecLiteral = 0 | [1-9][0-9]* {IntegerSuffix} HexLiteral = 0 [xX] 0* {HexDigit}* {IntegerSuffix} HexDigit = [0-9a-fA-F] OctLiteral = 0+ {OctDigit}* {IntegerSuffix} OctDigit = [0-7] IntegerSuffix = [uU]? [lL]? [uU]? /* float literals */ FloatLiteral = ({FLit1}|{FLit2}|{FLit3}|{FLit4}) ([fF]|[dD])? FLit1 = [0-9]+ \. [0-9]* {Exponent}? FLit2 = \. [0-9]+ {Exponent}? FLit3 = [0-9]+ {Exponent} FLit4 = [0-9]+ {Exponent}? Exponent = [eE] [+\-]? [0-9]+ %state IN_COMMENT, IN_DOXYGEN_COMMENT %% { /* keywords */ "__abstract" | "abstract" | "__alignof" | "array" | "__asm" | "__assume" | "__based" | "__box" | "break" | "case" | "catch" | "__cdecl" | "class" | "const" | "const_cast" | "continue" | "__declspec" | "default" | "__delegate" | "delegate" | "delete" | "deprecated" | "dllexport" | "dllimport" | "do" | "double" | "dynamic_cast" | "else" | "event" | "__event" | "__except" | "explicit" | "extern" | "false" | "__fastcall" | "__finally" | "finally" | "for" | "__forceinline" | "friend" | "friend_as" | "__gc" | "gcnew" | "generic" | "goto" | "enum" | "__hook" | "__identifier" | "if" | "__if_exists" | "__if_not_exists" | "initonly" | "__inline" | "inline" | "__int8" | "__int16" | "__int32" | "__int64" | "__interface" | "interface" | "interface" | "interior_ptr" | "__leave" | "literal" | "__m64" | "__m128" | "__m128d" | "__m128i" | "__multiple_inheritance" | "mutable" | "naked" | "namespace" | "new" | "__nogc" | "noinline" | "__noop" | "noreturn" | "nothrow" | "novtable" | "nullptr" | "operator" | "__pin" | "private" | "__property" | "property" | "property" | "protected" | "public" | "__raise" | "register" | "reinterpret_cast" | "return" | "safecast" | "__sealed" | "sealed" | "selectany" | "signed" | "__single_inheritance" | "sizeof" | "static" | "static_cast" | "__stdcall" | "struct" | "__super" | "switch" | "template" | "this" | "thread" | "throw" | "true" | "try" | "__try" | "__except" | "__try_cast" | "typedef" | "typeid" | "typeid" | "typename" | "__unaligned" | "__unhook" | "union" | "unsigned" | "using" | "uuid" | "__uuidof" | "value" | "__value" | "virtual" | "__virtual_inheritance" | "void" | "volatile" | "__w64" | "__wchar_t," | "while" { return KEYWORD_STYLE; } "bool" | "char" | "double" | "int" | "long" | "float" | "short" | "void" { return TYPE_STYLE; } /* literals */ "true" | "false" | (\" ( [^\"\n\\] | \\[^\n] )* (\n | \\\n | \")) | (\' ( [^\'\n\\] | \\[^\n] )* (\n | \\\n | \')) | {DecLiteral} | {OctLiteral} | {HexLiteral} | {FloatLiteral} { return LITERAL_STYLE; } /* preprocessor symbols */ "#define" | "#elif" | "#else" | "#endif" | "#error" | "#ifdef" | "#ifndef" | "#if" | "#import" | "#include" | "#line" | "#pragma" | "#undef" | "#using" { return PREPROC_STYLE; } /* separators */ "(" | ")" | "{" | "}" | "[" | "]" | ";" | "," | "." { return SEPARATOR_STYLE; } /* operators */ "=" | ">" | "<" | "!" | "~" | "?" | ":" | "+" | "-" | "*" | "/" | "&" | "|" | "^" | "%" { return OPERATOR_STYLE; } {ConstantIdentifier} { return PLAIN_STYLE; } {TypeIdentifier} { return TYPE_STYLE; } \n | {Identifier} | {WhiteSpace} { return PLAIN_STYLE; } // single line comment "//" [^\n]* \n | // short comment "/**/" { return CPP_COMMENT_STYLE; } // comment start "/**" { yybegin(IN_DOXYGEN_COMMENT); return DOXYGEN_COMMENT_STYLE;} "/*" { yybegin(IN_COMMENT); return CPP_COMMENT_STYLE;} } // normal comment mode { // comment unterminated ([^\n*]|\*+[^\n*/])* (\n | \*+\n) { return CPP_COMMENT_STYLE; } // comment terminated ([^\n*]|\*+[^\n*/])* \*+ "/" { yybegin(YYINITIAL); return CPP_COMMENT_STYLE; } } // doc comment mode { // comment unterminated .|\n { return DOXYGEN_COMMENT_STYLE; } // comment terminated \* "/" { yybegin(YYINITIAL); return DOXYGEN_COMMENT_STYLE; } "@" {Identifier} { return DOXYGEN_TAG_STYLE; } } /* error fallback */ .|\n { return PLAIN_STYLE; } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/highlighter/CppHighlighter.java000066400000000000000000001333441422762524200331610ustar00rootroot00000000000000/* The following code was generated by JFlex 1.4.1 on 8/2/06 6:03 AM */ /* * Copyright 2006 Arnout Engelen . * Copyright 2000-2006 Omnicore Software, Hans Kratz & Dennis Strein GbR, * Geert Bevin . * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: CppHighlighter.java 3431 2006-08-02 04:09:28Z gbevin $ */ package org.codelibs.jhighlight.highlighter; import java.io.IOException; import java.io.Reader; /** * This class is a scanner generated by * JFlex 1.4.1 * on 8/2/06 6:03 AM from the specification file * com/uwyn/jhighlight/highlighter/CppHighlighter.flex */ public class CppHighlighter implements ExplicitStateHighlighter { /** This character denotes the end of file */ public static final int YYEOF = -1; /** initial size of the lookahead buffer */ private static final int ZZ_BUFFERSIZE = 128; /** lexical states */ public static final int YYINITIAL = 0; public static final int IN_DOXYGEN_COMMENT = 2; public static final int IN_COMMENT = 1; /** * Translates characters to character classes */ private static final String ZZ_CMAP_PACKED = "\11\4\1\0\1\61\1\0\1\0\1\0\16\4\4\0\1\0\1\65"+ "\1\60\1\1\1\2\1\65\1\65\1\63\1\64\1\64\1\66\1\27"+ "\1\57\1\27\1\24\1\67\1\7\1\51\1\54\1\53\1\55\1\14"+ "\1\52\1\14\1\50\1\5\1\65\1\64\1\65\1\65\1\65\1\65"+ "\1\70\3\13\1\22\1\26\1\22\5\6\1\20\10\6\1\16\2\6"+ "\1\11\2\6\1\64\1\62\1\64\1\65\1\3\1\0\1\30\1\31"+ "\1\12\1\23\1\25\1\21\1\36\1\44\1\35\1\2\1\43\1\17"+ "\1\42\1\37\1\40\1\45\1\2\1\34\1\32\1\33\1\15\1\46"+ "\1\47\1\10\1\41\1\56\1\64\1\65\1\64\1\65\41\4\2\0"+ "\4\2\4\0\1\2\2\0\1\4\7\0\1\2\4\0\1\2\5\0"+ "\27\2\1\0\37\2\1\0\u013f\2\31\0\162\2\4\0\14\2\16\0"+ "\5\2\11\0\1\2\21\0\130\4\5\0\23\4\12\0\1\2\13\0"+ "\1\2\1\0\3\2\1\0\1\2\1\0\24\2\1\0\54\2\1\0"+ "\46\2\1\0\5\2\4\0\202\2\1\0\4\4\3\0\105\2\1\0"+ "\46\2\2\0\2\2\6\0\20\2\41\0\46\2\2\0\1\2\7\0"+ "\47\2\11\0\21\4\1\0\27\4\1\0\3\4\1\0\1\4\1\0"+ "\2\4\1\0\1\4\13\0\33\2\5\0\3\2\15\0\4\4\14\0"+ "\6\4\13\0\32\2\5\0\13\2\16\4\7\0\12\4\4\0\2\2"+ "\1\4\143\2\1\0\1\2\10\4\1\0\6\4\2\2\2\4\1\0"+ "\4\4\2\2\12\4\3\2\2\0\1\2\17\0\1\4\1\2\1\4"+ "\36\2\33\4\2\0\3\2\60\0\46\2\13\4\1\2\u014f\0\3\4"+ "\66\2\2\0\1\4\1\2\20\4\2\0\1\2\4\4\3\0\12\2"+ "\2\4\2\0\12\4\21\0\3\4\1\0\10\2\2\0\2\2\2\0"+ "\26\2\1\0\7\2\1\0\1\2\3\0\4\2\2\0\1\4\1\2"+ "\7\4\2\0\2\4\2\0\3\4\11\0\1\4\4\0\2\2\1\0"+ "\3\2\2\4\2\0\12\4\4\2\15\0\3\4\1\0\6\2\4\0"+ "\2\2\2\0\26\2\1\0\7\2\1\0\2\2\1\0\2\2\1\0"+ "\2\2\2\0\1\4\1\0\5\4\4\0\2\4\2\0\3\4\13\0"+ "\4\2\1\0\1\2\7\0\14\4\3\2\14\0\3\4\1\0\11\2"+ "\1\0\3\2\1\0\26\2\1\0\7\2\1\0\2\2\1\0\5\2"+ "\2\0\1\4\1\2\10\4\1\0\3\4\1\0\3\4\2\0\1\2"+ "\17\0\2\2\2\4\2\0\12\4\1\0\1\2\17\0\3\4\1\0"+ "\10\2\2\0\2\2\2\0\26\2\1\0\7\2\1\0\2\2\1\0"+ "\5\2\2\0\1\4\1\2\6\4\3\0\2\4\2\0\3\4\10\0"+ "\2\4\4\0\2\2\1\0\3\2\4\0\12\4\1\0\1\2\20\0"+ "\1\4\1\2\1\0\6\2\3\0\3\2\1\0\4\2\3\0\2\2"+ "\1\0\1\2\1\0\2\2\3\0\2\2\3\0\3\2\3\0\10\2"+ "\1\0\3\2\4\0\5\4\3\0\3\4\1\0\4\4\11\0\1\4"+ "\17\0\11\4\11\0\1\2\7\0\3\4\1\0\10\2\1\0\3\2"+ "\1\0\27\2\1\0\12\2\1\0\5\2\4\0\7\4\1\0\3\4"+ "\1\0\4\4\7\0\2\4\11\0\2\2\4\0\12\4\22\0\2\4"+ "\1\0\10\2\1\0\3\2\1\0\27\2\1\0\12\2\1\0\5\2"+ "\2\0\1\4\1\2\7\4\1\0\3\4\1\0\4\4\7\0\2\4"+ "\7\0\1\2\1\0\2\2\4\0\12\4\22\0\2\4\1\0\10\2"+ "\1\0\3\2\1\0\27\2\1\0\20\2\4\0\6\4\2\0\3\4"+ "\1\0\4\4\11\0\1\4\10\0\2\2\4\0\12\4\22\0\2\4"+ "\1\0\22\2\3\0\30\2\1\0\11\2\1\0\1\2\2\0\7\2"+ "\3\0\1\4\4\0\6\4\1\0\1\4\1\0\10\4\22\0\2\4"+ "\15\0\60\2\1\4\2\2\7\4\4\0\10\2\10\4\1\0\12\4"+ "\47\0\2\2\1\0\1\2\2\0\2\2\1\0\1\2\2\0\1\2"+ "\6\0\4\2\1\0\7\2\1\0\3\2\1\0\1\2\1\0\1\2"+ "\2\0\2\2\1\0\4\2\1\4\2\2\6\4\1\0\2\4\1\2"+ "\2\0\5\2\1\0\1\2\1\0\6\4\2\0\12\4\2\0\2\2"+ "\42\0\1\2\27\0\2\4\6\0\12\4\13\0\1\4\1\0\1\4"+ "\1\0\1\4\4\0\2\4\10\2\1\0\42\2\6\0\24\4\1\0"+ "\2\4\4\2\4\0\10\4\1\0\44\4\11\0\1\4\71\0\42\2"+ "\1\0\5\2\1\0\2\2\1\0\7\4\3\0\4\4\6\0\12\4"+ "\6\0\6\2\4\4\106\0\46\2\12\0\51\2\7\0\132\2\5\0"+ "\104\2\5\0\122\2\6\0\7\2\1\0\77\2\1\0\1\2\1\0"+ "\4\2\2\0\7\2\1\0\1\2\1\0\4\2\2\0\47\2\1\0"+ "\1\2\1\0\4\2\2\0\37\2\1\0\1\2\1\0\4\2\2\0"+ "\7\2\1\0\1\2\1\0\4\2\2\0\7\2\1\0\7\2\1\0"+ "\27\2\1\0\37\2\1\0\1\2\1\0\4\2\2\0\7\2\1\0"+ "\47\2\1\0\23\2\16\0\11\4\56\0\125\2\14\0\u026c\2\2\0"+ "\10\2\12\0\32\2\5\0\113\2\3\0\3\2\17\0\15\2\1\0"+ "\4\2\3\4\13\0\22\2\3\4\13\0\22\2\2\4\14\0\15\2"+ "\1\0\3\2\1\0\2\4\14\0\64\2\40\4\3\0\1\2\3\0"+ "\2\2\1\4\2\0\12\4\41\0\3\4\2\0\12\4\6\0\130\2"+ "\10\0\51\2\1\4\126\0\35\2\3\0\14\4\4\0\14\4\12\0"+ "\12\4\36\2\2\0\5\2\u038b\0\154\2\224\0\234\2\4\0\132\2"+ "\6\0\26\2\2\0\6\2\2\0\46\2\2\0\6\2\2\0\10\2"+ "\1\0\1\2\1\0\1\2\1\0\1\2\1\0\37\2\2\0\65\2"+ "\1\0\7\2\1\0\1\2\3\0\3\2\1\0\7\2\3\0\4\2"+ "\2\0\6\2\4\0\15\2\5\0\3\2\1\0\7\2\17\0\4\4"+ "\32\0\5\4\20\0\2\2\23\0\1\2\13\0\4\4\6\0\6\4"+ "\1\0\1\2\15\0\1\2\40\0\22\2\36\0\15\4\4\0\1\4"+ "\3\0\6\4\27\0\1\2\4\0\1\2\2\0\12\2\1\0\1\2"+ "\3\0\5\2\6\0\1\2\1\0\1\2\1\0\1\2\1\0\4\2"+ "\1\0\3\2\1\0\7\2\3\0\3\2\5\0\5\2\26\0\44\2"+ "\u0e81\0\3\2\31\0\11\2\6\4\1\0\5\2\2\0\5\2\4\0"+ "\126\2\2\0\2\4\2\0\3\2\1\0\137\2\5\0\50\2\4\0"+ "\136\2\21\0\30\2\70\0\20\2\u0200\0\u19b6\2\112\0\u51a6\2\132\0"+ "\u048d\2\u0773\0\u2ba4\2\u215c\0\u012e\2\2\0\73\2\225\0\7\2\14\0"+ "\5\2\5\0\1\2\1\4\12\2\1\0\15\2\1\0\5\2\1\0"+ "\1\2\1\0\2\2\1\0\2\2\1\0\154\2\41\0\u016b\2\22\0"+ "\100\2\2\0\66\2\50\0\15\2\3\0\20\4\20\0\4\4\17\0"+ "\2\2\30\0\3\2\31\0\1\2\6\0\5\2\1\0\207\2\2\0"+ "\1\4\4\0\1\2\13\0\12\4\7\0\32\2\4\0\1\2\1\0"+ "\32\2\12\0\132\2\3\0\6\2\2\0\6\2\2\0\6\2\2\0"+ "\3\2\3\0\2\2\3\0\2\2\22\0\3\4\4\0"; /** * Translates characters to character classes */ private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); /** * Translates DFA states to action switch labels. */ private static final int [] ZZ_ACTION = zzUnpackAction(); private static final String ZZ_ACTION_PACKED_0 = "\3\0\4\1\1\2\1\1\1\2\5\1\1\3\1\1"+ "\1\4\15\1\1\3\2\1\1\4\1\1\1\5\1\1"+ "\3\6\1\1\6\0\2\1\7\2\1\0\1\1\1\7"+ "\4\2\20\1\1\10\24\1\1\10\20\1\4\0\1\11"+ "\3\0\1\12\1\13\1\14\7\0\1\15\3\0\23\1"+ "\1\2\1\0\1\2\55\1\1\7\23\1\1\16\11\0"+ "\41\1\1\7\54\1\1\0\1\15\4\0\16\1\1\10"+ "\44\1\3\0\20\1\1\10\2\1\1\10\56\1\1\10"+ "\10\1"; private static int [] zzUnpackAction() { int [] result = new int[450]; int offset = 0; offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); return result; } private static int zzUnpackAction(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); do result[j++] = value; while (--count > 0); } return j; } /** * Translates a state to a row index in the transition table */ private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); private static final String ZZ_ROWMAP_PACKED_0 = "\0\0\0\71\0\162\0\253\0\344\0\u011d\0\u0156\0\u018f"+ "\0\u01c8\0\u0201\0\u023a\0\u0273\0\u02ac\0\u02e5\0\u031e\0\u0357"+ "\0\u0390\0\253\0\u03c9\0\u0402\0\u043b\0\u0474\0\u04ad\0\u04e6"+ "\0\u051f\0\u0558\0\u0591\0\u05ca\0\u0603\0\u063c\0\u0675\0\253"+ "\0\u06ae\0\u06e7\0\u0720\0\u0759\0\253\0\u0792\0\253\0\u07cb"+ "\0\u0804\0\u083d\0\u0876\0\u08af\0\u08e8\0\u0921\0\u095a\0\u0993"+ "\0\u09cc\0\u0a05\0\u0a3e\0\u0a77\0\u0ab0\0\u0ae9\0\253\0\u083d"+ "\0\u0b22\0\u0b5b\0\u0b94\0\u0bcd\0\u0c06\0\u0c3f\0\u0c78\0\u0cb1"+ "\0\u0cea\0\u0d23\0\u0d5c\0\u0d95\0\u0dce\0\u0e07\0\u0e40\0\u0e79"+ "\0\u0eb2\0\u0eeb\0\u0f24\0\u0f5d\0\u0f96\0\u0fcf\0\u1008\0\u1041"+ "\0\u107a\0\u10b3\0\u10ec\0\u1125\0\u115e\0\u1197\0\u11d0\0\u1209"+ "\0\u1242\0\u127b\0\u12b4\0\u12ed\0\u1326\0\u135f\0\u1398\0\u13d1"+ "\0\u140a\0\u1443\0\u147c\0\u14b5\0\u14ee\0\u011d\0\u1527\0\u1560"+ "\0\u1599\0\u15d2\0\u160b\0\u1644\0\u167d\0\u16b6\0\u16ef\0\u1728"+ "\0\u1761\0\u179a\0\u17d3\0\u180c\0\u1845\0\u187e\0\u06ae\0\u18b7"+ "\0\u06e7\0\u18f0\0\u1929\0\u1962\0\u0759\0\u0792\0\253\0\253"+ "\0\u199b\0\u19d4\0\u1a0d\0\u1a46\0\u1a7f\0\u1ab8\0\u1af1\0\u1b2a"+ "\0\u1b63\0\u1b9c\0\u1bd5\0\u1c0e\0\u1c47\0\u1c80\0\u1cb9\0\u1cf2"+ "\0\u1d2b\0\u1d64\0\u1d9d\0\u1dd6\0\u1e0f\0\u1e48\0\u1e81\0\u1eba"+ "\0\u1ef3\0\u1f2c\0\u1f65\0\u1f9e\0\u1fd7\0\u2010\0\u2049\0\u2082"+ "\0\u20bb\0\u20f4\0\u212d\0\u2166\0\u219f\0\u21d8\0\u2211\0\u224a"+ "\0\u2283\0\u22bc\0\u22f5\0\u232e\0\u2367\0\u23a0\0\u23d9\0\u2412"+ "\0\u244b\0\u2484\0\u24bd\0\u24f6\0\u252f\0\u2568\0\u25a1\0\u25da"+ "\0\u2613\0\u264c\0\u2685\0\u26be\0\u26f7\0\u2730\0\u2769\0\u27a2"+ "\0\u27db\0\u2814\0\u284d\0\u2886\0\u28bf\0\u28f8\0\u2931\0\u296a"+ "\0\u29a3\0\u29dc\0\u2a15\0\u2a4e\0\u2a87\0\u2ac0\0\u2af9\0\u2b32"+ "\0\u2b6b\0\u2ba4\0\u2bdd\0\u2c16\0\u2c4f\0\u2c88\0\u2cc1\0\u2cfa"+ "\0\u2d33\0\u2d6c\0\u2da5\0\u2dde\0\u2e17\0\u2e50\0\u2e89\0\u2ec2"+ "\0\u2efb\0\u2f34\0\u2f6d\0\u2fa6\0\u2fdf\0\u3018\0\u3051\0\u308a"+ "\0\u30c3\0\u30fc\0\u3135\0\u316e\0\u31a7\0\u31e0\0\u3219\0\u3252"+ "\0\u328b\0\u32c4\0\u32fd\0\u3336\0\u336f\0\u33a8\0\u33e1\0\u341a"+ "\0\u3453\0\u348c\0\u34c5\0\u34fe\0\u3537\0\u3570\0\u35a9\0\u35e2"+ "\0\u361b\0\u3654\0\u368d\0\u36c6\0\u36ff\0\u3738\0\u3771\0\u37aa"+ "\0\u37e3\0\u381c\0\u3855\0\u388e\0\u38c7\0\u3900\0\u011d\0\u3939"+ "\0\u3972\0\u39ab\0\u39e4\0\u3a1d\0\u3a56\0\u3a8f\0\u3ac8\0\u3b01"+ "\0\u3b3a\0\u3b73\0\u3bac\0\u3be5\0\u3c1e\0\u3c57\0\u3c90\0\u3cc9"+ "\0\u3d02\0\u3d3b\0\u3d74\0\u3dad\0\u3de6\0\u3e1f\0\u3e58\0\u3e91"+ "\0\u3eca\0\u3f03\0\u3f3c\0\u3f75\0\u3fae\0\u3fe7\0\u4020\0\u4059"+ "\0\u4092\0\u40cb\0\u4104\0\u413d\0\u4176\0\u41af\0\u41e8\0\u4221"+ "\0\u425a\0\u4293\0\u42cc\0\u4305\0\253\0\u433e\0\u4377\0\u43b0"+ "\0\u43e9\0\u4422\0\u445b\0\u4494\0\u44cd\0\u4506\0\u453f\0\u4578"+ "\0\u45b1\0\u45ea\0\u4623\0\u465c\0\u4695\0\u46ce\0\u4707\0\u4740"+ "\0\u4779\0\u47b2\0\u47eb\0\u4824\0\u485d\0\u4896\0\u48cf\0\u4908"+ "\0\u4941\0\u497a\0\u49b3\0\u49ec\0\u4a25\0\u4a5e\0\u4a97\0\u4ad0"+ "\0\u4b09\0\u4b42\0\u4b7b\0\u4bb4\0\u4bed\0\u4c26\0\u4c5f\0\u4c98"+ "\0\u4cd1\0\u4d0a\0\u4d43\0\u4d7c\0\u4db5\0\u4dee\0\u4e27\0\u4e60"+ "\0\u4e99\0\u4ed2\0\u4f0b\0\u4f44\0\u4f7d\0\u4fb6\0\u4fef\0\u5028"+ "\0\u5061\0\u509a\0\u50d3\0\u510c\0\u5145\0\u517e\0\u51b7\0\u51f0"+ "\0\u5229\0\u5262\0\u529b\0\u52d4\0\u530d\0\u5346\0\u537f\0\u53b8"+ "\0\u53f1\0\u542a\0\u5463\0\u549c\0\u54d5\0\u550e\0\u5547\0\u5580"+ "\0\u55b9\0\u55f2\0\u562b\0\u5664\0\u569d\0\u56d6\0\u570f\0\u5748"+ "\0\u5781\0\u57ba\0\u57f3\0\u582c\0\u5865\0\u589e\0\u58d7\0\u5910"+ "\0\u5949\0\u5982\0\u59bb\0\u59f4\0\u4740\0\u5a2d\0\u5a66\0\u5a9f"+ "\0\u5ad8\0\u5b11\0\u5b4a\0\u5b83\0\u5bbc\0\u5bf5\0\u5c2e\0\u5c67"+ "\0\u5ca0\0\u5cd9\0\u5d12\0\u5d4b\0\u5d84\0\u5dbd\0\u5df6\0\u5e2f"+ "\0\u5e68\0\253\0\u5ea1\0\u5eda\0\u5f13\0\u5f4c\0\u5f85\0\u5fbe"+ "\0\u5ff7\0\u6030"; private static int [] zzUnpackRowMap() { int [] result = new int[450]; int offset = 0; offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); return result; } private static int zzUnpackRowMap(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int high = packed.charAt(i++) << 16; result[j++] = high | packed.charAt(i++); } return j; } /** * The transition table of the DFA */ private static final int [] ZZ_TRANS = zzUnpackTrans(); private static final String ZZ_TRANS_PACKED_0 = "\1\4\1\5\1\6\1\7\1\4\1\10\1\11\1\12"+ "\1\6\1\11\1\13\1\11\1\10\1\14\1\11\1\15"+ "\1\11\1\16\1\11\1\17\1\20\1\21\1\11\1\22"+ "\1\23\1\24\1\25\1\26\1\27\1\30\1\31\1\32"+ "\1\33\1\6\1\34\2\6\1\35\1\36\1\37\6\10"+ "\1\6\1\40\1\41\2\4\1\42\1\40\2\22\1\43"+ "\1\4\61\44\1\45\4\44\1\46\2\44\66\47\1\50"+ "\1\47\1\51\72\0\1\52\1\0\1\52\1\0\3\52"+ "\1\0\1\52\1\0\2\52\1\53\1\52\1\54\1\52"+ "\1\0\1\52\1\55\1\0\1\56\1\52\6\0\1\57"+ "\7\0\1\60\2\0\6\52\15\0\22\6\1\0\2\6"+ "\1\0\27\6\13\0\1\52\1\6\1\61\1\6\3\62"+ "\1\6\1\62\1\6\2\62\1\6\1\62\1\6\1\62"+ "\1\6\1\62\1\6\1\0\1\6\1\62\1\0\20\6"+ "\6\62\1\6\13\0\1\52\1\0\1\52\1\0\1\10"+ "\1\52\1\10\1\0\1\52\1\0\1\52\1\10\1\63"+ "\1\64\1\65\1\66\1\67\1\70\1\67\1\71\1\72"+ "\1\73\21\0\6\10\14\0\1\52\1\74\1\11\1\74"+ "\3\11\1\74\1\11\1\74\2\11\1\74\1\11\1\74"+ "\1\11\1\74\1\11\1\74\1\0\1\74\1\11\1\0"+ "\20\74\6\11\1\74\13\0\1\52\1\0\1\52\1\0"+ "\1\75\1\52\1\76\1\77\1\100\1\0\1\52\1\76"+ "\1\63\1\64\1\65\1\66\1\67\1\70\1\67\1\71"+ "\1\72\1\73\21\0\1\75\5\76\15\0\15\6\1\101"+ "\4\6\1\0\2\6\1\0\1\102\7\6\1\103\3\6"+ "\1\104\12\6\14\0\13\6\1\105\6\6\1\0\2\6"+ "\1\0\2\6\1\106\4\6\1\107\17\6\14\0\22\6"+ "\1\0\2\6\1\0\5\6\1\110\2\6\1\111\16\6"+ "\14\0\15\6\1\112\4\6\1\0\2\6\1\0\1\113"+ "\3\6\1\114\1\115\2\6\1\116\16\6\14\0\15\6"+ "\1\117\4\6\1\0\1\120\1\6\1\0\10\6\1\121"+ "\1\122\15\6\17\0\1\71\1\0\1\71\4\0\1\71"+ "\33\0\6\71\15\0\6\6\1\123\6\6\1\124\4\6"+ "\1\0\2\6\1\0\7\6\1\125\6\6\1\126\10\6"+ "\14\0\22\6\1\0\2\6\1\0\1\6\1\127\2\6"+ "\1\130\22\6\14\0\22\6\1\0\2\6\1\0\4\6"+ "\1\131\3\6\1\132\16\6\14\0\22\6\1\0\1\133"+ "\1\6\1\0\1\134\2\6\1\135\1\6\1\136\6\6"+ "\1\137\2\6\1\140\7\6\14\0\22\6\1\0\1\141"+ "\1\6\1\0\4\6\1\142\4\6\1\143\2\6\1\144"+ "\12\6\14\0\22\6\1\0\1\145\1\6\1\0\27\6"+ "\14\0\17\6\1\146\2\6\1\0\2\6\1\0\7\6"+ "\1\147\17\6\14\0\10\6\1\150\11\6\1\0\1\151"+ "\1\6\1\0\10\6\1\152\16\6\14\0\13\6\1\153"+ "\6\6\1\0\1\154\1\6\1\0\1\155\7\6\1\156"+ "\16\6\14\0\22\6\1\0\2\6\1\0\15\6\1\157"+ "\11\6\14\0\13\6\1\160\6\6\1\0\2\6\1\0"+ "\27\6\14\0\13\6\1\161\6\6\1\0\2\6\1\0"+ "\4\6\1\162\22\6\14\0\22\6\1\0\2\6\1\0"+ "\1\163\4\6\1\164\2\6\1\165\16\6\14\0\22\6"+ "\1\0\2\6\1\0\14\6\1\166\12\6\12\0\60\167"+ "\2\67\1\170\6\167\61\171\1\67\1\172\1\67\5\171"+ "\66\0\1\173\1\174\1\0\61\175\1\45\4\175\1\176"+ "\63\175\1\45\4\175\1\176\1\177\1\175\67\0\1\200"+ "\3\0\2\201\2\0\1\201\1\0\4\201\1\0\7\201"+ "\1\0\2\201\1\0\20\201\6\0\1\201\13\0\1\52"+ "\1\0\1\52\1\0\3\52\1\0\1\52\1\0\2\52"+ "\1\0\1\52\1\0\1\52\1\0\1\52\3\0\1\52"+ "\21\0\6\52\45\0\1\202\4\0\1\203\66\0\1\204"+ "\60\0\1\205\62\0\1\206\14\0\1\207\2\0\1\210"+ "\52\0\1\211\15\0\1\212\2\0\1\213\62\0\1\214"+ "\35\0\1\52\1\6\1\62\1\6\3\62\1\6\1\62"+ "\1\215\2\62\1\216\1\62\1\217\1\62\1\220\1\62"+ "\1\221\1\0\1\222\1\62\1\0\1\223\1\224\1\225"+ "\1\226\1\227\1\230\1\231\1\232\2\6\1\233\1\6"+ "\1\234\1\235\1\236\1\237\6\62\1\6\13\0\1\52"+ "\1\6\1\62\1\6\3\62\1\6\1\62\1\6\2\62"+ "\1\6\1\62\1\6\1\62\1\6\1\62\1\6\1\0"+ "\1\6\1\62\1\0\20\6\6\62\1\6\27\0\2\67"+ "\2\65\51\0\1\52\1\0\1\52\1\0\3\52\1\0"+ "\1\52\1\0\2\52\1\67\1\70\1\65\1\66\1\0"+ "\1\52\3\0\1\52\21\0\6\52\30\0\2\67\53\0"+ "\1\52\1\0\1\52\1\0\3\52\1\0\1\52\1\0"+ "\2\52\1\67\1\70\1\0\1\52\1\0\1\52\3\0"+ "\1\52\21\0\6\52\20\0\1\71\1\0\1\71\4\0"+ "\1\71\4\0\3\67\1\0\2\72\21\0\6\71\20\0"+ "\1\240\1\0\1\240\4\0\1\240\12\0\1\241\20\0"+ "\6\240\14\0\1\52\1\0\1\52\1\0\1\242\1\52"+ "\1\242\1\0\1\52\1\0\1\52\1\242\1\0\1\52"+ "\1\0\1\52\1\0\1\52\3\0\1\52\1\241\20\0"+ "\6\242\15\0\22\74\1\0\2\74\1\0\27\74\13\0"+ "\1\52\1\0\1\52\1\0\1\75\1\52\1\75\1\0"+ "\1\52\1\0\1\52\1\75\1\0\1\52\1\0\1\52"+ "\1\67\1\70\1\67\1\71\1\72\1\73\21\0\6\75"+ "\14\0\1\52\1\0\1\52\1\0\1\75\1\52\1\76"+ "\1\0\1\52\1\0\1\52\1\76\1\63\1\64\1\65"+ "\1\66\1\67\1\70\1\67\1\71\1\72\1\73\21\0"+ "\1\75\5\76\20\0\1\77\1\0\1\77\2\0\3\77"+ "\2\63\2\65\3\77\1\0\2\77\1\0\2\77\16\0"+ "\6\77\14\0\1\52\1\0\1\52\1\0\1\100\1\52"+ "\1\100\1\0\1\52\1\77\2\100\1\63\1\64\1\65"+ "\1\66\1\77\1\100\1\77\1\0\1\77\1\100\1\0"+ "\2\77\16\0\6\100\15\0\22\6\1\0\2\6\1\0"+ "\1\243\26\6\14\0\22\6\1\0\2\6\1\0\2\6"+ "\1\244\1\245\23\6\14\0\22\6\1\0\2\6\1\0"+ "\7\6\1\246\17\6\14\0\22\6\1\0\2\6\1\0"+ "\1\247\26\6\14\0\22\6\1\0\2\6\1\0\5\6"+ "\1\250\21\6\14\0\22\6\1\0\2\6\1\0\5\6"+ "\1\251\21\6\14\0\22\6\1\0\2\6\1\0\2\6"+ "\1\252\2\6\1\253\21\6\14\0\22\6\1\0\2\6"+ "\1\0\3\6\1\254\23\6\14\0\22\6\1\0\2\6"+ "\1\0\7\6\1\255\17\6\14\0\22\6\1\0\2\6"+ "\1\0\10\6\1\256\16\6\14\0\15\6\1\124\4\6"+ "\1\0\2\6\1\0\27\6\14\0\22\6\1\0\2\6"+ "\1\0\5\6\1\257\21\6\14\0\22\6\1\0\2\6"+ "\1\0\7\6\1\260\17\6\14\0\22\6\1\0\2\6"+ "\1\0\4\6\1\146\22\6\14\0\15\6\1\261\4\6"+ "\1\0\2\6\1\0\27\6\14\0\15\6\1\262\1\6"+ "\1\263\2\6\1\0\2\6\1\0\15\6\1\264\11\6"+ "\14\0\13\6\1\265\6\6\1\0\2\6\1\0\27\6"+ "\14\0\22\6\1\0\2\6\1\0\7\6\1\266\17\6"+ "\14\0\22\6\1\0\2\6\1\0\3\6\1\267\11\6"+ "\1\270\11\6\14\0\22\6\1\0\2\6\1\0\2\6"+ "\1\244\24\6\14\0\13\6\1\271\6\6\1\0\2\6"+ "\1\0\27\6\14\0\22\6\1\0\1\272\1\6\1\0"+ "\27\6\14\0\22\6\1\0\2\6\1\0\2\6\1\273"+ "\24\6\14\0\22\6\1\0\2\6\1\0\4\6\1\274"+ "\22\6\14\0\22\6\1\0\1\275\1\6\1\0\27\6"+ "\14\0\22\6\1\0\2\6\1\0\10\6\1\276\16\6"+ "\14\0\15\6\1\277\4\6\1\0\2\6\1\0\1\300"+ "\26\6\14\0\17\6\1\301\2\6\1\0\2\6\1\0"+ "\27\6\14\0\22\6\1\0\2\6\1\0\1\302\3\6"+ "\1\303\22\6\14\0\22\6\1\0\2\6\1\0\6\6"+ "\1\304\17\6\1\305\14\0\22\6\1\0\2\6\1\0"+ "\10\6\1\306\16\6\14\0\22\6\1\0\2\6\1\0"+ "\5\6\1\307\21\6\14\0\22\6\1\0\2\6\1\0"+ "\12\6\1\310\14\6\14\0\13\6\1\244\6\6\1\0"+ "\2\6\1\0\11\6\1\146\15\6\14\0\22\6\1\0"+ "\2\6\1\0\15\6\1\311\11\6\14\0\22\6\1\0"+ "\2\6\1\0\4\6\1\312\1\313\21\6\14\0\22\6"+ "\1\0\2\6\1\0\3\6\1\314\1\6\1\315\1\316"+ "\20\6\14\0\15\6\1\317\4\6\1\0\2\6\1\0"+ "\3\6\1\320\1\6\1\321\21\6\14\0\22\6\1\0"+ "\2\6\1\0\7\6\1\322\17\6\14\0\22\6\1\0"+ "\2\6\1\0\7\6\1\323\17\6\14\0\22\6\1\0"+ "\2\6\1\0\3\6\1\324\23\6\14\0\15\6\1\325"+ "\4\6\1\0\2\6\1\0\27\6\14\0\22\6\1\0"+ "\2\6\1\0\17\6\1\146\7\6\14\0\22\6\1\0"+ "\2\6\1\0\12\6\1\326\1\327\13\6\14\0\22\6"+ "\1\0\2\6\1\0\3\6\1\330\1\331\1\332\10\6"+ "\1\160\10\6\14\0\22\6\1\0\1\333\1\6\1\0"+ "\27\6\14\0\22\6\1\0\2\6\1\0\3\6\1\334"+ "\23\6\14\0\22\6\1\0\2\6\1\0\1\6\1\335"+ "\25\6\14\0\22\6\1\0\2\6\1\0\5\6\1\336"+ "\2\6\1\337\16\6\14\0\15\6\1\340\4\6\1\0"+ "\2\6\1\0\27\6\14\0\22\6\1\0\2\6\1\0"+ "\4\6\1\341\22\6\14\0\15\6\1\342\4\6\1\0"+ "\2\6\1\0\5\6\1\250\21\6\14\0\22\6\1\0"+ "\2\6\1\0\5\6\1\343\21\6\12\0\61\167\1\67"+ "\7\167\61\171\1\67\7\171\66\0\1\344\2\0\61\174"+ "\1\45\7\174\2\0\22\201\1\0\2\201\1\0\27\201"+ "\47\0\1\345\56\0\1\346\104\0\1\347\52\0\1\54"+ "\101\0\1\347\2\0\1\350\67\0\1\351\57\0\1\352"+ "\70\0\1\346\13\0\1\203\43\0\1\353\123\0\1\354"+ "\53\0\1\355\42\0\21\6\1\356\1\0\2\6\1\0"+ "\27\6\14\0\13\6\1\357\6\6\1\0\2\6\1\0"+ "\7\6\1\360\17\6\14\0\22\6\1\0\1\361\1\6"+ "\1\0\27\6\14\0\22\6\1\0\2\6\1\0\1\362"+ "\4\6\1\115\2\6\1\363\16\6\14\0\22\6\1\0"+ "\1\364\1\6\1\0\27\6\14\0\6\6\1\365\13\6"+ "\1\0\2\6\1\0\16\6\1\126\10\6\14\0\15\6"+ "\1\366\4\6\1\0\2\6\1\0\1\6\1\127\1\367"+ "\24\6\14\0\22\6\1\0\2\6\1\0\1\370\7\6"+ "\1\371\16\6\14\0\13\6\1\372\6\6\1\0\1\373"+ "\1\6\1\0\3\6\1\374\1\6\1\375\21\6\14\0"+ "\22\6\1\0\2\6\1\0\4\6\1\376\22\6\14\0"+ "\22\6\1\0\2\6\1\0\1\377\26\6\14\0\17\6"+ "\1\u0100\1\6\1\u0101\1\0\2\6\1\0\7\6\1\u0102"+ "\17\6\14\0\10\6\1\146\11\6\1\0\2\6\1\0"+ "\27\6\14\0\22\6\1\0\2\6\1\0\10\6\1\u0103"+ "\16\6\14\0\13\6\1\u0104\6\6\1\0\2\6\1\0"+ "\21\6\1\u0105\1\u0106\4\6\14\0\22\6\1\0\2\6"+ "\1\0\10\6\1\u0107\16\6\14\0\22\6\1\0\2\6"+ "\1\0\4\6\1\u0108\1\u0109\21\6\14\0\22\6\1\0"+ "\2\6\1\0\1\163\4\6\1\u010a\21\6\14\0\10\6"+ "\1\u010b\11\6\1\0\2\6\1\0\22\6\1\u0106\4\6"+ "\17\0\1\240\1\0\1\240\4\0\1\240\4\0\3\67"+ "\24\0\6\240\20\0\1\240\1\0\1\240\4\0\1\240"+ "\33\0\6\240\14\0\1\52\1\0\1\52\1\0\1\242"+ "\1\52\1\242\1\0\1\52\1\0\1\52\1\242\1\0"+ "\1\52\1\0\1\52\1\67\1\70\1\67\2\0\1\52"+ "\21\0\6\242\15\0\22\6\1\0\2\6\1\0\2\6"+ "\1\313\24\6\14\0\22\6\1\0\1\146\1\6\1\0"+ "\27\6\14\0\10\6\1\u010c\11\6\1\0\2\6\1\0"+ "\27\6\14\0\22\6\1\0\2\6\1\0\2\6\1\u010d"+ "\1\u010e\23\6\14\0\22\6\1\0\2\6\1\0\4\6"+ "\1\u010f\22\6\14\0\21\6\1\146\1\0\2\6\1\0"+ "\27\6\14\0\22\6\1\0\2\6\1\0\7\6\1\u0110"+ "\17\6\14\0\22\6\1\0\2\6\1\0\5\6\1\u0111"+ "\21\6\14\0\22\6\1\0\2\6\1\0\10\6\1\u0109"+ "\16\6\14\0\22\6\1\0\1\u0112\1\6\1\0\27\6"+ "\14\0\22\6\1\0\2\6\1\0\6\6\1\u010f\20\6"+ "\14\0\22\6\1\0\2\6\1\0\1\u0113\26\6\14\0"+ "\22\6\1\0\1\u0114\1\6\1\0\27\6\14\0\22\6"+ "\1\0\2\6\1\0\1\u0115\26\6\14\0\22\6\1\0"+ "\1\u0116\1\6\1\0\5\6\1\u0117\21\6\14\0\22\6"+ "\1\0\1\u0118\1\6\1\0\27\6\14\0\22\6\1\0"+ "\2\6\1\0\1\u0119\26\6\14\0\22\6\1\0\2\6"+ "\1\0\4\6\1\u011a\22\6\14\0\22\6\1\0\2\6"+ "\1\0\1\6\1\343\25\6\14\0\22\6\1\0\2\6"+ "\1\0\1\u011b\26\6\14\0\22\6\1\0\1\u011c\1\6"+ "\1\0\27\6\14\0\15\6\1\u011d\4\6\1\0\2\6"+ "\1\0\27\6\14\0\22\6\1\0\2\6\1\0\12\6"+ "\1\146\14\6\14\0\22\6\1\0\2\6\1\0\7\6"+ "\1\u011e\17\6\14\0\22\6\1\0\2\6\1\0\3\6"+ "\1\u011f\23\6\14\0\22\6\1\0\2\6\1\0\1\u0120"+ "\26\6\14\0\22\6\1\0\2\6\1\0\1\u0121\26\6"+ "\14\0\15\6\1\u010f\4\6\1\0\2\6\1\0\27\6"+ "\14\0\22\6\1\0\1\u0122\1\6\1\0\27\6\14\0"+ "\15\6\1\327\4\6\1\0\2\6\1\0\27\6\14\0"+ "\22\6\1\0\1\u0123\1\6\1\0\27\6\14\0\22\6"+ "\1\0\2\6\1\0\3\6\1\u0124\23\6\14\0\13\6"+ "\1\u0125\6\6\1\0\2\6\1\0\27\6\14\0\22\6"+ "\1\0\2\6\1\0\7\6\1\327\17\6\14\0\22\6"+ "\1\0\1\u0126\1\6\1\0\27\6\14\0\22\6\1\0"+ "\2\6\1\0\4\6\1\u0113\22\6\14\0\22\6\1\0"+ "\2\6\1\0\3\6\1\245\23\6\14\0\22\6\1\0"+ "\2\6\1\0\15\6\1\u0127\11\6\14\0\22\6\1\0"+ "\1\u0128\1\6\1\0\27\6\14\0\22\6\1\0\1\u0129"+ "\1\6\1\0\10\6\1\154\16\6\14\0\22\6\1\0"+ "\2\6\1\0\2\6\1\146\24\6\14\0\13\6\1\u011c"+ "\6\6\1\0\2\6\1\0\27\6\14\0\22\6\1\0"+ "\2\6\1\0\7\6\1\u012a\17\6\14\0\22\6\1\0"+ "\2\6\1\0\5\6\1\u012b\21\6\14\0\22\6\1\0"+ "\2\6\1\0\5\6\1\u012c\21\6\14\0\22\6\1\0"+ "\1\u012d\1\6\1\0\27\6\14\0\22\6\1\0\2\6"+ "\1\0\3\6\1\u012e\23\6\14\0\22\6\1\0\1\154"+ "\1\6\1\0\27\6\14\0\22\6\1\0\1\u012f\1\6"+ "\1\0\27\6\14\0\22\6\1\0\2\6\1\0\10\6"+ "\1\146\16\6\14\0\15\6\1\u0130\4\6\1\0\2\6"+ "\1\0\27\6\14\0\22\6\1\0\1\u0131\1\6\1\0"+ "\27\6\14\0\22\6\1\0\1\250\1\6\1\0\27\6"+ "\14\0\22\6\1\0\2\6\1\0\14\6\1\u0132\12\6"+ "\14\0\22\6\1\0\1\u0133\1\6\1\0\27\6\14\0"+ "\22\6\1\0\2\6\1\0\7\6\1\u0134\17\6\14\0"+ "\22\6\1\0\2\6\1\0\4\6\1\u0135\22\6\14\0"+ "\22\6\1\0\2\6\1\0\1\265\26\6\14\0\15\6"+ "\1\u0136\4\6\1\0\2\6\1\0\27\6\14\0\22\6"+ "\1\0\2\6\1\0\16\6\1\u0137\10\6\14\0\22\6"+ "\1\0\2\6\1\0\3\6\1\u0138\11\6\1\u0139\11\6"+ "\14\0\13\6\1\244\6\6\1\0\2\6\1\0\27\6"+ "\14\0\22\6\1\0\2\6\1\0\3\6\1\u013a\23\6"+ "\14\0\22\6\1\0\2\6\1\0\1\u013b\26\6\14\0"+ "\15\6\1\244\4\6\1\0\2\6\1\0\27\6\101\0"+ "\1\45\40\0\1\u013c\56\0\1\350\70\0\1\u013d\64\0"+ "\1\u013d\107\0\1\u013e\65\0\1\350\52\0\1\u013f\111\0"+ "\1\u0140\66\0\1\u0141\34\0\22\6\1\0\1\u0142\1\6"+ "\1\0\27\6\14\0\22\6\1\0\2\6\1\0\5\6"+ "\1\u0143\21\6\14\0\22\6\1\0\2\6\1\0\1\u0144"+ "\13\6\1\234\12\6\14\0\22\6\1\0\2\6\1\0"+ "\1\u0145\26\6\14\0\22\6\1\0\2\6\1\0\2\6"+ "\1\u0146\24\6\14\0\22\6\1\0\2\6\1\0\4\6"+ "\1\u0147\22\6\14\0\10\6\1\u0148\4\6\1\u0149\4\6"+ "\1\0\2\6\1\0\27\6\14\0\10\6\1\u014a\11\6"+ "\1\0\2\6\1\0\27\6\14\0\22\6\1\0\2\6"+ "\1\0\5\6\1\u014b\21\6\14\0\22\6\1\0\2\6"+ "\1\0\2\6\1\u014c\7\6\1\146\14\6\14\0\22\6"+ "\1\0\2\6\1\0\2\6\1\327\24\6\14\0\6\6"+ "\1\146\13\6\1\0\2\6\1\0\27\6\14\0\22\6"+ "\1\0\2\6\1\0\15\6\1\u014d\11\6\14\0\22\6"+ "\1\0\2\6\1\0\1\300\26\6\14\0\21\6\1\u014e"+ "\1\0\2\6\1\0\27\6\14\0\22\6\1\0\2\6"+ "\1\0\7\6\1\u014f\17\6\14\0\22\6\1\0\2\6"+ "\1\0\11\6\1\u0150\15\6\14\0\22\6\1\0\2\6"+ "\1\0\5\6\1\124\21\6\14\0\1\6\1\u0151\20\6"+ "\1\0\2\6\1\0\27\6\14\0\22\6\1\0\1\u0152"+ "\1\6\1\0\27\6\14\0\15\6\1\317\4\6\1\0"+ "\2\6\1\0\3\6\1\u0153\23\6\14\0\22\6\1\0"+ "\2\6\1\0\6\6\1\231\1\6\1\u0154\16\6\14\0"+ "\15\6\1\u0155\4\6\1\0\2\6\1\0\27\6\14\0"+ "\22\6\1\0\2\6\1\0\24\6\1\u0156\2\6\14\0"+ "\22\6\1\0\2\6\1\0\25\6\1\146\1\6\14\0"+ "\22\6\1\0\2\6\1\0\10\6\1\u0121\16\6\14\0"+ "\22\6\1\0\2\6\1\0\10\6\1\u0157\16\6\14\0"+ "\22\6\1\0\2\6\1\0\7\6\1\146\17\6\14\0"+ "\22\6\1\0\2\6\1\0\4\6\1\u0158\22\6\14\0"+ "\22\6\1\0\2\6\1\0\14\6\1\u0159\12\6\14\0"+ "\22\6\1\0\2\6\1\0\14\6\1\146\12\6\14\0"+ "\22\6\1\0\2\6\1\0\3\6\1\u0150\23\6\14\0"+ "\22\6\1\0\2\6\1\0\5\6\1\u015a\21\6\14\0"+ "\22\6\1\0\2\6\1\0\6\6\1\146\20\6\14\0"+ "\22\6\1\0\2\6\1\0\6\6\1\304\20\6\14\0"+ "\22\6\1\0\2\6\1\0\4\6\1\u015b\22\6\14\0"+ "\22\6\1\0\2\6\1\0\3\6\1\u010f\23\6\14\0"+ "\22\6\1\0\2\6\1\0\7\6\1\u015c\17\6\14\0"+ "\15\6\1\u015d\4\6\1\0\2\6\1\0\27\6\14\0"+ "\6\6\1\u015e\13\6\1\0\2\6\1\0\27\6\14\0"+ "\22\6\1\0\2\6\1\0\12\6\1\u015e\14\6\14\0"+ "\22\6\1\0\2\6\1\0\3\6\1\244\2\6\1\u0137"+ "\20\6\14\0\13\6\1\u015f\6\6\1\0\2\6\1\0"+ "\27\6\14\0\22\6\1\0\1\u0160\1\6\1\0\27\6"+ "\14\0\22\6\1\0\2\6\1\0\12\6\1\u0161\14\6"+ "\14\0\22\6\1\0\2\6\1\0\4\6\1\u0109\22\6"+ "\14\0\22\6\1\0\2\6\1\0\5\6\1\u0162\21\6"+ "\14\0\22\6\1\0\2\6\1\0\3\6\1\146\23\6"+ "\14\0\22\6\1\0\2\6\1\0\4\6\1\u0163\22\6"+ "\14\0\22\6\1\0\2\6\1\0\11\6\1\146\15\6"+ "\14\0\22\6\1\0\2\6\1\0\13\6\1\146\13\6"+ "\14\0\10\6\1\u0164\11\6\1\0\2\6\1\0\27\6"+ "\14\0\10\6\1\u0165\11\6\1\0\2\6\1\0\27\6"+ "\14\0\22\6\1\0\2\6\1\0\5\6\1\u0166\21\6"+ "\14\0\10\6\1\u011e\11\6\1\0\2\6\1\0\27\6"+ "\14\0\22\6\1\0\2\6\1\0\10\6\1\u0167\16\6"+ "\14\0\15\6\1\u0137\4\6\1\0\2\6\1\0\27\6"+ "\14\0\21\6\1\u0168\1\0\2\6\1\0\5\6\1\250"+ "\1\6\1\u0169\17\6\14\0\22\6\1\0\2\6\1\0"+ "\1\250\26\6\14\0\22\6\1\0\2\6\1\0\3\6"+ "\1\u016a\23\6\14\0\22\6\1\0\2\6\1\0\2\6"+ "\1\u016b\24\6\14\0\22\6\1\0\2\6\1\0\7\6"+ "\1\244\17\6\14\0\22\6\1\0\2\6\1\0\4\6"+ "\1\u016c\22\6\14\0\22\6\1\0\2\6\1\0\10\6"+ "\1\u016d\16\6\14\0\22\6\1\0\2\6\1\0\4\6"+ "\1\u0136\22\6\14\0\22\6\1\0\2\6\1\0\15\6"+ "\1\u016e\11\6\14\0\22\6\1\0\2\6\1\0\2\6"+ "\1\u016f\24\6\14\0\22\6\1\0\2\6\1\0\4\6"+ "\1\u0170\22\6\14\0\22\6\1\0\2\6\1\0\3\6"+ "\1\314\23\6\14\0\15\6\1\317\4\6\1\0\2\6"+ "\1\0\27\6\14\0\22\6\1\0\2\6\1\0\1\u0171"+ "\26\6\14\0\22\6\1\0\2\6\1\0\5\6\1\231"+ "\21\6\14\0\22\6\1\0\2\6\1\0\1\u0172\26\6"+ "\14\0\22\6\1\0\1\u0173\1\6\1\0\27\6\14\0"+ "\22\6\1\0\1\u0174\1\6\1\0\27\6\14\0\13\6"+ "\1\u015b\6\6\1\0\2\6\1\0\27\6\14\0\22\6"+ "\1\0\2\6\1\0\3\6\1\166\23\6\50\0\1\u013d"+ "\66\0\1\u013d\51\0\1\u0175\107\0\1\u0176\76\0\1\u0177"+ "\30\0\10\6\1\u0178\11\6\1\0\2\6\1\0\27\6"+ "\14\0\21\6\1\u0126\1\0\2\6\1\0\27\6\14\0"+ "\15\6\1\252\4\6\1\0\2\6\1\0\27\6\14\0"+ "\22\6\1\0\2\6\1\0\16\6\1\244\10\6\14\0"+ "\22\6\1\0\2\6\1\0\3\6\1\u014e\23\6\14\0"+ "\10\6\1\u0179\11\6\1\0\2\6\1\0\27\6\14\0"+ "\15\6\1\u017a\4\6\1\0\2\6\1\0\27\6\14\0"+ "\22\6\1\0\1\u017b\1\6\1\0\27\6\14\0\22\6"+ "\1\0\1\u017c\1\6\1\0\27\6\14\0\22\6\1\0"+ "\2\6\1\0\6\6\1\u017d\20\6\14\0\13\6\1\u017e"+ "\6\6\1\0\2\6\1\0\27\6\14\0\22\6\1\0"+ "\1\116\1\6\1\0\27\6\14\0\10\6\1\u017f\11\6"+ "\1\0\2\6\1\0\27\6\14\0\22\6\1\0\2\6"+ "\1\0\6\6\1\u0180\20\6\14\0\1\6\1\u0123\20\6"+ "\1\0\2\6\1\0\27\6\14\0\22\6\1\0\1\u0181"+ "\1\6\1\0\7\6\1\u0182\17\6\14\0\22\6\1\0"+ "\2\6\1\0\7\6\1\u0183\17\6\14\0\22\6\1\0"+ "\1\u0184\1\6\1\0\20\6\1\146\1\u0185\1\u0106\1\u0186"+ "\3\6\14\0\22\6\1\0\2\6\1\0\15\6\1\146"+ "\11\6\14\0\22\6\1\0\2\6\1\0\3\6\1\u0187"+ "\23\6\14\0\22\6\1\0\2\6\1\0\20\6\1\u0188"+ "\6\6\14\0\22\6\1\0\2\6\1\0\15\6\1\u0139"+ "\11\6\14\0\22\6\1\0\2\6\1\0\3\6\1\u0189"+ "\23\6\14\0\22\6\1\0\2\6\1\0\1\u018a\26\6"+ "\14\0\22\6\1\0\2\6\1\0\7\6\1\340\17\6"+ "\14\0\22\6\1\0\2\6\1\0\1\u0178\26\6\14\0"+ "\21\6\1\u018b\1\0\2\6\1\0\27\6\14\0\15\6"+ "\1\u0120\4\6\1\0\2\6\1\0\27\6\14\0\22\6"+ "\1\0\2\6\1\0\15\6\1\u018c\11\6\14\0\15\6"+ "\1\u011e\4\6\1\0\2\6\1\0\27\6\14\0\10\6"+ "\1\u018d\11\6\1\0\2\6\1\0\27\6\14\0\22\6"+ "\1\0\2\6\1\0\5\6\1\u018e\21\6\14\0\10\6"+ "\1\u018f\11\6\1\0\2\6\1\0\27\6\14\0\22\6"+ "\1\0\2\6\1\0\1\u0125\26\6\14\0\22\6\1\0"+ "\2\6\1\0\3\6\1\u0190\23\6\14\0\22\6\1\0"+ "\2\6\1\0\1\u0191\26\6\14\0\10\6\1\u0150\11\6"+ "\1\0\2\6\1\0\27\6\14\0\17\6\1\146\2\6"+ "\1\0\2\6\1\0\27\6\14\0\22\6\1\0\1\u0167"+ "\1\6\1\0\27\6\14\0\22\6\1\0\2\6\1\0"+ "\1\u017e\26\6\14\0\22\6\1\0\1\u0192\1\6\1\0"+ "\27\6\14\0\22\6\1\0\2\6\1\0\3\6\1\u014d"+ "\23\6\14\0\17\6\1\u0193\2\6\1\0\2\6\1\0"+ "\5\6\1\u0194\21\6\14\0\22\6\1\0\2\6\1\0"+ "\7\6\1\u015d\17\6\14\0\22\6\1\0\2\6\1\0"+ "\3\6\1\116\23\6\14\0\22\6\1\0\2\6\1\0"+ "\15\6\1\u0193\11\6\14\0\22\6\1\0\2\6\1\0"+ "\10\6\1\154\16\6\14\0\22\6\1\0\2\6\1\0"+ "\3\6\1\u0195\23\6\14\0\22\6\1\0\2\6\1\0"+ "\3\6\1\244\23\6\14\0\10\6\1\u0196\11\6\1\0"+ "\2\6\1\0\27\6\14\0\22\6\1\0\2\6\1\0"+ "\4\6\1\u0197\22\6\35\0\1\347\100\0\1\u013d\65\0"+ "\1\u013d\42\0\15\6\1\146\4\6\1\0\2\6\1\0"+ "\27\6\14\0\22\6\1\0\1\u0198\1\6\1\0\27\6"+ "\14\0\22\6\1\0\2\6\1\0\2\6\1\u0199\24\6"+ "\14\0\22\6\1\0\2\6\1\0\6\6\1\u0137\20\6"+ "\14\0\22\6\1\0\2\6\1\0\15\6\1\u011e\11\6"+ "\14\0\22\6\1\0\2\6\1\0\7\6\1\u0126\17\6"+ "\14\0\22\6\1\0\2\6\1\0\12\6\1\244\14\6"+ "\14\0\22\6\1\0\2\6\1\0\1\u019a\26\6\14\0"+ "\15\6\1\u019b\4\6\1\0\2\6\1\0\27\6\14\0"+ "\6\6\1\u019c\13\6\1\0\2\6\1\0\27\6\14\0"+ "\22\6\1\0\2\6\1\0\10\6\1\u019d\16\6\14\0"+ "\22\6\1\0\2\6\1\0\3\6\1\u019e\23\6\14\0"+ "\22\6\1\0\2\6\1\0\4\6\1\u019f\22\6\14\0"+ "\22\6\1\0\2\6\1\0\22\6\1\146\4\6\14\0"+ "\22\6\1\0\2\6\1\0\24\6\1\146\2\6\14\0"+ "\22\6\1\0\2\6\1\0\5\6\1\u01a0\21\6\14\0"+ "\21\6\1\146\1\0\2\6\1\0\5\6\1\146\21\6"+ "\14\0\13\6\1\u01a1\6\6\1\0\2\6\1\0\27\6"+ "\14\0\22\6\1\0\2\6\1\0\4\6\1\u01a2\22\6"+ "\14\0\1\6\1\u01a3\20\6\1\0\2\6\1\0\27\6"+ "\14\0\22\6\1\0\2\6\1\0\10\6\1\u01a4\16\6"+ "\14\0\22\6\1\0\2\6\1\0\1\u0196\26\6\14\0"+ "\10\6\1\u01a5\11\6\1\0\2\6\1\0\27\6\14\0"+ "\22\6\1\0\2\6\1\0\5\6\1\u011e\21\6\14\0"+ "\22\6\1\0\2\6\1\0\1\u01a6\26\6\14\0\22\6"+ "\1\0\2\6\1\0\2\6\1\u011e\24\6\14\0\22\6"+ "\1\0\2\6\1\0\4\6\1\u01a7\22\6\14\0\22\6"+ "\1\0\2\6\1\0\1\u01a8\26\6\14\0\22\6\1\0"+ "\2\6\1\0\10\6\1\u01a9\16\6\14\0\22\6\1\0"+ "\2\6\1\0\10\6\1\116\16\6\14\0\22\6\1\0"+ "\2\6\1\0\3\6\1\327\23\6\14\0\22\6\1\0"+ "\2\6\1\0\3\6\1\u0120\23\6\14\0\22\6\1\0"+ "\2\6\1\0\5\6\1\332\21\6\14\0\22\6\1\0"+ "\2\6\1\0\15\6\1\u01aa\11\6\14\0\15\6\1\u0178"+ "\4\6\1\0\2\6\1\0\27\6\14\0\22\6\1\0"+ "\1\u01ab\1\6\1\0\27\6\14\0\22\6\1\0\2\6"+ "\1\0\5\6\1\u01ac\21\6\14\0\22\6\1\0\2\6"+ "\1\0\3\6\1\u01ad\23\6\14\0\22\6\1\0\2\6"+ "\1\0\5\6\1\u01ae\21\6\14\0\17\6\1\u0193\2\6"+ "\1\0\2\6\1\0\27\6\14\0\22\6\1\0\2\6"+ "\1\0\15\6\1\u0180\11\6\14\0\22\6\1\0\2\6"+ "\1\0\1\u01af\26\6\14\0\1\6\1\u01b0\20\6\1\0"+ "\2\6\1\0\27\6\14\0\22\6\1\0\2\6\1\0"+ "\1\313\26\6\14\0\22\6\1\0\2\6\1\0\4\6"+ "\1\u011e\22\6\14\0\22\6\1\0\2\6\1\0\7\6"+ "\1\u0120\17\6\14\0\22\6\1\0\2\6\1\0\15\6"+ "\1\u01b1\11\6\14\0\10\6\1\244\11\6\1\0\2\6"+ "\1\0\27\6\14\0\22\6\1\0\2\6\1\0\4\6"+ "\1\u01b2\22\6\14\0\22\6\1\0\1\231\1\6\1\0"+ "\27\6\14\0\1\6\1\u01b3\20\6\1\0\2\6\1\0"+ "\27\6\14\0\22\6\1\0\2\6\1\0\2\6\1\u01b4"+ "\24\6\14\0\1\6\1\u01b5\20\6\1\0\2\6\1\0"+ "\27\6\14\0\17\6\1\u01b6\2\6\1\0\2\6\1\0"+ "\27\6\14\0\15\6\1\u01ab\4\6\1\0\2\6\1\0"+ "\27\6\14\0\22\6\1\0\2\6\1\0\3\6\1\u01b7"+ "\23\6\14\0\22\6\1\0\2\6\1\0\4\6\1\u01b8"+ "\22\6\14\0\1\6\1\u0130\20\6\1\0\2\6\1\0"+ "\27\6\14\0\22\6\1\0\2\6\1\0\5\6\1\u01b9"+ "\21\6\14\0\22\6\1\0\2\6\1\0\3\6\1\313"+ "\23\6\14\0\22\6\1\0\1\u0181\1\6\1\0\27\6"+ "\14\0\22\6\1\0\2\6\1\0\5\6\1\u014d\21\6"+ "\14\0\22\6\1\0\2\6\1\0\27\6\1\u01ba\13\0"+ "\22\6\1\0\1\u01bb\1\6\1\0\27\6\14\0\22\6"+ "\1\0\2\6\1\0\7\6\1\u01bc\17\6\14\0\22\6"+ "\1\0\2\6\1\0\3\6\1\u01a5\23\6\14\0\22\6"+ "\1\0\2\6\1\0\14\6\1\u01bd\12\6\14\0\22\6"+ "\1\0\1\u01be\1\6\1\0\27\6\14\0\22\6\1\0"+ "\2\6\1\0\4\6\1\u01bf\22\6\14\0\22\6\1\0"+ "\2\6\1\0\5\6\1\u01c0\21\6\14\0\22\6\1\0"+ "\2\6\1\0\3\6\1\u01c1\23\6\14\0\22\6\1\0"+ "\2\6\1\0\1\u01c2\26\6\14\0\22\6\1\0\2\6"+ "\1\0\7\6\1\u01a8\17\6\12\0"; private static int [] zzUnpackTrans() { int [] result = new int[24681]; int offset = 0; offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); return result; } private static int zzUnpackTrans(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); value--; do result[j++] = value; while (--count > 0); } return j; } /* error codes */ private static final int ZZ_UNKNOWN_ERROR = 0; private static final int ZZ_NO_MATCH = 1; private static final int ZZ_PUSHBACK_2BIG = 2; /* error messages for the codes above */ private static final String ZZ_ERROR_MSG[] = { "Unkown internal scanner error", "Error: could not match input", "Error: pushback value was too large" }; /** * ZZ_ATTRIBUTE[aState] contains the attributes of state aState */ private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); private static final String ZZ_ATTRIBUTE_PACKED_0 = "\3\0\1\11\15\1\1\11\15\1\1\11\4\1\1\11"+ "\1\1\1\11\3\1\6\0\6\1\1\11\2\1\1\0"+ "\74\1\4\0\1\1\3\0\2\11\1\1\7\0\1\1"+ "\3\0\24\1\1\0\103\1\11\0\116\1\1\0\1\11"+ "\4\0\63\1\3\0\102\1\1\11\10\1"; private static int [] zzUnpackAttribute() { int [] result = new int[450]; int offset = 0; offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); return result; } private static int zzUnpackAttribute(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); do result[j++] = value; while (--count > 0); } return j; } /** the input device */ private java.io.Reader zzReader; /** the current state of the DFA */ private int zzState; /** the current lexical state */ private int zzLexicalState = YYINITIAL; /** this buffer contains the current text to be matched and is the source of the yytext() string */ private char zzBuffer[] = new char[ZZ_BUFFERSIZE]; /** the textposition at the last accepting state */ private int zzMarkedPos; /** the textposition at the last state to be included in yytext */ private int zzPushbackPos; /** the current text position in the buffer */ private int zzCurrentPos; /** startRead marks the beginning of the yytext() string in the buffer */ private int zzStartRead; /** endRead marks the last character in the buffer, that has been read from input */ private int zzEndRead; /** number of newlines encountered up to the start of the matched text */ private int yyline; /** the number of characters up to the start of the matched text */ private int yychar; /** * the number of characters from the last newline up to the start of the * matched text */ private int yycolumn; /** * zzAtBOL == true <=> the scanner is currently at the beginning of a line */ private boolean zzAtBOL = true; /** zzAtEOF == true <=> the scanner is at the EOF */ private boolean zzAtEOF; /* user code: */ /* styles */ public static final byte PLAIN_STYLE = 1; public static final byte KEYWORD_STYLE = 2; public static final byte TYPE_STYLE = 3; public static final byte OPERATOR_STYLE = 4; public static final byte SEPARATOR_STYLE = 5; public static final byte LITERAL_STYLE = 6; public static final byte CPP_COMMENT_STYLE = 7; public static final byte DOXYGEN_COMMENT_STYLE = 8; public static final byte DOXYGEN_TAG_STYLE = 9; public static final byte PREPROC_STYLE = 10; /* Highlighter implementation */ public int getStyleCount() { return 10; } public byte getStartState() { return YYINITIAL+1; } public byte getCurrentState() { return (byte) (yystate()+1); } public void setState(byte newState) { yybegin(newState-1); } public byte getNextToken() throws IOException { return (byte) yylex(); } public int getTokenLength() { return yylength(); } public void setReader(Reader r) { this.zzReader = r; } public CppHighlighter() { } /** * Creates a new scanner * There is also a java.io.InputStream version of this constructor. * * @param in the java.io.Reader to read input from. */ public CppHighlighter(java.io.Reader in) { this.zzReader = in; } /** * Creates a new scanner. * There is also java.io.Reader version of this constructor. * * @param in the java.io.Inputstream to read input from. */ public CppHighlighter(java.io.InputStream in) { this(new java.io.InputStreamReader(in)); } /** * Unpacks the compressed character translation table. * * @param packed the packed character translation table * @return the unpacked character translation table */ private static char [] zzUnpackCMap(String packed) { char [] map = new char[0x10000]; int i = 0; /* index in packed string */ int j = 0; /* index in unpacked array */ while (i < 1796) { int count = packed.charAt(i++); char value = packed.charAt(i++); do map[j++] = value; while (--count > 0); } return map; } /** * Refills the input buffer. * * @return false, iff there was new input. * * @exception java.io.IOException if any I/O-Error occurs */ private boolean zzRefill() throws java.io.IOException { /* first: make room (if you can) */ if (zzStartRead > 0) { System.arraycopy(zzBuffer, zzStartRead, zzBuffer, 0, zzEndRead-zzStartRead); /* translate stored positions */ zzEndRead-= zzStartRead; zzCurrentPos-= zzStartRead; zzMarkedPos-= zzStartRead; zzPushbackPos-= zzStartRead; zzStartRead = 0; } /* is the buffer big enough? */ if (zzCurrentPos >= zzBuffer.length) { /* if not: blow it up */ char newBuffer[] = new char[zzCurrentPos*2]; System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length); zzBuffer = newBuffer; } /* finally: fill the buffer with new input */ int numRead = zzReader.read(zzBuffer, zzEndRead, zzBuffer.length-zzEndRead); if (numRead < 0) { return true; } else { zzEndRead+= numRead; return false; } } /** * Closes the input stream. */ public final void yyclose() throws java.io.IOException { zzAtEOF = true; /* indicate end of file */ zzEndRead = zzStartRead; /* invalidate buffer */ if (zzReader != null) zzReader.close(); } /** * Resets the scanner to read from a new input stream. * Does not close the old reader. * * All internal variables are reset, the old input stream * cannot be reused (internal buffer is discarded and lost). * Lexical state is set to ZZ_INITIAL. * * @param reader the new input stream */ public final void yyreset(java.io.Reader reader) { zzReader = reader; zzAtBOL = true; zzAtEOF = false; zzEndRead = zzStartRead = 0; zzCurrentPos = zzMarkedPos = zzPushbackPos = 0; yyline = yychar = yycolumn = 0; zzLexicalState = YYINITIAL; } /** * Returns the current lexical state. */ public final int yystate() { return zzLexicalState; } /** * Enters a new lexical state * * @param newState the new lexical state */ public final void yybegin(int newState) { zzLexicalState = newState; } /** * Returns the text matched by the current regular expression. */ public final String yytext() { return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead ); } /** * Returns the character at position pos from the * matched text. * * It is equivalent to yytext().charAt(pos), but faster * * @param pos the position of the character to fetch. * A value from 0 to yylength()-1. * * @return the character at position pos */ public final char yycharat(int pos) { return zzBuffer[zzStartRead+pos]; } /** * Returns the length of the matched text region. */ public final int yylength() { return zzMarkedPos-zzStartRead; } /** * Reports an error that occured while scanning. * * In a wellformed scanner (no or only correct usage of * yypushback(int) and a match-all fallback rule) this method * will only be called with things that "Can't Possibly Happen". * If this method is called, something is seriously wrong * (e.g. a JFlex bug producing a faulty scanner etc.). * * Usual syntax/scanner level error handling should be done * in error fallback rules. * * @param errorCode the code of the errormessage to display */ private void zzScanError(int errorCode) { String message; try { message = ZZ_ERROR_MSG[errorCode]; } catch (ArrayIndexOutOfBoundsException e) { message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; } throw new Error(message); } /** * Pushes the specified amount of characters back into the input stream. * * They will be read again by then next call of the scanning method * * @param number the number of characters to be read again. * This number must not be greater than yylength()! */ public void yypushback(int number) { if ( number > yylength() ) zzScanError(ZZ_PUSHBACK_2BIG); zzMarkedPos -= number; } /** * Resumes scanning until the next regular expression is matched, * the end of input is encountered or an I/O-Error occurs. * * @return the next token * @exception java.io.IOException if any I/O-Error occurs */ public int yylex() throws java.io.IOException { int zzInput; int zzAction; // cached fields: int zzCurrentPosL; int zzMarkedPosL; int zzEndReadL = zzEndRead; char [] zzBufferL = zzBuffer; char [] zzCMapL = ZZ_CMAP; int [] zzTransL = ZZ_TRANS; int [] zzRowMapL = ZZ_ROWMAP; int [] zzAttrL = ZZ_ATTRIBUTE; while (true) { zzMarkedPosL = zzMarkedPos; zzAction = -1; zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; zzState = zzLexicalState; zzForAction: { while (true) { if (zzCurrentPosL < zzEndReadL) zzInput = zzBufferL[zzCurrentPosL++]; else if (zzAtEOF) { zzInput = YYEOF; break zzForAction; } else { // store back cached positions zzCurrentPos = zzCurrentPosL; zzMarkedPos = zzMarkedPosL; boolean eof = zzRefill(); // get translated positions and possibly new buffer zzCurrentPosL = zzCurrentPos; zzMarkedPosL = zzMarkedPos; zzBufferL = zzBuffer; zzEndReadL = zzEndRead; if (eof) { zzInput = YYEOF; break zzForAction; } else { zzInput = zzBufferL[zzCurrentPosL++]; } } int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ]; if (zzNext == -1) break zzForAction; zzState = zzNext; int zzAttributes = zzAttrL[zzState]; if ( (zzAttributes & 1) == 1 ) { zzAction = zzState; zzMarkedPosL = zzCurrentPosL; if ( (zzAttributes & 8) == 8 ) break zzForAction; } } } // store back cached position zzMarkedPos = zzMarkedPosL; switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { case 12: { return DOXYGEN_TAG_STYLE; } case 15: break; case 6: { return DOXYGEN_COMMENT_STYLE; } case 16: break; case 1: { return PLAIN_STYLE; } case 17: break; case 8: { return KEYWORD_STYLE; } case 18: break; case 14: { yybegin(IN_DOXYGEN_COMMENT); return DOXYGEN_COMMENT_STYLE; } case 19: break; case 4: { return OPERATOR_STYLE; } case 20: break; case 2: { return LITERAL_STYLE; } case 21: break; case 3: { return SEPARATOR_STYLE; } case 22: break; case 7: { return TYPE_STYLE; } case 23: break; case 5: { return CPP_COMMENT_STYLE; } case 24: break; case 11: { yybegin(YYINITIAL); return DOXYGEN_COMMENT_STYLE; } case 25: break; case 9: { yybegin(IN_COMMENT); return CPP_COMMENT_STYLE; } case 26: break; case 10: { yybegin(YYINITIAL); return CPP_COMMENT_STYLE; } case 27: break; case 13: { return PREPROC_STYLE; } case 28: break; default: if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { zzAtEOF = true; return YYEOF; } else { zzScanError(ZZ_NO_MATCH); } } } } } ExplicitStateHighlighter.java000066400000000000000000000025141422762524200351340ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/highlighter/* * Copyright 2000-2006 Omnicore Software, Hans Kratz & Dennis Strein GbR, * Geert Bevin . * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: ExplicitStateHighlighter.java 3108 2006-03-13 18:03:00Z gbevin $ */ package org.codelibs.jhighlight.highlighter; import java.io.IOException; import java.io.Reader; /** * Provides access to the lexical scanning of a highlighted language. * * @author Omnicore Software * @author Hans Kratz & Dennis Strein GbR * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @version $Revision: 3108 $ * @since 1.0 */ public interface ExplicitStateHighlighter { /** * Sets the reader that will be used to receive the text data. * * @param reader the Reader that has to be used */ void setReader(Reader reader); /** * Obtain the next token from the scanner. * * @return one of the tokens that are define in the scanner * @exception IOException when an error occurred during the parsing of * the reader */ byte getNextToken() throws IOException; /** * Returns the length of the matched text region. * * @return the length of the matched text region */ int getTokenLength(); } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/highlighter/GroovyHighlighter.flex000066400000000000000000000114741422762524200337400ustar00rootroot00000000000000/* * Copyright 2000-2006 Omnicore Software, Hans Kratz & Dennis Strein GbR, * Geert Bevin . * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id$ */ package org.codelibs.jhighlight.highlighter; import java.io.Reader; import java.io.IOException; %% %class GroovyHighlighter %implements ExplicitStateHighlighter %unicode %pack %buffer 128 %public %int %{ /* styles */ public static final byte PLAIN_STYLE = 1; public static final byte KEYWORD_STYLE = 2; public static final byte TYPE_STYLE = 3; public static final byte OPERATOR_STYLE = 4; public static final byte SEPARATOR_STYLE = 5; public static final byte LITERAL_STYLE = 6; public static final byte JAVA_COMMENT_STYLE = 7; public static final byte JAVADOC_COMMENT_STYLE = 8; public static final byte JAVADOC_TAG_STYLE = 9; /* Highlighter implementation */ public int getStyleCount() { return 9; } public byte getStartState() { return YYINITIAL+1; } public byte getCurrentState() { return (byte) (yystate()+1); } public void setState(byte newState) { yybegin(newState-1); } public byte getNextToken() throws IOException { return (byte) yylex(); } public int getTokenLength() { return yylength(); } public void setReader(Reader r) { this.zzReader = r; } public GroovyHighlighter() { } %} /* main character classes */ WhiteSpace = [ \t\f] /* identifiers */ ConstantIdentifier = {SimpleConstantIdentifier} SimpleConstantIdentifier = [A-Z0-9_]+ Identifier = [:jletter:][:jletterdigit:]* TypeIdentifier = {SimpleTypeIdentifier} SimpleTypeIdentifier = [A-Z][:jletterdigit:]* /* int literals */ DecLiteral = 0 | [1-9][0-9]* [lL]? HexLiteral = 0 [xX] 0* {HexDigit}* [lL]? HexDigit = [0-9a-fA-F] OctLiteral = 0+ {OctDigit}* [lL]? OctDigit = [0-7] /* float literals */ FloatLiteral = ({FLit1}|{FLit2}|{FLit3}|{FLit4}) ([fF]|[dD])? FLit1 = [0-9]+ \. [0-9]* {Exponent}? FLit2 = \. [0-9]+ {Exponent}? FLit3 = [0-9]+ {Exponent} FLit4 = [0-9]+ {Exponent}? Exponent = [eE] [+\-]? [0-9]+ %state IN_HEREDOC, IN_COMMENT, IN_JAVA_DOC_COMMENT %% { /* keywords */ "abstract" | "as" | "assert" | "break" | "case" | "catch" | "class" | "const" | "continue" | "def" | "do" | "else" | "extends" | "final" | "finally" | "for" | "default" | "implements" | "import" | "in" | "instanceof" | "interface" | "mixin" | "native" | "new" | "goto" | "if" | "public" | "super" | "switch" | "synchronized" | "package" | "private" | "protected" | "transient" | "return" | "static" | "while" | "this" | "throw" | "throws" | "try" | "volatile" | "strictfp" { return KEYWORD_STYLE; } "boolean" | "byte" | "char" | "double" | "int" | "long" | "float" | "short" | "void" { return TYPE_STYLE; } /* literals */ "true" | "false" | "null" | (\" ( [^\"\n\\] | \\[^\n] )* (\n | \\\n | \")) | (\' ( [^\'\n\\] | \\[^\n] )* (\n | \\\n | \')) | {DecLiteral} | {HexLiteral} | {OctLiteral} | {FloatLiteral} { return LITERAL_STYLE; } "\"\"\"" { yybegin(IN_HEREDOC); return LITERAL_STYLE;} /* separators */ "(" | ")" | "{" | "}" | "[" | "]" | ";" | "," | "." { return SEPARATOR_STYLE; } /* operators */ "=" | ">" | "<" | "!" | "~" | "?" | ":" | "+" | "-" | "*" | "/" | "&" | "|" | "^" | "%" { return OPERATOR_STYLE; } {ConstantIdentifier} { return PLAIN_STYLE; } {TypeIdentifier} { return TYPE_STYLE; } \n | {Identifier} | {WhiteSpace} { return PLAIN_STYLE; } // single line comment "//" [^\n]* \n | // short comment "/**/" { return JAVA_COMMENT_STYLE; } // comment start "/**" { yybegin(IN_JAVA_DOC_COMMENT); return JAVADOC_COMMENT_STYLE;} "/*" { yybegin(IN_COMMENT); return JAVA_COMMENT_STYLE;} } // normal comment mode { // comment unterminated .|\n { return LITERAL_STYLE; } // comment terminated \"\"\" { yybegin(YYINITIAL); return LITERAL_STYLE; } } // normal comment mode { // comment unterminated ([^\n*]|\*+[^\n*/])* (\n | \*+\n) { return JAVA_COMMENT_STYLE; } // comment terminated ([^\n*]|\*+[^\n*/])* \*+ "/" { yybegin(YYINITIAL); return JAVA_COMMENT_STYLE; } } // doc comment mode { // comment unterminated .|\n { return JAVADOC_COMMENT_STYLE; } // comment terminated \* "/" { yybegin(YYINITIAL); return JAVADOC_COMMENT_STYLE; } "@" {Identifier} { return JAVADOC_TAG_STYLE; } } /* error fallback */ .|\n { return PLAIN_STYLE; } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/highlighter/GroovyHighlighter.java000066400000000000000000001007521422762524200337210ustar00rootroot00000000000000/* The following code was generated by JFlex 1.4.1 on 8/2/06 6:03 AM */ /* * Copyright 2000-2006 Omnicore Software, Hans Kratz & Dennis Strein GbR, * Geert Bevin . * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: GroovyHighlighter.java 3431 2006-08-02 04:09:28Z gbevin $ */ package org.codelibs.jhighlight.highlighter; import java.io.IOException; import java.io.Reader; /** * This class is a scanner generated by * JFlex 1.4.1 * on 8/2/06 6:03 AM from the specification file * com/uwyn/jhighlight/highlighter/GroovyHighlighter.flex */ public class GroovyHighlighter implements ExplicitStateHighlighter { /** This character denotes the end of file */ public static final int YYEOF = -1; /** initial size of the lookahead buffer */ private static final int ZZ_BUFFERSIZE = 128; /** lexical states */ public static final int IN_HEREDOC = 1; public static final int YYINITIAL = 0; public static final int IN_COMMENT = 2; public static final int IN_JAVA_DOC_COMMENT = 3; /** * Translates characters to character classes */ private static final String ZZ_CMAP_PACKED = "\11\4\1\0\1\50\1\0\1\0\1\0\16\4\4\0\1\0\1\54"+ "\1\47\1\0\1\2\1\54\1\54\1\52\1\53\1\53\1\55\1\24"+ "\1\53\1\24\1\21\1\56\1\6\7\15\2\1\1\54\1\53\1\54"+ "\1\54\1\54\1\54\1\57\3\14\1\17\1\23\1\17\5\5\1\10"+ "\13\5\1\12\2\5\1\53\1\51\1\53\1\54\1\3\1\0\1\25"+ "\1\26\1\13\1\20\1\22\1\16\1\45\1\33\1\36\1\2\1\32"+ "\1\7\1\41\1\35\1\34\1\42\1\2\1\31\1\27\1\30\1\37"+ "\1\43\1\44\1\11\1\40\1\46\1\53\1\54\1\53\1\54\41\4"+ "\2\0\4\2\4\0\1\2\2\0\1\4\7\0\1\2\4\0\1\2"+ "\5\0\27\2\1\0\37\2\1\0\u013f\2\31\0\162\2\4\0\14\2"+ "\16\0\5\2\11\0\1\2\21\0\130\4\5\0\23\4\12\0\1\2"+ "\13\0\1\2\1\0\3\2\1\0\1\2\1\0\24\2\1\0\54\2"+ "\1\0\46\2\1\0\5\2\4\0\202\2\1\0\4\4\3\0\105\2"+ "\1\0\46\2\2\0\2\2\6\0\20\2\41\0\46\2\2\0\1\2"+ "\7\0\47\2\11\0\21\4\1\0\27\4\1\0\3\4\1\0\1\4"+ "\1\0\2\4\1\0\1\4\13\0\33\2\5\0\3\2\15\0\4\4"+ "\14\0\6\4\13\0\32\2\5\0\13\2\16\4\7\0\12\4\4\0"+ "\2\2\1\4\143\2\1\0\1\2\10\4\1\0\6\4\2\2\2\4"+ "\1\0\4\4\2\2\12\4\3\2\2\0\1\2\17\0\1\4\1\2"+ "\1\4\36\2\33\4\2\0\3\2\60\0\46\2\13\4\1\2\u014f\0"+ "\3\4\66\2\2\0\1\4\1\2\20\4\2\0\1\2\4\4\3\0"+ "\12\2\2\4\2\0\12\4\21\0\3\4\1\0\10\2\2\0\2\2"+ "\2\0\26\2\1\0\7\2\1\0\1\2\3\0\4\2\2\0\1\4"+ "\1\2\7\4\2\0\2\4\2\0\3\4\11\0\1\4\4\0\2\2"+ "\1\0\3\2\2\4\2\0\12\4\4\2\15\0\3\4\1\0\6\2"+ "\4\0\2\2\2\0\26\2\1\0\7\2\1\0\2\2\1\0\2\2"+ "\1\0\2\2\2\0\1\4\1\0\5\4\4\0\2\4\2\0\3\4"+ "\13\0\4\2\1\0\1\2\7\0\14\4\3\2\14\0\3\4\1\0"+ "\11\2\1\0\3\2\1\0\26\2\1\0\7\2\1\0\2\2\1\0"+ "\5\2\2\0\1\4\1\2\10\4\1\0\3\4\1\0\3\4\2\0"+ "\1\2\17\0\2\2\2\4\2\0\12\4\1\0\1\2\17\0\3\4"+ "\1\0\10\2\2\0\2\2\2\0\26\2\1\0\7\2\1\0\2\2"+ "\1\0\5\2\2\0\1\4\1\2\6\4\3\0\2\4\2\0\3\4"+ "\10\0\2\4\4\0\2\2\1\0\3\2\4\0\12\4\1\0\1\2"+ "\20\0\1\4\1\2\1\0\6\2\3\0\3\2\1\0\4\2\3\0"+ "\2\2\1\0\1\2\1\0\2\2\3\0\2\2\3\0\3\2\3\0"+ "\10\2\1\0\3\2\4\0\5\4\3\0\3\4\1\0\4\4\11\0"+ "\1\4\17\0\11\4\11\0\1\2\7\0\3\4\1\0\10\2\1\0"+ "\3\2\1\0\27\2\1\0\12\2\1\0\5\2\4\0\7\4\1\0"+ "\3\4\1\0\4\4\7\0\2\4\11\0\2\2\4\0\12\4\22\0"+ "\2\4\1\0\10\2\1\0\3\2\1\0\27\2\1\0\12\2\1\0"+ "\5\2\2\0\1\4\1\2\7\4\1\0\3\4\1\0\4\4\7\0"+ "\2\4\7\0\1\2\1\0\2\2\4\0\12\4\22\0\2\4\1\0"+ "\10\2\1\0\3\2\1\0\27\2\1\0\20\2\4\0\6\4\2\0"+ "\3\4\1\0\4\4\11\0\1\4\10\0\2\2\4\0\12\4\22\0"+ "\2\4\1\0\22\2\3\0\30\2\1\0\11\2\1\0\1\2\2\0"+ "\7\2\3\0\1\4\4\0\6\4\1\0\1\4\1\0\10\4\22\0"+ "\2\4\15\0\60\2\1\4\2\2\7\4\4\0\10\2\10\4\1\0"+ "\12\4\47\0\2\2\1\0\1\2\2\0\2\2\1\0\1\2\2\0"+ "\1\2\6\0\4\2\1\0\7\2\1\0\3\2\1\0\1\2\1\0"+ "\1\2\2\0\2\2\1\0\4\2\1\4\2\2\6\4\1\0\2\4"+ "\1\2\2\0\5\2\1\0\1\2\1\0\6\4\2\0\12\4\2\0"+ "\2\2\42\0\1\2\27\0\2\4\6\0\12\4\13\0\1\4\1\0"+ "\1\4\1\0\1\4\4\0\2\4\10\2\1\0\42\2\6\0\24\4"+ "\1\0\2\4\4\2\4\0\10\4\1\0\44\4\11\0\1\4\71\0"+ "\42\2\1\0\5\2\1\0\2\2\1\0\7\4\3\0\4\4\6\0"+ "\12\4\6\0\6\2\4\4\106\0\46\2\12\0\51\2\7\0\132\2"+ "\5\0\104\2\5\0\122\2\6\0\7\2\1\0\77\2\1\0\1\2"+ "\1\0\4\2\2\0\7\2\1\0\1\2\1\0\4\2\2\0\47\2"+ "\1\0\1\2\1\0\4\2\2\0\37\2\1\0\1\2\1\0\4\2"+ "\2\0\7\2\1\0\1\2\1\0\4\2\2\0\7\2\1\0\7\2"+ "\1\0\27\2\1\0\37\2\1\0\1\2\1\0\4\2\2\0\7\2"+ "\1\0\47\2\1\0\23\2\16\0\11\4\56\0\125\2\14\0\u026c\2"+ "\2\0\10\2\12\0\32\2\5\0\113\2\3\0\3\2\17\0\15\2"+ "\1\0\4\2\3\4\13\0\22\2\3\4\13\0\22\2\2\4\14\0"+ "\15\2\1\0\3\2\1\0\2\4\14\0\64\2\40\4\3\0\1\2"+ "\3\0\2\2\1\4\2\0\12\4\41\0\3\4\2\0\12\4\6\0"+ "\130\2\10\0\51\2\1\4\126\0\35\2\3\0\14\4\4\0\14\4"+ "\12\0\12\4\36\2\2\0\5\2\u038b\0\154\2\224\0\234\2\4\0"+ "\132\2\6\0\26\2\2\0\6\2\2\0\46\2\2\0\6\2\2\0"+ "\10\2\1\0\1\2\1\0\1\2\1\0\1\2\1\0\37\2\2\0"+ "\65\2\1\0\7\2\1\0\1\2\3\0\3\2\1\0\7\2\3\0"+ "\4\2\2\0\6\2\4\0\15\2\5\0\3\2\1\0\7\2\17\0"+ "\4\4\32\0\5\4\20\0\2\2\23\0\1\2\13\0\4\4\6\0"+ "\6\4\1\0\1\2\15\0\1\2\40\0\22\2\36\0\15\4\4\0"+ "\1\4\3\0\6\4\27\0\1\2\4\0\1\2\2\0\12\2\1\0"+ "\1\2\3\0\5\2\6\0\1\2\1\0\1\2\1\0\1\2\1\0"+ "\4\2\1\0\3\2\1\0\7\2\3\0\3\2\5\0\5\2\26\0"+ "\44\2\u0e81\0\3\2\31\0\11\2\6\4\1\0\5\2\2\0\5\2"+ "\4\0\126\2\2\0\2\4\2\0\3\2\1\0\137\2\5\0\50\2"+ "\4\0\136\2\21\0\30\2\70\0\20\2\u0200\0\u19b6\2\112\0\u51a6\2"+ "\132\0\u048d\2\u0773\0\u2ba4\2\u215c\0\u012e\2\2\0\73\2\225\0\7\2"+ "\14\0\5\2\5\0\1\2\1\4\12\2\1\0\15\2\1\0\5\2"+ "\1\0\1\2\1\0\2\2\1\0\2\2\1\0\154\2\41\0\u016b\2"+ "\22\0\100\2\2\0\66\2\50\0\15\2\3\0\20\4\20\0\4\4"+ "\17\0\2\2\30\0\3\2\31\0\1\2\6\0\5\2\1\0\207\2"+ "\2\0\1\4\4\0\1\2\13\0\12\4\7\0\32\2\4\0\1\2"+ "\1\0\32\2\12\0\132\2\3\0\6\2\2\0\6\2\2\0\6\2"+ "\2\0\3\2\3\0\2\2\3\0\2\2\22\0\3\4\4\0"; /** * Translates characters to character classes */ private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); /** * Translates DFA states to action switch labels. */ private static final int [] ZZ_ACTION = zzUnpackAction(); private static final String ZZ_ACTION_PACKED_0 = "\4\0\1\1\1\2\2\1\1\2\4\1\1\3\1\1"+ "\1\4\16\1\1\3\1\4\2\2\1\1\1\5\1\1"+ "\3\6\1\1\2\2\1\0\1\1\1\7\4\2\12\1"+ "\1\10\3\1\1\10\16\1\2\10\10\1\1\0\1\2"+ "\3\0\1\11\4\0\1\12\1\13\1\14\1\2\1\0"+ "\1\2\11\1\1\10\25\1\1\7\12\1\1\15\1\16"+ "\1\17\1\7\20\1\1\2\14\1\1\10\10\1\1\10"+ "\36\1"; private static int [] zzUnpackAction() { int [] result = new int[220]; int offset = 0; offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); return result; } private static int zzUnpackAction(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); do result[j++] = value; while (--count > 0); } return j; } /** * Translates a state to a row index in the transition table */ private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); private static final String ZZ_ROWMAP_PACKED_0 = "\0\0\0\60\0\140\0\220\0\300\0\360\0\u0120\0\u0150"+ "\0\u0180\0\u01b0\0\u01e0\0\u0210\0\u0240\0\u0270\0\u02a0\0\300"+ "\0\u02d0\0\u0300\0\u0330\0\u0360\0\u0390\0\u03c0\0\u03f0\0\u0420"+ "\0\u0450\0\u0480\0\u04b0\0\u04e0\0\u0510\0\u0540\0\300\0\u0570"+ "\0\300\0\u05a0\0\u05d0\0\300\0\u0600\0\300\0\u0630\0\u0660"+ "\0\u0690\0\u0690\0\u06c0\0\u06f0\0\u0720\0\u0750\0\u0780\0\u07b0"+ "\0\u07e0\0\u0810\0\u0840\0\u0870\0\u08a0\0\u08d0\0\u0900\0\u0930"+ "\0\u0960\0\u0990\0\u09c0\0\u09f0\0\u0a20\0\u0a50\0\u0a80\0\u0ab0"+ "\0\u0ae0\0\u0b10\0\u0b40\0\u0b70\0\u0ba0\0\u0bd0\0\u0c00\0\u0c30"+ "\0\u0c60\0\u0c90\0\u0cc0\0\u0cf0\0\u0d20\0\u0d50\0\u0d80\0\u0120"+ "\0\u0db0\0\u0de0\0\u0e10\0\u0e40\0\u0e70\0\u0ea0\0\u0ed0\0\u0f00"+ "\0\u0f30\0\u0f60\0\u0f90\0\u0fc0\0\u0540\0\u0ff0\0\u1020\0\u1050"+ "\0\u1080\0\u05d0\0\u0600\0\300\0\300\0\u10b0\0\u10e0\0\u1110"+ "\0\u1140\0\u1170\0\u11a0\0\u11d0\0\u1200\0\u1230\0\u1260\0\u1290"+ "\0\u12c0\0\u12f0\0\u1320\0\u1350\0\u1380\0\u13b0\0\u13e0\0\u1410"+ "\0\u1440\0\u1470\0\u14a0\0\u14d0\0\u1500\0\u1530\0\u1560\0\u1590"+ "\0\u15c0\0\u15f0\0\u1620\0\u1650\0\u1680\0\u16b0\0\u16e0\0\u1710"+ "\0\u1740\0\u1770\0\u17a0\0\u17d0\0\u1800\0\u1830\0\u1860\0\u1890"+ "\0\u18c0\0\u18f0\0\u1920\0\300\0\u1950\0\300\0\u0120\0\u1980"+ "\0\u19b0\0\u19e0\0\u1a10\0\u1a40\0\u1a70\0\u1aa0\0\u1ad0\0\u1b00"+ "\0\u1b30\0\u1b60\0\u1b90\0\u1bc0\0\u1bf0\0\u1c20\0\u1c50\0\u0120"+ "\0\u1c80\0\u1cb0\0\u1ce0\0\u1d10\0\u1d40\0\u1d70\0\u1da0\0\u1dd0"+ "\0\u1e00\0\u1e30\0\u1e60\0\u1e90\0\u1ec0\0\u1ef0\0\u1f20\0\u1f50"+ "\0\u1f80\0\u1fb0\0\u1fe0\0\u2010\0\u2040\0\u1650\0\u2070\0\u20a0"+ "\0\u20d0\0\u2100\0\u2130\0\u2160\0\u2190\0\u21c0\0\u21f0\0\u2220"+ "\0\u2250\0\u2280\0\u22b0\0\u22e0\0\u2310\0\u2340\0\u2370\0\u23a0"+ "\0\u23d0\0\u2400\0\u2430\0\u2460\0\u2490\0\u24c0\0\u24f0\0\u2520"+ "\0\u2550\0\u2580\0\u25b0\0\u25e0"; private static int [] zzUnpackRowMap() { int [] result = new int[220]; int offset = 0; offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); return result; } private static int zzUnpackRowMap(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int high = packed.charAt(i++) << 16; result[j++] = high | packed.charAt(i++); } return j; } /** * The transition table of the DFA */ private static final int [] ZZ_TRANS = zzUnpackTrans(); private static final String ZZ_TRANS_PACKED_0 = "\1\5\1\6\2\7\1\5\1\10\1\11\1\12\1\10"+ "\1\7\1\10\1\13\1\10\1\6\1\14\1\10\1\15"+ "\1\16\1\17\1\10\1\20\1\21\1\22\1\23\1\24"+ "\1\25\3\7\1\26\1\27\2\7\1\30\1\31\1\32"+ "\1\33\1\34\1\7\1\35\2\5\1\36\1\37\2\20"+ "\1\40\1\5\47\41\1\42\10\41\50\43\1\44\4\43"+ "\1\45\2\43\55\46\1\47\1\46\1\50\61\0\1\6"+ "\1\0\1\51\1\0\1\51\1\6\1\41\1\52\1\0"+ "\1\51\1\0\1\51\1\6\1\41\1\52\1\41\1\53"+ "\1\54\1\55\35\0\20\7\1\0\2\7\1\0\22\7"+ "\12\0\1\10\1\56\1\10\1\56\2\10\1\56\1\10"+ "\1\56\1\10\1\56\2\10\1\56\1\10\1\56\1\0"+ "\1\56\1\10\1\0\22\56\12\0\1\57\1\0\1\51"+ "\1\0\1\51\1\60\1\41\1\52\1\61\1\62\1\0"+ "\1\51\1\60\1\41\1\52\1\41\1\53\1\54\1\55"+ "\35\0\20\7\1\0\2\7\1\0\7\7\1\63\12\7"+ "\12\0\6\7\1\64\11\7\1\0\2\7\1\0\1\65"+ "\5\7\1\66\1\67\12\7\12\0\6\7\1\70\11\7"+ "\1\0\2\7\1\0\1\71\6\7\1\72\1\7\1\73"+ "\10\7\12\0\20\7\1\0\1\74\1\7\1\0\7\7"+ "\1\75\12\7\12\0\1\53\4\0\1\53\6\0\1\53"+ "\43\0\6\7\1\76\1\7\1\77\7\7\1\0\2\7"+ "\1\0\22\7\12\0\20\7\1\0\2\7\1\0\1\7"+ "\1\100\1\101\17\7\12\0\20\7\1\0\2\7\1\0"+ "\4\7\1\102\2\7\1\103\3\7\1\104\6\7\12\0"+ "\20\7\1\0\2\7\1\0\3\7\1\105\2\7\1\106"+ "\3\7\1\107\1\110\3\7\1\111\2\7\12\0\20\7"+ "\1\0\2\7\1\0\4\7\1\112\1\7\1\113\13\7"+ "\12\0\20\7\1\0\1\114\1\7\1\0\22\7\12\0"+ "\20\7\1\0\1\115\1\7\1\0\1\116\11\7\1\117"+ "\7\7\12\0\15\7\1\120\2\7\1\0\2\7\1\0"+ "\10\7\1\121\3\7\1\122\5\7\12\0\20\7\1\0"+ "\2\7\1\0\11\7\1\123\10\7\12\0\20\7\1\0"+ "\2\7\1\0\1\124\3\7\1\125\5\7\1\126\7\7"+ "\12\0\20\7\1\0\2\7\1\0\7\7\1\127\12\7"+ "\12\0\20\7\1\0\2\7\1\0\6\7\1\130\13\7"+ "\12\0\20\7\1\0\2\7\1\0\7\7\1\131\12\7"+ "\11\0\47\132\1\133\1\41\1\134\6\132\50\135\1\41"+ "\1\136\1\41\5\135\55\0\1\137\1\140\50\0\1\141"+ "\10\0\50\142\1\44\4\142\1\143\52\142\1\44\4\142"+ "\1\143\1\144\1\142\56\0\1\145\3\0\2\146\1\0"+ "\1\146\1\0\6\146\1\0\3\146\1\0\2\146\1\0"+ "\22\146\12\0\1\51\1\0\1\51\1\0\2\51\1\0"+ "\1\51\1\0\1\51\1\0\2\51\1\0\1\51\3\0"+ "\1\51\35\0\1\53\4\0\1\53\6\0\1\53\3\41"+ "\1\0\2\54\35\0\1\147\4\0\1\147\6\0\1\147"+ "\6\0\1\150\34\0\1\151\1\0\1\51\1\0\1\51"+ "\1\151\1\0\1\51\1\0\1\51\1\0\1\51\1\151"+ "\1\0\1\51\3\0\1\51\1\150\34\0\20\56\1\0"+ "\2\56\1\0\22\56\12\0\1\57\1\0\1\51\1\0"+ "\1\51\1\57\1\0\1\51\1\0\1\51\1\0\1\51"+ "\1\57\1\41\1\52\1\41\1\53\1\54\1\55\35\0"+ "\1\57\1\0\1\51\1\0\1\51\1\60\1\41\1\52"+ "\1\0\1\51\1\0\1\51\1\60\1\41\1\52\1\41"+ "\1\53\1\54\1\55\35\0\1\61\4\0\1\61\2\41"+ "\2\0\6\61\1\0\2\61\1\0\2\61\32\0\1\62"+ "\1\0\1\51\1\0\1\51\1\62\1\41\1\52\1\0"+ "\1\51\1\61\2\62\1\61\1\62\1\61\1\0\1\61"+ "\1\62\1\0\2\61\32\0\20\7\1\0\2\7\1\0"+ "\10\7\1\152\11\7\12\0\20\7\1\0\2\7\1\0"+ "\1\153\21\7\12\0\20\7\1\0\2\7\1\0\2\7"+ "\1\154\1\155\16\7\12\0\20\7\1\0\2\7\1\0"+ "\1\156\21\7\12\0\20\7\1\0\2\7\1\0\10\7"+ "\1\157\11\7\12\0\20\7\1\0\2\7\1\0\7\7"+ "\1\160\12\7\12\0\6\7\1\161\11\7\1\0\2\7"+ "\1\0\22\7\12\0\20\7\1\0\2\7\1\0\4\7"+ "\1\120\15\7\12\0\20\7\1\0\2\7\1\0\10\7"+ "\1\162\11\7\12\0\15\7\1\163\2\7\1\0\2\7"+ "\1\0\22\7\12\0\20\7\1\0\2\7\1\0\12\7"+ "\1\164\7\7\12\0\20\7\1\0\2\7\1\0\2\7"+ "\1\154\17\7\12\0\20\7\1\0\2\7\1\0\3\7"+ "\1\165\16\7\12\0\20\7\1\0\2\7\1\0\2\7"+ "\1\166\17\7\12\0\20\7\1\0\2\7\1\0\2\7"+ "\1\167\17\7\12\0\20\7\1\0\1\170\1\7\1\0"+ "\22\7\12\0\20\7\1\0\2\7\1\0\7\7\1\171"+ "\12\7\12\0\20\7\1\0\2\7\1\0\3\7\1\172"+ "\16\7\12\0\20\7\1\0\2\7\1\0\1\173\3\7"+ "\1\174\15\7\12\0\20\7\1\0\2\7\1\0\7\7"+ "\1\175\12\7\12\0\20\7\1\0\2\7\1\0\15\7"+ "\1\176\4\7\12\0\20\7\1\0\2\7\1\0\10\7"+ "\1\177\11\7\12\0\20\7\1\0\2\7\1\0\11\7"+ "\1\200\10\7\12\0\20\7\1\0\2\7\1\0\1\201"+ "\11\7\1\202\1\120\6\7\12\0\20\7\1\0\2\7"+ "\1\0\4\7\1\203\4\7\1\204\10\7\12\0\20\7"+ "\1\0\2\7\1\0\3\7\1\205\16\7\12\0\20\7"+ "\1\0\2\7\1\0\17\7\1\120\2\7\12\0\20\7"+ "\1\0\2\7\1\0\3\7\1\206\16\7\12\0\6\7"+ "\1\207\11\7\1\0\2\7\1\0\22\7\12\0\20\7"+ "\1\0\2\7\1\0\2\7\1\210\1\211\16\7\12\0"+ "\20\7\1\0\2\7\1\0\15\7\1\212\4\7\12\0"+ "\10\7\1\213\7\7\1\0\2\7\1\0\22\7\12\0"+ "\12\7\1\214\5\7\1\0\2\7\1\0\22\7\12\0"+ "\20\7\1\0\2\7\1\0\7\7\1\215\1\7\1\216"+ "\10\7\12\0\20\7\1\0\2\7\1\0\1\7\1\217"+ "\20\7\12\0\6\7\1\220\11\7\1\0\2\7\1\0"+ "\11\7\1\221\10\7\12\0\20\7\1\0\2\7\1\0"+ "\11\7\1\222\10\7\12\0\20\7\1\0\2\7\1\0"+ "\3\7\1\223\16\7\11\0\47\132\2\41\1\134\6\132"+ "\47\0\1\224\10\0\50\132\1\41\7\132\50\135\1\41"+ "\7\135\55\0\1\225\2\0\50\140\1\44\7\140\47\0"+ "\1\226\11\0\20\146\1\0\2\146\1\0\22\146\12\0"+ "\1\147\4\0\1\147\6\0\1\147\3\41\40\0\1\147"+ "\4\0\1\147\6\0\1\147\43\0\1\151\1\0\1\51"+ "\1\0\1\51\1\151\1\0\1\51\1\0\1\51\1\0"+ "\1\51\1\151\1\41\1\52\1\41\2\0\1\51\35\0"+ "\20\7\1\0\2\7\1\0\20\7\1\227\1\7\12\0"+ "\20\7\1\0\2\7\1\0\2\7\1\204\17\7\12\0"+ "\20\7\1\0\1\120\1\7\1\0\22\7\12\0\12\7"+ "\1\230\5\7\1\0\2\7\1\0\22\7\12\0\20\7"+ "\1\0\2\7\1\0\4\7\1\227\15\7\12\0\20\7"+ "\1\0\2\7\1\0\2\7\1\231\1\232\16\7\12\0"+ "\20\7\1\0\2\7\1\0\1\233\21\7\12\0\20\7"+ "\1\0\2\7\1\0\2\7\1\202\17\7\12\0\20\7"+ "\1\0\2\7\1\0\1\234\21\7\12\0\20\7\1\0"+ "\2\7\1\0\1\235\21\7\12\0\20\7\1\0\2\7"+ "\1\0\1\7\1\236\20\7\12\0\20\7\1\0\1\237"+ "\1\7\1\0\22\7\12\0\20\7\1\0\2\7\1\0"+ "\3\7\1\240\16\7\12\0\20\7\1\0\1\241\1\7"+ "\1\0\22\7\12\0\20\7\1\0\2\7\1\0\1\242"+ "\21\7\12\0\6\7\1\243\11\7\1\0\2\7\1\0"+ "\22\7\12\0\20\7\1\0\1\227\1\7\1\0\22\7"+ "\12\0\20\7\1\0\2\7\1\0\3\7\1\244\16\7"+ "\12\0\20\7\1\0\2\7\1\0\11\7\1\245\10\7"+ "\12\0\20\7\1\0\2\7\1\0\4\7\1\233\15\7"+ "\12\0\20\7\1\0\1\72\1\7\1\0\22\7\12\0"+ "\12\7\1\246\5\7\1\0\2\7\1\0\22\7\12\0"+ "\20\7\1\0\2\7\1\0\3\7\1\155\16\7\12\0"+ "\20\7\1\0\2\7\1\0\10\7\1\247\11\7\12\0"+ "\20\7\1\0\1\250\1\7\1\0\22\7\12\0\20\7"+ "\1\0\2\7\1\0\7\7\1\251\12\7\12\0\20\7"+ "\1\0\2\7\1\0\2\7\1\120\17\7\12\0\20\7"+ "\1\0\2\7\1\0\12\7\1\252\7\7\12\0\20\7"+ "\1\0\2\7\1\0\11\7\1\253\10\7\12\0\6\7"+ "\1\250\11\7\1\0\2\7\1\0\22\7\12\0\20\7"+ "\1\0\2\7\1\0\3\7\1\254\16\7\12\0\20\7"+ "\1\0\1\255\1\7\1\0\22\7\12\0\6\7\1\256"+ "\11\7\1\0\2\7\1\0\7\7\1\241\12\7\12\0"+ "\20\7\1\0\2\7\1\0\11\7\1\257\10\7\12\0"+ "\20\7\1\0\2\7\1\0\5\7\1\260\14\7\12\0"+ "\20\7\1\0\2\7\1\0\3\7\1\261\16\7\12\0"+ "\20\7\1\0\2\7\1\0\16\7\1\262\3\7\12\0"+ "\6\7\1\244\11\7\1\0\2\7\1\0\22\7\12\0"+ "\20\7\1\0\2\7\1\0\1\263\21\7\12\0\17\7"+ "\1\227\1\0\2\7\1\0\22\7\12\0\6\7\1\154"+ "\11\7\1\0\2\7\1\0\22\7\12\0\20\7\1\0"+ "\2\7\1\0\7\7\1\120\12\7\67\0\1\44\2\0"+ "\20\7\1\0\2\7\1\0\6\7\1\120\13\7\12\0"+ "\20\7\1\0\2\7\1\0\3\7\1\120\16\7\12\0"+ "\20\7\1\0\2\7\1\0\11\7\1\264\10\7\12\0"+ "\20\7\1\0\2\7\1\0\3\7\1\227\16\7\12\0"+ "\6\7\1\265\11\7\1\0\2\7\1\0\22\7\12\0"+ "\20\7\1\0\2\7\1\0\12\7\1\266\7\7\12\0"+ "\6\7\1\172\11\7\1\0\2\7\1\0\22\7\12\0"+ "\20\7\1\0\2\7\1\0\10\7\1\267\11\7\12\0"+ "\20\7\1\0\2\7\1\0\4\7\1\270\15\7\12\0"+ "\20\7\1\0\2\7\1\0\4\7\1\231\15\7\12\0"+ "\20\7\1\0\2\7\1\0\5\7\1\120\14\7\12\0"+ "\20\7\1\0\1\271\1\7\1\0\22\7\12\0\20\7"+ "\1\0\2\7\1\0\11\7\1\272\10\7\12\0\12\7"+ "\1\273\5\7\1\0\2\7\1\0\22\7\12\0\20\7"+ "\1\0\2\7\1\0\6\7\1\274\13\7\12\0\20\7"+ "\1\0\2\7\1\0\2\7\1\275\17\7\12\0\20\7"+ "\1\0\2\7\1\0\17\7\1\276\2\7\12\0\20\7"+ "\1\0\2\7\1\0\4\7\1\257\15\7\12\0\20\7"+ "\1\0\2\7\1\0\16\7\1\154\3\7\12\0\20\7"+ "\1\0\2\7\1\0\1\277\21\7\12\0\20\7\1\0"+ "\2\7\1\0\4\7\1\300\15\7\12\0\20\7\1\0"+ "\1\301\1\7\1\0\22\7\12\0\20\7\1\0\2\7"+ "\1\0\10\7\1\120\11\7\12\0\20\7\1\0\2\7"+ "\1\0\1\302\21\7\12\0\20\7\1\0\1\303\1\7"+ "\1\0\22\7\12\0\20\7\1\0\2\7\1\0\1\304"+ "\21\7\12\0\20\7\1\0\2\7\1\0\3\7\1\130"+ "\16\7\12\0\20\7\1\0\2\7\1\0\10\7\1\305"+ "\11\7\12\0\6\7\1\306\11\7\1\0\2\7\1\0"+ "\22\7\12\0\6\7\1\231\11\7\1\0\2\7\1\0"+ "\22\7\12\0\17\7\1\204\1\0\2\7\1\0\22\7"+ "\12\0\20\7\1\0\2\7\1\0\1\307\21\7\12\0"+ "\20\7\1\0\2\7\1\0\1\310\21\7\12\0\12\7"+ "\1\120\5\7\1\0\2\7\1\0\22\7\12\0\20\7"+ "\1\0\2\7\1\0\3\7\1\311\16\7\12\0\20\7"+ "\1\0\2\7\1\0\4\7\1\312\15\7\12\0\20\7"+ "\1\0\2\7\1\0\11\7\1\313\10\7\12\0\20\7"+ "\1\0\2\7\1\0\10\7\1\314\11\7\12\0\15\7"+ "\1\315\2\7\1\0\2\7\1\0\22\7\12\0\20\7"+ "\1\0\2\7\1\0\14\7\1\316\5\7\12\0\20\7"+ "\1\0\2\7\1\0\20\7\1\154\1\7\12\0\12\7"+ "\1\317\5\7\1\0\2\7\1\0\22\7\12\0\20\7"+ "\1\0\2\7\1\0\3\7\1\154\16\7\12\0\20\7"+ "\1\0\2\7\1\0\12\7\1\154\7\7\12\0\20\7"+ "\1\0\2\7\1\0\13\7\1\120\6\7\12\0\12\7"+ "\1\231\5\7\1\0\2\7\1\0\22\7\12\0\20\7"+ "\1\0\2\7\1\0\10\7\1\227\11\7\12\0\15\7"+ "\1\320\2\7\1\0\2\7\1\0\22\7\12\0\20\7"+ "\1\0\2\7\1\0\7\7\1\321\12\7\12\0\20\7"+ "\1\0\1\322\1\7\1\0\22\7\12\0\12\7\1\323"+ "\5\7\1\0\2\7\1\0\22\7\12\0\20\7\1\0"+ "\2\7\1\0\1\324\21\7\12\0\20\7\1\0\1\325"+ "\1\7\1\0\22\7\12\0\20\7\1\0\2\7\1\0"+ "\3\7\1\326\16\7\12\0\20\7\1\0\2\7\1\0"+ "\15\7\1\120\4\7\12\0\20\7\1\0\2\7\1\0"+ "\10\7\1\327\11\7\12\0\20\7\1\0\2\7\1\0"+ "\10\7\1\231\11\7\12\0\20\7\1\0\1\330\1\7"+ "\1\0\22\7\12\0\12\7\1\154\5\7\1\0\2\7"+ "\1\0\22\7\12\0\20\7\1\0\2\7\1\0\10\7"+ "\1\331\11\7\12\0\20\7\1\0\1\332\1\7\1\0"+ "\22\7\12\0\20\7\1\0\2\7\1\0\11\7\1\333"+ "\10\7\12\0\20\7\1\0\2\7\1\0\7\7\1\334"+ "\12\7\12\0\20\7\1\0\2\7\1\0\3\7\1\204"+ "\16\7\12\0\17\7\1\120\1\0\2\7\1\0\22\7"+ "\12\0\20\7\1\0\2\7\1\0\21\7\1\326\12\0"+ "\15\7\1\120\2\7\1\0\2\7\1\0\22\7\11\0"; private static int [] zzUnpackTrans() { int [] result = new int[9744]; int offset = 0; offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); return result; } private static int zzUnpackTrans(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); value--; do result[j++] = value; while (--count > 0); } return j; } /* error codes */ private static final int ZZ_UNKNOWN_ERROR = 0; private static final int ZZ_NO_MATCH = 1; private static final int ZZ_PUSHBACK_2BIG = 2; /* error messages for the codes above */ private static final String ZZ_ERROR_MSG[] = { "Unkown internal scanner error", "Error: could not match input", "Error: pushback value was too large" }; /** * ZZ_ATTRIBUTE[aState] contains the attributes of state aState */ private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); private static final String ZZ_ATTRIBUTE_PACKED_0 = "\4\0\1\11\12\1\1\11\16\1\1\11\1\1\1\11"+ "\2\1\1\11\1\1\1\11\5\1\1\0\55\1\1\0"+ "\1\1\3\0\1\1\4\0\2\11\2\1\1\0\53\1"+ "\1\11\1\1\1\11\106\1"; private static int [] zzUnpackAttribute() { int [] result = new int[220]; int offset = 0; offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); return result; } private static int zzUnpackAttribute(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); do result[j++] = value; while (--count > 0); } return j; } /** the input device */ private java.io.Reader zzReader; /** the current state of the DFA */ private int zzState; /** the current lexical state */ private int zzLexicalState = YYINITIAL; /** this buffer contains the current text to be matched and is the source of the yytext() string */ private char zzBuffer[] = new char[ZZ_BUFFERSIZE]; /** the textposition at the last accepting state */ private int zzMarkedPos; /** the textposition at the last state to be included in yytext */ private int zzPushbackPos; /** the current text position in the buffer */ private int zzCurrentPos; /** startRead marks the beginning of the yytext() string in the buffer */ private int zzStartRead; /** endRead marks the last character in the buffer, that has been read from input */ private int zzEndRead; /** number of newlines encountered up to the start of the matched text */ private int yyline; /** the number of characters up to the start of the matched text */ private int yychar; /** * the number of characters from the last newline up to the start of the * matched text */ private int yycolumn; /** * zzAtBOL == true <=> the scanner is currently at the beginning of a line */ private boolean zzAtBOL = true; /** zzAtEOF == true <=> the scanner is at the EOF */ private boolean zzAtEOF; /* user code: */ /* styles */ public static final byte PLAIN_STYLE = 1; public static final byte KEYWORD_STYLE = 2; public static final byte TYPE_STYLE = 3; public static final byte OPERATOR_STYLE = 4; public static final byte SEPARATOR_STYLE = 5; public static final byte LITERAL_STYLE = 6; public static final byte JAVA_COMMENT_STYLE = 7; public static final byte JAVADOC_COMMENT_STYLE = 8; public static final byte JAVADOC_TAG_STYLE = 9; /* Highlighter implementation */ public int getStyleCount() { return 9; } public byte getStartState() { return YYINITIAL+1; } public byte getCurrentState() { return (byte) (yystate()+1); } public void setState(byte newState) { yybegin(newState-1); } public byte getNextToken() throws IOException { return (byte) yylex(); } public int getTokenLength() { return yylength(); } public void setReader(Reader r) { this.zzReader = r; } public GroovyHighlighter() { } /** * Creates a new scanner * There is also a java.io.InputStream version of this constructor. * * @param in the java.io.Reader to read input from. */ public GroovyHighlighter(java.io.Reader in) { this.zzReader = in; } /** * Creates a new scanner. * There is also java.io.Reader version of this constructor. * * @param in the java.io.Inputstream to read input from. */ public GroovyHighlighter(java.io.InputStream in) { this(new java.io.InputStreamReader(in)); } /** * Unpacks the compressed character translation table. * * @param packed the packed character translation table * @return the unpacked character translation table */ private static char [] zzUnpackCMap(String packed) { char [] map = new char[0x10000]; int i = 0; /* index in packed string */ int j = 0; /* index in unpacked array */ while (i < 1778) { int count = packed.charAt(i++); char value = packed.charAt(i++); do map[j++] = value; while (--count > 0); } return map; } /** * Refills the input buffer. * * @return false, iff there was new input. * * @exception java.io.IOException if any I/O-Error occurs */ private boolean zzRefill() throws java.io.IOException { /* first: make room (if you can) */ if (zzStartRead > 0) { System.arraycopy(zzBuffer, zzStartRead, zzBuffer, 0, zzEndRead-zzStartRead); /* translate stored positions */ zzEndRead-= zzStartRead; zzCurrentPos-= zzStartRead; zzMarkedPos-= zzStartRead; zzPushbackPos-= zzStartRead; zzStartRead = 0; } /* is the buffer big enough? */ if (zzCurrentPos >= zzBuffer.length) { /* if not: blow it up */ char newBuffer[] = new char[zzCurrentPos*2]; System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length); zzBuffer = newBuffer; } /* finally: fill the buffer with new input */ int numRead = zzReader.read(zzBuffer, zzEndRead, zzBuffer.length-zzEndRead); if (numRead < 0) { return true; } else { zzEndRead+= numRead; return false; } } /** * Closes the input stream. */ public final void yyclose() throws java.io.IOException { zzAtEOF = true; /* indicate end of file */ zzEndRead = zzStartRead; /* invalidate buffer */ if (zzReader != null) zzReader.close(); } /** * Resets the scanner to read from a new input stream. * Does not close the old reader. * * All internal variables are reset, the old input stream * cannot be reused (internal buffer is discarded and lost). * Lexical state is set to ZZ_INITIAL. * * @param reader the new input stream */ public final void yyreset(java.io.Reader reader) { zzReader = reader; zzAtBOL = true; zzAtEOF = false; zzEndRead = zzStartRead = 0; zzCurrentPos = zzMarkedPos = zzPushbackPos = 0; yyline = yychar = yycolumn = 0; zzLexicalState = YYINITIAL; } /** * Returns the current lexical state. */ public final int yystate() { return zzLexicalState; } /** * Enters a new lexical state * * @param newState the new lexical state */ public final void yybegin(int newState) { zzLexicalState = newState; } /** * Returns the text matched by the current regular expression. */ public final String yytext() { return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead ); } /** * Returns the character at position pos from the * matched text. * * It is equivalent to yytext().charAt(pos), but faster * * @param pos the position of the character to fetch. * A value from 0 to yylength()-1. * * @return the character at position pos */ public final char yycharat(int pos) { return zzBuffer[zzStartRead+pos]; } /** * Returns the length of the matched text region. */ public final int yylength() { return zzMarkedPos-zzStartRead; } /** * Reports an error that occured while scanning. * * In a wellformed scanner (no or only correct usage of * yypushback(int) and a match-all fallback rule) this method * will only be called with things that "Can't Possibly Happen". * If this method is called, something is seriously wrong * (e.g. a JFlex bug producing a faulty scanner etc.). * * Usual syntax/scanner level error handling should be done * in error fallback rules. * * @param errorCode the code of the errormessage to display */ private void zzScanError(int errorCode) { String message; try { message = ZZ_ERROR_MSG[errorCode]; } catch (ArrayIndexOutOfBoundsException e) { message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; } throw new Error(message); } /** * Pushes the specified amount of characters back into the input stream. * * They will be read again by then next call of the scanning method * * @param number the number of characters to be read again. * This number must not be greater than yylength()! */ public void yypushback(int number) { if ( number > yylength() ) zzScanError(ZZ_PUSHBACK_2BIG); zzMarkedPos -= number; } /** * Resumes scanning until the next regular expression is matched, * the end of input is encountered or an I/O-Error occurs. * * @return the next token * @exception java.io.IOException if any I/O-Error occurs */ public int yylex() throws java.io.IOException { int zzInput; int zzAction; // cached fields: int zzCurrentPosL; int zzMarkedPosL; int zzEndReadL = zzEndRead; char [] zzBufferL = zzBuffer; char [] zzCMapL = ZZ_CMAP; int [] zzTransL = ZZ_TRANS; int [] zzRowMapL = ZZ_ROWMAP; int [] zzAttrL = ZZ_ATTRIBUTE; while (true) { zzMarkedPosL = zzMarkedPos; zzAction = -1; zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; zzState = zzLexicalState; zzForAction: { while (true) { if (zzCurrentPosL < zzEndReadL) zzInput = zzBufferL[zzCurrentPosL++]; else if (zzAtEOF) { zzInput = YYEOF; break zzForAction; } else { // store back cached positions zzCurrentPos = zzCurrentPosL; zzMarkedPos = zzMarkedPosL; boolean eof = zzRefill(); // get translated positions and possibly new buffer zzCurrentPosL = zzCurrentPos; zzMarkedPosL = zzMarkedPos; zzBufferL = zzBuffer; zzEndReadL = zzEndRead; if (eof) { zzInput = YYEOF; break zzForAction; } else { zzInput = zzBufferL[zzCurrentPosL++]; } } int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ]; if (zzNext == -1) break zzForAction; zzState = zzNext; int zzAttributes = zzAttrL[zzState]; if ( (zzAttributes & 1) == 1 ) { zzAction = zzState; zzMarkedPosL = zzCurrentPosL; if ( (zzAttributes & 8) == 8 ) break zzForAction; } } } // store back cached position zzMarkedPos = zzMarkedPosL; switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { case 5: { return JAVA_COMMENT_STYLE; } case 16: break; case 1: { return PLAIN_STYLE; } case 17: break; case 8: { return KEYWORD_STYLE; } case 18: break; case 4: { return OPERATOR_STYLE; } case 19: break; case 2: { return LITERAL_STYLE; } case 20: break; case 11: { yybegin(YYINITIAL); return JAVADOC_COMMENT_STYLE; } case 21: break; case 10: { yybegin(YYINITIAL); return JAVA_COMMENT_STYLE; } case 22: break; case 3: { return SEPARATOR_STYLE; } case 23: break; case 7: { return TYPE_STYLE; } case 24: break; case 9: { yybegin(IN_COMMENT); return JAVA_COMMENT_STYLE; } case 25: break; case 15: { yybegin(YYINITIAL); return LITERAL_STYLE; } case 26: break; case 14: { yybegin(IN_JAVA_DOC_COMMENT); return JAVADOC_COMMENT_STYLE; } case 27: break; case 12: { return JAVADOC_TAG_STYLE; } case 28: break; case 13: { yybegin(IN_HEREDOC); return LITERAL_STYLE; } case 29: break; case 6: { return JAVADOC_COMMENT_STYLE; } case 30: break; default: if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { zzAtEOF = true; return YYEOF; } else { zzScanError(ZZ_NO_MATCH); } } } } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/highlighter/JavaHighlighter.flex000066400000000000000000000111621422762524200333260ustar00rootroot00000000000000/* * Copyright 2000-2006 Omnicore Software, Hans Kratz & Dennis Strein GbR, * Geert Bevin . * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id$ */ package org.codelibs.jhighlight.highlighter; import java.io.Reader; import java.io.IOException; %% %class JavaHighlighter %implements ExplicitStateHighlighter %unicode %pack %buffer 128 %public %int %{ public static boolean ASSERT_IS_KEYWORD = false; /* styles */ public static final byte PLAIN_STYLE = 1; public static final byte KEYWORD_STYLE = 2; public static final byte TYPE_STYLE = 3; public static final byte OPERATOR_STYLE = 4; public static final byte SEPARATOR_STYLE = 5; public static final byte LITERAL_STYLE = 6; public static final byte JAVA_COMMENT_STYLE = 7; public static final byte JAVADOC_COMMENT_STYLE = 8; public static final byte JAVADOC_TAG_STYLE = 9; /* Highlighter implementation */ public int getStyleCount() { return 9; } public byte getStartState() { return YYINITIAL+1; } public byte getCurrentState() { return (byte) (yystate()+1); } public void setState(byte newState) { yybegin(newState-1); } public byte getNextToken() throws IOException { return (byte) yylex(); } public int getTokenLength() { return yylength(); } public void setReader(Reader r) { this.zzReader = r; } public JavaHighlighter() { } %} /* main character classes */ WhiteSpace = [ \t\f] /* identifiers */ ConstantIdentifier = {SimpleConstantIdentifier} SimpleConstantIdentifier = [A-Z0-9_]+ Identifier = [:jletter:][:jletterdigit:]* TypeIdentifier = {SimpleTypeIdentifier} SimpleTypeIdentifier = [A-Z][:jletterdigit:]* /* int literals */ DecLiteral = 0 | [1-9][0-9]* [lL]? HexLiteral = 0 [xX] 0* {HexDigit}* [lL]? HexDigit = [0-9a-fA-F] OctLiteral = 0+ {OctDigit}* [lL]? OctDigit = [0-7] /* float literals */ FloatLiteral = ({FLit1}|{FLit2}|{FLit3}|{FLit4}) ([fF]|[dD])? FLit1 = [0-9]+ \. [0-9]* {Exponent}? FLit2 = \. [0-9]+ {Exponent}? FLit3 = [0-9]+ {Exponent} FLit4 = [0-9]+ {Exponent}? Exponent = [eE] [+\-]? [0-9]+ %state IN_COMMENT, IN_JAVA_DOC_COMMENT %% { /* keywords */ "abstract" | "break" | "case" | "catch" | "class" | "const" | "continue" | "do" | "else" | "extends" | "final" | "finally" | "for" | "default" | "implements" | "import" | "instanceof" | "interface" | "native" | "new" | "goto" | "if" | "public" | "super" | "switch" | "synchronized" | "package" | "private" | "protected" | "transient" | "return" | "static" | "while" | "this" | "throw" | "throws" | "try" | "volatile" | "strictfp" { return KEYWORD_STYLE; } "boolean" | "byte" | "char" | "double" | "int" | "long" | "float" | "short" | "void" { return TYPE_STYLE; } "assert" { return ASSERT_IS_KEYWORD ? KEYWORD_STYLE : PLAIN_STYLE; } /* literals */ "true" | "false" | "null" | (\" ( [^\"\n\\] | \\[^\n] )* (\n | \\\n | \")) | (\' ( [^\'\n\\] | \\[^\n] )* (\n | \\\n | \')) | {DecLiteral} | {HexLiteral} | {OctLiteral} | {FloatLiteral} { return LITERAL_STYLE; } /* separators */ "(" | ")" | "{" | "}" | "[" | "]" | ";" | "," | "." { return SEPARATOR_STYLE; } /* operators */ "=" | ">" | "<" | "!" | "~" | "?" | ":" | "+" | "-" | "*" | "/" | "&" | "|" | "^" | "%" { return OPERATOR_STYLE; } {ConstantIdentifier} { return PLAIN_STYLE; } {TypeIdentifier} { return TYPE_STYLE; } \n | {Identifier} | {WhiteSpace} { return PLAIN_STYLE; } // single line comment "//" [^\n]* \n | // short comment "/**/" { return JAVA_COMMENT_STYLE; } // comment start "/**" { yybegin(IN_JAVA_DOC_COMMENT); return JAVADOC_COMMENT_STYLE;} "/*" { yybegin(IN_COMMENT); return JAVA_COMMENT_STYLE;} } // normal comment mode { // comment unterminated ([^\n*]|\*+[^\n*/])* (\n | \*+\n) { return JAVA_COMMENT_STYLE; } // comment terminated ([^\n*]|\*+[^\n*/])* \*+ "/" { yybegin(YYINITIAL); return JAVA_COMMENT_STYLE; } } // doc comment mode { // comment unterminated .|\n { return JAVADOC_COMMENT_STYLE; } // comment terminated \* "/" { yybegin(YYINITIAL); return JAVADOC_COMMENT_STYLE; } "@" {Identifier} { return JAVADOC_TAG_STYLE; } } /* error fallback */ .|\n { return PLAIN_STYLE; } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/highlighter/JavaHighlighter.java000066400000000000000000001001251422762524200333070ustar00rootroot00000000000000/* The following code was generated by JFlex 1.4.1 on 8/2/06 6:03 AM */ /* * Copyright 2000-2006 Omnicore Software, Hans Kratz & Dennis Strein GbR, * Geert Bevin . * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: JavaHighlighter.java 3431 2006-08-02 04:09:28Z gbevin $ */ package org.codelibs.jhighlight.highlighter; import java.io.IOException; import java.io.Reader; /** * This class is a scanner generated by * JFlex 1.4.1 * on 8/2/06 6:03 AM from the specification file * com/uwyn/jhighlight/highlighter/JavaHighlighter.flex */ public class JavaHighlighter implements ExplicitStateHighlighter { /** This character denotes the end of file */ public static final int YYEOF = -1; /** initial size of the lookahead buffer */ private static final int ZZ_BUFFERSIZE = 128; /** lexical states */ public static final int YYINITIAL = 0; public static final int IN_COMMENT = 1; public static final int IN_JAVA_DOC_COMMENT = 2; /** * Translates characters to character classes */ private static final String ZZ_CMAP_PACKED = "\11\4\1\0\1\50\1\0\1\0\1\0\16\4\4\0\1\0\1\54"+ "\1\47\1\0\1\2\1\54\1\54\1\52\1\53\1\53\1\55\1\24"+ "\1\53\1\24\1\21\1\56\1\6\7\15\2\1\1\54\1\53\1\54"+ "\1\54\1\54\1\54\1\57\3\14\1\17\1\23\1\17\5\5\1\10"+ "\13\5\1\12\2\5\1\53\1\51\1\53\1\54\1\3\1\0\1\25"+ "\1\26\1\13\1\20\1\22\1\16\1\45\1\33\1\36\1\2\1\32"+ "\1\7\1\41\1\35\1\34\1\42\1\2\1\31\1\27\1\30\1\37"+ "\1\43\1\44\1\11\1\40\1\46\1\53\1\54\1\53\1\54\41\4"+ "\2\0\4\2\4\0\1\2\2\0\1\4\7\0\1\2\4\0\1\2"+ "\5\0\27\2\1\0\37\2\1\0\u013f\2\31\0\162\2\4\0\14\2"+ "\16\0\5\2\11\0\1\2\21\0\130\4\5\0\23\4\12\0\1\2"+ "\13\0\1\2\1\0\3\2\1\0\1\2\1\0\24\2\1\0\54\2"+ "\1\0\46\2\1\0\5\2\4\0\202\2\1\0\4\4\3\0\105\2"+ "\1\0\46\2\2\0\2\2\6\0\20\2\41\0\46\2\2\0\1\2"+ "\7\0\47\2\11\0\21\4\1\0\27\4\1\0\3\4\1\0\1\4"+ "\1\0\2\4\1\0\1\4\13\0\33\2\5\0\3\2\15\0\4\4"+ "\14\0\6\4\13\0\32\2\5\0\13\2\16\4\7\0\12\4\4\0"+ "\2\2\1\4\143\2\1\0\1\2\10\4\1\0\6\4\2\2\2\4"+ "\1\0\4\4\2\2\12\4\3\2\2\0\1\2\17\0\1\4\1\2"+ "\1\4\36\2\33\4\2\0\3\2\60\0\46\2\13\4\1\2\u014f\0"+ "\3\4\66\2\2\0\1\4\1\2\20\4\2\0\1\2\4\4\3\0"+ "\12\2\2\4\2\0\12\4\21\0\3\4\1\0\10\2\2\0\2\2"+ "\2\0\26\2\1\0\7\2\1\0\1\2\3\0\4\2\2\0\1\4"+ "\1\2\7\4\2\0\2\4\2\0\3\4\11\0\1\4\4\0\2\2"+ "\1\0\3\2\2\4\2\0\12\4\4\2\15\0\3\4\1\0\6\2"+ "\4\0\2\2\2\0\26\2\1\0\7\2\1\0\2\2\1\0\2\2"+ "\1\0\2\2\2\0\1\4\1\0\5\4\4\0\2\4\2\0\3\4"+ "\13\0\4\2\1\0\1\2\7\0\14\4\3\2\14\0\3\4\1\0"+ "\11\2\1\0\3\2\1\0\26\2\1\0\7\2\1\0\2\2\1\0"+ "\5\2\2\0\1\4\1\2\10\4\1\0\3\4\1\0\3\4\2\0"+ "\1\2\17\0\2\2\2\4\2\0\12\4\1\0\1\2\17\0\3\4"+ "\1\0\10\2\2\0\2\2\2\0\26\2\1\0\7\2\1\0\2\2"+ "\1\0\5\2\2\0\1\4\1\2\6\4\3\0\2\4\2\0\3\4"+ "\10\0\2\4\4\0\2\2\1\0\3\2\4\0\12\4\1\0\1\2"+ "\20\0\1\4\1\2\1\0\6\2\3\0\3\2\1\0\4\2\3\0"+ "\2\2\1\0\1\2\1\0\2\2\3\0\2\2\3\0\3\2\3\0"+ "\10\2\1\0\3\2\4\0\5\4\3\0\3\4\1\0\4\4\11\0"+ "\1\4\17\0\11\4\11\0\1\2\7\0\3\4\1\0\10\2\1\0"+ "\3\2\1\0\27\2\1\0\12\2\1\0\5\2\4\0\7\4\1\0"+ "\3\4\1\0\4\4\7\0\2\4\11\0\2\2\4\0\12\4\22\0"+ "\2\4\1\0\10\2\1\0\3\2\1\0\27\2\1\0\12\2\1\0"+ "\5\2\2\0\1\4\1\2\7\4\1\0\3\4\1\0\4\4\7\0"+ "\2\4\7\0\1\2\1\0\2\2\4\0\12\4\22\0\2\4\1\0"+ "\10\2\1\0\3\2\1\0\27\2\1\0\20\2\4\0\6\4\2\0"+ "\3\4\1\0\4\4\11\0\1\4\10\0\2\2\4\0\12\4\22\0"+ "\2\4\1\0\22\2\3\0\30\2\1\0\11\2\1\0\1\2\2\0"+ "\7\2\3\0\1\4\4\0\6\4\1\0\1\4\1\0\10\4\22\0"+ "\2\4\15\0\60\2\1\4\2\2\7\4\4\0\10\2\10\4\1\0"+ "\12\4\47\0\2\2\1\0\1\2\2\0\2\2\1\0\1\2\2\0"+ "\1\2\6\0\4\2\1\0\7\2\1\0\3\2\1\0\1\2\1\0"+ "\1\2\2\0\2\2\1\0\4\2\1\4\2\2\6\4\1\0\2\4"+ "\1\2\2\0\5\2\1\0\1\2\1\0\6\4\2\0\12\4\2\0"+ "\2\2\42\0\1\2\27\0\2\4\6\0\12\4\13\0\1\4\1\0"+ "\1\4\1\0\1\4\4\0\2\4\10\2\1\0\42\2\6\0\24\4"+ "\1\0\2\4\4\2\4\0\10\4\1\0\44\4\11\0\1\4\71\0"+ "\42\2\1\0\5\2\1\0\2\2\1\0\7\4\3\0\4\4\6\0"+ "\12\4\6\0\6\2\4\4\106\0\46\2\12\0\51\2\7\0\132\2"+ "\5\0\104\2\5\0\122\2\6\0\7\2\1\0\77\2\1\0\1\2"+ "\1\0\4\2\2\0\7\2\1\0\1\2\1\0\4\2\2\0\47\2"+ "\1\0\1\2\1\0\4\2\2\0\37\2\1\0\1\2\1\0\4\2"+ "\2\0\7\2\1\0\1\2\1\0\4\2\2\0\7\2\1\0\7\2"+ "\1\0\27\2\1\0\37\2\1\0\1\2\1\0\4\2\2\0\7\2"+ "\1\0\47\2\1\0\23\2\16\0\11\4\56\0\125\2\14\0\u026c\2"+ "\2\0\10\2\12\0\32\2\5\0\113\2\3\0\3\2\17\0\15\2"+ "\1\0\4\2\3\4\13\0\22\2\3\4\13\0\22\2\2\4\14\0"+ "\15\2\1\0\3\2\1\0\2\4\14\0\64\2\40\4\3\0\1\2"+ "\3\0\2\2\1\4\2\0\12\4\41\0\3\4\2\0\12\4\6\0"+ "\130\2\10\0\51\2\1\4\126\0\35\2\3\0\14\4\4\0\14\4"+ "\12\0\12\4\36\2\2\0\5\2\u038b\0\154\2\224\0\234\2\4\0"+ "\132\2\6\0\26\2\2\0\6\2\2\0\46\2\2\0\6\2\2\0"+ "\10\2\1\0\1\2\1\0\1\2\1\0\1\2\1\0\37\2\2\0"+ "\65\2\1\0\7\2\1\0\1\2\3\0\3\2\1\0\7\2\3\0"+ "\4\2\2\0\6\2\4\0\15\2\5\0\3\2\1\0\7\2\17\0"+ "\4\4\32\0\5\4\20\0\2\2\23\0\1\2\13\0\4\4\6\0"+ "\6\4\1\0\1\2\15\0\1\2\40\0\22\2\36\0\15\4\4\0"+ "\1\4\3\0\6\4\27\0\1\2\4\0\1\2\2\0\12\2\1\0"+ "\1\2\3\0\5\2\6\0\1\2\1\0\1\2\1\0\1\2\1\0"+ "\4\2\1\0\3\2\1\0\7\2\3\0\3\2\5\0\5\2\26\0"+ "\44\2\u0e81\0\3\2\31\0\11\2\6\4\1\0\5\2\2\0\5\2"+ "\4\0\126\2\2\0\2\4\2\0\3\2\1\0\137\2\5\0\50\2"+ "\4\0\136\2\21\0\30\2\70\0\20\2\u0200\0\u19b6\2\112\0\u51a6\2"+ "\132\0\u048d\2\u0773\0\u2ba4\2\u215c\0\u012e\2\2\0\73\2\225\0\7\2"+ "\14\0\5\2\5\0\1\2\1\4\12\2\1\0\15\2\1\0\5\2"+ "\1\0\1\2\1\0\2\2\1\0\2\2\1\0\154\2\41\0\u016b\2"+ "\22\0\100\2\2\0\66\2\50\0\15\2\3\0\20\4\20\0\4\4"+ "\17\0\2\2\30\0\3\2\31\0\1\2\6\0\5\2\1\0\207\2"+ "\2\0\1\4\4\0\1\2\13\0\12\4\7\0\32\2\4\0\1\2"+ "\1\0\32\2\12\0\132\2\3\0\6\2\2\0\6\2\2\0\6\2"+ "\2\0\3\2\3\0\2\2\3\0\2\2\22\0\3\4\4\0"; /** * Translates characters to character classes */ private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); /** * Translates DFA states to action switch labels. */ private static final int [] ZZ_ACTION = zzUnpackAction(); private static final String ZZ_ACTION_PACKED_0 = "\3\0\1\1\1\2\2\1\1\2\4\1\1\3\1\1"+ "\1\4\15\1\1\3\1\4\1\1\1\5\1\1\3\6"+ "\1\1\3\2\1\0\1\1\1\7\4\2\12\1\1\10"+ "\22\1\1\10\10\1\4\0\1\11\3\0\1\12\1\13"+ "\1\14\1\2\1\0\1\2\37\1\1\7\11\1\1\15"+ "\1\7\20\1\1\2\14\1\1\10\11\1\1\10\12\1"+ "\1\16\25\1"; private static int [] zzUnpackAction() { int [] result = new int[214]; int offset = 0; offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); return result; } private static int zzUnpackAction(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); do result[j++] = value; while (--count > 0); } return j; } /** * Translates a state to a row index in the transition table */ private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); private static final String ZZ_ROWMAP_PACKED_0 = "\0\0\0\60\0\140\0\220\0\300\0\360\0\u0120\0\u0150"+ "\0\u0180\0\u01b0\0\u01e0\0\u0210\0\u0240\0\u0270\0\220\0\u02a0"+ "\0\u02d0\0\u0300\0\u0330\0\u0360\0\u0390\0\u03c0\0\u03f0\0\u0420"+ "\0\u0450\0\u0480\0\u04b0\0\u04e0\0\220\0\u0510\0\u0540\0\220"+ "\0\u0570\0\220\0\u05a0\0\u05d0\0\u0600\0\220\0\u0600\0\u0630"+ "\0\u0660\0\u0690\0\u06c0\0\u06f0\0\u0720\0\u0750\0\u0780\0\u07b0"+ "\0\u07e0\0\u0810\0\u0840\0\u0870\0\u08a0\0\u08d0\0\u0900\0\u0930"+ "\0\u0960\0\u0990\0\u09c0\0\u09f0\0\u0a20\0\u0a50\0\u0a80\0\u0ab0"+ "\0\u0ae0\0\u0b10\0\u0b40\0\u0b70\0\u0ba0\0\u0bd0\0\u0c00\0\u0c30"+ "\0\u0c60\0\u0c90\0\u0cc0\0\u0cf0\0\360\0\u0d20\0\u0d50\0\u0d80"+ "\0\u0db0\0\u0de0\0\u0e10\0\u0e40\0\u0e70\0\u04b0\0\u0ea0\0\u04e0"+ "\0\u0ed0\0\u0f00\0\u0f30\0\u0540\0\u0570\0\220\0\220\0\u0f60"+ "\0\u0f90\0\u0fc0\0\u0ff0\0\u1020\0\u1050\0\u1080\0\u10b0\0\u10e0"+ "\0\u1110\0\u1140\0\u1170\0\u11a0\0\u11d0\0\u1200\0\u1230\0\u1260"+ "\0\u1290\0\u12c0\0\u12f0\0\u1320\0\u1350\0\u1380\0\u13b0\0\u13e0"+ "\0\u1410\0\u1440\0\u1470\0\u14a0\0\u14d0\0\u1500\0\u1530\0\u1560"+ "\0\u1590\0\u15c0\0\u15f0\0\u1620\0\u1650\0\u1680\0\u16b0\0\u16e0"+ "\0\u1710\0\u1740\0\u1770\0\u17a0\0\u17d0\0\360\0\u1800\0\u1830"+ "\0\u1860\0\u1890\0\u18c0\0\u18f0\0\u1920\0\u1950\0\u1980\0\u19b0"+ "\0\u19e0\0\u1a10\0\u1a40\0\u1a70\0\u1aa0\0\u1ad0\0\360\0\u1b00"+ "\0\u1b30\0\u1b60\0\u1b90\0\u1bc0\0\u1bf0\0\u1c20\0\u1c50\0\u1c80"+ "\0\u1cb0\0\u1ce0\0\u1d10\0\u1d40\0\u1d70\0\u1da0\0\u1dd0\0\u1e00"+ "\0\u1e30\0\u1e60\0\u1e90\0\u1ec0\0\u1ef0\0\u1500\0\u1f20\0\u1f50"+ "\0\u1f80\0\u1fb0\0\u1fe0\0\u2010\0\u2040\0\u2070\0\u20a0\0\u20d0"+ "\0\360\0\u2100\0\u2130\0\u2160\0\u2190\0\u21c0\0\u21f0\0\u2220"+ "\0\u2250\0\u2280\0\u22b0\0\u22e0\0\u2310\0\u2340\0\u2370\0\u23a0"+ "\0\u23d0\0\u2400\0\u2430\0\u2460\0\u2490\0\u24c0"; private static int [] zzUnpackRowMap() { int [] result = new int[214]; int offset = 0; offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); return result; } private static int zzUnpackRowMap(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int high = packed.charAt(i++) << 16; result[j++] = high | packed.charAt(i++); } return j; } /** * The transition table of the DFA */ private static final int [] ZZ_TRANS = zzUnpackTrans(); private static final String ZZ_TRANS_PACKED_0 = "\1\4\1\5\2\6\1\4\1\7\1\10\1\11\1\7"+ "\1\6\1\7\1\12\1\7\1\5\1\13\1\7\1\14"+ "\1\15\1\16\1\7\1\17\1\20\1\21\1\22\1\23"+ "\1\24\3\6\1\25\1\26\3\6\1\27\1\30\1\31"+ "\1\32\1\6\1\33\2\4\1\34\1\35\2\17\1\36"+ "\1\4\50\37\1\40\4\37\1\41\2\37\55\42\1\43"+ "\1\42\1\44\61\0\1\5\1\0\1\45\1\0\1\45"+ "\1\5\1\46\1\47\1\0\1\45\1\0\1\45\1\5"+ "\1\46\1\47\1\46\1\50\1\51\1\52\35\0\20\6"+ "\1\0\2\6\1\0\22\6\12\0\1\7\1\53\1\7"+ "\1\53\2\7\1\53\1\7\1\53\1\7\1\53\2\7"+ "\1\53\1\7\1\53\1\0\1\53\1\7\1\0\22\53"+ "\12\0\1\54\1\0\1\45\1\0\1\45\1\55\1\46"+ "\1\47\1\56\1\57\1\0\1\45\1\55\1\46\1\47"+ "\1\46\1\50\1\51\1\52\35\0\20\6\1\0\2\6"+ "\1\0\7\6\1\60\12\6\12\0\6\6\1\61\11\6"+ "\1\0\2\6\1\0\1\62\5\6\1\63\1\64\12\6"+ "\12\0\6\6\1\65\11\6\1\0\2\6\1\0\1\66"+ "\6\6\1\67\1\6\1\70\10\6\12\0\20\6\1\0"+ "\1\71\1\6\1\0\7\6\1\72\12\6\12\0\1\50"+ "\4\0\1\50\6\0\1\50\43\0\6\6\1\73\1\6"+ "\1\74\7\6\1\0\2\6\1\0\22\6\12\0\20\6"+ "\1\0\2\6\1\0\1\6\1\75\1\76\17\6\12\0"+ "\20\6\1\0\2\6\1\0\4\6\1\77\2\6\1\100"+ "\3\6\1\101\6\6\12\0\20\6\1\0\2\6\1\0"+ "\3\6\1\102\2\6\1\103\3\6\1\104\1\105\3\6"+ "\1\106\2\6\12\0\20\6\1\0\2\6\1\0\4\6"+ "\1\107\1\6\1\110\13\6\12\0\20\6\1\0\1\111"+ "\1\6\1\0\22\6\12\0\20\6\1\0\1\112\1\6"+ "\1\0\1\113\11\6\1\114\7\6\12\0\15\6\1\115"+ "\2\6\1\0\2\6\1\0\10\6\1\116\3\6\1\117"+ "\5\6\12\0\20\6\1\0\2\6\1\0\1\120\3\6"+ "\1\121\5\6\1\122\7\6\12\0\20\6\1\0\2\6"+ "\1\0\7\6\1\123\12\6\12\0\20\6\1\0\2\6"+ "\1\0\6\6\1\124\13\6\12\0\20\6\1\0\2\6"+ "\1\0\7\6\1\125\12\6\11\0\47\126\2\46\1\127"+ "\6\126\50\130\1\46\1\131\1\46\5\130\55\0\1\132"+ "\1\133\1\0\50\134\1\40\4\134\1\135\52\134\1\40"+ "\4\134\1\135\1\136\1\134\56\0\1\137\3\0\2\140"+ "\1\0\1\140\1\0\6\140\1\0\3\140\1\0\2\140"+ "\1\0\22\140\12\0\1\45\1\0\1\45\1\0\2\45"+ "\1\0\1\45\1\0\1\45\1\0\2\45\1\0\1\45"+ "\3\0\1\45\35\0\1\50\4\0\1\50\6\0\1\50"+ "\3\46\1\0\2\51\35\0\1\141\4\0\1\141\6\0"+ "\1\141\6\0\1\142\34\0\1\143\1\0\1\45\1\0"+ "\1\45\1\143\1\0\1\45\1\0\1\45\1\0\1\45"+ "\1\143\1\0\1\45\3\0\1\45\1\142\34\0\20\53"+ "\1\0\2\53\1\0\22\53\12\0\1\54\1\0\1\45"+ "\1\0\1\45\1\54\1\0\1\45\1\0\1\45\1\0"+ "\1\45\1\54\1\46\1\47\1\46\1\50\1\51\1\52"+ "\35\0\1\54\1\0\1\45\1\0\1\45\1\55\1\46"+ "\1\47\1\0\1\45\1\0\1\45\1\55\1\46\1\47"+ "\1\46\1\50\1\51\1\52\35\0\1\56\4\0\1\56"+ "\2\46\2\0\6\56\1\0\2\56\1\0\2\56\32\0"+ "\1\57\1\0\1\45\1\0\1\45\1\57\1\46\1\47"+ "\1\0\1\45\1\56\2\57\1\56\1\57\1\56\1\0"+ "\1\56\1\57\1\0\2\56\32\0\20\6\1\0\2\6"+ "\1\0\10\6\1\144\11\6\12\0\20\6\1\0\2\6"+ "\1\0\1\145\21\6\12\0\20\6\1\0\2\6\1\0"+ "\2\6\1\146\1\147\16\6\12\0\20\6\1\0\2\6"+ "\1\0\1\150\21\6\12\0\20\6\1\0\2\6\1\0"+ "\10\6\1\151\11\6\12\0\20\6\1\0\2\6\1\0"+ "\7\6\1\152\12\6\12\0\6\6\1\153\11\6\1\0"+ "\2\6\1\0\22\6\12\0\20\6\1\0\2\6\1\0"+ "\4\6\1\115\15\6\12\0\20\6\1\0\2\6\1\0"+ "\10\6\1\154\11\6\12\0\15\6\1\155\2\6\1\0"+ "\2\6\1\0\22\6\12\0\20\6\1\0\2\6\1\0"+ "\12\6\1\156\7\6\12\0\20\6\1\0\2\6\1\0"+ "\2\6\1\146\17\6\12\0\20\6\1\0\2\6\1\0"+ "\3\6\1\157\16\6\12\0\20\6\1\0\2\6\1\0"+ "\2\6\1\160\17\6\12\0\20\6\1\0\2\6\1\0"+ "\2\6\1\161\17\6\12\0\20\6\1\0\1\162\1\6"+ "\1\0\22\6\12\0\20\6\1\0\2\6\1\0\7\6"+ "\1\163\12\6\12\0\20\6\1\0\2\6\1\0\3\6"+ "\1\164\16\6\12\0\20\6\1\0\2\6\1\0\1\165"+ "\3\6\1\166\15\6\12\0\20\6\1\0\2\6\1\0"+ "\7\6\1\167\12\6\12\0\20\6\1\0\2\6\1\0"+ "\15\6\1\170\4\6\12\0\20\6\1\0\2\6\1\0"+ "\10\6\1\171\11\6\12\0\20\6\1\0\2\6\1\0"+ "\11\6\1\172\10\6\12\0\20\6\1\0\2\6\1\0"+ "\1\173\11\6\1\174\1\115\6\6\12\0\20\6\1\0"+ "\2\6\1\0\4\6\1\175\4\6\1\176\10\6\12\0"+ "\20\6\1\0\2\6\1\0\3\6\1\177\16\6\12\0"+ "\20\6\1\0\2\6\1\0\17\6\1\115\2\6\12\0"+ "\20\6\1\0\2\6\1\0\3\6\1\200\16\6\12\0"+ "\6\6\1\201\11\6\1\0\2\6\1\0\22\6\12\0"+ "\20\6\1\0\2\6\1\0\2\6\1\202\1\203\16\6"+ "\12\0\20\6\1\0\2\6\1\0\15\6\1\204\4\6"+ "\12\0\12\6\1\205\5\6\1\0\2\6\1\0\22\6"+ "\12\0\20\6\1\0\2\6\1\0\7\6\1\206\1\6"+ "\1\207\10\6\12\0\20\6\1\0\2\6\1\0\1\6"+ "\1\210\20\6\12\0\6\6\1\211\11\6\1\0\2\6"+ "\1\0\11\6\1\212\10\6\12\0\20\6\1\0\2\6"+ "\1\0\11\6\1\213\10\6\12\0\20\6\1\0\2\6"+ "\1\0\3\6\1\214\16\6\11\0\50\126\1\46\7\126"+ "\50\130\1\46\7\130\55\0\1\215\2\0\50\133\1\40"+ "\7\133\1\0\20\140\1\0\2\140\1\0\22\140\12\0"+ "\1\141\4\0\1\141\6\0\1\141\3\46\40\0\1\141"+ "\4\0\1\141\6\0\1\141\43\0\1\143\1\0\1\45"+ "\1\0\1\45\1\143\1\0\1\45\1\0\1\45\1\0"+ "\1\45\1\143\1\46\1\47\1\46\2\0\1\45\35\0"+ "\20\6\1\0\2\6\1\0\20\6\1\216\1\6\12\0"+ "\20\6\1\0\2\6\1\0\2\6\1\176\17\6\12\0"+ "\20\6\1\0\1\115\1\6\1\0\22\6\12\0\12\6"+ "\1\217\5\6\1\0\2\6\1\0\22\6\12\0\20\6"+ "\1\0\2\6\1\0\4\6\1\216\15\6\12\0\20\6"+ "\1\0\2\6\1\0\2\6\1\220\1\221\16\6\12\0"+ "\20\6\1\0\2\6\1\0\1\222\21\6\12\0\20\6"+ "\1\0\2\6\1\0\2\6\1\174\17\6\12\0\20\6"+ "\1\0\2\6\1\0\1\223\21\6\12\0\20\6\1\0"+ "\2\6\1\0\1\224\21\6\12\0\20\6\1\0\2\6"+ "\1\0\1\6\1\225\20\6\12\0\20\6\1\0\1\226"+ "\1\6\1\0\22\6\12\0\20\6\1\0\2\6\1\0"+ "\3\6\1\227\16\6\12\0\20\6\1\0\1\230\1\6"+ "\1\0\22\6\12\0\20\6\1\0\2\6\1\0\1\231"+ "\21\6\12\0\6\6\1\232\11\6\1\0\2\6\1\0"+ "\22\6\12\0\20\6\1\0\1\216\1\6\1\0\22\6"+ "\12\0\20\6\1\0\2\6\1\0\3\6\1\233\16\6"+ "\12\0\20\6\1\0\2\6\1\0\11\6\1\234\10\6"+ "\12\0\20\6\1\0\2\6\1\0\4\6\1\222\15\6"+ "\12\0\20\6\1\0\1\67\1\6\1\0\22\6\12\0"+ "\12\6\1\235\5\6\1\0\2\6\1\0\22\6\12\0"+ "\20\6\1\0\2\6\1\0\3\6\1\147\16\6\12\0"+ "\20\6\1\0\2\6\1\0\10\6\1\236\11\6\12\0"+ "\20\6\1\0\1\237\1\6\1\0\22\6\12\0\20\6"+ "\1\0\2\6\1\0\7\6\1\240\12\6\12\0\20\6"+ "\1\0\2\6\1\0\2\6\1\115\17\6\12\0\20\6"+ "\1\0\2\6\1\0\12\6\1\241\7\6\12\0\20\6"+ "\1\0\2\6\1\0\11\6\1\242\10\6\12\0\6\6"+ "\1\237\11\6\1\0\2\6\1\0\22\6\12\0\20\6"+ "\1\0\2\6\1\0\3\6\1\243\16\6\12\0\20\6"+ "\1\0\1\244\1\6\1\0\22\6\12\0\6\6\1\245"+ "\11\6\1\0\2\6\1\0\7\6\1\246\12\6\12\0"+ "\20\6\1\0\2\6\1\0\5\6\1\247\14\6\12\0"+ "\20\6\1\0\2\6\1\0\3\6\1\250\16\6\12\0"+ "\20\6\1\0\2\6\1\0\16\6\1\251\3\6\12\0"+ "\6\6\1\233\11\6\1\0\2\6\1\0\22\6\12\0"+ "\20\6\1\0\2\6\1\0\1\252\21\6\12\0\17\6"+ "\1\216\1\0\2\6\1\0\22\6\12\0\6\6\1\146"+ "\11\6\1\0\2\6\1\0\22\6\12\0\20\6\1\0"+ "\2\6\1\0\7\6\1\115\12\6\67\0\1\40\2\0"+ "\20\6\1\0\2\6\1\0\6\6\1\115\13\6\12\0"+ "\20\6\1\0\2\6\1\0\3\6\1\115\16\6\12\0"+ "\20\6\1\0\2\6\1\0\11\6\1\253\10\6\12\0"+ "\20\6\1\0\2\6\1\0\3\6\1\216\16\6\12\0"+ "\6\6\1\254\11\6\1\0\2\6\1\0\22\6\12\0"+ "\20\6\1\0\2\6\1\0\12\6\1\255\7\6\12\0"+ "\6\6\1\164\11\6\1\0\2\6\1\0\22\6\12\0"+ "\20\6\1\0\2\6\1\0\10\6\1\256\11\6\12\0"+ "\20\6\1\0\2\6\1\0\4\6\1\257\15\6\12\0"+ "\20\6\1\0\2\6\1\0\4\6\1\260\15\6\12\0"+ "\20\6\1\0\2\6\1\0\5\6\1\115\14\6\12\0"+ "\20\6\1\0\1\261\1\6\1\0\22\6\12\0\20\6"+ "\1\0\2\6\1\0\11\6\1\262\10\6\12\0\12\6"+ "\1\263\5\6\1\0\2\6\1\0\22\6\12\0\20\6"+ "\1\0\2\6\1\0\6\6\1\264\13\6\12\0\20\6"+ "\1\0\2\6\1\0\2\6\1\265\17\6\12\0\20\6"+ "\1\0\2\6\1\0\17\6\1\266\2\6\12\0\20\6"+ "\1\0\2\6\1\0\4\6\1\267\15\6\12\0\20\6"+ "\1\0\2\6\1\0\16\6\1\146\3\6\12\0\20\6"+ "\1\0\2\6\1\0\1\270\21\6\12\0\20\6\1\0"+ "\2\6\1\0\4\6\1\271\15\6\12\0\20\6\1\0"+ "\1\272\1\6\1\0\22\6\12\0\20\6\1\0\2\6"+ "\1\0\4\6\1\220\15\6\12\0\20\6\1\0\2\6"+ "\1\0\1\273\21\6\12\0\20\6\1\0\1\274\1\6"+ "\1\0\22\6\12\0\20\6\1\0\2\6\1\0\1\275"+ "\21\6\12\0\20\6\1\0\2\6\1\0\3\6\1\124"+ "\16\6\12\0\20\6\1\0\2\6\1\0\10\6\1\276"+ "\11\6\12\0\6\6\1\277\11\6\1\0\2\6\1\0"+ "\22\6\12\0\6\6\1\220\11\6\1\0\2\6\1\0"+ "\22\6\12\0\17\6\1\176\1\0\2\6\1\0\22\6"+ "\12\0\20\6\1\0\2\6\1\0\1\300\21\6\12\0"+ "\20\6\1\0\2\6\1\0\3\6\1\301\16\6\12\0"+ "\20\6\1\0\2\6\1\0\1\302\21\6\12\0\12\6"+ "\1\115\5\6\1\0\2\6\1\0\22\6\12\0\20\6"+ "\1\0\2\6\1\0\3\6\1\303\16\6\12\0\20\6"+ "\1\0\2\6\1\0\4\6\1\304\15\6\12\0\20\6"+ "\1\0\2\6\1\0\11\6\1\305\10\6\12\0\20\6"+ "\1\0\2\6\1\0\10\6\1\115\11\6\12\0\20\6"+ "\1\0\2\6\1\0\10\6\1\306\11\6\12\0\15\6"+ "\1\307\2\6\1\0\2\6\1\0\22\6\12\0\20\6"+ "\1\0\2\6\1\0\14\6\1\310\5\6\12\0\20\6"+ "\1\0\2\6\1\0\20\6\1\146\1\6\12\0\12\6"+ "\1\311\5\6\1\0\2\6\1\0\22\6\12\0\20\6"+ "\1\0\2\6\1\0\3\6\1\146\16\6\12\0\20\6"+ "\1\0\2\6\1\0\12\6\1\146\7\6\12\0\20\6"+ "\1\0\2\6\1\0\13\6\1\115\6\6\12\0\12\6"+ "\1\220\5\6\1\0\2\6\1\0\22\6\12\0\20\6"+ "\1\0\2\6\1\0\10\6\1\216\11\6\12\0\15\6"+ "\1\312\2\6\1\0\2\6\1\0\22\6\12\0\20\6"+ "\1\0\2\6\1\0\7\6\1\313\12\6\12\0\20\6"+ "\1\0\1\314\1\6\1\0\22\6\12\0\12\6\1\315"+ "\5\6\1\0\2\6\1\0\22\6\12\0\20\6\1\0"+ "\2\6\1\0\1\316\21\6\12\0\20\6\1\0\1\317"+ "\1\6\1\0\22\6\12\0\20\6\1\0\2\6\1\0"+ "\3\6\1\320\16\6\12\0\20\6\1\0\2\6\1\0"+ "\15\6\1\115\4\6\12\0\20\6\1\0\2\6\1\0"+ "\10\6\1\321\11\6\12\0\20\6\1\0\2\6\1\0"+ "\10\6\1\220\11\6\12\0\20\6\1\0\1\322\1\6"+ "\1\0\22\6\12\0\12\6\1\146\5\6\1\0\2\6"+ "\1\0\22\6\12\0\20\6\1\0\2\6\1\0\10\6"+ "\1\323\11\6\12\0\20\6\1\0\1\324\1\6\1\0"+ "\22\6\12\0\20\6\1\0\2\6\1\0\11\6\1\325"+ "\10\6\12\0\20\6\1\0\2\6\1\0\7\6\1\326"+ "\12\6\12\0\20\6\1\0\2\6\1\0\3\6\1\176"+ "\16\6\12\0\17\6\1\115\1\0\2\6\1\0\22\6"+ "\12\0\20\6\1\0\2\6\1\0\21\6\1\320\12\0"+ "\15\6\1\115\2\6\1\0\2\6\1\0\22\6\11\0"; private static int [] zzUnpackTrans() { int [] result = new int[9456]; int offset = 0; offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); return result; } private static int zzUnpackTrans(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); value--; do result[j++] = value; while (--count > 0); } return j; } /* error codes */ private static final int ZZ_UNKNOWN_ERROR = 0; private static final int ZZ_NO_MATCH = 1; private static final int ZZ_PUSHBACK_2BIG = 2; /* error messages for the codes above */ private static final String ZZ_ERROR_MSG[] = { "Unkown internal scanner error", "Error: could not match input", "Error: pushback value was too large" }; /** * ZZ_ATTRIBUTE[aState] contains the attributes of state aState */ private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); private static final String ZZ_ATTRIBUTE_PACKED_0 = "\3\0\1\11\12\1\1\11\15\1\1\11\2\1\1\11"+ "\1\1\1\11\3\1\1\11\2\1\1\0\54\1\4\0"+ "\1\1\3\0\2\11\2\1\1\0\164\1"; private static int [] zzUnpackAttribute() { int [] result = new int[214]; int offset = 0; offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); return result; } private static int zzUnpackAttribute(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); do result[j++] = value; while (--count > 0); } return j; } /** the input device */ private java.io.Reader zzReader; /** the current state of the DFA */ private int zzState; /** the current lexical state */ private int zzLexicalState = YYINITIAL; /** this buffer contains the current text to be matched and is the source of the yytext() string */ private char zzBuffer[] = new char[ZZ_BUFFERSIZE]; /** the textposition at the last accepting state */ private int zzMarkedPos; /** the textposition at the last state to be included in yytext */ private int zzPushbackPos; /** the current text position in the buffer */ private int zzCurrentPos; /** startRead marks the beginning of the yytext() string in the buffer */ private int zzStartRead; /** endRead marks the last character in the buffer, that has been read from input */ private int zzEndRead; /** number of newlines encountered up to the start of the matched text */ private int yyline; /** the number of characters up to the start of the matched text */ private int yychar; /** * the number of characters from the last newline up to the start of the * matched text */ private int yycolumn; /** * zzAtBOL == true <=> the scanner is currently at the beginning of a line */ private boolean zzAtBOL = true; /** zzAtEOF == true <=> the scanner is at the EOF */ private boolean zzAtEOF; /* user code: */ public static boolean ASSERT_IS_KEYWORD = false; /* styles */ public static final byte PLAIN_STYLE = 1; public static final byte KEYWORD_STYLE = 2; public static final byte TYPE_STYLE = 3; public static final byte OPERATOR_STYLE = 4; public static final byte SEPARATOR_STYLE = 5; public static final byte LITERAL_STYLE = 6; public static final byte JAVA_COMMENT_STYLE = 7; public static final byte JAVADOC_COMMENT_STYLE = 8; public static final byte JAVADOC_TAG_STYLE = 9; /* Highlighter implementation */ public int getStyleCount() { return 9; } public byte getStartState() { return YYINITIAL+1; } public byte getCurrentState() { return (byte) (yystate()+1); } public void setState(byte newState) { yybegin(newState-1); } public byte getNextToken() throws IOException { return (byte) yylex(); } public int getTokenLength() { return yylength(); } public void setReader(Reader r) { this.zzReader = r; } public JavaHighlighter() { } /** * Creates a new scanner * There is also a java.io.InputStream version of this constructor. * * @param in the java.io.Reader to read input from. */ public JavaHighlighter(java.io.Reader in) { this.zzReader = in; } /** * Creates a new scanner. * There is also java.io.Reader version of this constructor. * * @param in the java.io.Inputstream to read input from. */ public JavaHighlighter(java.io.InputStream in) { this(new java.io.InputStreamReader(in)); } /** * Unpacks the compressed character translation table. * * @param packed the packed character translation table * @return the unpacked character translation table */ private static char [] zzUnpackCMap(String packed) { char [] map = new char[0x10000]; int i = 0; /* index in packed string */ int j = 0; /* index in unpacked array */ while (i < 1778) { int count = packed.charAt(i++); char value = packed.charAt(i++); do map[j++] = value; while (--count > 0); } return map; } /** * Refills the input buffer. * * @return false, iff there was new input. * * @exception java.io.IOException if any I/O-Error occurs */ private boolean zzRefill() throws java.io.IOException { /* first: make room (if you can) */ if (zzStartRead > 0) { System.arraycopy(zzBuffer, zzStartRead, zzBuffer, 0, zzEndRead-zzStartRead); /* translate stored positions */ zzEndRead-= zzStartRead; zzCurrentPos-= zzStartRead; zzMarkedPos-= zzStartRead; zzPushbackPos-= zzStartRead; zzStartRead = 0; } /* is the buffer big enough? */ if (zzCurrentPos >= zzBuffer.length) { /* if not: blow it up */ char newBuffer[] = new char[zzCurrentPos*2]; System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length); zzBuffer = newBuffer; } /* finally: fill the buffer with new input */ int numRead = zzReader.read(zzBuffer, zzEndRead, zzBuffer.length-zzEndRead); if (numRead < 0) { return true; } else { zzEndRead+= numRead; return false; } } /** * Closes the input stream. */ public final void yyclose() throws java.io.IOException { zzAtEOF = true; /* indicate end of file */ zzEndRead = zzStartRead; /* invalidate buffer */ if (zzReader != null) zzReader.close(); } /** * Resets the scanner to read from a new input stream. * Does not close the old reader. * * All internal variables are reset, the old input stream * cannot be reused (internal buffer is discarded and lost). * Lexical state is set to ZZ_INITIAL. * * @param reader the new input stream */ public final void yyreset(java.io.Reader reader) { zzReader = reader; zzAtBOL = true; zzAtEOF = false; zzEndRead = zzStartRead = 0; zzCurrentPos = zzMarkedPos = zzPushbackPos = 0; yyline = yychar = yycolumn = 0; zzLexicalState = YYINITIAL; } /** * Returns the current lexical state. */ public final int yystate() { return zzLexicalState; } /** * Enters a new lexical state * * @param newState the new lexical state */ public final void yybegin(int newState) { zzLexicalState = newState; } /** * Returns the text matched by the current regular expression. */ public final String yytext() { return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead ); } /** * Returns the character at position pos from the * matched text. * * It is equivalent to yytext().charAt(pos), but faster * * @param pos the position of the character to fetch. * A value from 0 to yylength()-1. * * @return the character at position pos */ public final char yycharat(int pos) { return zzBuffer[zzStartRead+pos]; } /** * Returns the length of the matched text region. */ public final int yylength() { return zzMarkedPos-zzStartRead; } /** * Reports an error that occured while scanning. * * In a wellformed scanner (no or only correct usage of * yypushback(int) and a match-all fallback rule) this method * will only be called with things that "Can't Possibly Happen". * If this method is called, something is seriously wrong * (e.g. a JFlex bug producing a faulty scanner etc.). * * Usual syntax/scanner level error handling should be done * in error fallback rules. * * @param errorCode the code of the errormessage to display */ private void zzScanError(int errorCode) { String message; try { message = ZZ_ERROR_MSG[errorCode]; } catch (ArrayIndexOutOfBoundsException e) { message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; } throw new Error(message); } /** * Pushes the specified amount of characters back into the input stream. * * They will be read again by then next call of the scanning method * * @param number the number of characters to be read again. * This number must not be greater than yylength()! */ public void yypushback(int number) { if ( number > yylength() ) zzScanError(ZZ_PUSHBACK_2BIG); zzMarkedPos -= number; } /** * Resumes scanning until the next regular expression is matched, * the end of input is encountered or an I/O-Error occurs. * * @return the next token * @exception java.io.IOException if any I/O-Error occurs */ public int yylex() throws java.io.IOException { int zzInput; int zzAction; // cached fields: int zzCurrentPosL; int zzMarkedPosL; int zzEndReadL = zzEndRead; char [] zzBufferL = zzBuffer; char [] zzCMapL = ZZ_CMAP; int [] zzTransL = ZZ_TRANS; int [] zzRowMapL = ZZ_ROWMAP; int [] zzAttrL = ZZ_ATTRIBUTE; while (true) { zzMarkedPosL = zzMarkedPos; zzAction = -1; zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; zzState = zzLexicalState; zzForAction: { while (true) { if (zzCurrentPosL < zzEndReadL) zzInput = zzBufferL[zzCurrentPosL++]; else if (zzAtEOF) { zzInput = YYEOF; break zzForAction; } else { // store back cached positions zzCurrentPos = zzCurrentPosL; zzMarkedPos = zzMarkedPosL; boolean eof = zzRefill(); // get translated positions and possibly new buffer zzCurrentPosL = zzCurrentPos; zzMarkedPosL = zzMarkedPos; zzBufferL = zzBuffer; zzEndReadL = zzEndRead; if (eof) { zzInput = YYEOF; break zzForAction; } else { zzInput = zzBufferL[zzCurrentPosL++]; } } int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ]; if (zzNext == -1) break zzForAction; zzState = zzNext; int zzAttributes = zzAttrL[zzState]; if ( (zzAttributes & 1) == 1 ) { zzAction = zzState; zzMarkedPosL = zzCurrentPosL; if ( (zzAttributes & 8) == 8 ) break zzForAction; } } } // store back cached position zzMarkedPos = zzMarkedPosL; switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { case 14: { return ASSERT_IS_KEYWORD ? KEYWORD_STYLE : PLAIN_STYLE; } case 15: break; case 5: { return JAVA_COMMENT_STYLE; } case 16: break; case 1: { return PLAIN_STYLE; } case 17: break; case 8: { return KEYWORD_STYLE; } case 18: break; case 4: { return OPERATOR_STYLE; } case 19: break; case 2: { return LITERAL_STYLE; } case 20: break; case 11: { yybegin(YYINITIAL); return JAVADOC_COMMENT_STYLE; } case 21: break; case 10: { yybegin(YYINITIAL); return JAVA_COMMENT_STYLE; } case 22: break; case 3: { return SEPARATOR_STYLE; } case 23: break; case 7: { return TYPE_STYLE; } case 24: break; case 9: { yybegin(IN_COMMENT); return JAVA_COMMENT_STYLE; } case 25: break; case 13: { yybegin(IN_JAVA_DOC_COMMENT); return JAVADOC_COMMENT_STYLE; } case 26: break; case 12: { return JAVADOC_TAG_STYLE; } case 27: break; case 6: { return JAVADOC_COMMENT_STYLE; } case 28: break; default: if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { zzAtEOF = true; return YYEOF; } else { zzScanError(ZZ_NO_MATCH); } } } } } JavaScriptHighlighter.flex000066400000000000000000000065321422762524200344410ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/highlighter/* * Copyright 2000-2006 Omnicore Software, Hans Kratz & Dennis Strein GbR, * Geert Bevin , * Ulf Dittmer (ulf[remove] at ulfdittmer dot com). * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id$ */ package org.codelibs.jhighlight.highlighter; import java.io.Reader; import java.io.IOException; %% %class JavaScriptHighlighter %implements ExplicitStateHighlighter %unicode %pack %buffer 128 %public %int %{ /* styles */ public static final byte PLAIN_STYLE = 1; public static final byte KEYWORD_STYLE = 2; public static final byte OPERATOR_STYLE = 3; public static final byte SEPARATOR_STYLE = 4; public static final byte LITERAL_STYLE = 5; public static final byte JAVA_COMMENT_STYLE = 6; /* Highlighter implementation */ public int getStyleCount() { return 6; } public byte getStartState() { return YYINITIAL+1; } public byte getCurrentState() { return (byte) (yystate()+1); } public void setState(byte newState) { yybegin(newState-1); } public byte getNextToken() throws IOException { return (byte) yylex(); } public int getTokenLength() { return yylength(); } public void setReader(Reader r) { this.zzReader = r; } public JavaScriptHighlighter() { } %} /* main character classes */ WhiteSpace = [ \t\f] /* identifiers */ ConstantIdentifier = {SimpleConstantIdentifier} SimpleConstantIdentifier = [A-Z0-9_]+ Identifier = [:jletter:][:jletterdigit:]* /* int literals */ DecLiteral = 0 | [1-9][0-9]* /* float literals */ FloatLiteral = ({FLit1}|{FLit2}|{FLit3}|{FLit4}) FLit1 = [0-9]+ \. [0-9]* {Exponent}? FLit2 = \. [0-9]+ {Exponent}? FLit3 = [0-9]+ {Exponent} FLit4 = [0-9]+ {Exponent}? Exponent = [eE] [+\-]? [0-9]+ %state IN_COMMENT %% { /* keywords */ "break" | "case" | "continue" | "do" | "else" | "for" | "default" | "new" | "in" | "goto" | "if" | "switch" | "return" | "while" | "var" | "function" | "with" | "const" | "this" { return KEYWORD_STYLE; } /* literals */ "true" | "false" | "null" | (\" ( [^\"\n\\] | \\[^\n] )* (\n | \\\n | \")) | (\' ( [^\'\n\\] | \\[^\n] )* (\n | \\\n | \')) | {DecLiteral} | {FloatLiteral} { return LITERAL_STYLE; } /* separators */ "(" | ")" | "{" | "}" | "[" | "]" | ";" | "," | "." { return SEPARATOR_STYLE; } /* operators */ "=" | ">" | "<" | "!" | "~" | "?" | ":" | "+" | "-" | "*" | "/" | "&" | "|" | "^" | "%" { return OPERATOR_STYLE; } {ConstantIdentifier} { return PLAIN_STYLE; } \n | {Identifier} | {WhiteSpace} { return PLAIN_STYLE; } // single line comment "//" [^\n]* \n | // short comment "/**/" { return JAVA_COMMENT_STYLE; } // comment start "/*" { yybegin(IN_COMMENT); return JAVA_COMMENT_STYLE;} } // normal comment mode { // comment unterminated ([^\n*]|\*+[^\n*/])* (\n | \*+\n) { return JAVA_COMMENT_STYLE; } // comment terminated ([^\n*]|\*+[^\n*/])* \*+ "/" { yybegin(YYINITIAL); return JAVA_COMMENT_STYLE; } } /* error fallback */ .|\n { return PLAIN_STYLE; } JavaScriptHighlighter.java000066400000000000000000000576471422762524200344410ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/highlighter/* The following code was generated by JFlex 1.4.1 on 8/2/06 6:03 AM */ /* * Copyright 2000-2006 Omnicore Software, Hans Kratz & Dennis Strein GbR, * Geert Bevin , * Ulf Dittmer (ulf[remove] at ulfdittmer dot com). * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: JavaScriptHighlighter.java 3431 2006-08-02 04:09:28Z gbevin $ */ package org.codelibs.jhighlight.highlighter; import java.io.IOException; import java.io.Reader; /** * This class is a scanner generated by * JFlex 1.4.1 * on 8/2/06 6:03 AM from the specification file * com/uwyn/jhighlight/highlighter/JavaScriptHighlighter.flex */ public class JavaScriptHighlighter implements ExplicitStateHighlighter { /** This character denotes the end of file */ public static final int YYEOF = -1; /** initial size of the lookahead buffer */ private static final int ZZ_BUFFERSIZE = 128; /** lexical states */ public static final int YYINITIAL = 0; public static final int IN_COMMENT = 1; /** * Translates characters to character classes */ private static final String ZZ_CMAP_PACKED = "\11\4\1\0\1\34\1\0\1\0\1\0\16\4\4\0\1\0\1\40"+ "\1\33\1\0\1\2\1\40\1\40\1\36\1\37\1\37\1\41\1\10"+ "\1\37\1\10\1\5\1\42\1\1\11\1\1\40\1\37\1\40\1\40"+ "\1\40\1\40\1\0\4\3\1\7\25\3\1\37\1\35\1\37\1\40"+ "\1\3\1\0\1\13\1\11\1\15\1\24\1\6\1\26\1\30\1\31"+ "\1\22\1\2\1\14\1\25\1\2\1\20\1\17\2\2\1\12\1\16"+ "\1\21\1\23\1\32\1\27\3\2\1\37\1\40\1\37\1\40\41\4"+ "\2\0\4\2\4\0\1\2\2\0\1\4\7\0\1\2\4\0\1\2"+ "\5\0\27\2\1\0\37\2\1\0\u013f\2\31\0\162\2\4\0\14\2"+ "\16\0\5\2\11\0\1\2\21\0\130\4\5\0\23\4\12\0\1\2"+ "\13\0\1\2\1\0\3\2\1\0\1\2\1\0\24\2\1\0\54\2"+ "\1\0\46\2\1\0\5\2\4\0\202\2\1\0\4\4\3\0\105\2"+ "\1\0\46\2\2\0\2\2\6\0\20\2\41\0\46\2\2\0\1\2"+ "\7\0\47\2\11\0\21\4\1\0\27\4\1\0\3\4\1\0\1\4"+ "\1\0\2\4\1\0\1\4\13\0\33\2\5\0\3\2\15\0\4\4"+ "\14\0\6\4\13\0\32\2\5\0\13\2\16\4\7\0\12\4\4\0"+ "\2\2\1\4\143\2\1\0\1\2\10\4\1\0\6\4\2\2\2\4"+ "\1\0\4\4\2\2\12\4\3\2\2\0\1\2\17\0\1\4\1\2"+ "\1\4\36\2\33\4\2\0\3\2\60\0\46\2\13\4\1\2\u014f\0"+ "\3\4\66\2\2\0\1\4\1\2\20\4\2\0\1\2\4\4\3\0"+ "\12\2\2\4\2\0\12\4\21\0\3\4\1\0\10\2\2\0\2\2"+ "\2\0\26\2\1\0\7\2\1\0\1\2\3\0\4\2\2\0\1\4"+ "\1\2\7\4\2\0\2\4\2\0\3\4\11\0\1\4\4\0\2\2"+ "\1\0\3\2\2\4\2\0\12\4\4\2\15\0\3\4\1\0\6\2"+ "\4\0\2\2\2\0\26\2\1\0\7\2\1\0\2\2\1\0\2\2"+ "\1\0\2\2\2\0\1\4\1\0\5\4\4\0\2\4\2\0\3\4"+ "\13\0\4\2\1\0\1\2\7\0\14\4\3\2\14\0\3\4\1\0"+ "\11\2\1\0\3\2\1\0\26\2\1\0\7\2\1\0\2\2\1\0"+ "\5\2\2\0\1\4\1\2\10\4\1\0\3\4\1\0\3\4\2\0"+ "\1\2\17\0\2\2\2\4\2\0\12\4\1\0\1\2\17\0\3\4"+ "\1\0\10\2\2\0\2\2\2\0\26\2\1\0\7\2\1\0\2\2"+ "\1\0\5\2\2\0\1\4\1\2\6\4\3\0\2\4\2\0\3\4"+ "\10\0\2\4\4\0\2\2\1\0\3\2\4\0\12\4\1\0\1\2"+ "\20\0\1\4\1\2\1\0\6\2\3\0\3\2\1\0\4\2\3\0"+ "\2\2\1\0\1\2\1\0\2\2\3\0\2\2\3\0\3\2\3\0"+ "\10\2\1\0\3\2\4\0\5\4\3\0\3\4\1\0\4\4\11\0"+ "\1\4\17\0\11\4\11\0\1\2\7\0\3\4\1\0\10\2\1\0"+ "\3\2\1\0\27\2\1\0\12\2\1\0\5\2\4\0\7\4\1\0"+ "\3\4\1\0\4\4\7\0\2\4\11\0\2\2\4\0\12\4\22\0"+ "\2\4\1\0\10\2\1\0\3\2\1\0\27\2\1\0\12\2\1\0"+ "\5\2\2\0\1\4\1\2\7\4\1\0\3\4\1\0\4\4\7\0"+ "\2\4\7\0\1\2\1\0\2\2\4\0\12\4\22\0\2\4\1\0"+ "\10\2\1\0\3\2\1\0\27\2\1\0\20\2\4\0\6\4\2\0"+ "\3\4\1\0\4\4\11\0\1\4\10\0\2\2\4\0\12\4\22\0"+ "\2\4\1\0\22\2\3\0\30\2\1\0\11\2\1\0\1\2\2\0"+ "\7\2\3\0\1\4\4\0\6\4\1\0\1\4\1\0\10\4\22\0"+ "\2\4\15\0\60\2\1\4\2\2\7\4\4\0\10\2\10\4\1\0"+ "\12\4\47\0\2\2\1\0\1\2\2\0\2\2\1\0\1\2\2\0"+ "\1\2\6\0\4\2\1\0\7\2\1\0\3\2\1\0\1\2\1\0"+ "\1\2\2\0\2\2\1\0\4\2\1\4\2\2\6\4\1\0\2\4"+ "\1\2\2\0\5\2\1\0\1\2\1\0\6\4\2\0\12\4\2\0"+ "\2\2\42\0\1\2\27\0\2\4\6\0\12\4\13\0\1\4\1\0"+ "\1\4\1\0\1\4\4\0\2\4\10\2\1\0\42\2\6\0\24\4"+ "\1\0\2\4\4\2\4\0\10\4\1\0\44\4\11\0\1\4\71\0"+ "\42\2\1\0\5\2\1\0\2\2\1\0\7\4\3\0\4\4\6\0"+ "\12\4\6\0\6\2\4\4\106\0\46\2\12\0\51\2\7\0\132\2"+ "\5\0\104\2\5\0\122\2\6\0\7\2\1\0\77\2\1\0\1\2"+ "\1\0\4\2\2\0\7\2\1\0\1\2\1\0\4\2\2\0\47\2"+ "\1\0\1\2\1\0\4\2\2\0\37\2\1\0\1\2\1\0\4\2"+ "\2\0\7\2\1\0\1\2\1\0\4\2\2\0\7\2\1\0\7\2"+ "\1\0\27\2\1\0\37\2\1\0\1\2\1\0\4\2\2\0\7\2"+ "\1\0\47\2\1\0\23\2\16\0\11\4\56\0\125\2\14\0\u026c\2"+ "\2\0\10\2\12\0\32\2\5\0\113\2\3\0\3\2\17\0\15\2"+ "\1\0\4\2\3\4\13\0\22\2\3\4\13\0\22\2\2\4\14\0"+ "\15\2\1\0\3\2\1\0\2\4\14\0\64\2\40\4\3\0\1\2"+ "\3\0\2\2\1\4\2\0\12\4\41\0\3\4\2\0\12\4\6\0"+ "\130\2\10\0\51\2\1\4\126\0\35\2\3\0\14\4\4\0\14\4"+ "\12\0\12\4\36\2\2\0\5\2\u038b\0\154\2\224\0\234\2\4\0"+ "\132\2\6\0\26\2\2\0\6\2\2\0\46\2\2\0\6\2\2\0"+ "\10\2\1\0\1\2\1\0\1\2\1\0\1\2\1\0\37\2\2\0"+ "\65\2\1\0\7\2\1\0\1\2\3\0\3\2\1\0\7\2\3\0"+ "\4\2\2\0\6\2\4\0\15\2\5\0\3\2\1\0\7\2\17\0"+ "\4\4\32\0\5\4\20\0\2\2\23\0\1\2\13\0\4\4\6\0"+ "\6\4\1\0\1\2\15\0\1\2\40\0\22\2\36\0\15\4\4\0"+ "\1\4\3\0\6\4\27\0\1\2\4\0\1\2\2\0\12\2\1\0"+ "\1\2\3\0\5\2\6\0\1\2\1\0\1\2\1\0\1\2\1\0"+ "\4\2\1\0\3\2\1\0\7\2\3\0\3\2\5\0\5\2\26\0"+ "\44\2\u0e81\0\3\2\31\0\11\2\6\4\1\0\5\2\2\0\5\2"+ "\4\0\126\2\2\0\2\4\2\0\3\2\1\0\137\2\5\0\50\2"+ "\4\0\136\2\21\0\30\2\70\0\20\2\u0200\0\u19b6\2\112\0\u51a6\2"+ "\132\0\u048d\2\u0773\0\u2ba4\2\u215c\0\u012e\2\2\0\73\2\225\0\7\2"+ "\14\0\5\2\5\0\1\2\1\4\12\2\1\0\15\2\1\0\5\2"+ "\1\0\1\2\1\0\2\2\1\0\2\2\1\0\154\2\41\0\u016b\2"+ "\22\0\100\2\2\0\66\2\50\0\15\2\3\0\20\4\20\0\4\4"+ "\17\0\2\2\30\0\3\2\31\0\1\2\6\0\5\2\1\0\207\2"+ "\2\0\1\4\4\0\1\2\13\0\12\4\7\0\32\2\4\0\1\2"+ "\1\0\32\2\12\0\132\2\3\0\6\2\2\0\6\2\2\0\6\2"+ "\2\0\3\2\3\0\2\2\3\0\2\2\22\0\3\4\4\0"; /** * Translates characters to character classes */ private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); /** * Translates DFA states to action switch labels. */ private static final int [] ZZ_ACTION = zzUnpackAction(); private static final String ZZ_ACTION_PACKED_0 = "\2\0\1\1\1\2\1\1\1\3\1\1\1\4\16\1"+ "\1\3\1\4\1\1\1\5\2\1\1\2\1\0\12\1"+ "\1\6\7\1\1\0\1\2\3\0\1\7\3\0\1\10"+ "\1\2\1\0\1\2\16\1\1\0\5\1\1\2\10\1"; private static int [] zzUnpackAction() { int [] result = new int[90]; int offset = 0; offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); return result; } private static int zzUnpackAction(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); do result[j++] = value; while (--count > 0); } return j; } /** * Translates a state to a row index in the transition table */ private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); private static final String ZZ_ROWMAP_PACKED_0 = "\0\0\0\43\0\106\0\151\0\214\0\257\0\322\0\106"+ "\0\365\0\u0118\0\u013b\0\u015e\0\u0181\0\u01a4\0\u01c7\0\u01ea"+ "\0\u020d\0\u0230\0\u0253\0\u0276\0\u0299\0\u02bc\0\106\0\u02df"+ "\0\u0302\0\106\0\u0325\0\u0348\0\u036b\0\u038e\0\u03b1\0\u03d4"+ "\0\u03f7\0\u041a\0\u043d\0\u0460\0\u0483\0\u04a6\0\u04c9\0\u04ec"+ "\0\214\0\u050f\0\u0532\0\u0555\0\u0578\0\u059b\0\u05be\0\u05e1"+ "\0\u0299\0\106\0\u0604\0\u02bc\0\u0627\0\u064a\0\u066d\0\u0302"+ "\0\u0325\0\106\0\u0690\0\u0690\0\u06b3\0\u06d6\0\u06f9\0\u071c"+ "\0\u073f\0\u0762\0\u0785\0\u07a8\0\u07cb\0\u07ee\0\u0811\0\u0834"+ "\0\u0857\0\u087a\0\u089d\0\u08c0\0\u08e3\0\u0906\0\u0929\0\u094c"+ "\0\u096f\0\214\0\u0992\0\u09b5\0\u09d8\0\u09fb\0\u0a1e\0\u0a41"+ "\0\u0a64\0\u0a87"; private static int [] zzUnpackRowMap() { int [] result = new int[90]; int offset = 0; offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); return result; } private static int zzUnpackRowMap(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int high = packed.charAt(i++) << 16; result[j++] = high | packed.charAt(i++); } return j; } /** * The transition table of the DFA */ private static final int [] ZZ_TRANS = zzUnpackTrans(); private static final String ZZ_TRANS_PACKED_0 = "\1\3\1\4\2\5\1\3\1\6\1\7\1\5\1\10"+ "\1\11\1\12\2\5\1\13\1\14\1\5\1\15\1\16"+ "\1\17\1\5\1\20\1\5\1\21\1\22\1\23\1\5"+ "\1\24\1\25\2\3\1\26\1\27\2\10\1\30\34\31"+ "\1\32\4\31\1\33\1\31\44\0\1\4\1\0\1\34"+ "\1\0\1\35\1\36\1\37\34\0\4\5\1\0\2\5"+ "\1\0\22\5\11\0\1\35\42\0\4\5\1\0\2\5"+ "\1\0\14\5\1\40\5\5\11\0\4\5\1\0\2\5"+ "\1\0\1\5\1\41\20\5\11\0\4\5\1\0\1\42"+ "\1\5\1\0\22\5\11\0\4\5\1\0\2\5\1\0"+ "\2\5\1\40\3\5\1\43\13\5\11\0\4\5\1\0"+ "\2\5\1\0\16\5\1\44\3\5\11\0\4\5\1\0"+ "\1\45\1\5\1\0\12\5\1\46\7\5\11\0\4\5"+ "\1\0\2\5\1\0\1\5\1\47\16\5\1\50\1\5"+ "\11\0\4\5\1\0\2\5\1\0\7\5\1\51\5\5"+ "\1\51\4\5\11\0\4\5\1\0\1\52\1\5\1\0"+ "\6\5\1\51\13\5\11\0\4\5\1\0\2\5\1\0"+ "\2\5\1\53\3\5\1\54\3\5\1\55\7\5\11\0"+ "\4\5\1\0\2\5\1\0\11\5\1\56\6\5\1\57"+ "\1\5\11\0\4\5\1\0\2\5\1\0\6\5\1\60"+ "\13\5\11\0\4\5\1\0\2\5\1\0\2\5\1\54"+ "\17\5\10\0\33\61\2\62\1\63\5\61\34\64\1\62"+ "\1\65\1\62\4\64\41\0\1\66\1\67\34\70\1\32"+ "\4\70\1\71\35\70\1\32\4\70\1\71\1\72\1\0"+ "\1\34\1\0\1\34\3\0\1\34\34\0\1\35\4\0"+ "\2\36\34\0\1\73\6\0\1\74\33\0\1\75\1\0"+ "\1\34\3\0\1\34\1\74\33\0\4\5\1\0\2\5"+ "\1\0\5\5\1\76\14\5\11\0\4\5\1\0\1\77"+ "\1\5\1\0\22\5\11\0\4\5\1\0\2\5\1\0"+ "\10\5\1\100\11\5\11\0\4\5\1\0\2\5\1\0"+ "\7\5\1\101\12\5\11\0\4\5\1\0\2\5\1\0"+ "\11\5\1\102\10\5\11\0\4\5\1\0\2\5\1\0"+ "\16\5\1\51\3\5\11\0\4\5\1\0\2\5\1\0"+ "\14\5\1\103\5\5\11\0\4\5\1\0\2\5\1\0"+ "\12\5\1\104\7\5\11\0\4\5\1\0\2\5\1\0"+ "\11\5\1\105\10\5\11\0\4\5\1\0\2\5\1\0"+ "\15\5\1\106\4\5\11\0\4\5\1\0\2\5\1\0"+ "\14\5\1\107\5\5\11\0\4\5\1\0\2\5\1\0"+ "\1\5\1\51\20\5\11\0\4\5\1\0\2\5\1\0"+ "\7\5\1\110\12\5\11\0\4\5\1\0\2\5\1\0"+ "\10\5\1\111\11\5\11\0\4\5\1\0\2\5\1\0"+ "\11\5\1\112\10\5\11\0\4\5\1\0\2\5\1\0"+ "\10\5\1\113\11\5\10\0\34\61\1\62\6\61\34\64"+ "\1\62\6\64\41\0\1\114\1\0\34\67\1\32\6\67"+ "\1\0\1\73\42\0\1\75\1\0\1\34\3\0\1\34"+ "\34\0\4\5\1\0\1\51\1\5\1\0\22\5\11\0"+ "\4\5\1\0\2\5\1\0\2\5\1\115\17\5\11\0"+ "\4\5\1\0\2\5\1\0\12\5\1\116\7\5\11\0"+ "\4\5\1\0\2\5\1\0\5\5\1\117\2\5\1\120"+ "\11\5\11\0\4\5\1\0\2\5\1\0\10\5\1\121"+ "\11\5\11\0\4\5\1\0\2\5\1\0\14\5\1\122"+ "\5\5\11\0\4\5\1\0\1\122\1\5\1\0\22\5"+ "\11\0\4\5\1\0\2\5\1\0\5\5\1\51\14\5"+ "\11\0\4\5\1\0\2\5\1\0\2\5\1\123\17\5"+ "\11\0\4\5\1\0\2\5\1\0\5\5\1\104\14\5"+ "\11\0\4\5\1\0\2\5\1\0\4\5\1\124\15\5"+ "\11\0\4\5\1\0\2\5\1\0\20\5\1\51\1\5"+ "\11\0\4\5\1\0\2\5\1\0\14\5\1\76\5\5"+ "\11\0\4\5\1\0\2\5\1\0\6\5\1\51\13\5"+ "\52\0\1\32\1\0\4\5\1\0\2\5\1\0\3\5"+ "\1\51\16\5\11\0\4\5\1\0\2\5\1\0\1\5"+ "\1\125\20\5\11\0\4\5\1\0\2\5\1\0\10\5"+ "\1\51\11\5\11\0\4\5\1\0\2\5\1\0\11\5"+ "\1\126\10\5\11\0\4\5\1\0\2\5\1\0\4\5"+ "\1\111\15\5\11\0\4\5\1\0\2\5\1\0\12\5"+ "\1\127\7\5\11\0\4\5\1\0\2\5\1\0\10\5"+ "\1\130\11\5\11\0\4\5\1\0\2\5\1\0\7\5"+ "\1\51\12\5\11\0\4\5\1\0\2\5\1\0\7\5"+ "\1\131\12\5\11\0\4\5\1\0\2\5\1\0\14\5"+ "\1\117\5\5\11\0\4\5\1\0\2\5\1\0\11\5"+ "\1\132\10\5\11\0\4\5\1\0\2\5\1\0\12\5"+ "\1\76\7\5\11\0\4\5\1\0\2\5\1\0\6\5"+ "\1\125\13\5\10\0"; private static int [] zzUnpackTrans() { int [] result = new int[2730]; int offset = 0; offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); return result; } private static int zzUnpackTrans(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); value--; do result[j++] = value; while (--count > 0); } return j; } /* error codes */ private static final int ZZ_UNKNOWN_ERROR = 0; private static final int ZZ_NO_MATCH = 1; private static final int ZZ_PUSHBACK_2BIG = 2; /* error messages for the codes above */ private static final String ZZ_ERROR_MSG[] = { "Unkown internal scanner error", "Error: could not match input", "Error: pushback value was too large" }; /** * ZZ_ATTRIBUTE[aState] contains the attributes of state aState */ private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); private static final String ZZ_ATTRIBUTE_PACKED_0 = "\2\0\1\11\4\1\1\11\16\1\1\11\2\1\1\11"+ "\3\1\1\0\22\1\1\0\1\11\3\0\1\1\3\0"+ "\1\11\1\1\1\0\17\1\1\0\16\1"; private static int [] zzUnpackAttribute() { int [] result = new int[90]; int offset = 0; offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); return result; } private static int zzUnpackAttribute(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); do result[j++] = value; while (--count > 0); } return j; } /** the input device */ private java.io.Reader zzReader; /** the current state of the DFA */ private int zzState; /** the current lexical state */ private int zzLexicalState = YYINITIAL; /** this buffer contains the current text to be matched and is the source of the yytext() string */ private char zzBuffer[] = new char[ZZ_BUFFERSIZE]; /** the textposition at the last accepting state */ private int zzMarkedPos; /** the textposition at the last state to be included in yytext */ private int zzPushbackPos; /** the current text position in the buffer */ private int zzCurrentPos; /** startRead marks the beginning of the yytext() string in the buffer */ private int zzStartRead; /** endRead marks the last character in the buffer, that has been read from input */ private int zzEndRead; /** number of newlines encountered up to the start of the matched text */ private int yyline; /** the number of characters up to the start of the matched text */ private int yychar; /** * the number of characters from the last newline up to the start of the * matched text */ private int yycolumn; /** * zzAtBOL == true <=> the scanner is currently at the beginning of a line */ private boolean zzAtBOL = true; /** zzAtEOF == true <=> the scanner is at the EOF */ private boolean zzAtEOF; /* user code: */ /* styles */ public static final byte PLAIN_STYLE = 1; public static final byte KEYWORD_STYLE = 2; public static final byte OPERATOR_STYLE = 3; public static final byte SEPARATOR_STYLE = 4; public static final byte LITERAL_STYLE = 5; public static final byte JAVA_COMMENT_STYLE = 6; /* Highlighter implementation */ public int getStyleCount() { return 6; } public byte getStartState() { return YYINITIAL+1; } public byte getCurrentState() { return (byte) (yystate()+1); } public void setState(byte newState) { yybegin(newState-1); } public byte getNextToken() throws IOException { return (byte) yylex(); } public int getTokenLength() { return yylength(); } public void setReader(Reader r) { this.zzReader = r; } public JavaScriptHighlighter() { } /** * Creates a new scanner * There is also a java.io.InputStream version of this constructor. * * @param in the java.io.Reader to read input from. */ public JavaScriptHighlighter(java.io.Reader in) { this.zzReader = in; } /** * Creates a new scanner. * There is also java.io.Reader version of this constructor. * * @param in the java.io.Inputstream to read input from. */ public JavaScriptHighlighter(java.io.InputStream in) { this(new java.io.InputStreamReader(in)); } /** * Unpacks the compressed character translation table. * * @param packed the packed character translation table * @return the unpacked character translation table */ private static char [] zzUnpackCMap(String packed) { char [] map = new char[0x10000]; int i = 0; /* index in packed string */ int j = 0; /* index in unpacked array */ while (i < 1758) { int count = packed.charAt(i++); char value = packed.charAt(i++); do map[j++] = value; while (--count > 0); } return map; } /** * Refills the input buffer. * * @return false, iff there was new input. * * @exception java.io.IOException if any I/O-Error occurs */ private boolean zzRefill() throws java.io.IOException { /* first: make room (if you can) */ if (zzStartRead > 0) { System.arraycopy(zzBuffer, zzStartRead, zzBuffer, 0, zzEndRead-zzStartRead); /* translate stored positions */ zzEndRead-= zzStartRead; zzCurrentPos-= zzStartRead; zzMarkedPos-= zzStartRead; zzPushbackPos-= zzStartRead; zzStartRead = 0; } /* is the buffer big enough? */ if (zzCurrentPos >= zzBuffer.length) { /* if not: blow it up */ char newBuffer[] = new char[zzCurrentPos*2]; System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length); zzBuffer = newBuffer; } /* finally: fill the buffer with new input */ int numRead = zzReader.read(zzBuffer, zzEndRead, zzBuffer.length-zzEndRead); if (numRead < 0) { return true; } else { zzEndRead+= numRead; return false; } } /** * Closes the input stream. */ public final void yyclose() throws java.io.IOException { zzAtEOF = true; /* indicate end of file */ zzEndRead = zzStartRead; /* invalidate buffer */ if (zzReader != null) zzReader.close(); } /** * Resets the scanner to read from a new input stream. * Does not close the old reader. * * All internal variables are reset, the old input stream * cannot be reused (internal buffer is discarded and lost). * Lexical state is set to ZZ_INITIAL. * * @param reader the new input stream */ public final void yyreset(java.io.Reader reader) { zzReader = reader; zzAtBOL = true; zzAtEOF = false; zzEndRead = zzStartRead = 0; zzCurrentPos = zzMarkedPos = zzPushbackPos = 0; yyline = yychar = yycolumn = 0; zzLexicalState = YYINITIAL; } /** * Returns the current lexical state. */ public final int yystate() { return zzLexicalState; } /** * Enters a new lexical state * * @param newState the new lexical state */ public final void yybegin(int newState) { zzLexicalState = newState; } /** * Returns the text matched by the current regular expression. */ public final String yytext() { return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead ); } /** * Returns the character at position pos from the * matched text. * * It is equivalent to yytext().charAt(pos), but faster * * @param pos the position of the character to fetch. * A value from 0 to yylength()-1. * * @return the character at position pos */ public final char yycharat(int pos) { return zzBuffer[zzStartRead+pos]; } /** * Returns the length of the matched text region. */ public final int yylength() { return zzMarkedPos-zzStartRead; } /** * Reports an error that occured while scanning. * * In a wellformed scanner (no or only correct usage of * yypushback(int) and a match-all fallback rule) this method * will only be called with things that "Can't Possibly Happen". * If this method is called, something is seriously wrong * (e.g. a JFlex bug producing a faulty scanner etc.). * * Usual syntax/scanner level error handling should be done * in error fallback rules. * * @param errorCode the code of the errormessage to display */ private void zzScanError(int errorCode) { String message; try { message = ZZ_ERROR_MSG[errorCode]; } catch (ArrayIndexOutOfBoundsException e) { message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; } throw new Error(message); } /** * Pushes the specified amount of characters back into the input stream. * * They will be read again by then next call of the scanning method * * @param number the number of characters to be read again. * This number must not be greater than yylength()! */ public void yypushback(int number) { if ( number > yylength() ) zzScanError(ZZ_PUSHBACK_2BIG); zzMarkedPos -= number; } /** * Resumes scanning until the next regular expression is matched, * the end of input is encountered or an I/O-Error occurs. * * @return the next token * @exception java.io.IOException if any I/O-Error occurs */ public int yylex() throws java.io.IOException { int zzInput; int zzAction; // cached fields: int zzCurrentPosL; int zzMarkedPosL; int zzEndReadL = zzEndRead; char [] zzBufferL = zzBuffer; char [] zzCMapL = ZZ_CMAP; int [] zzTransL = ZZ_TRANS; int [] zzRowMapL = ZZ_ROWMAP; int [] zzAttrL = ZZ_ATTRIBUTE; while (true) { zzMarkedPosL = zzMarkedPos; zzAction = -1; zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; zzState = zzLexicalState; zzForAction: { while (true) { if (zzCurrentPosL < zzEndReadL) zzInput = zzBufferL[zzCurrentPosL++]; else if (zzAtEOF) { zzInput = YYEOF; break zzForAction; } else { // store back cached positions zzCurrentPos = zzCurrentPosL; zzMarkedPos = zzMarkedPosL; boolean eof = zzRefill(); // get translated positions and possibly new buffer zzCurrentPosL = zzCurrentPos; zzMarkedPosL = zzMarkedPos; zzBufferL = zzBuffer; zzEndReadL = zzEndRead; if (eof) { zzInput = YYEOF; break zzForAction; } else { zzInput = zzBufferL[zzCurrentPosL++]; } } int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ]; if (zzNext == -1) break zzForAction; zzState = zzNext; int zzAttributes = zzAttrL[zzState]; if ( (zzAttributes & 1) == 1 ) { zzAction = zzState; zzMarkedPosL = zzCurrentPosL; if ( (zzAttributes & 8) == 8 ) break zzForAction; } } } // store back cached position zzMarkedPos = zzMarkedPosL; switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { case 1: { return PLAIN_STYLE; } case 9: break; case 8: { yybegin(YYINITIAL); return JAVA_COMMENT_STYLE; } case 10: break; case 4: { return OPERATOR_STYLE; } case 11: break; case 5: { return JAVA_COMMENT_STYLE; } case 12: break; case 3: { return SEPARATOR_STYLE; } case 13: break; case 7: { yybegin(IN_COMMENT); return JAVA_COMMENT_STYLE; } case 14: break; case 6: { return KEYWORD_STYLE; } case 15: break; case 2: { return LITERAL_STYLE; } case 16: break; default: if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { zzAtEOF = true; return YYEOF; } else { zzScanError(ZZ_NO_MATCH); } } } } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/highlighter/XmlHighlighter.flex000066400000000000000000000204621422762524200332100ustar00rootroot00000000000000/* * Copyright 2000-2006 Omnicore Software, Hans Kratz & Dennis Strein GbR, * Geert Bevin . * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id$ */ package org.codelibs.jhighlight.highlighter; import java.io.Reader; import java.io.IOException; %% %class XmlHighlighter %implements ExplicitStateHighlighter %unicode %pack %buffer 128 %public %int %{ /* styles */ public static final byte PLAIN_STYLE = 1; public static final byte CHAR_DATA = 2; public static final byte TAG_SYMBOLS = 3; public static final byte COMMENT = 4; public static final byte ATTRIBUTE_VALUE = 5; public static final byte ATTRIBUTE_NAME = 6; public static final byte PROCESSING_INSTRUCTION = 7; public static final byte TAG_NAME = 8; public static final byte RIFE_TAG = 9; public static final byte RIFE_NAME = 10; /* Highlighter implementation */ public int getStyleCount() { return 10; } public byte getStartState() { return YYINITIAL+1; } public byte getCurrentState() { return (byte) (yystate()+1); } public void setState(byte newState) { yybegin(newState-1); } public byte getNextToken() { try { return (byte) yylex(); } catch (IOException e) { throw new InternalError(); } } public int getTokenLength() { return yylength(); } public void setReader(Reader r) { this.zzReader = r; } public XmlHighlighter() { } private int mReturningState; private int mReturningStateTag; %} /* main character classes */ WhiteSpace = [ \t\f] WhiteSpaceNewline = [ \t\f\n\r] /* identifiers */ Letter = ([:jletterdigit:]|"."|"-"|"_"|":") Name = ([:jletter:]|"_"|":") {Letter}* RifeBeginStartComment = ("") RifeEndComment = ("") RifeBeginStartCompact = ("[!"{WhiteSpaceNewline}*("V"|"B"|"BV"|"I"){WhiteSpace}) RifeBeginStopCompact = ("]") RifeEndCompact = ("[!/"{WhiteSpaceNewline}*("V"|"B"|"BV"){WhiteSpaceNewline}*"]") RifeBeginStartVelocity = ("${"{WhiteSpaceNewline}*("v"|"b"|"bv"|"i"){WhiteSpace}) RifeBeginStopVelocity = ("/"? "}") RifeEndVelocity = ("${/"{WhiteSpaceNewline}*("v"|"b"|"bv"){WhiteSpaceNewline}*"}") RifeBeginStartRegular = ("") RifeEndRegular = ("") %state IN_RIFE_TAG_COMMENT, IN_RIFE_TAG_COMPACT, IN_RIFE_TAG_VELOCITY, IN_RIFE_TAG_REGULAR, IN_RIFE_NAME_SINGLEQUOTED, IN_RIFE_NAME_QUOTED, IN_RIFE_NAME, IN_COMMENT, TAG_START, IN_TAG, IN_SINGLE_QUOTE_STRING, IN_DOUBLE_QUOTE_STRING, IN_PROCESSING_INSTRUCTION, IN_CDATA_SECTION %% { // tokens... "<" { yybegin(TAG_START); return TAG_SYMBOLS; } " { {Name} { yybegin(IN_TAG); return TAG_NAME; } ">" { yybegin(YYINITIAL); return TAG_SYMBOLS; } . { yybegin(IN_TAG); return PLAIN_STYLE; } } { {RifeBeginStartComment} { mReturningState = yystate(); yybegin(IN_RIFE_TAG_COMMENT); return RIFE_TAG; } {RifeEndComment} { return RIFE_TAG; } {RifeBeginStartCompact} { mReturningState = yystate(); yybegin(IN_RIFE_TAG_COMPACT); return RIFE_TAG; } {RifeEndCompact} { return RIFE_TAG; } {RifeBeginStartVelocity} { mReturningState = yystate(); yybegin(IN_RIFE_TAG_VELOCITY); return RIFE_TAG; } {RifeEndVelocity} { return RIFE_TAG; } {RifeBeginStartRegular} { mReturningState = yystate(); yybegin(IN_RIFE_TAG_REGULAR); return RIFE_TAG; } {RifeEndRegular} { return RIFE_TAG; } "/>" { yybegin(YYINITIAL); return TAG_SYMBOLS; } ">" { yybegin(YYINITIAL); return TAG_SYMBOLS; } "=" { return TAG_SYMBOLS; } {Name} { return ATTRIBUTE_NAME; } "\'" { yybegin(IN_SINGLE_QUOTE_STRING); return ATTRIBUTE_VALUE; } "\"" { yybegin(IN_DOUBLE_QUOTE_STRING); return ATTRIBUTE_VALUE; } . { return PLAIN_STYLE; } } { {RifeBeginStartComment} { mReturningState = yystate(); yybegin(IN_RIFE_TAG_COMMENT); return RIFE_TAG; } {RifeEndComment} { return RIFE_TAG; } {RifeBeginStartCompact} { mReturningState = yystate(); yybegin(IN_RIFE_TAG_COMPACT); return RIFE_TAG; } {RifeEndCompact} { return RIFE_TAG; } {RifeBeginStartVelocity} { mReturningState = yystate(); yybegin(IN_RIFE_TAG_VELOCITY); return RIFE_TAG; } {RifeEndVelocity} { return RIFE_TAG; } {RifeBeginStartRegular} { mReturningState = yystate(); yybegin(IN_RIFE_TAG_REGULAR); return RIFE_TAG; } {RifeEndRegular} { return RIFE_TAG; } [^\'\n\[\]<>{}]* { return ATTRIBUTE_VALUE; } \[ { return ATTRIBUTE_VALUE; } \] { return ATTRIBUTE_VALUE; } \{ { return ATTRIBUTE_VALUE; } \} { return ATTRIBUTE_VALUE; } \n { return ATTRIBUTE_VALUE; } \' { yybegin(IN_TAG); return ATTRIBUTE_VALUE; } . { yybegin(IN_TAG); return TAG_SYMBOLS; } } { {RifeBeginStartComment} { mReturningState = yystate(); yybegin(IN_RIFE_TAG_COMMENT); return RIFE_TAG; } {RifeEndComment} { return RIFE_TAG; } {RifeBeginStartCompact} { mReturningState = yystate(); yybegin(IN_RIFE_TAG_COMPACT); return RIFE_TAG; } {RifeEndCompact} { return RIFE_TAG; } {RifeBeginStartVelocity} { mReturningState = yystate(); yybegin(IN_RIFE_TAG_VELOCITY); return RIFE_TAG; } {RifeEndVelocity} { return RIFE_TAG; } {RifeBeginStartRegular} { mReturningState = yystate(); yybegin(IN_RIFE_TAG_REGULAR); return RIFE_TAG; } {RifeEndRegular} { return RIFE_TAG; } [^\"\n\[\]<>{}]* { return ATTRIBUTE_VALUE; } \[ { return ATTRIBUTE_VALUE; } \] { return ATTRIBUTE_VALUE; } \{ { return ATTRIBUTE_VALUE; } \} { return ATTRIBUTE_VALUE; } \n { return ATTRIBUTE_VALUE; } \" { yybegin(IN_TAG); return ATTRIBUTE_VALUE; } . { yybegin(IN_TAG); return TAG_SYMBOLS; } } { ([^?\n]| "?"+ [^>?\n])* (\n | "?"\n) { return PROCESSING_INSTRUCTION; } ([^?\n]| "?"+ [^>?\n])* "?"+ ">" { yybegin(YYINITIAL); return PROCESSING_INSTRUCTION; } } { [^\]\n]* { return CHAR_DATA; } "]]>" { yybegin(YYINITIAL); return CHAR_DATA; } . { return CHAR_DATA; } } { [^\-\n]* { return COMMENT; } "-->" { yybegin(YYINITIAL); return COMMENT; } . { return COMMENT; } } { [^\-\>\']* { return RIFE_TAG; } {RifeBeginStopComment} { yybegin(mReturningState); return RIFE_TAG; } "\'" { mReturningStateTag = yystate(); yybegin(IN_RIFE_NAME_SINGLEQUOTED); return RIFE_NAME; } . { return RIFE_TAG; } } { [^\]\']* { return RIFE_TAG; } {RifeBeginStopCompact} { yybegin(mReturningState); return RIFE_TAG; } "\'" { mReturningStateTag = yystate(); yybegin(IN_RIFE_NAME_SINGLEQUOTED); return RIFE_NAME; } . { return RIFE_TAG; } } { {RifeBeginStopVelocity} { yybegin(mReturningState); return RIFE_TAG; } [^\s\t\}]* { mReturningStateTag = yystate(); yybegin(IN_RIFE_NAME); return RIFE_NAME; } . { return RIFE_TAG; } } { [^\>\"]* { return RIFE_TAG; } {RifeBeginStopRegular} { yybegin(mReturningState); return RIFE_TAG; } "\"" { mReturningStateTag = yystate(); yybegin(IN_RIFE_NAME_QUOTED); return RIFE_NAME; } . { return RIFE_TAG; } } { \' { yybegin(mReturningStateTag); return RIFE_NAME; } . { return RIFE_NAME; } } { \" { yybegin(mReturningStateTag); return RIFE_NAME; } . { return RIFE_NAME; } } { {RifeBeginStopVelocity} { yybegin(mReturningState); return RIFE_TAG; } . { return RIFE_NAME; } } /* error fallback */ .|\n { return PLAIN_STYLE; } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/highlighter/XmlHighlighter.java000066400000000000000000000703271422762524200332000ustar00rootroot00000000000000/* The following code was generated by JFlex 1.4.1 on 8/2/06 6:03 AM */ /* * Copyright 2000-2006 Omnicore Software, Hans Kratz & Dennis Strein GbR, * Geert Bevin . * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: XmlHighlighter.java 3431 2006-08-02 04:09:28Z gbevin $ */ package org.codelibs.jhighlight.highlighter; import java.io.IOException; import java.io.Reader; /** * This class is a scanner generated by * JFlex 1.4.1 * on 8/2/06 6:03 AM from the specification file * com/uwyn/jhighlight/highlighter/XmlHighlighter.flex */ public class XmlHighlighter implements ExplicitStateHighlighter { /** This character denotes the end of file */ public static final int YYEOF = -1; /** initial size of the lookahead buffer */ private static final int ZZ_BUFFERSIZE = 128; /** lexical states */ public static final int TAG_START = 9; public static final int IN_CDATA_SECTION = 14; public static final int IN_RIFE_NAME_QUOTED = 6; public static final int IN_SINGLE_QUOTE_STRING = 11; public static final int IN_RIFE_TAG_REGULAR = 4; public static final int IN_PROCESSING_INSTRUCTION = 13; public static final int IN_DOUBLE_QUOTE_STRING = 12; public static final int IN_RIFE_NAME = 7; public static final int IN_TAG = 10; public static final int IN_RIFE_NAME_SINGLEQUOTED = 5; public static final int IN_RIFE_TAG_VELOCITY = 3; public static final int IN_COMMENT = 8; public static final int YYINITIAL = 0; public static final int IN_RIFE_TAG_COMMENT = 1; public static final int IN_RIFE_TAG_COMPACT = 2; /** * Translates characters to character classes */ private static final String ZZ_CMAP_PACKED = "\11\3\1\40\1\34\1\0\1\1\1\2\16\3\4\0\1\1\1\10"+ "\1\37\1\0\1\20\2\0\1\36\5\0\1\4\1\3\1\15\12\3"+ "\1\6\1\0\1\7\1\35\1\14\1\27\1\0\1\32\1\12\1\30"+ "\1\31\4\5\1\13\12\5\1\33\1\5\1\11\4\5\1\16\1\0"+ "\1\17\1\0\1\5\1\0\1\5\1\23\6\5\1\24\10\5\1\26"+ "\1\41\2\5\1\22\4\5\1\21\1\0\1\25\1\0\41\3\2\0"+ "\4\5\4\0\1\5\2\0\1\3\7\0\1\5\4\0\1\5\5\0"+ "\27\5\1\0\37\5\1\0\u013f\5\31\0\162\5\4\0\14\5\16\0"+ "\5\5\11\0\1\5\21\0\130\3\5\0\23\3\12\0\1\5\13\0"+ "\1\5\1\0\3\5\1\0\1\5\1\0\24\5\1\0\54\5\1\0"+ "\46\5\1\0\5\5\4\0\202\5\1\0\4\3\3\0\105\5\1\0"+ "\46\5\2\0\2\5\6\0\20\5\41\0\46\5\2\0\1\5\7\0"+ "\47\5\11\0\21\3\1\0\27\3\1\0\3\3\1\0\1\3\1\0"+ "\2\3\1\0\1\3\13\0\33\5\5\0\3\5\15\0\4\3\14\0"+ "\6\3\13\0\32\5\5\0\13\5\16\3\7\0\12\3\4\0\2\5"+ "\1\3\143\5\1\0\1\5\10\3\1\0\6\3\2\5\2\3\1\0"+ "\4\3\2\5\12\3\3\5\2\0\1\5\17\0\1\3\1\5\1\3"+ "\36\5\33\3\2\0\3\5\60\0\46\5\13\3\1\5\u014f\0\3\3"+ "\66\5\2\0\1\3\1\5\20\3\2\0\1\5\4\3\3\0\12\5"+ "\2\3\2\0\12\3\21\0\3\3\1\0\10\5\2\0\2\5\2\0"+ "\26\5\1\0\7\5\1\0\1\5\3\0\4\5\2\0\1\3\1\5"+ "\7\3\2\0\2\3\2\0\3\3\11\0\1\3\4\0\2\5\1\0"+ "\3\5\2\3\2\0\12\3\4\5\15\0\3\3\1\0\6\5\4\0"+ "\2\5\2\0\26\5\1\0\7\5\1\0\2\5\1\0\2\5\1\0"+ "\2\5\2\0\1\3\1\0\5\3\4\0\2\3\2\0\3\3\13\0"+ "\4\5\1\0\1\5\7\0\14\3\3\5\14\0\3\3\1\0\11\5"+ "\1\0\3\5\1\0\26\5\1\0\7\5\1\0\2\5\1\0\5\5"+ "\2\0\1\3\1\5\10\3\1\0\3\3\1\0\3\3\2\0\1\5"+ "\17\0\2\5\2\3\2\0\12\3\1\0\1\5\17\0\3\3\1\0"+ "\10\5\2\0\2\5\2\0\26\5\1\0\7\5\1\0\2\5\1\0"+ "\5\5\2\0\1\3\1\5\6\3\3\0\2\3\2\0\3\3\10\0"+ "\2\3\4\0\2\5\1\0\3\5\4\0\12\3\1\0\1\5\20\0"+ "\1\3\1\5\1\0\6\5\3\0\3\5\1\0\4\5\3\0\2\5"+ "\1\0\1\5\1\0\2\5\3\0\2\5\3\0\3\5\3\0\10\5"+ "\1\0\3\5\4\0\5\3\3\0\3\3\1\0\4\3\11\0\1\3"+ "\17\0\11\3\11\0\1\5\7\0\3\3\1\0\10\5\1\0\3\5"+ "\1\0\27\5\1\0\12\5\1\0\5\5\4\0\7\3\1\0\3\3"+ "\1\0\4\3\7\0\2\3\11\0\2\5\4\0\12\3\22\0\2\3"+ "\1\0\10\5\1\0\3\5\1\0\27\5\1\0\12\5\1\0\5\5"+ "\2\0\1\3\1\5\7\3\1\0\3\3\1\0\4\3\7\0\2\3"+ "\7\0\1\5\1\0\2\5\4\0\12\3\22\0\2\3\1\0\10\5"+ "\1\0\3\5\1\0\27\5\1\0\20\5\4\0\6\3\2\0\3\3"+ "\1\0\4\3\11\0\1\3\10\0\2\5\4\0\12\3\22\0\2\3"+ "\1\0\22\5\3\0\30\5\1\0\11\5\1\0\1\5\2\0\7\5"+ "\3\0\1\3\4\0\6\3\1\0\1\3\1\0\10\3\22\0\2\3"+ "\15\0\60\5\1\3\2\5\7\3\4\0\10\5\10\3\1\0\12\3"+ "\47\0\2\5\1\0\1\5\2\0\2\5\1\0\1\5\2\0\1\5"+ "\6\0\4\5\1\0\7\5\1\0\3\5\1\0\1\5\1\0\1\5"+ "\2\0\2\5\1\0\4\5\1\3\2\5\6\3\1\0\2\3\1\5"+ "\2\0\5\5\1\0\1\5\1\0\6\3\2\0\12\3\2\0\2\5"+ "\42\0\1\5\27\0\2\3\6\0\12\3\13\0\1\3\1\0\1\3"+ "\1\0\1\3\4\0\2\3\10\5\1\0\42\5\6\0\24\3\1\0"+ "\2\3\4\5\4\0\10\3\1\0\44\3\11\0\1\3\71\0\42\5"+ "\1\0\5\5\1\0\2\5\1\0\7\3\3\0\4\3\6\0\12\3"+ "\6\0\6\5\4\3\106\0\46\5\12\0\51\5\7\0\132\5\5\0"+ "\104\5\5\0\122\5\6\0\7\5\1\0\77\5\1\0\1\5\1\0"+ "\4\5\2\0\7\5\1\0\1\5\1\0\4\5\2\0\47\5\1\0"+ "\1\5\1\0\4\5\2\0\37\5\1\0\1\5\1\0\4\5\2\0"+ "\7\5\1\0\1\5\1\0\4\5\2\0\7\5\1\0\7\5\1\0"+ "\27\5\1\0\37\5\1\0\1\5\1\0\4\5\2\0\7\5\1\0"+ "\47\5\1\0\23\5\16\0\11\3\56\0\125\5\14\0\u026c\5\2\0"+ "\10\5\12\0\32\5\5\0\113\5\3\0\3\5\17\0\15\5\1\0"+ "\4\5\3\3\13\0\22\5\3\3\13\0\22\5\2\3\14\0\15\5"+ "\1\0\3\5\1\0\2\3\14\0\64\5\40\3\3\0\1\5\3\0"+ "\2\5\1\3\2\0\12\3\41\0\3\3\2\0\12\3\6\0\130\5"+ "\10\0\51\5\1\3\126\0\35\5\3\0\14\3\4\0\14\3\12\0"+ "\12\3\36\5\2\0\5\5\u038b\0\154\5\224\0\234\5\4\0\132\5"+ "\6\0\26\5\2\0\6\5\2\0\46\5\2\0\6\5\2\0\10\5"+ "\1\0\1\5\1\0\1\5\1\0\1\5\1\0\37\5\2\0\65\5"+ "\1\0\7\5\1\0\1\5\3\0\3\5\1\0\7\5\3\0\4\5"+ "\2\0\6\5\4\0\15\5\5\0\3\5\1\0\7\5\17\0\4\3"+ "\32\0\5\3\20\0\2\5\23\0\1\5\13\0\4\3\6\0\6\3"+ "\1\0\1\5\15\0\1\5\40\0\22\5\36\0\15\3\4\0\1\3"+ "\3\0\6\3\27\0\1\5\4\0\1\5\2\0\12\5\1\0\1\5"+ "\3\0\5\5\6\0\1\5\1\0\1\5\1\0\1\5\1\0\4\5"+ "\1\0\3\5\1\0\7\5\3\0\3\5\5\0\5\5\26\0\44\5"+ "\u0e81\0\3\5\31\0\11\5\6\3\1\0\5\5\2\0\5\5\4\0"+ "\126\5\2\0\2\3\2\0\3\5\1\0\137\5\5\0\50\5\4\0"+ "\136\5\21\0\30\5\70\0\20\5\u0200\0\u19b6\5\112\0\u51a6\5\132\0"+ "\u048d\5\u0773\0\u2ba4\5\u215c\0\u012e\5\2\0\73\5\225\0\7\5\14\0"+ "\5\5\5\0\1\5\1\3\12\5\1\0\15\5\1\0\5\5\1\0"+ "\1\5\1\0\2\5\1\0\2\5\1\0\154\5\41\0\u016b\5\22\0"+ "\100\5\2\0\66\5\50\0\15\5\3\0\20\3\20\0\4\3\17\0"+ "\2\5\30\0\3\5\31\0\1\5\6\0\5\5\1\0\207\5\2\0"+ "\1\3\4\0\1\5\13\0\12\3\7\0\32\5\4\0\1\5\1\0"+ "\32\5\12\0\132\5\3\0\6\5\2\0\6\5\2\0\6\5\2\0"+ "\3\5\3\0\2\5\3\0\2\5\22\0\3\3\4\0"; /** * Translates characters to character classes */ private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); /** * Translates DFA states to action switch labels. */ private static final int [] ZZ_ACTION = zzUnpackAction(); private static final String ZZ_ACTION_PACKED_0 = "\1\1\2\2\1\3\1\2\3\0\1\4\2\0\2\5"+ "\1\0\1\6\2\1\1\7\2\1\3\2\1\10\1\2"+ "\1\11\2\3\1\2\1\12\1\13\1\14\1\13\2\4"+ "\1\15\1\16\1\17\1\20\2\1\1\20\1\21\1\22"+ "\1\23\1\5\2\24\3\5\1\25\2\5\2\1\1\26"+ "\2\6\1\0\1\7\1\0\1\27\10\0\1\30\16\0"+ "\1\31\1\0\1\32\1\33\4\0\1\34\4\0\1\35"+ "\10\0\1\36\1\37\7\0\1\40"; private static int [] zzUnpackAction() { int [] result = new int[118]; int offset = 0; offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); return result; } private static int zzUnpackAction(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); do result[j++] = value; while (--count > 0); } return j; } /** * Translates a state to a row index in the transition table */ private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); private static final String ZZ_ROWMAP_PACKED_0 = "\0\0\0\42\0\104\0\146\0\210\0\252\0\314\0\356"+ "\0\u0110\0\u0132\0\u0154\0\u0176\0\u0198\0\u01ba\0\u01dc\0\u01fe"+ "\0\u0220\0\u0242\0\u0264\0\u0286\0\u02a8\0\u02ca\0\u01fe\0\u01fe"+ "\0\u02ec\0\u01fe\0\u030e\0\u0330\0\u0352\0\u01fe\0\u01fe\0\u01fe"+ "\0\u0374\0\u0396\0\u03b8\0\u01fe\0\u03da\0\u01fe\0\u03fc\0\u041e"+ "\0\u0440\0\u0462\0\u01fe\0\u01fe\0\u01fe\0\u0484\0\u041e\0\u01fe"+ "\0\u0264\0\u01fe\0\u04a6\0\u01fe\0\u04c8\0\u04ea\0\u050c\0\u052e"+ "\0\u01fe\0\u0550\0\u0572\0\u0594\0\u05b6\0\u05d8\0\u01fe\0\u05fa"+ "\0\u061c\0\u063e\0\u0660\0\u0682\0\u05b6\0\u050c\0\u052e\0\u01fe"+ "\0\u06a4\0\u06c6\0\u06e8\0\u070a\0\u072c\0\u074e\0\u0770\0\u0792"+ "\0\u07b4\0\u07d6\0\u07f8\0\u081a\0\u083c\0\u085e\0\u01fe\0\u0880"+ "\0\u01fe\0\u08a2\0\u08c4\0\u08e6\0\u0908\0\u092a\0\u01fe\0\u094c"+ "\0\u096e\0\u0990\0\u09b2\0\u01fe\0\u08a2\0\u09d4\0\u09f6\0\u0a18"+ "\0\u0a3a\0\u0a5c\0\u0a7e\0\u0aa0\0\u01fe\0\u01fe\0\u0ac2\0\u0ae4"+ "\0\u0b06\0\u0b28\0\u0b4a\0\u0b6c\0\u0b8e\0\u01fe"; private static int [] zzUnpackRowMap() { int [] result = new int[118]; int offset = 0; offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); return result; } private static int zzUnpackRowMap(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int high = packed.charAt(i++) << 16; result[j++] = high | packed.charAt(i++); } return j; } /** * The transition table of the DFA */ private static final int [] ZZ_TRANS = zzUnpackTrans(); private static final String ZZ_TRANS_PACKED_0 = "\1\20\1\21\5\20\1\22\6\20\1\23\1\20\1\24"+ "\17\20\1\21\1\20\4\25\1\26\7\25\1\27\21\25"+ "\1\30\3\25\17\31\1\32\16\31\1\30\3\31\15\33"+ "\1\34\7\33\1\32\12\33\2\27\14\35\1\32\22\35"+ "\1\36\2\35\34\37\1\20\1\37\1\40\37\37\1\20"+ "\2\37\1\40\17\37\1\41\7\37\1\32\6\37\1\20"+ "\5\37\4\42\1\43\27\42\1\20\5\42\5\44\2\45"+ "\2\44\3\45\1\46\3\44\1\45\1\44\3\45\1\44"+ "\1\45\1\44\4\45\1\20\4\44\1\45\5\20\2\47"+ "\1\50\1\20\3\47\1\46\1\51\1\23\1\20\1\52"+ "\1\20\3\47\1\20\1\47\1\20\4\47\1\20\1\53"+ "\1\54\1\55\1\20\1\47\7\56\1\57\4\56\1\60"+ "\1\56\1\61\1\62\1\63\1\62\3\56\1\62\6\56"+ "\1\62\1\56\1\64\3\56\7\65\1\57\4\65\1\60"+ "\1\65\1\61\1\62\1\66\1\62\3\65\1\62\6\65"+ "\1\62\2\65\1\64\2\65\27\67\1\70\4\67\1\71"+ "\5\67\17\72\1\73\14\72\1\20\5\72\43\0\1\21"+ "\36\0\1\21\11\0\1\74\4\0\1\75\10\0\1\76"+ "\1\77\22\0\1\100\52\0\1\101\20\0\4\25\1\0"+ "\7\25\1\0\21\25\1\0\3\25\4\0\1\102\35\0"+ "\17\31\1\0\16\31\1\0\3\31\25\33\1\0\12\33"+ "\2\0\25\33\1\32\12\33\2\0\14\35\1\0\22\35"+ "\1\0\2\35\25\0\1\32\14\0\4\42\1\0\27\42"+ "\1\0\5\42\4\0\1\103\40\0\4\45\2\0\3\45"+ "\4\0\1\45\1\0\3\45\1\0\1\45\1\0\4\45"+ "\5\0\1\45\3\0\4\47\2\0\3\47\4\0\1\47"+ "\1\0\3\47\1\0\1\47\1\0\4\47\5\0\1\47"+ "\10\0\1\104\4\0\1\105\10\0\1\76\27\0\1\46"+ "\30\0\4\47\2\0\3\47\4\0\1\47\1\101\3\47"+ "\1\0\1\47\1\0\4\47\5\0\1\47\7\56\1\0"+ "\4\56\1\0\1\56\2\0\1\56\1\0\3\56\1\0"+ "\6\56\1\0\1\56\1\0\12\56\1\0\4\56\1\0"+ "\1\56\2\0\1\56\1\101\3\56\1\0\6\56\1\0"+ "\1\56\1\0\3\56\7\65\1\0\4\65\1\0\1\65"+ "\2\0\1\65\1\0\3\65\1\0\6\65\1\0\2\65"+ "\1\0\11\65\1\0\4\65\1\0\1\65\2\0\1\65"+ "\1\101\3\65\1\0\6\65\1\0\2\65\1\0\2\65"+ "\27\106\1\107\4\106\1\71\21\106\1\110\12\106\1\111"+ "\4\106\1\71\5\106\17\72\1\0\14\72\1\0\5\72"+ "\17\0\1\112\26\0\1\113\11\0\1\114\51\0\1\115"+ "\21\0\1\116\34\0\2\117\6\0\1\120\1\121\1\120"+ "\1\0\1\122\16\0\1\117\3\0\1\117\2\0\2\123"+ "\12\0\1\124\4\0\1\125\1\126\1\125\7\0\1\123"+ "\3\0\1\123\15\0\1\32\41\0\1\127\31\0\1\130"+ "\35\0\14\106\1\110\12\106\1\111\4\106\1\0\5\106"+ "\14\0\1\131\31\0\1\132\65\0\1\133\17\0\1\134"+ "\55\0\1\135\1\136\1\135\16\0\2\117\6\0\1\120"+ "\1\121\1\120\20\0\1\117\3\0\1\117\2\0\1\137"+ "\36\0\1\137\2\0\1\137\7\0\1\120\26\0\1\137"+ "\2\0\2\122\6\0\1\140\1\141\21\0\1\122\3\0"+ "\1\122\2\0\2\123\17\0\1\125\1\126\1\125\7\0"+ "\1\123\3\0\1\123\2\0\2\124\17\0\1\142\1\143"+ "\10\0\1\124\3\0\1\124\2\0\1\144\36\0\1\144"+ "\2\0\1\144\20\0\1\125\15\0\1\144\5\0\1\145"+ "\36\0\2\146\6\0\1\147\1\150\1\147\1\0\1\151"+ "\16\0\1\146\3\0\1\146\32\0\1\152\32\0\1\153"+ "\1\154\17\0\1\155\36\0\1\155\2\0\1\155\20\0"+ "\1\135\15\0\1\155\2\0\2\140\14\0\1\27\14\0"+ "\1\140\3\0\1\140\2\0\2\140\6\0\1\140\5\0"+ "\1\27\14\0\1\140\3\0\1\140\2\0\2\142\22\0"+ "\1\27\6\0\1\142\3\0\1\142\2\0\2\142\17\0"+ "\1\142\2\0\1\27\6\0\1\142\3\0\1\142\2\0"+ "\2\146\6\0\1\147\1\150\1\147\20\0\1\146\3\0"+ "\1\146\2\0\1\156\36\0\1\156\2\0\1\156\7\0"+ "\1\147\26\0\1\156\2\0\2\151\6\0\1\157\1\160"+ "\21\0\1\151\3\0\1\151\33\0\1\161\10\0\1\153"+ "\12\0\1\27\23\0\1\153\2\0\1\153\12\0\1\27"+ "\5\0\1\153\15\0\1\153\2\0\2\157\1\0\1\162"+ "\27\0\1\157\3\0\1\157\2\0\2\157\1\0\1\162"+ "\4\0\1\157\22\0\1\157\3\0\1\157\34\0\1\163"+ "\12\0\1\164\67\0\1\165\23\0\1\27\43\0\1\166"+ "\23\0"; private static int [] zzUnpackTrans() { int [] result = new int[2992]; int offset = 0; offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); return result; } private static int zzUnpackTrans(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); value--; do result[j++] = value; while (--count > 0); } return j; } /* error codes */ private static final int ZZ_UNKNOWN_ERROR = 0; private static final int ZZ_NO_MATCH = 1; private static final int ZZ_PUSHBACK_2BIG = 2; /* error messages for the codes above */ private static final String ZZ_ERROR_MSG[] = { "Unkown internal scanner error", "Error: could not match input", "Error: pushback value was too large" }; /** * ZZ_ATTRIBUTE[aState] contains the attributes of state aState */ private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); private static final String ZZ_ATTRIBUTE_PACKED_0 = "\5\1\3\0\1\1\2\0\2\1\1\0\1\1\1\11"+ "\6\1\2\11\1\1\1\11\3\1\3\11\3\1\1\11"+ "\1\1\1\11\4\1\3\11\2\1\1\11\1\1\1\11"+ "\1\1\1\11\4\1\1\11\2\1\1\0\1\1\1\0"+ "\1\11\10\0\1\11\16\0\1\11\1\0\1\11\1\1"+ "\4\0\1\11\4\0\1\11\10\0\2\11\7\0\1\11"; private static int [] zzUnpackAttribute() { int [] result = new int[118]; int offset = 0; offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); return result; } private static int zzUnpackAttribute(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); do result[j++] = value; while (--count > 0); } return j; } /** the input device */ private java.io.Reader zzReader; /** the current state of the DFA */ private int zzState; /** the current lexical state */ private int zzLexicalState = YYINITIAL; /** this buffer contains the current text to be matched and is the source of the yytext() string */ private char zzBuffer[] = new char[ZZ_BUFFERSIZE]; /** the textposition at the last accepting state */ private int zzMarkedPos; /** the textposition at the last state to be included in yytext */ private int zzPushbackPos; /** the current text position in the buffer */ private int zzCurrentPos; /** startRead marks the beginning of the yytext() string in the buffer */ private int zzStartRead; /** endRead marks the last character in the buffer, that has been read from input */ private int zzEndRead; /** number of newlines encountered up to the start of the matched text */ private int yyline; /** the number of characters up to the start of the matched text */ private int yychar; /** * the number of characters from the last newline up to the start of the * matched text */ private int yycolumn; /** * zzAtBOL == true <=> the scanner is currently at the beginning of a line */ private boolean zzAtBOL = true; /** zzAtEOF == true <=> the scanner is at the EOF */ private boolean zzAtEOF; /* user code: */ /* styles */ public static final byte PLAIN_STYLE = 1; public static final byte CHAR_DATA = 2; public static final byte TAG_SYMBOLS = 3; public static final byte COMMENT = 4; public static final byte ATTRIBUTE_VALUE = 5; public static final byte ATTRIBUTE_NAME = 6; public static final byte PROCESSING_INSTRUCTION = 7; public static final byte TAG_NAME = 8; public static final byte RIFE_TAG = 9; public static final byte RIFE_NAME = 10; /* Highlighter implementation */ public int getStyleCount() { return 10; } public byte getStartState() { return YYINITIAL+1; } public byte getCurrentState() { return (byte) (yystate()+1); } public void setState(byte newState) { yybegin(newState-1); } public byte getNextToken() { try { return (byte) yylex(); } catch (IOException e) { throw new InternalError(); } } public int getTokenLength() { return yylength(); } public void setReader(Reader r) { this.zzReader = r; } public XmlHighlighter() { } private int mReturningState; private int mReturningStateTag; /** * Creates a new scanner * There is also a java.io.InputStream version of this constructor. * * @param in the java.io.Reader to read input from. */ public XmlHighlighter(java.io.Reader in) { this.zzReader = in; } /** * Creates a new scanner. * There is also java.io.Reader version of this constructor. * * @param in the java.io.Inputstream to read input from. */ public XmlHighlighter(java.io.InputStream in) { this(new java.io.InputStreamReader(in)); } /** * Unpacks the compressed character translation table. * * @param packed the packed character translation table * @return the unpacked character translation table */ private static char [] zzUnpackCMap(String packed) { char [] map = new char[0x10000]; int i = 0; /* index in packed string */ int j = 0; /* index in unpacked array */ while (i < 1736) { int count = packed.charAt(i++); char value = packed.charAt(i++); do map[j++] = value; while (--count > 0); } return map; } /** * Refills the input buffer. * * @return false, iff there was new input. * * @exception java.io.IOException if any I/O-Error occurs */ private boolean zzRefill() throws java.io.IOException { /* first: make room (if you can) */ if (zzStartRead > 0) { System.arraycopy(zzBuffer, zzStartRead, zzBuffer, 0, zzEndRead-zzStartRead); /* translate stored positions */ zzEndRead-= zzStartRead; zzCurrentPos-= zzStartRead; zzMarkedPos-= zzStartRead; zzPushbackPos-= zzStartRead; zzStartRead = 0; } /* is the buffer big enough? */ if (zzCurrentPos >= zzBuffer.length) { /* if not: blow it up */ char newBuffer[] = new char[zzCurrentPos*2]; System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length); zzBuffer = newBuffer; } /* finally: fill the buffer with new input */ int numRead = zzReader.read(zzBuffer, zzEndRead, zzBuffer.length-zzEndRead); if (numRead < 0) { return true; } else { zzEndRead+= numRead; return false; } } /** * Closes the input stream. */ public final void yyclose() throws java.io.IOException { zzAtEOF = true; /* indicate end of file */ zzEndRead = zzStartRead; /* invalidate buffer */ if (zzReader != null) zzReader.close(); } /** * Resets the scanner to read from a new input stream. * Does not close the old reader. * * All internal variables are reset, the old input stream * cannot be reused (internal buffer is discarded and lost). * Lexical state is set to ZZ_INITIAL. * * @param reader the new input stream */ public final void yyreset(java.io.Reader reader) { zzReader = reader; zzAtBOL = true; zzAtEOF = false; zzEndRead = zzStartRead = 0; zzCurrentPos = zzMarkedPos = zzPushbackPos = 0; yyline = yychar = yycolumn = 0; zzLexicalState = YYINITIAL; } /** * Returns the current lexical state. */ public final int yystate() { return zzLexicalState; } /** * Enters a new lexical state * * @param newState the new lexical state */ public final void yybegin(int newState) { zzLexicalState = newState; } /** * Returns the text matched by the current regular expression. */ public final String yytext() { return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead ); } /** * Returns the character at position pos from the * matched text. * * It is equivalent to yytext().charAt(pos), but faster * * @param pos the position of the character to fetch. * A value from 0 to yylength()-1. * * @return the character at position pos */ public final char yycharat(int pos) { return zzBuffer[zzStartRead+pos]; } /** * Returns the length of the matched text region. */ public final int yylength() { return zzMarkedPos-zzStartRead; } /** * Reports an error that occured while scanning. * * In a wellformed scanner (no or only correct usage of * yypushback(int) and a match-all fallback rule) this method * will only be called with things that "Can't Possibly Happen". * If this method is called, something is seriously wrong * (e.g. a JFlex bug producing a faulty scanner etc.). * * Usual syntax/scanner level error handling should be done * in error fallback rules. * * @param errorCode the code of the errormessage to display */ private void zzScanError(int errorCode) { String message; try { message = ZZ_ERROR_MSG[errorCode]; } catch (ArrayIndexOutOfBoundsException e) { message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; } throw new Error(message); } /** * Pushes the specified amount of characters back into the input stream. * * They will be read again by then next call of the scanning method * * @param number the number of characters to be read again. * This number must not be greater than yylength()! */ public void yypushback(int number) { if ( number > yylength() ) zzScanError(ZZ_PUSHBACK_2BIG); zzMarkedPos -= number; } /** * Resumes scanning until the next regular expression is matched, * the end of input is encountered or an I/O-Error occurs. * * @return the next token * @exception java.io.IOException if any I/O-Error occurs */ public int yylex() throws java.io.IOException { int zzInput; int zzAction; // cached fields: int zzCurrentPosL; int zzMarkedPosL; int zzEndReadL = zzEndRead; char [] zzBufferL = zzBuffer; char [] zzCMapL = ZZ_CMAP; int [] zzTransL = ZZ_TRANS; int [] zzRowMapL = ZZ_ROWMAP; int [] zzAttrL = ZZ_ATTRIBUTE; while (true) { zzMarkedPosL = zzMarkedPos; zzAction = -1; zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; zzState = zzLexicalState; zzForAction: { while (true) { if (zzCurrentPosL < zzEndReadL) zzInput = zzBufferL[zzCurrentPosL++]; else if (zzAtEOF) { zzInput = YYEOF; break zzForAction; } else { // store back cached positions zzCurrentPos = zzCurrentPosL; zzMarkedPos = zzMarkedPosL; boolean eof = zzRefill(); // get translated positions and possibly new buffer zzCurrentPosL = zzCurrentPos; zzMarkedPosL = zzMarkedPos; zzBufferL = zzBuffer; zzEndReadL = zzEndRead; if (eof) { zzInput = YYEOF; break zzForAction; } else { zzInput = zzBufferL[zzCurrentPosL++]; } } int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ]; if (zzNext == -1) break zzForAction; zzState = zzNext; int zzAttributes = zzAttrL[zzState]; if ( (zzAttributes & 1) == 1 ) { zzAction = zzState; zzMarkedPosL = zzCurrentPosL; if ( (zzAttributes & 8) == 8 ) break zzForAction; } } } // store back cached position zzMarkedPos = zzMarkedPosL; switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { case 27: { yybegin(IN_COMMENT); return COMMENT; } case 33: break; case 5: { return ATTRIBUTE_VALUE; } case 34: break; case 4: { return COMMENT; } case 35: break; case 21: { yybegin(IN_TAG); return ATTRIBUTE_VALUE; } case 36: break; case 20: { yybegin(IN_TAG); return TAG_SYMBOLS; } case 37: break; case 13: { yybegin(IN_TAG); return PLAIN_STYLE; } case 38: break; case 14: { yybegin(IN_TAG); return TAG_NAME; } case 39: break; case 3: { mReturningStateTag = yystate(); yybegin(IN_RIFE_NAME); return RIFE_NAME; } case 40: break; case 10: { mReturningStateTag = yystate(); yybegin(IN_RIFE_NAME_QUOTED); return RIFE_NAME; } case 41: break; case 31: { mReturningState = yystate(); yybegin(IN_RIFE_TAG_COMMENT); return RIFE_TAG; } case 42: break; case 24: { yybegin(YYINITIAL); return PROCESSING_INSTRUCTION; } case 43: break; case 28: { mReturningState = yystate(); yybegin(IN_RIFE_TAG_COMPACT); return RIFE_TAG; } case 44: break; case 22: { return PROCESSING_INSTRUCTION; } case 45: break; case 8: { mReturningStateTag = yystate(); yybegin(IN_RIFE_NAME_SINGLEQUOTED); return RIFE_NAME; } case 46: break; case 15: { yybegin(YYINITIAL); return TAG_SYMBOLS; } case 47: break; case 30: { mReturningState = yystate(); yybegin(IN_RIFE_TAG_REGULAR); return RIFE_TAG; } case 48: break; case 11: { return RIFE_NAME; } case 49: break; case 23: { yybegin(IN_PROCESSING_INSTRUCTION); return PROCESSING_INSTRUCTION; } case 50: break; case 17: { return TAG_SYMBOLS; } case 51: break; case 29: { mReturningState = yystate(); yybegin(IN_RIFE_TAG_VELOCITY); return RIFE_TAG; } case 52: break; case 1: { return PLAIN_STYLE; } case 53: break; case 2: { return RIFE_TAG; } case 54: break; case 18: { yybegin(IN_SINGLE_QUOTE_STRING); return ATTRIBUTE_VALUE; } case 55: break; case 26: { yybegin(YYINITIAL); return CHAR_DATA; } case 56: break; case 25: { yybegin(YYINITIAL); return COMMENT; } case 57: break; case 19: { yybegin(IN_DOUBLE_QUOTE_STRING); return ATTRIBUTE_VALUE; } case 58: break; case 32: { yybegin(IN_CDATA_SECTION); return CHAR_DATA; } case 59: break; case 12: { yybegin(mReturningStateTag); return RIFE_NAME; } case 60: break; case 16: { return ATTRIBUTE_NAME; } case 61: break; case 6: { return CHAR_DATA; } case 62: break; case 9: { yybegin(mReturningState); return RIFE_TAG; } case 63: break; case 7: { yybegin(TAG_START); return TAG_SYMBOLS; } case 64: break; default: if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { zzAtEOF = true; return YYEOF; } else { zzScanError(ZZ_NO_MATCH); } } } } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/renderer/000077500000000000000000000000001422762524200267155ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/renderer/CppXhtmlRenderer.java000066400000000000000000000057661422762524200330240ustar00rootroot00000000000000/* * Copyright 2006 Arnout Engelen * Copyright 2004-2006 Geert Bevin * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: CppXhtmlRenderer.java 3108 2006-03-13 18:03:00Z gbevin $ */ package org.codelibs.jhighlight.renderer; import java.util.HashMap; import java.util.Map; import org.codelibs.jhighlight.highlighter.CppHighlighter; import org.codelibs.jhighlight.highlighter.ExplicitStateHighlighter; /** * Generates highlighted syntax in XHTML from Cpp source. * * @author Arnout Engelen (arnouten[remove] at bzzt dot net) * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @version $Revision: 0$ */ public class CppXhtmlRenderer extends XhtmlRenderer { public final static HashMap DEFAULT_CSS = new HashMap() {{ put("h1", "font-family: sans-serif; " + "font-size: 16pt; " + "font-weight: bold; " + "color: rgb(0,0,0); " + "background: rgb(210,210,210); " + "border: solid 1px black; " + "padding: 5px; " + "text-align: center;"); put("code", "color: rgb(0,0,0); " + "font-family: monospace; " + "font-size: 12px; " + "white-space: nowrap;"); put(".cpp_plain", "color: rgb(0,0,0);"); put(".cpp_keyword", "color: rgb(0,0,0); " + "font-weight: bold;"); put(".cpp_type", "color: rgb(0,44,221);"); put(".cpp_operator", "color: rgb(0,124,31);"); put(".cpp_separator", "color: rgb(0,33,255);"); put(".cpp_literal", "color: rgb(188,0,0);"); put(".cpp_comment", "color: rgb(147,147,147); " + "background-color: rgb(247,247,247);"); put(".cpp_doxygen_comment", "color: rgb(147,147,147); " + "background-color: rgb(247,247,247); " + "font-style: italic;"); put(".cpp_doxygen_tag", "color: rgb(147,147,147); " + "background-color: rgb(247,247,247); " + "font-style: italic; " + "font-weight: bold;"); put(".cpp_preproc", "color: purple;"); }}; protected Map getDefaultCssStyles() { return DEFAULT_CSS; } protected String getCssClass(int style) { switch (style) { case CppHighlighter.PLAIN_STYLE: return "cpp_plain"; case CppHighlighter.KEYWORD_STYLE: return "cpp_keyword"; case CppHighlighter.TYPE_STYLE: return "cpp_type"; case CppHighlighter.OPERATOR_STYLE: return "cpp_operator"; case CppHighlighter.SEPARATOR_STYLE: return "cpp_separator"; case CppHighlighter.LITERAL_STYLE: return "cpp_literal"; case CppHighlighter.CPP_COMMENT_STYLE: return "cpp_comment"; case CppHighlighter.DOXYGEN_COMMENT_STYLE: return "cpp_doxygen_comment"; case CppHighlighter.DOXYGEN_TAG_STYLE: return "cpp_doxygen_tag"; case CppHighlighter.PREPROC_STYLE: return "cpp_preproc"; } return null; } protected ExplicitStateHighlighter getHighlighter() { return new CppHighlighter(); } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/renderer/GroovyXhtmlRenderer.java000066400000000000000000000055221422762524200335550ustar00rootroot00000000000000/* * Copyright 2004-2006 Geert Bevin * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: GroovyXhtmlRenderer.java 3108 2006-03-13 18:03:00Z gbevin $ */ package org.codelibs.jhighlight.renderer; import java.util.HashMap; import java.util.Map; import org.codelibs.jhighlight.highlighter.ExplicitStateHighlighter; import org.codelibs.jhighlight.highlighter.GroovyHighlighter; /** * Generates highlighted syntax in XHTML from Groovy source. * * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @version $Revision: 3108 $ * @since 1.0 */ public class GroovyXhtmlRenderer extends XhtmlRenderer { public final static HashMap DEFAULT_CSS = new HashMap() {{ put("h1", "font-family: sans-serif; " + "font-size: 16pt; " + "font-weight: bold; " + "color: rgb(0,0,0); " + "background: rgb(210,210,210); " + "border: solid 1px black; " + "padding: 5px; " + "text-align: center;"); put("code", "color: rgb(0,0,0); " + "font-family: monospace; " + "font-size: 12px; " + "white-space: nowrap;"); put(".java_plain", "color: rgb(0,0,0);"); put(".java_keyword", "color: rgb(0,0,0); " + "font-weight: bold;"); put(".java_type", "color: rgb(0,44,221);"); put(".java_operator", "color: rgb(0,124,31);"); put(".java_separator", "color: rgb(0,33,255);"); put(".java_literal", "color: rgb(188,0,0);"); put(".java_comment", "color: rgb(147,147,147); " + "background-color: rgb(247,247,247);"); put(".java_javadoc_comment", "color: rgb(147,147,147); " + "background-color: rgb(247,247,247); " + "font-style: italic;"); put(".java_javadoc_tag", "color: rgb(147,147,147); " + "background-color: rgb(247,247,247); " + "font-style: italic; " + "font-weight: bold;"); }}; protected Map getDefaultCssStyles() { return DEFAULT_CSS; } protected String getCssClass(int style) { switch (style) { case GroovyHighlighter.PLAIN_STYLE: return "java_plain"; case GroovyHighlighter.KEYWORD_STYLE: return "java_keyword"; case GroovyHighlighter.TYPE_STYLE: return "java_type"; case GroovyHighlighter.OPERATOR_STYLE: return "java_operator"; case GroovyHighlighter.SEPARATOR_STYLE: return "java_separator"; case GroovyHighlighter.LITERAL_STYLE: return "java_literal"; case GroovyHighlighter.JAVA_COMMENT_STYLE: return "java_comment"; case GroovyHighlighter.JAVADOC_COMMENT_STYLE: return "java_javadoc_comment"; case GroovyHighlighter.JAVADOC_TAG_STYLE: return "java_javadoc_tag"; } return null; } protected ExplicitStateHighlighter getHighlighter() { return new GroovyHighlighter(); } } JavaScriptXhtmlRenderer.java000066400000000000000000000054201422762524200342540ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/renderer/* * Copyright 2004-2006 Geert Bevin . * Ulf Dittmer (ulf[remove] at ulfdittmer dot com) * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: JavaScriptXhtmlRenderer.java 3431 2006-08-02 04:09:28Z gbevin $ */ package org.codelibs.jhighlight.renderer; import java.util.HashMap; import java.util.Map; import org.codelibs.jhighlight.highlighter.ExplicitStateHighlighter; import org.codelibs.jhighlight.highlighter.JavaScriptHighlighter; /** * Generates highlighted syntax in XHTML from Java source. * * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @author Ulf Dittmer (ulf[remove] at ulfdittmer dot com) * @version $Revision: 3431 $ * @since 1.1 */ public class JavaScriptXhtmlRenderer extends XhtmlRenderer { public final static HashMap DEFAULT_CSS = new HashMap() {{ put("h1", "font-family: sans-serif; " + "font-size: 16pt; " + "font-weight: bold; " + "color: rgb(0,0,0); " + "background: rgb(210,210,210); " + "border: solid 1px black; " + "padding: 5px; " + "text-align: center;"); put("code", "color: rgb(0,0,0); " + "font-family: monospace; " + "font-size: 12px; " + "white-space: nowrap;"); put(".java_plain", "color: rgb(0,0,0);"); put(".java_keyword", "color: rgb(0,0,0); " + "font-weight: bold;"); put(".java_type", "color: rgb(0,44,221);"); put(".java_operator", "color: rgb(0,124,31);"); put(".java_separator", "color: rgb(0,33,255);"); put(".java_literal", "color: rgb(188,0,0);"); put(".java_comment", "color: rgb(147,147,147); " + "background-color: rgb(247,247,247);"); put(".java_javadoc_comment", "color: rgb(147,147,147); " + "background-color: rgb(247,247,247); " + "font-style: italic;"); put(".java_javadoc_tag", "color: rgb(147,147,147); " + "background-color: rgb(247,247,247); " + "font-style: italic; " + "font-weight: bold;"); }}; protected Map getDefaultCssStyles() { return DEFAULT_CSS; } protected String getCssClass(int style) { switch (style) { case JavaScriptHighlighter.PLAIN_STYLE: return "java_plain"; case JavaScriptHighlighter.KEYWORD_STYLE: return "java_keyword"; case JavaScriptHighlighter.OPERATOR_STYLE: return "java_operator"; case JavaScriptHighlighter.SEPARATOR_STYLE: return "java_separator"; case JavaScriptHighlighter.LITERAL_STYLE: return "java_literal"; case JavaScriptHighlighter.JAVA_COMMENT_STYLE: return "java_comment"; } return null; } protected ExplicitStateHighlighter getHighlighter() { return new JavaScriptHighlighter(); } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/renderer/JavaXhtmlRenderer.java000066400000000000000000000056161422762524200331550ustar00rootroot00000000000000/* * Copyright 2004-2006 Geert Bevin * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: JavaXhtmlRenderer.java 3108 2006-03-13 18:03:00Z gbevin $ */ package org.codelibs.jhighlight.renderer; import java.util.HashMap; import java.util.Map; import org.codelibs.jhighlight.highlighter.ExplicitStateHighlighter; import org.codelibs.jhighlight.highlighter.JavaHighlighter; /** * Generates highlighted syntax in XHTML from Java source. * * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @version $Revision: 3108 $ * @since 1.0 */ public class JavaXhtmlRenderer extends XhtmlRenderer { public final static HashMap DEFAULT_CSS = new HashMap() {{ put("h1", "font-family: sans-serif; " + "font-size: 16pt; " + "font-weight: bold; " + "color: rgb(0,0,0); " + "background: rgb(210,210,210); " + "border: solid 1px black; " + "padding: 5px; " + "text-align: center;"); put("code", "color: rgb(0,0,0); " + "font-family: monospace; " + "font-size: 12px; " + "white-space: nowrap;"); put(".java_plain", "color: rgb(0,0,0);"); put(".java_keyword", "color: rgb(0,0,0); " + "font-weight: bold;"); put(".java_type", "color: rgb(0,44,221);"); put(".java_operator", "color: rgb(0,124,31);"); put(".java_separator", "color: rgb(0,33,255);"); put(".java_literal", "color: rgb(188,0,0);"); put(".java_comment", "color: rgb(147,147,147); " + "background-color: rgb(247,247,247);"); put(".java_javadoc_comment", "color: rgb(147,147,147); " + "background-color: rgb(247,247,247); " + "font-style: italic;"); put(".java_javadoc_tag", "color: rgb(147,147,147); " + "background-color: rgb(247,247,247); " + "font-style: italic; " + "font-weight: bold;"); }}; protected Map getDefaultCssStyles() { return DEFAULT_CSS; } protected String getCssClass(int style) { switch (style) { case JavaHighlighter.PLAIN_STYLE: return "java_plain"; case JavaHighlighter.KEYWORD_STYLE: return "java_keyword"; case JavaHighlighter.TYPE_STYLE: return "java_type"; case JavaHighlighter.OPERATOR_STYLE: return "java_operator"; case JavaHighlighter.SEPARATOR_STYLE: return "java_separator"; case JavaHighlighter.LITERAL_STYLE: return "java_literal"; case JavaHighlighter.JAVA_COMMENT_STYLE: return "java_comment"; case JavaHighlighter.JAVADOC_COMMENT_STYLE: return "java_javadoc_comment"; case JavaHighlighter.JAVADOC_TAG_STYLE: return "java_javadoc_tag"; } return null; } protected ExplicitStateHighlighter getHighlighter() { JavaHighlighter highlighter = new JavaHighlighter(); highlighter.ASSERT_IS_KEYWORD = true; return highlighter; } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/renderer/Renderer.java000066400000000000000000000042771422762524200313400ustar00rootroot00000000000000/* * Copyright 2004-2006 Geert Bevin * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: Renderer.java 3108 2006-03-13 18:03:00Z gbevin $ */ package org.codelibs.jhighlight.renderer; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; /** * Provides interface to render the source code highlighting. * * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @version $Revision: 3108 $ * @since 1.0 */ public interface Renderer extends com.uwyn.jhighlight.renderer.Renderer { /** * Transforms source code that's provided through an * InputStream to highlighted syntax and writes it back to * an OutputStream. * * @param name The name of the source file. * @param in The input stream that provides the source code that needs to * be transformed. * @param out The output stream to which to result should be written. * @param encoding The encoding that will be used to read and write the * text. * @param fragment true if the result should be a fragment; * or false if it should be a complete document * @see #highlight(String, String, String, boolean) * @since 1.0 */ public void highlight(String name, InputStream in, OutputStream out, String encoding, boolean fragment) throws IOException; /** * Transforms source code that's provided through a * String to highlighted syntax and returns it as a * String. * * @param name The name of the source file. * @param in The input string that provides the source code that needs to * be transformed. * @param encoding The encoding that will be used to read and write the * text. * @param fragment true if the result should be a fragment; * or false if it should be a complete document * @return the highlighted source code as a string * @see #highlight(String, InputStream, OutputStream, String, boolean) * @since 1.0 */ public String highlight(String name, String in, String encoding, boolean fragment) throws IOException; } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/renderer/XhtmlRenderer.java000066400000000000000000000227661422762524200323600ustar00rootroot00000000000000/* * Copyright 2004-2006 Geert Bevin * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: XhtmlRenderer.java 3108 2006-03-13 18:03:00Z gbevin $ */ package org.codelibs.jhighlight.renderer; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.StringReader; import java.io.Writer; import java.net.URL; import java.net.URLConnection; import java.util.Iterator; import java.util.Map; import java.util.Properties; import java.util.logging.Logger; import org.apache.commons.io.output.ByteArrayOutputStream; import org.codelibs.jhighlight.JHighlightVersion; import org.codelibs.jhighlight.highlighter.ExplicitStateHighlighter; import org.codelibs.jhighlight.tools.ExceptionUtils; import org.codelibs.jhighlight.tools.StringUtils; /** * Provides an abstract base class to perform source code to XHTML syntax * highlighting. * * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @version $Revision: 3108 $ * @since 1.0 */ public abstract class XhtmlRenderer implements Renderer { /** * Transforms source code that's provided through an * InputStream to highlighted syntax in XHTML and writes it * back to an OutputStream. *

If the highlighting has to become a fragment, no CSS styles will be * generated. *

For complete documents, there's a collection of default styles that * will be included. It's possible to override these by changing the * provided jhighlight.properties file. It's best to look at * this file in the JHighlight archive and modify the styles that are * there already. * * @param name The name of the source file. * @param in The input stream that provides the source code that needs to * be transformed. * @param out The output stream to which to resulting XHTML should be * written. * @param encoding The encoding that will be used to read and write the * text. * @param fragment true if the generated XHTML should be a * fragment; or false if it should be a complete page * @see #highlight(String, String, String, boolean) * @since 1.0 */ public void highlight(String name, InputStream in, OutputStream out, String encoding, boolean fragment) throws IOException { ExplicitStateHighlighter highlighter = getHighlighter(); Reader isr; Writer osw; if (null == encoding) { isr = new InputStreamReader(in); osw = new OutputStreamWriter(out); } else { isr = new InputStreamReader(in, encoding); osw = new OutputStreamWriter(out, encoding); } BufferedReader r = new BufferedReader(isr); BufferedWriter w = new BufferedWriter(osw); if (fragment) { w.write(getXhtmlHeaderFragment(name)); } else { w.write(getXhtmlHeader(name)); } String line; String token; int length; int style; String css_class; int previous_style = 0; boolean newline = false; while ((line = r.readLine()) != null) { line += "\n"; line = StringUtils.convertTabsToSpaces(line, 4); // should be optimized by reusing a custom LineReader class Reader lineReader = new StringReader(line); highlighter.setReader(lineReader); int index = 0; while (index < line.length()) { style = highlighter.getNextToken(); length = highlighter.getTokenLength(); token = line.substring(index, index + length); if (style != previous_style || newline) { css_class = getCssClass(style); if (css_class != null) { if (previous_style != 0 && !newline) { w.write(""); } w.write(""); previous_style = style; } } newline = false; w.write(StringUtils.replace(StringUtils.encodeHtml(StringUtils.replace(token, "\n", "")), " ", " ")); index += length; } w.write("
\n"); newline = true; } if (!fragment) w.write(getXhtmlFooter()); w.flush(); w.close(); } /** * Transforms source code that's provided through a * String to highlighted syntax in XHTML and returns it * as a String. *

If the highlighting has to become a fragment, no CSS styles will be * generated. * * @param name The name of the source file. * @param in The input string that provides the source code that needs to * be transformed. * @param encoding The encoding that will be used to read and write the * text. * @param fragment true if the generated XHTML should be a * fragment; or false if it should be a complete page * or false if it should be a complete document * @return the highlighted source code as XHTML in a string * @see #highlight(String, InputStream, OutputStream, String, boolean) * @since 1.0 */ public String highlight(String name, String in, String encoding, boolean fragment) throws IOException { try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { highlight(name, new ByteArrayInputStream(in.getBytes(encoding)), out, encoding, fragment); return out.toString(encoding); } } /** * Returns a map of all the CSS styles that the renderer requires, * together with default definitions for them. * * @return The map of CSS styles. * @since 1.0 */ protected abstract Map getDefaultCssStyles(); /** * Looks up the CSS class identifier that corresponds to the syntax style. * * @param style The syntax style. * @return The requested CSS class identifier; or *

null if the syntax style isn't supported. * @since 1.0 */ protected abstract String getCssClass(int style); /** * Returns the language-specific highlighting lexer that should be used * * @return The requested highlighting lexer. * @since 1.0 */ protected abstract ExplicitStateHighlighter getHighlighter(); /** * Returns all the CSS class definitions that should appear within the * style XHTML tag. *

This should support all the classes that the * getCssClass(int) method returns. * * @return The CSS class definitions * @see #getCssClass(int) * @since 1.0 */ protected String getCssClassDefinitions() { StringBuffer css = new StringBuffer(); Properties properties = new Properties(); URL jhighlighter_props = getClass().getClassLoader().getResource("jhighlight.properties"); if (jhighlighter_props != null) { try { URLConnection connection = jhighlighter_props.openConnection(); connection.setUseCaches(false); InputStream is = connection.getInputStream(); try { properties.load(is); } finally { is.close(); } } catch (IOException e) { Logger.getLogger("org.codelibs.jhighlight").warning("Error while reading the '" + jhighlighter_props.toExternalForm() + "' resource, using default CSS styles.\n" + ExceptionUtils.getExceptionStackTrace(e)); } } Iterator it = getDefaultCssStyles().entrySet().iterator(); Map.Entry entry; while (it.hasNext()) { entry = (Map.Entry)it.next(); String key = (String)entry.getKey(); css.append(key); css.append(" {\n"); if (properties.containsKey(key)) { css.append(properties.get(key)); } else { css.append(entry.getValue()); } css.append("\n}\n"); } return css.toString(); } /** * Returns the XHTML header that preceedes the highlighted source code. *

It will integrate the CSS class definitions and use the source's * name to indicate in XHTML which file has been highlighted. * * @param name The name of the source file. * @return The constructed XHTML header. * @since 1.0 */ protected String getXhtmlHeader(String name) { if (null == name) { name = ""; } return "\n" + "\n" + "\n" + " \n" + " \n" + " " + StringUtils.encodeHtml(name) + "\n" + " \n" + " \n" + "\n" + "\n" + "

" + StringUtils.encodeHtml(name) + "

" + ""; } /** * Returns the XHTML header that preceedes the highlighted source code for * a fragment. * * @param name The name of the source file. * @return The constructed XHTML header. * @since 1.0 */ protected String getXhtmlHeaderFragment(String name) { if (null == name) { name = ""; } return "\n"; } /** * Returns the XHTML footer that nicely finishes the file after the * highlighted source code. * * @return The requested XHTML footer. * @since 1.0 */ protected String getXhtmlFooter() { return "\n\n\n"; } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/renderer/XhtmlRendererFactory.java000066400000000000000000000054031422762524200336750ustar00rootroot00000000000000/* * Copyright 2004-2006 Geert Bevin * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: XhtmlRendererFactory.java 3108 2006-03-13 18:03:00Z gbevin $ */ package org.codelibs.jhighlight.renderer; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; /** * Provides a single point of entry to instantiate Xhtml renderers. * * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @version $Revision: 3108 $ * @since 1.0 */ public abstract class XhtmlRendererFactory { public final static String GROOVY = "groovy"; public final static String JAVA = "java"; public final static String BEANSHELL = "beanshell"; public final static String BSH = "bsh"; public final static String XML = "xml"; public final static String XHTML = "xhtml"; public final static String LZX = "lzx"; public final static String HTML = "html"; public final static String CPP = "cpp"; public final static String CXX = "cxx"; public final static String CPLUSPLUS = "c++"; private final static Map RENDERERS_CLASSNAMES = new HashMap() {{ put(GROOVY, GroovyXhtmlRenderer.class.getName()); put(JAVA, JavaXhtmlRenderer.class.getName()); put(BEANSHELL, JavaXhtmlRenderer.class.getName()); put(BSH, JavaXhtmlRenderer.class.getName()); put(XML, XmlXhtmlRenderer.class.getName()); put(XHTML, XmlXhtmlRenderer.class.getName()); put(LZX, XmlXhtmlRenderer.class.getName()); put(HTML, XmlXhtmlRenderer.class.getName()); put(CPP, CppXhtmlRenderer.class.getName()); put(CXX, CppXhtmlRenderer.class.getName()); put(CPLUSPLUS, CppXhtmlRenderer.class.getName()); }}; /** * Instantiates an instance of a known XhtmlRenderer according to * the type that's provided. * * @param type The type of renderer, look at the static variables of this * class to see which ones are supported. * @return an instance of the XhtmlRenderer that corresponds to the type; or *

null if the type wasn't known * @since 1.0 */ public static Renderer getRenderer(String type) { String classname = (String)RENDERERS_CLASSNAMES.get(type.toLowerCase()); if (null == classname) { return null; } try { Class klass = Class.forName(classname); return (Renderer)klass.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } } /** * Returned a set with all the supported XHTML renderer types. * * @return a Set with the supported XHTML renderer types as strings. * @since 1.0 */ public static Set getSupportedTypes() { return Collections.unmodifiableSet(RENDERERS_CLASSNAMES.keySet()); } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/renderer/XmlXhtmlRenderer.java000066400000000000000000000057431422762524200330350ustar00rootroot00000000000000/* * Copyright 2004-2006 Geert Bevin * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: XmlXhtmlRenderer.java 3108 2006-03-13 18:03:00Z gbevin $ */ package org.codelibs.jhighlight.renderer; import java.util.HashMap; import java.util.Map; import org.codelibs.jhighlight.highlighter.ExplicitStateHighlighter; import org.codelibs.jhighlight.highlighter.XmlHighlighter; /** * Generates highlighted syntax in XHTML from XML source. *

RIFE template tags are also * supported and will be clearly highlighted. * * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @version $Revision: 3108 $ * @since 1.0 */ public class XmlXhtmlRenderer extends XhtmlRenderer { public final static HashMap DEFAULT_CSS = new HashMap() {{ put("h1", "font-family: sans-serif; "+ "font-size: 16pt; "+ "font-weight: bold; "+ "color: rgb(0,0,0); "+ "background: rgb(210,210,210); "+ "border: solid 1px black; "+ "padding: 5px; "+ "text-align: center;"); put("code", "color: rgb(0,0,0); "+ "font-family: monospace; "+ "font-size: 12px; " + "white-space: nowrap;"); put(".xml_plain", "color: rgb(0,0,0);"); put(".xml_char_data", "color: rgb(0,0,0);"); put(".xml_tag_symbols", "color: rgb(0,59,255);"); put(".xml_comment", "color: rgb(147,147,147); "+ "background-color: rgb(247,247,247);"); put(".xml_attribute_value", "color: rgb(193,0,0);"); put(".xml_attribute_name", "color: rgb(0,0,0); "+ "font-weight: bold;"); put(".xml_processing_instruction", "color: rgb(0,0,0); "+ "font-weight: bold; "+ "font-style: italic;"); put(".xml_tag_name", "color: rgb(0,55,255);"); put(".xml_rife_tag", "color: rgb(0,0,0); "+ "background-color: rgb(228,230,160);"); put(".xml_rife_name", "color: rgb(0,0,196); "+ "background-color: rgb(228,230,160);"); }}; protected Map getDefaultCssStyles() { return DEFAULT_CSS; } protected String getCssClass(int style) { switch (style) { case XmlHighlighter.PLAIN_STYLE: return "xml_plain"; case XmlHighlighter.CHAR_DATA: return "xml_char_data"; case XmlHighlighter.TAG_SYMBOLS: return "xml_tag_symbols"; case XmlHighlighter.COMMENT: return "xml_comment"; case XmlHighlighter.ATTRIBUTE_VALUE: return "xml_attribute_value"; case XmlHighlighter.ATTRIBUTE_NAME: return "xml_attribute_name"; case XmlHighlighter.PROCESSING_INSTRUCTION: return "xml_processing_instruction"; case XmlHighlighter.TAG_NAME: return "xml_tag_name"; case XmlHighlighter.RIFE_TAG: return "xml_rife_tag"; case XmlHighlighter.RIFE_NAME: return "xml_rife_name"; } return null; } protected ExplicitStateHighlighter getHighlighter() { return new XmlHighlighter(); } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/servlet/000077500000000000000000000000001422762524200265735ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/servlet/HighlightFilter.java000066400000000000000000000147731422762524200325270ustar00rootroot00000000000000/* * Copyright 2004-2006 Geert Bevin ; and * Frederic Daoud * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: HighlightFilter.java 3183 2006-04-13 21:06:25Z gbevin $ */ package org.codelibs.jhighlight.servlet; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; import org.apache.commons.io.output.ByteArrayOutputStream; import org.codelibs.jhighlight.renderer.Renderer; import org.codelibs.jhighlight.renderer.XhtmlRendererFactory; import org.codelibs.jhighlight.tools.FileUtils; /** * A servlet filter that offers on-the-fly syntax highlighting for Java, HTML, * XHTML, XML and LZX files. *

The filter should be declared in a similar fashion as this: *

<filter>
 *    <filter-name>jhighlight</filter-name>
 *    <filter-class>org.codelibs.jhighlight.servlet.HighlightFilter</filter-class>
 *</filter>
 *
 *<filter-mapping>
 *    <filter-name>jhighlight</filter-name>
 *    <url-pattern>/*</url-pattern>
 *</filter-mapping>
*

It will respond to files with the following extensions: * .javas, .htmls, .htms, * .xhtmls, .xmls and .lzxs. These will * be automatically mapped to files without the last s in the * filenames. Thus, for example, a request like this: *

http://myhost.com/folder/MySource.javas
*

will retrieve this file: *

http://myhost.com/folder/MySource.java
*

The contents of this file will be automatically highlighted and the * resulting HTML will be served. * * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @version $Revision: 3183 $ * @since 1.0 */ public final class HighlightFilter implements Filter { public void init(FilterConfig filterConfig) { } public void destroy() { } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { HttpServletRequest http_request = (HttpServletRequest)request; HttpServletResponse http_response = (HttpServletResponse)response; Renderer renderer = null; String uri = http_request.getRequestURI(); String extension = FileUtils.getExtension(uri); if (extension != null && extension.endsWith("s")) { renderer = XhtmlRendererFactory.getRenderer(extension.substring(0, extension.length()-1)); } if (renderer != null) { SourceRequestWrapper request_wrapper = new SourceRequestWrapper(http_request); CharResponseWrapper response_wrapper = new CharResponseWrapper(http_response); chain.doFilter(request_wrapper, response_wrapper); OutputStream out = response.getOutputStream(); try { if (HttpServletResponse.SC_OK == response_wrapper.getStatus()) { InputStream is = new ByteArrayInputStream(response_wrapper.getWrappedOutputStream().toByteArray()); try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) { String encoding = request.getCharacterEncoding(); if (null == encoding) { encoding = "UTF-8"; } String name = http_request.getServletPath().substring(1); name = name.substring(0, name.length() - 1); renderer.highlight(name, is, os, encoding, false); String highlighted = os.toString("ISO-8859-1"); response.setContentType("text/html"); response.setContentLength(highlighted.length()); out.write(highlighted.getBytes("ISO-8859-1")); } } else { out.write(response_wrapper.getWrappedOutputStream().toByteArray()); } } finally { out.close(); } } else { chain.doFilter(request, response); } } else { chain.doFilter(request, response); } } private static class SourceRequestWrapper extends HttpServletRequestWrapper { public SourceRequestWrapper(HttpServletRequest request) { super(request); } public String getServletPath() { String path = super.getServletPath(); return path.substring(0, path.length() - 1); } public String getPathTranslated() { String path = super.getPathTranslated(); return path.substring(0, path.length() - 1); } public String getRequestURI() { String uri = super.getRequestURI(); return uri.substring(0, uri.length() - 1); } public StringBuffer getRequestURL() { StringBuffer url = super.getRequestURL(); url.setLength(url.length() - 1); return url; } } private static class CharResponseWrapper extends HttpServletResponseWrapper { private ServletOutputStreamWrapper mOutput; private int mStatus = HttpServletResponse.SC_OK; public ServletOutputStreamWrapper getWrappedOutputStream() { return mOutput; } public CharResponseWrapper(HttpServletResponse response) { super(response); mOutput = new ServletOutputStreamWrapper(); } public ServletOutputStream getOutputStream() throws IOException { return mOutput; } public void setStatus(int status) { mStatus = status; super.setStatus(status); } public void sendError(int status, String msg) throws IOException { mStatus = status; super.sendError(status, msg); } public void sendError(int status) throws IOException { mStatus = status; super.sendError(status); } public int getStatus() { return mStatus; } } private static class ServletOutputStreamWrapper extends ServletOutputStream { protected ByteArrayOutputStream mOutput; public ServletOutputStreamWrapper() { mOutput = new ByteArrayOutputStream(); } public void write(int b) throws IOException { mOutput.write(b); } public byte[] toByteArray() { return mOutput.toByteArray(); } } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/tools/000077500000000000000000000000001422762524200262475ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/tools/ExceptionUtils.java000066400000000000000000000026641422762524200321010ustar00rootroot00000000000000/* * Copyright 2001-2006 Geert Bevin * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: ExceptionUtils.java 3108 2006-03-13 18:03:00Z gbevin $ */ package org.codelibs.jhighlight.tools; import java.io.PrintWriter; import java.io.StringWriter; /** * Collection of utility methods to work with exceptions. * * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @version $Revision: 3108 $ * @since 1.0 */ public abstract class ExceptionUtils { private ExceptionUtils() { } /** * Obtains the entire stracktrace of an exception and converts it into a * string. * * @param exception the exception whose stacktrace has to be converted * @return the stracktrace, converted into a string * @since 1.0 */ public static String getExceptionStackTrace(Throwable exception) { if (null == exception) throw new IllegalArgumentException("exception can't be null;"); String stack_trace = null; StringWriter string_writer = new StringWriter(); PrintWriter print_writer = new PrintWriter(string_writer); exception.printStackTrace(print_writer); stack_trace = string_writer.getBuffer().toString(); print_writer.close(); try { string_writer.close(); } // JDK 1.2.2 compatibility catch (Throwable e2) { } return stack_trace; } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/tools/FileUtils.java000066400000000000000000000067071422762524200310240ustar00rootroot00000000000000/* * Copyright 2001-2006 Geert Bevin * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: FileUtils.java 3108 2006-03-13 18:03:00Z gbevin $ */ package org.codelibs.jhighlight.tools; import java.io.File; import java.util.ArrayList; import java.util.Iterator; import java.util.regex.Pattern; /** * Collection of utility methods to work with files. * * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @version $Revision: 3108 $ * @since 1.0 */ public abstract class FileUtils { private FileUtils() { } /** * Recursively traverse a directory hierachy and obtain a list of all * absolute file names. *

Regular expression patterns can be provided to explicitly include * and exclude certain file names. * * @param file the directory whose file hierarchy will be traversed * @param included an array of regular expression patterns that will be * used to determine which files should be included; or *

null if all files should be included * @param excluded an array of regular expression patterns that will be * used to determine which files should be excluded; or *

null if no files should be excluded * @return the list of absolute file names * @since 1.0 */ public static ArrayList getFileList(File file, Pattern[] included, Pattern[] excluded) { return getFileList(file, included, excluded, true); } private static ArrayList getFileList(File file, Pattern[] included, Pattern[] excluded, boolean root) { if (null == file) { return new ArrayList(); } ArrayList filelist = new ArrayList(); if (file.isDirectory()) { String[] list = file.list(); if (null != list) { String list_entry; for (int i = 0; i < list.length; i++) { list_entry = list[i]; File next_file = new File(file.getAbsolutePath() + File.separator + list_entry); ArrayList dir = getFileList(next_file, included, excluded, false); Iterator dir_it = dir.iterator(); String file_name; while (dir_it.hasNext()) { file_name = (String)dir_it.next(); if (root) { // if the file is not accepted, don't process it further if (!StringUtils.filter(file_name, included, excluded)) { continue; } } else { file_name = file.getName() + File.separator + file_name; } int filelist_size = filelist.size(); for (int j = 0; j < filelist_size; j++) { if (((String)filelist.get(j)).compareTo(file_name) > 0) { filelist.add(j, file_name); break; } } if (filelist.size() == filelist_size) { filelist.add(file_name); } } } } } else if (file.isFile()) { String file_name = file.getName(); if (root) { if (StringUtils.filter(file_name, included, excluded)) { filelist.add(file_name); } } else { filelist.add(file_name); } } return filelist; } public static String getExtension(String fileName) { if (null == fileName) throw new IllegalArgumentException("fileName can't be null."); String ext = null; int index = fileName.lastIndexOf('.'); if (index > 0 && index < fileName.length() - 1) { ext = fileName.substring(index+1).toLowerCase(); } return ext; } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/tools/StringUtils.java000066400000000000000000000533611422762524200314110ustar00rootroot00000000000000/* * Copyright 2001-2006 Geert Bevin * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: StringUtils.java 3108 2006-03-13 18:03:00Z gbevin $ */ package org.codelibs.jhighlight.tools; import java.util.ArrayList; import java.util.Iterator; import java.util.regex.Pattern; import org.codelibs.jhighlight.fastutil.chars.Char2ObjectOpenHashMap; /** * General purpose class containing common String manipulation * methods. * * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @version $Revision: 3108 $ * @since 1.0 */ public abstract class StringUtils { private static final Char2ObjectOpenHashMap mHtmlEncodeMap = new Char2ObjectOpenHashMap(); static { // Html encoding mapping according to the HTML 4.0 spec // http://www.w3.org/TR/REC-html40/sgml/entities.html // Special characters for HTML mHtmlEncodeMap.put('\u0026', "&"); mHtmlEncodeMap.put('\u003C', "<"); mHtmlEncodeMap.put('\u003E', ">"); mHtmlEncodeMap.put('\u0022', """); mHtmlEncodeMap.put('\u0152', "Œ"); mHtmlEncodeMap.put('\u0153', "œ"); mHtmlEncodeMap.put('\u0160', "Š"); mHtmlEncodeMap.put('\u0161', "š"); mHtmlEncodeMap.put('\u0178', "Ÿ"); mHtmlEncodeMap.put('\u02C6', "ˆ"); mHtmlEncodeMap.put('\u02DC', "˜"); mHtmlEncodeMap.put('\u2002', " "); mHtmlEncodeMap.put('\u2003', " "); mHtmlEncodeMap.put('\u2009', " "); mHtmlEncodeMap.put('\u200C', "‌"); mHtmlEncodeMap.put('\u200D', "‍"); mHtmlEncodeMap.put('\u200E', "‎"); mHtmlEncodeMap.put('\u200F', "‏"); mHtmlEncodeMap.put('\u2013', "–"); mHtmlEncodeMap.put('\u2014', "—"); mHtmlEncodeMap.put('\u2018', "‘"); mHtmlEncodeMap.put('\u2019', "’"); mHtmlEncodeMap.put('\u201A', "‚"); mHtmlEncodeMap.put('\u201C', "“"); mHtmlEncodeMap.put('\u201D', "”"); mHtmlEncodeMap.put('\u201E', "„"); mHtmlEncodeMap.put('\u2020', "†"); mHtmlEncodeMap.put('\u2021', "‡"); mHtmlEncodeMap.put('\u2030', "‰"); mHtmlEncodeMap.put('\u2039', "‹"); mHtmlEncodeMap.put('\u203A', "›"); mHtmlEncodeMap.put('\u20AC', "€"); // Character entity references for ISO 8859-1 characters mHtmlEncodeMap.put('\u00A0', " "); mHtmlEncodeMap.put('\u00A1', "¡"); mHtmlEncodeMap.put('\u00A2', "¢"); mHtmlEncodeMap.put('\u00A3', "£"); mHtmlEncodeMap.put('\u00A4', "¤"); mHtmlEncodeMap.put('\u00A5', "¥"); mHtmlEncodeMap.put('\u00A6', "¦"); mHtmlEncodeMap.put('\u00A7', "§"); mHtmlEncodeMap.put('\u00A8', "¨"); mHtmlEncodeMap.put('\u00A9', "©"); mHtmlEncodeMap.put('\u00AA', "ª"); mHtmlEncodeMap.put('\u00AB', "«"); mHtmlEncodeMap.put('\u00AC', "¬"); mHtmlEncodeMap.put('\u00AD', "­"); mHtmlEncodeMap.put('\u00AE', "®"); mHtmlEncodeMap.put('\u00AF', "¯"); mHtmlEncodeMap.put('\u00B0', "°"); mHtmlEncodeMap.put('\u00B1', "±"); mHtmlEncodeMap.put('\u00B2', "²"); mHtmlEncodeMap.put('\u00B3', "³"); mHtmlEncodeMap.put('\u00B4', "´"); mHtmlEncodeMap.put('\u00B5', "µ"); mHtmlEncodeMap.put('\u00B6', "¶"); mHtmlEncodeMap.put('\u00B7', "·"); mHtmlEncodeMap.put('\u00B8', "¸"); mHtmlEncodeMap.put('\u00B9', "¹"); mHtmlEncodeMap.put('\u00BA', "º"); mHtmlEncodeMap.put('\u00BB', "»"); mHtmlEncodeMap.put('\u00BC', "¼"); mHtmlEncodeMap.put('\u00BD', "½"); mHtmlEncodeMap.put('\u00BE', "¾"); mHtmlEncodeMap.put('\u00BF', "¿"); mHtmlEncodeMap.put('\u00C0', "À"); mHtmlEncodeMap.put('\u00C1', "Á"); mHtmlEncodeMap.put('\u00C2', "Â"); mHtmlEncodeMap.put('\u00C3', "Ã"); mHtmlEncodeMap.put('\u00C4', "Ä"); mHtmlEncodeMap.put('\u00C5', "Å"); mHtmlEncodeMap.put('\u00C6', "Æ"); mHtmlEncodeMap.put('\u00C7', "Ç"); mHtmlEncodeMap.put('\u00C8', "È"); mHtmlEncodeMap.put('\u00C9', "É"); mHtmlEncodeMap.put('\u00CA', "Ê"); mHtmlEncodeMap.put('\u00CB', "Ë"); mHtmlEncodeMap.put('\u00CC', "Ì"); mHtmlEncodeMap.put('\u00CD', "Í"); mHtmlEncodeMap.put('\u00CE', "Î"); mHtmlEncodeMap.put('\u00CF', "Ï"); mHtmlEncodeMap.put('\u00D0', "Ð"); mHtmlEncodeMap.put('\u00D1', "Ñ"); mHtmlEncodeMap.put('\u00D2', "Ò"); mHtmlEncodeMap.put('\u00D3', "Ó"); mHtmlEncodeMap.put('\u00D4', "Ô"); mHtmlEncodeMap.put('\u00D5', "Õ"); mHtmlEncodeMap.put('\u00D6', "Ö"); mHtmlEncodeMap.put('\u00D7', "×"); mHtmlEncodeMap.put('\u00D8', "Ø"); mHtmlEncodeMap.put('\u00D9', "Ù"); mHtmlEncodeMap.put('\u00DA', "Ú"); mHtmlEncodeMap.put('\u00DB', "Û"); mHtmlEncodeMap.put('\u00DC', "Ü"); mHtmlEncodeMap.put('\u00DD', "Ý"); mHtmlEncodeMap.put('\u00DE', "Þ"); mHtmlEncodeMap.put('\u00DF', "ß"); mHtmlEncodeMap.put('\u00E0', "à"); mHtmlEncodeMap.put('\u00E1', "á"); mHtmlEncodeMap.put('\u00E2', "â"); mHtmlEncodeMap.put('\u00E3', "ã"); mHtmlEncodeMap.put('\u00E4', "ä"); mHtmlEncodeMap.put('\u00E5', "å"); mHtmlEncodeMap.put('\u00E6', "æ"); mHtmlEncodeMap.put('\u00E7', "ç"); mHtmlEncodeMap.put('\u00E8', "è"); mHtmlEncodeMap.put('\u00E9', "é"); mHtmlEncodeMap.put('\u00EA', "ê"); mHtmlEncodeMap.put('\u00EB', "ë"); mHtmlEncodeMap.put('\u00EC', "ì"); mHtmlEncodeMap.put('\u00ED', "í"); mHtmlEncodeMap.put('\u00EE', "î"); mHtmlEncodeMap.put('\u00EF', "ï"); mHtmlEncodeMap.put('\u00F0', "ð"); mHtmlEncodeMap.put('\u00F1', "ñ"); mHtmlEncodeMap.put('\u00F2', "ò"); mHtmlEncodeMap.put('\u00F3', "ó"); mHtmlEncodeMap.put('\u00F4', "ô"); mHtmlEncodeMap.put('\u00F5', "õ"); mHtmlEncodeMap.put('\u00F6', "ö"); mHtmlEncodeMap.put('\u00F7', "÷"); mHtmlEncodeMap.put('\u00F8', "ø"); mHtmlEncodeMap.put('\u00F9', "ù"); mHtmlEncodeMap.put('\u00FA', "ú"); mHtmlEncodeMap.put('\u00FB', "û"); mHtmlEncodeMap.put('\u00FC', "ü"); mHtmlEncodeMap.put('\u00FD', "ý"); mHtmlEncodeMap.put('\u00FE', "þ"); mHtmlEncodeMap.put('\u00FF', "ÿ"); // Mathematical, Greek and Symbolic characters for HTML mHtmlEncodeMap.put('\u0192', "ƒ"); mHtmlEncodeMap.put('\u0391', "Α"); mHtmlEncodeMap.put('\u0392', "Β"); mHtmlEncodeMap.put('\u0393', "Γ"); mHtmlEncodeMap.put('\u0394', "Δ"); mHtmlEncodeMap.put('\u0395', "Ε"); mHtmlEncodeMap.put('\u0396', "Ζ"); mHtmlEncodeMap.put('\u0397', "Η"); mHtmlEncodeMap.put('\u0398', "Θ"); mHtmlEncodeMap.put('\u0399', "Ι"); mHtmlEncodeMap.put('\u039A', "Κ"); mHtmlEncodeMap.put('\u039B', "Λ"); mHtmlEncodeMap.put('\u039C', "Μ"); mHtmlEncodeMap.put('\u039D', "Ν"); mHtmlEncodeMap.put('\u039E', "Ξ"); mHtmlEncodeMap.put('\u039F', "Ο"); mHtmlEncodeMap.put('\u03A0', "Π"); mHtmlEncodeMap.put('\u03A1', "Ρ"); mHtmlEncodeMap.put('\u03A3', "Σ"); mHtmlEncodeMap.put('\u03A4', "Τ"); mHtmlEncodeMap.put('\u03A5', "Υ"); mHtmlEncodeMap.put('\u03A6', "Φ"); mHtmlEncodeMap.put('\u03A7', "Χ"); mHtmlEncodeMap.put('\u03A8', "Ψ"); mHtmlEncodeMap.put('\u03A9', "Ω"); mHtmlEncodeMap.put('\u03B1', "α"); mHtmlEncodeMap.put('\u03B2', "β"); mHtmlEncodeMap.put('\u03B3', "γ"); mHtmlEncodeMap.put('\u03B4', "δ"); mHtmlEncodeMap.put('\u03B5', "ε"); mHtmlEncodeMap.put('\u03B6', "ζ"); mHtmlEncodeMap.put('\u03B7', "η"); mHtmlEncodeMap.put('\u03B8', "θ"); mHtmlEncodeMap.put('\u03B9', "ι"); mHtmlEncodeMap.put('\u03BA', "κ"); mHtmlEncodeMap.put('\u03BB', "λ"); mHtmlEncodeMap.put('\u03BC', "μ"); mHtmlEncodeMap.put('\u03BD', "ν"); mHtmlEncodeMap.put('\u03BE', "ξ"); mHtmlEncodeMap.put('\u03BF', "ο"); mHtmlEncodeMap.put('\u03C0', "π"); mHtmlEncodeMap.put('\u03C1', "ρ"); mHtmlEncodeMap.put('\u03C2', "ς"); mHtmlEncodeMap.put('\u03C3', "σ"); mHtmlEncodeMap.put('\u03C4', "τ"); mHtmlEncodeMap.put('\u03C5', "υ"); mHtmlEncodeMap.put('\u03C6', "φ"); mHtmlEncodeMap.put('\u03C7', "χ"); mHtmlEncodeMap.put('\u03C8', "ψ"); mHtmlEncodeMap.put('\u03C9', "ω"); mHtmlEncodeMap.put('\u03D1', "ϑ"); mHtmlEncodeMap.put('\u03D2', "ϒ"); mHtmlEncodeMap.put('\u03D6', "ϖ"); mHtmlEncodeMap.put('\u2022', "•"); mHtmlEncodeMap.put('\u2026', "…"); mHtmlEncodeMap.put('\u2032', "′"); mHtmlEncodeMap.put('\u2033', "″"); mHtmlEncodeMap.put('\u203E', "‾"); mHtmlEncodeMap.put('\u2044', "⁄"); mHtmlEncodeMap.put('\u2118', "℘"); mHtmlEncodeMap.put('\u2111', "ℑ"); mHtmlEncodeMap.put('\u211C', "ℜ"); mHtmlEncodeMap.put('\u2122', "™"); mHtmlEncodeMap.put('\u2135', "ℵ"); mHtmlEncodeMap.put('\u2190', "←"); mHtmlEncodeMap.put('\u2191', "↑"); mHtmlEncodeMap.put('\u2192', "→"); mHtmlEncodeMap.put('\u2193', "↓"); mHtmlEncodeMap.put('\u2194', "↔"); mHtmlEncodeMap.put('\u21B5', "↵"); mHtmlEncodeMap.put('\u21D0', "⇐"); mHtmlEncodeMap.put('\u21D1', "⇑"); mHtmlEncodeMap.put('\u21D2', "⇒"); mHtmlEncodeMap.put('\u21D3', "⇓"); mHtmlEncodeMap.put('\u21D4', "⇔"); mHtmlEncodeMap.put('\u2200', "∀"); mHtmlEncodeMap.put('\u2202', "∂"); mHtmlEncodeMap.put('\u2203', "∃"); mHtmlEncodeMap.put('\u2205', "∅"); mHtmlEncodeMap.put('\u2207', "∇"); mHtmlEncodeMap.put('\u2208', "∈"); mHtmlEncodeMap.put('\u2209', "∉"); mHtmlEncodeMap.put('\u220B', "∋"); mHtmlEncodeMap.put('\u220F', "∏"); mHtmlEncodeMap.put('\u2211', "∑"); mHtmlEncodeMap.put('\u2212', "−"); mHtmlEncodeMap.put('\u2217', "∗"); mHtmlEncodeMap.put('\u221A', "√"); mHtmlEncodeMap.put('\u221D', "∝"); mHtmlEncodeMap.put('\u221E', "∞"); mHtmlEncodeMap.put('\u2220', "∠"); mHtmlEncodeMap.put('\u2227', "∧"); mHtmlEncodeMap.put('\u2228', "∨"); mHtmlEncodeMap.put('\u2229', "∩"); mHtmlEncodeMap.put('\u222A', "∪"); mHtmlEncodeMap.put('\u222B', "∫"); mHtmlEncodeMap.put('\u2234', "∴"); mHtmlEncodeMap.put('\u223C', "∼"); mHtmlEncodeMap.put('\u2245', "≅"); mHtmlEncodeMap.put('\u2248', "≈"); mHtmlEncodeMap.put('\u2260', "≠"); mHtmlEncodeMap.put('\u2261', "≡"); mHtmlEncodeMap.put('\u2264', "≤"); mHtmlEncodeMap.put('\u2265', "≥"); mHtmlEncodeMap.put('\u2282', "⊂"); mHtmlEncodeMap.put('\u2283', "⊃"); mHtmlEncodeMap.put('\u2284', "⊄"); mHtmlEncodeMap.put('\u2286', "⊆"); mHtmlEncodeMap.put('\u2287', "⊇"); mHtmlEncodeMap.put('\u2295', "⊕"); mHtmlEncodeMap.put('\u2297', "⊗"); mHtmlEncodeMap.put('\u22A5', "⊥"); mHtmlEncodeMap.put('\u22C5', "⋅"); mHtmlEncodeMap.put('\u2308', "⌈"); mHtmlEncodeMap.put('\u2309', "⌉"); mHtmlEncodeMap.put('\u230A', "⌊"); mHtmlEncodeMap.put('\u230B', "⌋"); mHtmlEncodeMap.put('\u2329', "⟨"); mHtmlEncodeMap.put('\u232A', "⟩"); mHtmlEncodeMap.put('\u25CA', "◊"); mHtmlEncodeMap.put('\u2660', "♠"); mHtmlEncodeMap.put('\u2663', "♣"); mHtmlEncodeMap.put('\u2665', "♥"); mHtmlEncodeMap.put('\u2666', "♦"); } private StringUtils() { } /** * Transforms a provided String object into a new string, * containing only valid Html characters. * * @param source The string that has to be transformed into a valid Html * string. * * @return The encoded String object. * * @since 1.0 */ public static String encodeHtml(String source) { return encode(source, mHtmlEncodeMap); } /** * Transforms a provided String object into a new string, * using the mapping that are provided through the supplied encoding table. * * @param source The string that has to be transformed into a valid string, * using the mappings that are provided through the supplied encoding table. * @param encodingTables A Map object containing the mappings to * transform characters into valid entities. The keys of this map should be * Character objects and the values String * objects. * * @return The encoded String object. * * @since 1.0 */ private static String encode(String source, Char2ObjectOpenHashMap encodingTable) { if (null == source) { return null; } if (null == encodingTable) { return source; } StringBuffer encoded_string = null; char[] string_to_encode_array = source.toCharArray(); int last_match = -1; int difference = 0; for (int i = 0; i < string_to_encode_array.length; i++) { char char_to_encode = string_to_encode_array[i]; if (encodingTable.containsKey(char_to_encode)) { if (null == encoded_string) { encoded_string = new StringBuffer(source.length()); } difference = i - (last_match + 1); if (difference > 0) { encoded_string.append(string_to_encode_array, last_match + 1, difference); } encoded_string.append(encodingTable.get(char_to_encode)); last_match = i; } } if (null == encoded_string) { return source; } else { difference = string_to_encode_array.length - (last_match + 1); if (difference > 0) { encoded_string.append(string_to_encode_array, last_match + 1, difference); } return encoded_string.toString(); } } /** * Checks if the name filters through an including and an excluding * regular expression. * * @param name The String that will be filtered. * @param included The regular expressions that needs to succeed * @param excluded The regular expressions that needs to fail * * @return true if the name filtered through correctly; or *

* false otherwise. * * @since 1.0 */ public static boolean filter(String name, Pattern included, Pattern excluded) { Pattern[] included_array = null; if (included != null) { included_array = new Pattern[] {included}; } Pattern[] excluded_array = null; if (excluded != null) { excluded_array = new Pattern[] {excluded}; } return filter(name, included_array, excluded_array); } /** * Checks if the name filters through a series of including and excluding * regular expressions. * * @param name The String that will be filtered. * @param included An array of regular expressions that need to succeed * @param excluded An array of regular expressions that need to fail * * @return true if the name filtered through correctly; or *

* false otherwise. * * @since 1.0 */ public static boolean filter(String name, Pattern[] included, Pattern[] excluded) { if (null == name) { return false; } boolean accepted = false; // retain only the includes if (null == included) { accepted = true; } else { Pattern pattern; for (int i = 0; i < included.length; i++) { pattern = included[i]; if (pattern != null && pattern.matcher(name).matches()) { accepted = true; break; } } } // remove the excludes if (accepted && excluded != null) { Pattern pattern; for (int i = 0; i < excluded.length; i++) { pattern = excluded[i]; if (pattern != null && pattern.matcher(name).matches()) { accepted = false; break; } } } return accepted; } /** * Splits a string into different parts, using a seperator string to detect * the seperation boundaries in a case-sensitive manner. The seperator will * not be included in the list of parts. * * @param source The string that will be split into parts. * @param seperator The seperator string that will be used to determine the * parts. * * @return An ArrayList containing the parts as * String objects. * * @since 1.0 */ public static ArrayList split(String source, String seperator) { return split(source, seperator, true); } /** * Splits a string into different parts, using a seperator string to detect * the seperation boundaries. The seperator will not be included in the list * of parts. * * @param source The string that will be split into parts. * @param seperator The seperator string that will be used to determine the * parts. * @param matchCase A boolean indicating if the match is going * to be performed in a case-sensitive manner or not. * * @return An ArrayList containing the parts as * String objects. * * @since 1.0 */ public static ArrayList split(String source, String seperator, boolean matchCase) { ArrayList substrings = new ArrayList(); if (null == source) { return substrings; } if (null == seperator) { substrings.add(source); return substrings; } int current_index = 0; int delimiter_index = 0; String element = null; String source_lookup_reference = null; if (!matchCase) { source_lookup_reference = source.toLowerCase(); seperator = seperator.toLowerCase(); } else { source_lookup_reference = source; } while (current_index <= source_lookup_reference.length()) { delimiter_index = source_lookup_reference.indexOf(seperator, current_index); if (-1 == delimiter_index) { element = new String(source.substring(current_index, source.length())); substrings.add(element); current_index = source.length() + 1; } else { element = new String(source.substring(current_index, delimiter_index)); substrings.add(element); current_index = delimiter_index + seperator.length(); } } return substrings; } /** * Searches for a string within a specified string in a case-sensitive * manner and replaces every match with another string. * * @param source The string in which the matching parts will be replaced. * @param stringToReplace The string that will be searched for. * @param replacementString The string that will replace each matching part. * * @return A new String object containing the replacement * result. * * @since 1.0 */ public static String replace(String source, String stringToReplace, String replacementString) { return replace(source, stringToReplace, replacementString, true); } /** * Searches for a string within a specified string and replaces every match * with another string. * * @param source The string in which the matching parts will be replaced. * @param stringToReplace The string that will be searched for. * @param replacementString The string that will replace each matching part. * @param matchCase A boolean indicating if the match is going * to be performed in a case-sensitive manner or not. * * @return A new String object containing the replacement * result. * * @since 1.0 */ public static String replace(String source, String stringToReplace, String replacementString, boolean matchCase) { if (null == source) { return null; } if (null == stringToReplace) { return source; } if (null == replacementString) { return source; } Iterator string_parts = split(source, stringToReplace, matchCase).iterator(); StringBuffer new_string = new StringBuffer(); synchronized (new_string) // speed increase by thread lock pre-allocation { while (string_parts.hasNext()) { String string_part = (String)string_parts.next(); new_string.append(string_part); if (string_parts.hasNext()) { new_string.append(replacementString); } } return new_string.toString(); } } /** * Creates a new string that contains the provided string a number of times. * * @param source The string that will be repeated. * @param count The number of times that the string will be repeated. * @return A new String object containing the repeated * concatenation result. * * @since 1.0 */ public static String repeat(String source, int count) { if (null == source) { return null; } StringBuffer new_string = new StringBuffer(); synchronized (new_string) // speed increase by thread lock pre-allocation { while (count > 0) { new_string.append(source); count --; } return new_string.toString(); } } /** * Converts all tabs on a line to spaces according to the provided tab * width. * * @param line The line whose tabs have to be converted. * @param tabWidth The tab width. * @return A new String object containing the line with the * replaced tabs. * @since 1.0 */ public static String convertTabsToSpaces(String line, int tabWidth) { StringBuffer result = new StringBuffer(); synchronized (result) // speed increase by thread lock pre-allocation { int tab_index = -1; int last_tab_index = 0; int added_chars = 0; int tab_size; while ((tab_index = line.indexOf("\t", last_tab_index)) != -1) { tab_size = tabWidth - ((tab_index + added_chars) % tabWidth); if (0 == tab_size) { tab_size = tabWidth; } added_chars += tab_size - 1; result.append(line.substring(last_tab_index, tab_index)); result.append(StringUtils.repeat(" ", tab_size)); last_tab_index = tab_index + 1; } if (0 == last_tab_index) { return line; } else { result.append(line.substring(last_tab_index)); } } return result.toString(); } } jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/tools/exceptions/000077500000000000000000000000001422762524200304305ustar00rootroot00000000000000FileUtilsErrorException.java000066400000000000000000000015401422762524200360050ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/java/org/codelibs/jhighlight/tools/exceptions/* * Copyright 2001-2006 Geert Bevin * Distributed under the terms of either: * - the common development and distribution license (CDDL), v1.0; or * - the GNU Lesser General Public License, v2.1 or later * $Id: FileUtilsErrorException.java 3108 2006-03-13 18:03:00Z gbevin $ */ package org.codelibs.jhighlight.tools.exceptions; /** * Exception that will be trigger when unexpected errors occur during the * functionalities of the {@link org.codelibs.jhighlight.tools.FileUtils} class. * * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @version $Revision: 3108 $ * @since 1.0 */ public class FileUtilsErrorException extends Exception { public FileUtilsErrorException(String message) { super(message); } public FileUtilsErrorException(String message, Throwable cause) { super(message, cause); } } jhighlight-jhighlight-1.1.0/src/main/resources/000077500000000000000000000000001422762524200215045ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/main/resources/JHIGHLIGHT_VERSION000066400000000000000000000000041422762524200242470ustar00rootroot000000000000001.1 jhighlight-jhighlight-1.1.0/src/main/resources/jhighlight.properties000066400000000000000000000042361422762524200257500ustar00rootroot00000000000000h1 = \ \ font-family: sans-serif; \ font-size: 16pt; \ font-weight: bold; \ color: rgb(0,0,0); \ background: rgb(210,210,210); \ border: solid 1px black; \ padding: 5px; \ text-align: center; code = \ \ color: rgb(0,0,0); \ font-family: monospace; \ font-size: 12px; \ white-space: nowrap; .java_plain = \ \ color: rgb(0,0,0); .java_keyword = \ \ color: rgb(0,0,0); \ font-weight: bold; .java_type = \ \ color: rgb(0,44,221); .java_operator = \ \ color: rgb(0,124,31); .java_separator = \ \ color: rgb(0,33,255); .java_literal = \ \ color: rgb(188,0,0); .java_comment = \ \ color: rgb(147,147,147); \ background-color: rgb(247,247,247); .java_javadoc_comment = \ \ color: rgb(147,147,147); \ background-color: rgb(247,247,247); \ font-style: italic; .java_javadoc_tag = \ \ color: rgb(147,147,147); \ background-color: rgb(247,247,247); \ font-style: italic; \ font-weight: bold; .xml_plain = \ \ color: rgb(0,0,0); .xml_char_data = \ \ color: rgb(0,0,0); .xml_tag_symbols = \ \ color: rgb(0,59,255); .xml_comment = \ \ color: rgb(147,147,147); \ background-color: rgb(247,247,247); .xml_attribute_value = \ \ color: rgb(193,0,0); .xml_attribute_name = \ \ color: rgb(0,0,0); \ font-weight: bold; .xml_processing_instruction = \ \ color: rgb(0,0,0); \ font-weight: bold; \ font-style: italic; .xml_tag_name = \ \ color: rgb(0,55,255); .xml_rife_tag = \ \ color: rgb(0,0,0); \ background-color: rgb(228,230,160); .xml_rife_name = \ \ color: rgb(0,0,196); \ background-color: rgb(228,230,160); .cpp_plain \ \ color: rgb(0,0,0); .cpp_keyword \ \ color: rgb(0,0,0); \ font-weight: bold; .cpp_type \ \ color: rgb(0,44,221); .cpp_operator \ \ color: rgb(0,124,31); .cpp_separator \ \ color: rgb(0,33,255); .cpp_literal \ \ color: rgb(188,0,0); .cpp_comment \ \ color: rgb(147,147,147); \ background-color: rgb(247,247,247); .cpp_doxygen_comment \ \ color: rgb(147,147,147); \ background-color: rgb(247,247,247); \ font-style: italic; .cpp_doxygen_tag \ \ color: rgb(147,147,147); \ background-color: rgb(247,247,247); \ font-style: italic; \ font-weight: bold; .cpp_preproc \ \ color: purple; jhighlight-jhighlight-1.1.0/src/test/000077500000000000000000000000001422762524200175255ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/test/java/000077500000000000000000000000001422762524200204465ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/test/java/com/000077500000000000000000000000001422762524200212245ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/test/java/com/uwyn/000077500000000000000000000000001422762524200222265ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/test/java/com/uwyn/jhighlight/000077500000000000000000000000001422762524200243475ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/test/java/com/uwyn/jhighlight/renderer/000077500000000000000000000000001422762524200261555ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/test/java/com/uwyn/jhighlight/renderer/XhtmlRendererFactoryTest.java000066400000000000000000000227251422762524200340030ustar00rootroot00000000000000package com.uwyn.jhighlight.renderer; import static com.uwyn.jhighlight.renderer.XhtmlRendererFactory.CPP; import static com.uwyn.jhighlight.renderer.XhtmlRendererFactory.GROOVY; import static com.uwyn.jhighlight.renderer.XhtmlRendererFactory.JAVA; import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Test; public class XhtmlRendererFactoryTest { @SuppressWarnings("deprecation") @Test public void rendererOnCpp() throws IOException { Renderer renderer = XhtmlRendererFactory.getRenderer(CPP); String in = "int value = 10;"; String codeAsHtml = renderer.highlight("test.cpp", in, "utf-8", false); assertEquals( "\n" + "\n" + "\n" + " \n" + " \n" + " test.cpp\n" + " \n" + " \n" + "\n" + "\n" + "

test.cpp

int value = 10;
\n" + "
\n" + "\n" + "\n", codeAsHtml); } @SuppressWarnings("deprecation") @Test public void rendererOnGroovy() throws IOException { Renderer renderer = XhtmlRendererFactory.getRenderer(GROOVY); String in = "int value = 10;"; String codeAsHtml = renderer.highlight("test.groovy", in, "utf-8", false); assertEquals( "\n" + "\n" + "\n" + " \n" + " \n" + " test.groovy\n" + " \n" + " \n" + "\n" + "\n" + "

test.groovy

int value = 10;
\n" + "
\n" + "\n" + "\n", codeAsHtml); } @SuppressWarnings("deprecation") @Test public void rendererOnJava() throws IOException { Renderer renderer = XhtmlRendererFactory.getRenderer(JAVA); String in = "int value = 10;"; String codeAsHtml = renderer.highlight("test.java", in, "utf-8", false); assertEquals( "\n" + "\n" + "\n" + " \n" + " \n" + " test.java\n" + " \n" + " \n" + "\n" + "\n" + "

test.java

int value = 10;
\n" + "
\n" + "\n" + "\n", codeAsHtml); } } jhighlight-jhighlight-1.1.0/src/test/java/org/000077500000000000000000000000001422762524200212355ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/test/java/org/codelibs/000077500000000000000000000000001422762524200230215ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/test/java/org/codelibs/jhighlight/000077500000000000000000000000001422762524200251425ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/test/java/org/codelibs/jhighlight/renderer/000077500000000000000000000000001422762524200267505ustar00rootroot00000000000000XhtmlRendererFactoryTest.java000066400000000000000000000225661422762524200345220ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/test/java/org/codelibs/jhighlight/rendererpackage org.codelibs.jhighlight.renderer; import static org.codelibs.jhighlight.renderer.XhtmlRendererFactory.CPP; import static org.codelibs.jhighlight.renderer.XhtmlRendererFactory.GROOVY; import static org.codelibs.jhighlight.renderer.XhtmlRendererFactory.JAVA; import static org.junit.Assert.assertEquals; import java.io.IOException; import org.junit.Test; public class XhtmlRendererFactoryTest { @Test public void rendererOnCpp() throws IOException { Renderer renderer = XhtmlRendererFactory.getRenderer(CPP); String in = "int value = 10;"; String codeAsHtml = renderer.highlight("test.cpp", in, "utf-8", false); assertEquals( "\n" + "\n" + "\n" + " \n" + " \n" + " test.cpp\n" + " \n" + " \n" + "\n" + "\n" + "

test.cpp

int value = 10;
\n" + "
\n" + "\n" + "\n", codeAsHtml); } @Test public void rendererOnGroovy() throws IOException { Renderer renderer = XhtmlRendererFactory.getRenderer(GROOVY); String in = "int value = 10;"; String codeAsHtml = renderer.highlight("test.groovy", in, "utf-8", false); assertEquals( "\n" + "\n" + "\n" + " \n" + " \n" + " test.groovy\n" + " \n" + " \n" + "\n" + "\n" + "

test.groovy

int value = 10;
\n" + "
\n" + "\n" + "\n", codeAsHtml); } @Test public void rendererOnJava() throws IOException { Renderer renderer = XhtmlRendererFactory.getRenderer(JAVA); String in = "int value = 10;"; String codeAsHtml = renderer.highlight("test.java", in, "utf-8", false); assertEquals( "\n" + "\n" + "\n" + " \n" + " \n" + " test.java\n" + " \n" + " \n" + "\n" + "\n" + "

test.java

int value = 10;
\n" + "
\n" + "\n" + "\n", codeAsHtml); } } jhighlight-jhighlight-1.1.0/src/test/java/org/codelibs/jhighlight/tools/000077500000000000000000000000001422762524200263025ustar00rootroot00000000000000jhighlight-jhighlight-1.1.0/src/test/java/org/codelibs/jhighlight/tools/StringUtilsTest.java000066400000000000000000000011461422762524200322760ustar00rootroot00000000000000package org.codelibs.jhighlight.tools; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import org.codelibs.jhighlight.tools.StringUtils; import org.junit.Test; public class StringUtilsTest { @Test public void encodeHtml() { assertEquals("abc", StringUtils.encodeHtml("abc")); assertEquals("a&c", StringUtils.encodeHtml("a&c")); assertEquals("<b>abc</b>", StringUtils.encodeHtml("abc")); assertNull(StringUtils.encodeHtml(null)); assertEquals("", StringUtils.encodeHtml("")); } }