List of usage examples for java.util SortedMap firstKey
K firstKey();
From source file:org.apache.fop.afp.fonts.RasterFont.java
/** * Get the character set metrics for the specified point size. * * @param sizeInMpt the point size (in mpt) * @return the character set metrics//from w w w . j av a2s .c o m */ public CharacterSet getCharacterSet(int sizeInMpt) { Integer requestedSize = Integer.valueOf(sizeInMpt); CharacterSet csm = (CharacterSet) charSets.get(requestedSize); double sizeInPt = sizeInMpt / 1000.0; if (csm != null) { return csm; } if (substitutionCharSets != null) { //Check first if a substitution has already been added csm = (CharacterSet) substitutionCharSets.get(requestedSize); } if (csm == null && !charSets.isEmpty()) { // No match or substitution found, but there exist entries // for other sizes // Get char set with nearest, smallest font size SortedMap<Integer, CharacterSet> smallerSizes = charSets.headMap(requestedSize); SortedMap<Integer, CharacterSet> largerSizes = charSets.tailMap(requestedSize); int smallerSize = smallerSizes.isEmpty() ? 0 : ((Integer) smallerSizes.lastKey()).intValue(); int largerSize = largerSizes.isEmpty() ? Integer.MAX_VALUE : ((Integer) largerSizes.firstKey()).intValue(); Integer fontSize; if (!smallerSizes.isEmpty() && (sizeInMpt - smallerSize) <= (largerSize - sizeInMpt)) { fontSize = Integer.valueOf(smallerSize); } else { fontSize = Integer.valueOf(largerSize); } csm = (CharacterSet) charSets.get(fontSize); if (csm != null) { // Add the substitute mapping, so subsequent calls will // find it immediately if (substitutionCharSets == null) { substitutionCharSets = new HashMap<Integer, CharacterSet>(); } substitutionCharSets.put(requestedSize, csm); // do not output the warning if the font size is closer to an integer less than 0.1 if (!(Math.abs(fontSize.intValue() / 1000.0 - sizeInPt) < 0.1)) { String msg = "No " + sizeInPt + "pt font " + getFontName() + " found, substituted with " + fontSize.intValue() / 1000f + "pt font"; LOG.warn(msg); } } } if (csm == null) { // Still no match -> error String msg = "No font found for font " + getFontName() + " with point size " + sizeInPt; LOG.error(msg); throw new FontRuntimeException(msg); } return csm; }
From source file:com.redhat.rhn.frontend.action.kickstart.PowerManagementAction.java
/** * Sets the page attributes.//from www .j a va 2 s.co m * * @param request the request * @param context the context * @param server the server * @param user the user * @param strutsDelegate the Struts delegate * @param errors ActionErrors that might have already been raised */ private void setAttributes(HttpServletRequest request, RequestContext context, Server server, User user, StrutsDelegate strutsDelegate, ActionErrors errors) { request.setAttribute(RequestContext.SID, server.getId()); request.setAttribute(RequestContext.SYSTEM, server); SortedMap<String, String> types = setUpPowerTypes(request, strutsDelegate, errors); ensureAgentInstalled(request, strutsDelegate, errors); if (types.size() > 0) { SystemRecord record = getSystemRecord(user, server); if (record == null) { request.setAttribute(POWER_TYPE, types.get(types.firstKey())); } else { request.setAttribute(POWER_TYPE, record.getPowerType()); request.setAttribute(POWER_ADDRESS, record.getPowerAddress()); request.setAttribute(POWER_USERNAME, record.getPowerUsername()); request.setAttribute(POWER_PASSWORD, record.getPowerPassword()); request.setAttribute(POWER_ID, record.getPowerId()); } } }
From source file:org.cloudata.core.client.TabletLocationCache.java
protected TabletInfo findFromCache(String tableName, TreeMap<Row.Key, TabletInfo> cache, Row.Key cacheRowKey, Row.Key dataRowKey) {//from w w w . java 2 s . com cacheLock.obtainReadLock(); try { if (cache.containsKey(cacheRowKey)) { TabletInfo tabletInfo = cache.get(cacheRowKey); if (tabletInfo.belongRowRange(cacheRowKey)) { return tabletInfo; } else { return null; } } SortedMap<Row.Key, TabletInfo> tailMap = cache.tailMap(cacheRowKey); if (tailMap.isEmpty()) { return null; } Row.Key tailFirst = tailMap.firstKey(); TabletInfo tabletInfo = tailMap.get(tailFirst); if (tableName.equals(tabletInfo.getTableName()) && tabletInfo.belongRowRange(dataRowKey)) { return tabletInfo; } else { return null; } } finally { cacheLock.releaseReadLock(); } }
From source file:com.hyperaware.conference.android.fragment.HomeFragment.java
private void updateHappeningNowCard() { ViewGroup time_groups = (ViewGroup) cardHappeningNow.findViewById(R.id.vg_time_groups); time_groups.removeAllViews();/*from w ww. j a v a2s. c om*/ final SortedMap<DateRange, List<AgendaItem>> happening = AgendaItems .happeningNow(agenda.getItems().values(), timeAtUpdate); if (happening.size() > 0) { populateTimeGroups(happening, time_groups); cardHappeningNow.setVisibility(View.VISIBLE); happeningNowStartTime = happening.firstKey().start; } else { cardHappeningNow.setVisibility(View.GONE); } }
From source file:com.hyperaware.conference.android.fragment.HomeFragment.java
private void updateUpNextCard() { ViewGroup time_groups = (ViewGroup) cardUpNext.findViewById(R.id.vg_time_groups); time_groups.removeAllViews();/*from w w w. j a va 2s.co m*/ final SortedMap<DateRange, List<AgendaItem>> up_next = AgendaItems.upNext(agenda.getItems().values(), timeAtUpdate, TimeUnit.DAYS.toMillis(1), TimeUnit.HOURS.toMillis(1)); if (up_next.size() > 0) { populateTimeGroups(up_next, time_groups); cardUpNext.setVisibility(View.VISIBLE); upNextStartTime = up_next.firstKey().start; } else { cardUpNext.setVisibility(View.GONE); } }
From source file:org.codehaus.plexus.archiver.jar.JarArchiver.java
/** * try to guess the name of the given file. * <p/>/*from ww w . j ava 2s .c om*/ * <p>If this jar has a classpath attribute in its manifest, we * can assume that it will only require an index of jars listed * there. try to find which classpath entry is most likely the * one the given file name points to.</p> * <p/> * <p>In the absence of a classpath attribute, assume the other * files will be placed inside the same directory as this jar and * use their basename.</p> * <p/> * <p>if there is a classpath and the given file doesn't match any * of its entries, return null.</p> * * @param fileName . * @param classpath . * @return The guessed name */ protected static String findJarName(String fileName, String[] classpath) { if (classpath == null) { return new File(fileName).getName(); } fileName = fileName.replace(File.separatorChar, '/'); SortedMap<String, String> matches = new TreeMap<String, String>(new Comparator<String>() { // longest match comes first public int compare(String o1, String o2) { if ((o1 != null) && (o2 != null)) { return o2.length() - o1.length(); } return 0; } }); for (String aClasspath : classpath) { if (fileName.endsWith(aClasspath)) { matches.put(aClasspath, aClasspath); } else { int slash = aClasspath.indexOf("/"); String candidate = aClasspath; while (slash > -1) { candidate = candidate.substring(slash + 1); if (fileName.endsWith(candidate)) { matches.put(candidate, aClasspath); break; } slash = candidate.indexOf("/"); } } } return matches.size() == 0 ? null : matches.get(matches.firstKey()); }
From source file:edu.mit.ll.graphulo.pig.backend.GraphuloOneTableStorage.java
@Override protected Tuple getTuple(Key key, Value value) throws IOException { SortedMap<Key, Value> rowKVs = WholeRowIterator.decodeRow(key, value); Tuple tuple = TupleFactory.getInstance().newTuple(columns.size() + 1); final Text cfHolder = new Text(); final Text cqHolder = new Text(); final Text row = key.getRow(); int tupleOffset = 0; tuple.set(tupleOffset, new DataByteArray(Text.decode(row.getBytes(), 0, row.getLength()))); for (Column column : this.columns) { tupleOffset++;// www .j a v a2 s . c o m switch (column.getType()) { case LITERAL: cfHolder.set(column.getColumnFamily()); if (null != column.getColumnQualifier()) { cqHolder.set(column.getColumnQualifier()); } else { cqHolder.set(EMPTY_TEXT); } // Get the key where our literal would exist (accounting for // "colf:colq" or "colf:" empty colq) Key literalStartKey = new Key(row, cfHolder, cqHolder); SortedMap<Key, Value> tailMap = rowKVs.tailMap(literalStartKey); // Find the element if (tailMap.isEmpty()) { tuple.set(tupleOffset, EMPTY_DATA_BYTE_ARRAY); } else { Key actualKey = tailMap.firstKey(); // Only place it in the tuple if it matches the user // request, avoid using a value from a // key with the wrong colqual if (0 == literalStartKey.compareTo(actualKey, PartialKey.ROW_COLFAM_COLQUAL)) { tuple.set(tupleOffset, new DataByteArray(tailMap.get(actualKey).get())); } else { // This row doesn't have the column we were looking for tuple.set(tupleOffset, EMPTY_DATA_BYTE_ARRAY); } } break; case COLFAM_PREFIX: cfHolder.set(column.getColumnFamily()); Range colfamPrefixRange = Range.prefix(row, cfHolder); Key colfamPrefixStartKey = new Key(row, cfHolder); SortedMap<Key, Value> cfTailMap = rowKVs.tailMap(colfamPrefixStartKey); // Find the element if (cfTailMap.isEmpty()) { tuple.set(tupleOffset, EMPTY_DATA_BYTE_ARRAY); } else { HashMap<String, DataByteArray> tupleMap = new HashMap<String, DataByteArray>(); // Build up a map for all the entries in this row that match // the colfam prefix for (Entry<Key, Value> entry : cfTailMap.entrySet()) { if (colfamPrefixRange.contains(entry.getKey())) { entry.getKey().getColumnFamily(cfHolder); entry.getKey().getColumnQualifier(cqHolder); DataByteArray val = new DataByteArray(entry.getValue().get()); // Avoid adding an extra ':' when colqual is empty if (0 == cqHolder.getLength()) { tupleMap.put(cfHolder.toString(), val); } else { tupleMap.put(cfHolder.toString() + COLON + cqHolder.toString(), val); } } else { break; } } if (!tupleMap.isEmpty()) { tuple.set(tupleOffset, tupleMap); } } break; case COLQUAL_PREFIX: cfHolder.set(column.getColumnFamily()); cqHolder.set(column.getColumnQualifier()); Range colqualPrefixRange = Range.prefix(row, cfHolder, cqHolder); Key colqualPrefixStartKey = new Key(row, cfHolder, cqHolder); SortedMap<Key, Value> cqTailMap = rowKVs.tailMap(colqualPrefixStartKey); if (cqTailMap.isEmpty()) { tuple.set(tupleOffset, EMPTY_DATA_BYTE_ARRAY); } else { HashMap<String, DataByteArray> tupleMap = new HashMap<String, DataByteArray>(); // Build up a map for all the entries in this row that match // the colqual prefix for (Entry<Key, Value> entry : cqTailMap.entrySet()) { if (colqualPrefixRange.contains(entry.getKey())) { entry.getKey().getColumnFamily(cfHolder); entry.getKey().getColumnQualifier(cqHolder); DataByteArray val = new DataByteArray(entry.getValue().get()); // Avoid the extra ':' on empty colqual if (0 == cqHolder.getLength()) { tupleMap.put(cfHolder.toString(), val); } else { tupleMap.put(cfHolder.toString() + COLON + cqHolder.toString(), val); } } else { break; } } if (!tupleMap.isEmpty()) { tuple.set(tupleOffset, tupleMap); } } break; default: break; } } return tuple; }
From source file:viper.api.time.TimeEncodedList.java
/** * Get the value at the specified index in the list. * @param index the index into the list// ww w . jav a 2 s . c om * @return the value at the specified index */ public Object get(Instant index) { assert index != null; SortedMap m = values.tailMap(index); if (!m.isEmpty() && m.firstKey().equals(index)) { return ((LelNode) m.get(index)).getValue(); } m = values.headMap(index); if (!m.isEmpty()) { LelNode v = (LelNode) m.get(m.lastKey()); if (v.getEnd().compareTo(index) > 0) { return v.getValue(); } } return null; }
From source file:viper.api.time.TimeEncodedList.java
/** * {@inheritDoc}/*from w w w.j ava 2s .c om*/ */ public Comparable firstAfterOrAt(Comparable c) { SortedMap tail = values.tailMap(c); if (!tail.isEmpty()) { return (Comparable) tail.firstKey(); } return null; }
From source file:hudson.plugins.jobConfigHistory.FileHistoryDaoTest.java
private void testGetRevisions(SortedMap<String, HistoryDescr> result) { assertEquals(5, result.size());//from w ww .j a va 2s.c o m assertEquals("2012-11-21_11-29-12", result.firstKey()); assertEquals("2012-11-21_11-42-05", result.lastKey()); final HistoryDescr firstValue = result.get(result.firstKey()); final HistoryDescr lastValue = result.get(result.lastKey()); assertEquals("Created", firstValue.getOperation()); assertEquals("anonymous", firstValue.getUserID()); assertEquals("Changed", lastValue.getOperation()); }