| | |
| | | |
| | | private String description; |
| | | |
| | | private Integer ordinal; |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param keyString |
| | | * from properties file |
| | | * @param includesOrdinal |
| | | * when true expects ordinals to be encoded in the keystring; |
| | | * when false the mandate is relaxed |
| | | * @return MessagePropertyKey created from string |
| | | */ |
| | | static public MessagePropertyKey parseString(String keyString, |
| | | boolean includesOrdinal) |
| | | static public MessagePropertyKey parseString(String keyString) |
| | | { |
| | | |
| | | String description; |
| | | Integer ordinal = null; |
| | | |
| | | String k = keyString; |
| | | |
| | | if (includesOrdinal) |
| | | { |
| | | int li = k.lastIndexOf("_"); |
| | | if (li != -1) |
| | | { |
| | | description = k.substring(0, li).toUpperCase(); |
| | | } |
| | | else |
| | | { |
| | | throw new IllegalArgumentException("Incorrectly formatted key " |
| | | + keyString); |
| | | } |
| | | |
| | | try |
| | | { |
| | | String ordString = k.substring(li + 1); |
| | | ordinal = Integer.parseInt(ordString); |
| | | } |
| | | catch (Exception nfe) |
| | | { |
| | | throw new IllegalArgumentException( |
| | | "Error parsing ordinal for key " + keyString); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | description = k; |
| | | } |
| | | return new MessagePropertyKey(description, ordinal); |
| | | return new MessagePropertyKey(keyString); |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @param description |
| | | * of this key |
| | | * @param ordinal |
| | | * of this key |
| | | */ |
| | | public MessagePropertyKey(String description, Integer ordinal) |
| | | public MessagePropertyKey(String description) |
| | | { |
| | | this.description = description; |
| | | this.ordinal = ordinal; |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * Gets the ordinal of this key. |
| | | * |
| | | * @return ordinal of this key |
| | | */ |
| | | public Integer getOrdinal() |
| | | { |
| | | return this.ordinal; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the name of the MessageDescriptor as it should appear in the |
| | | * messages file. |
| | | * |
| | |
| | | */ |
| | | public String getPropertyKeyName(boolean includeOrdinal) |
| | | { |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append(description); |
| | | if (ordinal != null && includeOrdinal) |
| | | { |
| | | sb.append("_"); |
| | | sb.append(ordinal); |
| | | } |
| | | return sb.toString(); |
| | | return description; |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public int compareTo(MessagePropertyKey k) |
| | | { |
| | | if (ordinal == k.ordinal) |
| | | { |
| | | return description.compareTo(k.description); |
| | | } |
| | | else |
| | | { |
| | | return ordinal.compareTo(k.ordinal); |
| | | } |
| | | return description.compareTo(k.description); |
| | | } |
| | | |
| | | } |