public void testSortOrder(){
SortedMap map=makeTestSortedMap(oneFactory);
map.put("A","a");
map.get("B");
map.put("C","c");
assertEquals("First key should be A",map.firstKey(),"A");
assertEquals("Last key should be C",map.lastKey(),"C");
assertEquals("First key in tail map should be B",map.tailMap("B").firstKey(),"B");
assertEquals("Last key in head map should be B",map.headMap("C").lastKey(),"B");
assertEquals("Last key in submap should be B",map.subMap("A","C").lastKey(),"B");
Comparator c=map.comparator();
assertTrue("natural order, so comparator should be null",c == null);
}

Example 2

From project jboss-jstl-api_spec, under directory /src/main/java/javax/servlet/jsp/jstl/sql/.

/**
* Note: If there exist duplicate message ids in the {@code msgs} list, the first one wins.However, the source paths from subsequent duplicates will be added to the source paths for the message.
* @param localeString The language/locale string of this bundle of messages, or null if unknown.Should only be null for bundles newly extracted from source files. Should always be set for bundles parsed from message files/resources.
* @param msgs The list of messages. List order will become the iteration order.
*/
public SoyMsgBundleImpl(@Nullable String localeString,List<SoyMsg> msgs){
this.localeString=localeString;
SortedMap<Long,SoyMsg> tempMsgMap=Maps.newTreeMap();
for ( SoyMsg msg : msgs) {
checkArgument(Objects.equal(msg.getLocaleString(),localeString));
long msgId=msg.getId();
if (!tempMsgMap.containsKey(msgId)) {
tempMsgMap.put(msgId,msg);
}
else {
SoyMsg existingMsg=tempMsgMap.get(msgId);
for ( String source : msg.getSourcePaths()) {
existingMsg.addSourcePath(source);
}
}
}
msgMap=ImmutableMap.copyOf(tempMsgMap);
}

/**
* <p>If row data is available, return the <code>SortedMap</code> array element at the index specified by <code>rowIndex</code> of the array returned by calling <code>getRows()</code> on the underlying <code>Result</code>. If no wrapped data is available, return <code>null</code>.</p> <p>Note that, if a non-<code>null</code> <code>Map</code> is returned by this method, it will contain the values of the columns for the current row, keyed by column name. Column name comparisons must be performed in a case-insensitive manner.</p>
* @throws FacesException if an error occurs getting the row data
* @throws IllegalArgumentException if now row data is availableat the currently specified row index
*/
public SortedMap<String,Object> getRowData(){
if (result == null) {
return (null);
}
else if (!isRowAvailable()) {
throw new NoRowAvailableException();
}
else {
return ((SortedMap<String,Object>)rows[index]);
}
}