com.ibm.icu.util.VersionInfo Java Examples

The following examples show how to use com.ibm.icu.util.VersionInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestICUVersionRecord.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public void test_roundTrip2() {

        final ICUVersionRecord r1 = new ICUVersionRecord(
                VersionInfo.getInstance(3, 6, 2, 1),//
                VersionInfo.getInstance(1, 8, 5, 7),//
                VersionInfo.getInstance(6, 3, 1, 8),//
                VersionInfo.getInstance(4, 6, 8, 12)//
                );

        final ICUVersionRecord r2 = new ICUVersionRecord( 
            VersionInfo.getInstance(3, 6, 2, 1),//
            VersionInfo.getInstance(1, 8, 5, 7),//
            VersionInfo.getInstance(6, 3, 1, 8),//
            VersionInfo.getInstance(4, 6, 8, 12)//
            );
        
        assertTrue(r1.equals(r2));
        
        assertFalse(r1.equals(ICUVersionRecord.newInstance()));
        
        final ICUVersionRecord r3 = (ICUVersionRecord) SerializerUtil
                .deserialize(SerializerUtil.serialize(r1));

        assertTrue(r1.equals(r3));

    }
 
Example #2
Source File: UnicodeSet.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean contains(int ch) {
    VersionInfo v = UCharacter.getAge(ch);
    // Reference comparison ok; VersionInfo caches and reuses
    // unique objects.
    return !Utility.sameObjects(v, NO_VERSION) &&
            v.compareTo(version) <= 0;
}
 
Example #3
Source File: ICUVersionRecord.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private void writeVersionInfo(final VersionInfo v, final ObjectOutput out)
        throws IOException {

    out.writeInt(v.getMajor());
    out.writeInt(v.getMinor());
    out.writeInt(v.getMicro());
    out.writeInt(v.getMilli());

}
 
Example #4
Source File: ICUVersionRecord.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Factory returns a record reporting on the ICU dependency as currently
 * linked with the code base.
 */
public static ICUVersionRecord newInstance() {
    
    final ICUVersionRecord r = new ICUVersionRecord(//
            VersionInfo.ICU_VERSION,//
            VersionInfo.UCOL_RUNTIME_VERSION,//
            VersionInfo.UCOL_BUILDER_VERSION,//
            VersionInfo.UCOL_TAILORINGS_VERSION//
            );

    return r;

}
 
Example #5
Source File: ICUBinary.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Same as readHeader(), but returns a VersionInfo rather than a compact int.
 */
public static VersionInfo readHeaderAndDataVersion(ByteBuffer bytes,
                                                         int dataFormat,
                                                         Authenticate authenticate)
                                                            throws IOException {
    return getVersionInfoFromCompactInt(readHeader(bytes, dataFormat, authenticate));
}
 
Example #6
Source File: ICUDebug.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public static VersionInfo getInstanceLenient(String s) {
    // Extracting ASCII numbers up to 4 delimited by
    // any non digit characters
    int[] ver = new int[4];
    boolean numeric = false;
    int i = 0, vidx = 0;
    while (i < s.length()) {
        char c = s.charAt(i++);
        if (c < '0' || c > '9') {
            if (numeric) {
                if (vidx == 3) {
                    // up to 4 numbers
                    break;
                }
                numeric = false;
                vidx++;
            }
        } else {
            if (numeric) {
                ver[vidx] = ver[vidx] * 10 + (c - '0');
                if (ver[vidx] > 255) {
                    // VersionInfo does not support numbers
                    // greater than 255.  In such case, we
                    // ignore the number and the rest
                    ver[vidx] = 0;
                    break;
                }
            } else {
                numeric = true;
                ver[vidx] = c - '0';
            }
        }
    }

    return VersionInfo.getInstance(ver[0], ver[1], ver[2], ver[3]);
}
 
Example #7
Source File: StringPrep.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
private StringPrep(ByteBuffer bytes) throws IOException {
    StringPrepDataReader reader = new StringPrepDataReader(bytes);

    // read the indexes
    indexes = reader.readIndexes(INDEX_TOP);

    sprepTrie = new CharTrie(bytes, null);

    //indexes[INDEX_MAPPING_DATA_SIZE] store the size of mappingData in bytes
    // load the rest of the data data and initialize the data members
    mappingData = reader.read(indexes[INDEX_MAPPING_DATA_SIZE]/2);

    // get the options
    doNFKC            = ((indexes[OPTIONS] & NORMALIZATION_ON) > 0);
    checkBiDi         = ((indexes[OPTIONS] & CHECK_BIDI_ON) > 0);
    sprepUniVer   = getVersionInfo(reader.getUnicodeVersion());
    normCorrVer   = getVersionInfo(indexes[NORM_CORRECTNS_LAST_UNI_VERSION]);
    VersionInfo normUniVer = UCharacter.getUnicodeVersion();
    if(normUniVer.compareTo(sprepUniVer) < 0 && /* the Unicode version of SPREP file must be less than the Unicode Vesion of the normalization data */
       normUniVer.compareTo(normCorrVer) < 0 && /* the Unicode version of the NormalizationCorrections.txt file should be less than the Unicode Vesion of the normalization data */
       ((indexes[OPTIONS] & NORMALIZATION_ON) > 0) /* normalization turned on*/
       ){
        throw new IOException("Normalization Correction version not supported");
    }

    if(checkBiDi) {
        bdp=UBiDiProps.INSTANCE;
    }
}
 
Example #8
Source File: StringPrep.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
private static VersionInfo getVersionInfo(int comp){
    int micro = comp & 0xFF;
    int milli =(comp >> 8)  & 0xFF;
    int minor =(comp >> 16) & 0xFF;
    int major =(comp >> 24) & 0xFF;
    return VersionInfo.getInstance(major,minor,milli,micro);
}
 
Example #9
Source File: RuleBasedCollator.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Get the version of this collator object.
 * 
 * @return the version object associated with this collator
 * @stable ICU 2.8
 */
@Override
public VersionInfo getVersion() {
    int version = tailoring.version;
    int rtVersion = VersionInfo.UCOL_RUNTIME_VERSION.getMajor();
    return VersionInfo.getInstance(
            (version >>> 24) + (rtVersion << 4) + (rtVersion >> 4),
            ((version >> 16) & 0xff), ((version >> 8) & 0xff), (version & 0xff));
}
 
Example #10
Source File: ICUBinary.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Same as readHeader(), but returns a VersionInfo rather than a compact int.
 */
public static VersionInfo readHeaderAndDataVersion(ByteBuffer bytes,
                                                         int dataFormat,
                                                         Authenticate authenticate)
                                                            throws IOException {
    return getVersionInfoFromCompactInt(readHeader(bytes, dataFormat, authenticate));
}
 
Example #11
Source File: CollationTailoring.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
void setVersion(int baseVersion, int rulesVersion) {
    // See comments for version field.
    int r = (rulesVersion >> 16) & 0xff00;
    int s = (rulesVersion >> 16) & 0xff;
    int t = (rulesVersion >> 8) & 0xff;
    int q = rulesVersion & 0xff;
    version = (VersionInfo.UCOL_BUILDER_VERSION.getMajor() << 24) |
            (baseVersion & 0xffc000) |  // UCA version u.v.w
            ((r + (r >> 6)) & 0x3f00) |
            (((s << 3) + (s >> 5) + t + (q << 4) + (q >> 4)) & 0xff);
}
 
Example #12
Source File: CollationTailoring.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
static VersionInfo makeBaseVersion(VersionInfo ucaVersion) {
    return VersionInfo.getInstance(
            VersionInfo.UCOL_BUILDER_VERSION.getMajor(),
            (ucaVersion.getMajor() << 3) + ucaVersion.getMinor(),
            ucaVersion.getMilli() << 6,
            0);
}
 
Example #13
Source File: ICUDebug.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
public static VersionInfo getInstanceLenient(String s) {
    // Extracting ASCII numbers up to 4 delimited by
    // any non digit characters
    int[] ver = new int[4];
    boolean numeric = false;
    int i = 0, vidx = 0;
    while (i < s.length()) {
        char c = s.charAt(i++);
        if (c < '0' || c > '9') {
            if (numeric) {
                if (vidx == 3) {
                    // up to 4 numbers
                    break;
                }
                numeric = false;
                vidx++;
            }
        } else {
            if (numeric) {
                ver[vidx] = ver[vidx] * 10 + (c - '0');
                if (ver[vidx] > 255) {
                    // VersionInfo does not support numbers
                    // greater than 255.  In such case, we
                    // ignore the number and the rest
                    ver[vidx] = 0;
                    break;
                }
            } else {
                numeric = true;
                ver[vidx] = c - '0';
            }
        }
    }

    return VersionInfo.getInstance(ver[0], ver[1], ver[2], ver[3]);
}
 
Example #14
Source File: RuleBasedCollator.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Get the UCA version of this collator object.
 * 
 * @return the version object associated with this collator
 * @stable ICU 2.8
 */
@Override
public VersionInfo getUCAVersion() {
    VersionInfo v = getVersion();
    // Note: This is tied to how the current implementation encodes the UCA version
    // in the overall getVersion().
    // Alternatively, we could load the root collator and get at lower-level data from there.
    // Either way, it will reflect the input collator's UCA version only
    // if it is a known implementation.
    // (C++ comment) It would be cleaner to make this a virtual Collator method.
    // (In Java, it is virtual.)
    return VersionInfo.getInstance(v.getMinor() >> 3, v.getMinor() & 7, v.getMilli() >> 6, 0);
}
 
Example #15
Source File: UnicodeSet.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
@Override
public boolean contains(int ch) {
    VersionInfo v = UCharacter.getAge(ch);
    // Reference comparison ok; VersionInfo caches and reuses
    // unique objects.
    return !Utility.sameObjects(v, NO_VERSION) &&
            v.compareTo(version) <= 0;
}
 
Example #16
Source File: StringPrep.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
private static VersionInfo getVersionInfo(int comp){
    int micro = comp & 0xFF;
    int milli =(comp >> 8)  & 0xFF;
    int minor =(comp >> 16) & 0xFF;
    int major =(comp >> 24) & 0xFF;
    return VersionInfo.getInstance(major,minor,milli,micro);
}
 
Example #17
Source File: StringPrep.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
private StringPrep(ByteBuffer bytes) throws IOException {
    StringPrepDataReader reader = new StringPrepDataReader(bytes);

    // read the indexes
    indexes = reader.readIndexes(INDEX_TOP);

    sprepTrie = new CharTrie(bytes, null);

    //indexes[INDEX_MAPPING_DATA_SIZE] store the size of mappingData in bytes
    // load the rest of the data data and initialize the data members
    mappingData = reader.read(indexes[INDEX_MAPPING_DATA_SIZE]/2);

    // get the options
    doNFKC            = ((indexes[OPTIONS] & NORMALIZATION_ON) > 0);
    checkBiDi         = ((indexes[OPTIONS] & CHECK_BIDI_ON) > 0);
    sprepUniVer   = getVersionInfo(reader.getUnicodeVersion());
    normCorrVer   = getVersionInfo(indexes[NORM_CORRECTNS_LAST_UNI_VERSION]);
    VersionInfo normUniVer = UCharacter.getUnicodeVersion();
    if(normUniVer.compareTo(sprepUniVer) < 0 && /* the Unicode version of SPREP file must be less than the Unicode Vesion of the normalization data */
       normUniVer.compareTo(normCorrVer) < 0 && /* the Unicode version of the NormalizationCorrections.txt file should be less than the Unicode Vesion of the normalization data */
       ((indexes[OPTIONS] & NORMALIZATION_ON) > 0) /* normalization turned on*/
       ){
        throw new IOException("Normalization Correction version not supported");
    }

    if(checkBiDi) {
        bdp=UBiDiProps.INSTANCE;
    }
}
 
Example #18
Source File: ICUDataVersion.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * This function retrieves the data version from icuver and returns a VersionInfo object with that version information.
 *
 * @return Current icu data version
 */
public static VersionInfo getDataVersion() {
    UResourceBundle icudatares = null;
    try {
        icudatares = UResourceBundle.getBundleInstance(
                ICUData.ICU_BASE_NAME,
                ICUDataVersion.U_ICU_VERSION_BUNDLE,
                ICUResourceBundle.ICU_DATA_CLASS_LOADER);
        icudatares = icudatares.get(ICUDataVersion.U_ICU_DATA_KEY);
    } catch (MissingResourceException ex) {
        return null;
    }
    
    return  VersionInfo.getInstance(icudatares.getString());
}
 
Example #19
Source File: TestICUPortabilityBug.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Unit test for ICU generation of Unicode sort keys.
 * <pre>
 * Input   : "__globalRowStore"
 * 
 * Expected: [7, -124, 7, -124, 53, 63, 69, 43, 41, 63, 75, 69, 85, 77, 79, 69, 75, 49, 1, 20, 1, 126, -113, -124, -113, 8]
 * </pre>
 */
public void test_ICU_Unicode_SortKey() {
    
    final String input = "__globalRowStore";

    // Buffer reused for each String from which a sort key is derived.
    final RawCollationKey raw = new RawCollationKey(128);

    /*
     * Setup the collator by specifying the locale, strength, and
     * decomposition mode.
     */
    final Locale locale = new Locale("en", "US");
    
    final RuleBasedCollator collator = (RuleBasedCollator) Collator
            .getInstance(locale);

    collator.setStrength(Collator.TERTIARY);

    collator.setDecomposition(Collator.NO_DECOMPOSITION);

    collator.getRawCollationKey(input, raw);

    // do not include the nul byte
    final byte[] actual = new byte[raw.size - 1];

    // copy data from the buffer.
    System.arraycopy(raw.bytes/* src */, 0/* srcPos */, actual/* dest */,
            0/* destPos */, actual.length);

    if (log.isInfoEnabled()) {
        log.info("Actual  : " + Arrays.toString(actual));
    }
    
    /*
     * The expected Unicode sort key (this depends on the runtime ICU
     * version).
     */
    final byte[] expected;
    if (VersionInfo.ICU_VERSION.getMajor() == 3
            && VersionInfo.ICU_VERSION.getMinor() == 6) {
        /*
         * bigdata was initially deployed against v3.6.
         */
        expected = new byte[] { 7, -124, 7, -124, 53, 63, 69, 43, 41, 63,
                75, 69, 85, 77, 79, 69, 75, 49, 1, 20, 1, 126, -113, -124,
                -113, 8 };
    } else if (VersionInfo.ICU_VERSION.getMajor() == 4
            && VersionInfo.ICU_VERSION.getMinor() == 8) {
        /*
         * The next bundled version was 4.8.
         */
        expected = new byte[] { 6, 12, 6, 12, 51, 61, 67, 41, 39, 61, 73,
                67, 83, 75, 77, 67, 73, 47, 1, 20, 1, 126, -113, -124,
                -113, 8};
    } else {

        throw new AssertionFailedError("Not an expected ICU version: "
                + VersionInfo.ICU_VERSION);

    }

    if (log.isInfoEnabled()) {
        log.info("Expected: " + Arrays.toString(expected));
    }

    if (!Arrays.equals(expected, actual)) {
        fail("Expected: " + Arrays.toString(expected) + ", " + //
                "Actual: " + Arrays.toString(actual));
    }

}
 
Example #20
Source File: ICUResourceBundleReader.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
VersionInfo getVersion() {
    return ICUBinary.getVersionInfoFromCompactInt(dataVersion);
}
 
Example #21
Source File: ICUVersionRecord.java    From database with GNU General Public License v2.0 4 votes vote down vote up
ICUVersionRecord(//
        VersionInfo icuVersion,//
        VersionInfo ucolRuntimeVesion,//
        VersionInfo ucolBuilderVersion,//
        VersionInfo ucolTailoringsVersion//
) {

    this.icuVersion = icuVersion;

    this.ucolRuntimeVersion = ucolRuntimeVesion;

    this.ucolBuilderVersion = ucolBuilderVersion;

    this.ucolTailoringsVersion = ucolTailoringsVersion;

}
 
Example #22
Source File: ICUBinary.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a VersionInfo for the bytes in the compact version integer.
 */
public static VersionInfo getVersionInfoFromCompactInt(int version) {
    return VersionInfo.getInstance(
            version >>> 24, (version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff);
}
 
Example #23
Source File: ICUResourceBundleReader.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
VersionInfo getVersion() {
    return ICUBinary.getVersionInfoFromCompactInt(dataVersion);
}
 
Example #24
Source File: StringPrep.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
private static VersionInfo getVersionInfo(byte[] version){
    if(version.length != 4){
        return null;
    }
    return VersionInfo.getInstance((int)version[0],(int) version[1],(int) version[2],(int) version[3]);
}
 
Example #25
Source File: ICUBinary.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a VersionInfo for the bytes in the compact version integer.
 */
public static VersionInfo getVersionInfoFromCompactInt(int version) {
    return VersionInfo.getInstance(
            version >>> 24, (version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff);
}
 
Example #26
Source File: StringPrep.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
private static VersionInfo getVersionInfo(byte[] version){
    if(version.length != 4){
        return null;
    }
    return VersionInfo.getInstance((int)version[0],(int) version[1],(int) version[2],(int) version[3]);
}
 
Example #27
Source File: UCharacterProperty.java    From trekarta with GNU General Public License v3.0 3 votes vote down vote up
/**
 * <p>Get the "age" of the code point.</p>
 * <p>The "age" is the Unicode version when the code point was first
 * designated (as a non-character or for Private Use) or assigned a
 * character.</p>
 * <p>This can be useful to avoid emitting code points to receiving
 * processes that do not accept newer characters.</p>
 * <p>The data is from the UCD file DerivedAge.txt.</p>
 * <p>This API does not check the validity of the codepoint.</p>
 * @param codepoint The code point.
 * @return the Unicode version number
 */
public VersionInfo getAge(int codepoint)
{
    int version = getAdditional(codepoint, 0) >> AGE_SHIFT_;
    return VersionInfo.getInstance(
                       (version >> FIRST_NIBBLE_SHIFT_) & LAST_NIBBLE_MASK_,
                       version & LAST_NIBBLE_MASK_, 0, 0);
}
 
Example #28
Source File: UCharacterProperty.java    From fitnotifications with Apache License 2.0 3 votes vote down vote up
/**
 * <p>Get the "age" of the code point.</p>
 * <p>The "age" is the Unicode version when the code point was first
 * designated (as a non-character or for Private Use) or assigned a
 * character.</p>
 * <p>This can be useful to avoid emitting code points to receiving
 * processes that do not accept newer characters.</p>
 * <p>The data is from the UCD file DerivedAge.txt.</p>
 * <p>This API does not check the validity of the codepoint.</p>
 * @param codepoint The code point.
 * @return the Unicode version number
 */
public VersionInfo getAge(int codepoint)
{
    int version = getAdditional(codepoint, 0) >> AGE_SHIFT_;
    return VersionInfo.getInstance(
                       (version >> FIRST_NIBBLE_SHIFT_) & LAST_NIBBLE_MASK_,
                       version & LAST_NIBBLE_MASK_, 0, 0);
}
 
Example #29
Source File: ICUVersionRecord.java    From database with GNU General Public License v2.0 3 votes vote down vote up
private VersionInfo readVersionInfo(final ObjectInput in) throws IOException {

        final int major = in.readInt();
        final int minor = in.readInt();
        final int micro = in.readInt();
        final int milli = in.readInt();
        
        return VersionInfo.getInstance(major, minor, milli, micro);
        
    }
 
Example #30
Source File: ICUVersionRecord.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * The ICU software version number.
 * 
 * @see VersionInfo#ICU_VERSION
 */
public VersionInfo getICUVersion() {
    return icuVersion;
}