Java Code Examples for com.ibm.icu.util.UResourceBundle#ARRAY

The following examples show how to use com.ibm.icu.util.UResourceBundle#ARRAY . 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: RelativeDateTimeFormatter.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
private String getDateTimePattern(ICUResourceBundle r) {
    String calType = r.getStringWithFallback("calendar/default");
    if (calType == null || calType.equals("")) {
        calType = "gregorian";
    }
    String resourcePath = "calendar/" + calType + "/DateTimePatterns";
    ICUResourceBundle patternsRb = r.findWithFallback(resourcePath);
    if (patternsRb == null && calType.equals("gregorian")) {
        // Try with gregorian.
        patternsRb = r.findWithFallback("calendar/gregorian/DateTimePatterns");
    }
    if (patternsRb == null || patternsRb.getSize() < 9) {
        // Undefined or too few elements.
        return "{1} {0}";
    } else {
        int elementType = patternsRb.get(8).getType();
        if (elementType == UResourceBundle.ARRAY) {
            return patternsRb.get(8).getString(0);
        } else {
            return patternsRb.getString(8);
        }
    }
}
 
Example 2
Source File: ICUResourceBundleReader.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
Array getArray(int res) {
    int type=RES_GET_TYPE(res);
    if(!URES_IS_ARRAY(type)) {
        return null;
    }
    int offset=RES_GET_OFFSET(res);
    if(offset == 0) {
        return EMPTY_ARRAY;
    }
    Object value = resourceCache.get(res);
    if(value != null) {
        return (Array)value;
    }
    Array array = (type == UResourceBundle.ARRAY) ?
            new Array32(this, offset) : new Array16(this, offset);
    return (Array)resourceCache.putIfAbsent(res, array, 0);
}
 
Example 3
Source File: CalendarData.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
public String[] getDateTimePatterns(){
    ICUResourceBundle bundle = get("DateTimePatterns");
    ArrayList<String> list = new ArrayList<String>();
    UResourceBundleIterator iter = bundle.getIterator();
    while (iter.hasNext()) {
        UResourceBundle patResource = iter.next();
        int resourceType = patResource.getType();
        switch (resourceType) {
            case UResourceBundle.STRING:
                list.add(patResource.getString());
                break;
            case UResourceBundle.ARRAY:
                String[] items = patResource.getStringArray();
                list.add(items[0]);
                break;
        }
    }

    return list.toArray(new String[list.size()]);
}
 
Example 4
Source File: CalendarData.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
public String[] getOverrides(){
    ICUResourceBundle bundle = get("DateTimePatterns");
    ArrayList<String> list = new ArrayList<String>();
    UResourceBundleIterator iter = bundle.getIterator();
    while (iter.hasNext()) {
        UResourceBundle patResource = iter.next();
        int resourceType = patResource.getType();
        switch (resourceType) {
            case UResourceBundle.STRING:
                list.add(null);
                break;
            case UResourceBundle.ARRAY:
                String[] items = patResource.getStringArray();
                list.add(items[1]);
                break;
        }
    }
    return list.toArray(new String[list.size()]);
}
 
Example 5
Source File: ICUResourceBundleReader.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
Array getArray(int res) {
    int type=RES_GET_TYPE(res);
    if(!URES_IS_ARRAY(type)) {
        return null;
    }
    int offset=RES_GET_OFFSET(res);
    if(offset == 0) {
        return EMPTY_ARRAY;
    }
    Object value = resourceCache.get(res);
    if(value != null) {
        return (Array)value;
    }
    Array array = (type == UResourceBundle.ARRAY) ?
            new Array32(this, offset) : new Array16(this, offset);
    return (Array)resourceCache.putIfAbsent(res, array, 0);
}
 
Example 6
Source File: UResource.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Only for debugging.
 */
@Override
public String toString() {
    switch(getType()) {
    case UResourceBundle.STRING:
        return getString();
    case UResourceBundle.INT:
        return Integer.toString(getInt());
    case UResourceBundle.INT_VECTOR:
        int[] iv = getIntVector();
        StringBuilder sb = new StringBuilder("[");
        sb.append(iv.length).append("]{");
        if (iv.length != 0) {
            sb.append(iv[0]);
            for (int i = 1; i < iv.length; ++i) {
                sb.append(", ").append(iv[i]);
            }
        }
        return sb.append('}').toString();
    case UResourceBundle.BINARY:
        return "(binary blob)";
    case UResourceBundle.ARRAY:
        return "(array)";
    case UResourceBundle.TABLE:
        return "(table)";
    default:  // should not occur
        return "???";
    }
}
 
Example 7
Source File: RelativeDateFormat.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
private MessageFormat initializeCombinedFormat(Calendar cal, ULocale locale) {
    String pattern;
    ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(
        ICUData.ICU_BASE_NAME, locale);
    String resourcePath = "calendar/" + cal.getType() + "/DateTimePatterns";
    ICUResourceBundle patternsRb= rb.findWithFallback(resourcePath);
    if (patternsRb == null && !cal.getType().equals("gregorian")) {
        // Try again with gregorian, if not already attempted.
        patternsRb = rb.findWithFallback("calendar/gregorian/DateTimePatterns");
    }

    if (patternsRb == null || patternsRb.getSize() < 9) {
        // Undefined or too few elements.
        pattern = "{1} {0}";
    } else {
        int glueIndex = 8;
        if (patternsRb.getSize() >= 13) {
          if (fDateStyle >= DateFormat.FULL && fDateStyle <= DateFormat.SHORT) {
              glueIndex += fDateStyle + 1;
          } else
              if (fDateStyle >= DateFormat.RELATIVE_FULL &&
                  fDateStyle <= DateFormat.RELATIVE_SHORT) {
                  glueIndex += fDateStyle + 1 - DateFormat.RELATIVE;
              }
        }
        int elementType = patternsRb.get(glueIndex).getType();
        if (elementType == UResourceBundle.ARRAY) {
            pattern = patternsRb.get(glueIndex).getString(0);
        } else {
            pattern = patternsRb.getString(glueIndex);
        }
    }
    combinedFormatHasDateAtStart = pattern.startsWith("{1}");
    fCombinedFormat = new MessageFormat(pattern, locale);
    return fCombinedFormat;
}
 
Example 8
Source File: UResource.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Only for debugging.
 */
@Override
public String toString() {
    switch(getType()) {
    case UResourceBundle.STRING:
        return getString();
    case UResourceBundle.INT:
        return Integer.toString(getInt());
    case UResourceBundle.INT_VECTOR:
        int[] iv = getIntVector();
        StringBuilder sb = new StringBuilder("[");
        sb.append(iv.length).append("]{");
        if (iv.length != 0) {
            sb.append(iv[0]);
            for (int i = 1; i < iv.length; ++i) {
                sb.append(", ").append(iv[i]);
            }
        }
        return sb.append('}').toString();
    case UResourceBundle.BINARY:
        return "(binary blob)";
    case UResourceBundle.ARRAY:
        return "(array)";
    case UResourceBundle.TABLE:
        return "(table)";
    default:  // should not occur
        return "???";
    }
}
 
Example 9
Source File: ICUResourceBundleReader.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
static boolean URES_IS_ARRAY(int type) {
    return type == UResourceBundle.ARRAY || type == ICUResourceBundle.ARRAY16;
}
 
Example 10
Source File: ICUResourceBundleReader.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
static boolean URES_IS_ARRAY(int type) {
    return type == UResourceBundle.ARRAY || type == ICUResourceBundle.ARRAY16;
}