View Javadoc
1   /*
2   Copyright (c) 2011 James Ahlborn
3   
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7   
8       http://www.apache.org/licenses/LICENSE-2.0
9   
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16  
17  package com.healthmarketscience.jackcess.impl;
18  
19  
20  
21  /**
22   * Various constants used for creating "general" (access 2010+) sort order
23   * text index entries.
24   *
25   * @author James Ahlborn
26   */
27  public class GeneralIndexCodes extends GeneralLegacyIndexCodes {
28  
29    // stash the codes in some resource files
30    private static final String CODES_FILE = 
31      DatabaseImpl.RESOURCE_PATH + "index_codes_gen.txt";
32    private static final String EXT_CODES_FILE = 
33      DatabaseImpl.RESOURCE_PATH + "index_codes_ext_gen.txt";
34  
35    private static final class Codes
36    {
37      /** handlers for the first 256 chars.  use nested class to lazy load the
38          handlers */
39      private static final CharHandler[] _values = loadCodes(
40          CODES_FILE, FIRST_CHAR, LAST_CHAR);
41    }
42    
43    private static final class ExtCodes
44    {
45      /** handlers for the rest of the chars in BMP 0.  use nested class to
46          lazy load the handlers */
47      private static final CharHandler[] _values = loadCodes(
48          EXT_CODES_FILE, FIRST_EXT_CHAR, LAST_EXT_CHAR);
49    }
50  
51    static final GeneralIndexCodes GEN_INSTANCE = new GeneralIndexCodes();
52  
53    GeneralIndexCodes() {
54    }
55  
56    /**
57     * Returns the CharHandler for the given character.
58     */
59    @Override
60    CharHandler getCharHandler(char c)
61    {
62      if(c <= LAST_CHAR) {
63        return Codes._values[c];
64      }
65  
66      int extOffset = asUnsignedChar(c) - asUnsignedChar(FIRST_EXT_CHAR);
67      return ExtCodes._values[extOffset];
68    }
69  
70  }