List of usage examples for com.google.common.collect ImmutableSortedMap tailMap
public ImmutableSortedMap<K, V> tailMap(K fromKey, boolean inclusive)
From source file:edu.mit.streamjit.util.bytecode.methodhandles.Combinators.java
private static MethodHandle lookupswitch0(ImmutableSortedMap<Integer, MethodHandle> cases, MethodHandle defaultCase) { if (cases.isEmpty()) return defaultCase; if (cases.size() == 1) { Map.Entry<Integer, MethodHandle> next = cases.entrySet().iterator().next(); return MethodHandles.guardWithTest(eq(next.getKey()), MethodHandles.dropArguments(next.getValue(), 0, int.class), //discard the case index defaultCase);/*from ww w .j a v a 2 s . com*/ } int median = median(cases.keySet().asList()); return MethodHandles.guardWithTest(le(median), lookupswitch0(cases.headMap(median, true), defaultCase), lookupswitch0(cases.tailMap(median, false), defaultCase)); }
From source file:com.google.cloud.dns.testing.LocalDnsHelper.java
/** * Lists record sets for a zone. Next page token is the ID of the last record listed. *//*from w w w . j a va 2s .co m*/ @VisibleForTesting Response listDnsRecords(String projectId, String zoneName, String query) { Map<String, Object> options = OptionParsers.parseListDnsRecordsOptions(query); Response response = checkListOptions(options); if (response != null) { return response; } ZoneContainer zoneContainer = findZone(projectId, zoneName); if (zoneContainer == null) { return Error.NOT_FOUND.response( String.format("The 'parameters.managedZone' resource named '%s' does not exist.", zoneName)); } ImmutableSortedMap<String, ResourceRecordSet> dnsRecords = zoneContainer.dnsRecords().get(); String[] fields = (String[]) options.get("fields"); String name = (String) options.get("name"); String type = (String) options.get("type"); String pageToken = (String) options.get("pageToken"); ImmutableSortedMap<String, ResourceRecordSet> fragment = pageToken != null ? dnsRecords.tailMap(pageToken, false) : dnsRecords; Integer maxResults = options.get("maxResults") == null ? null : Integer.valueOf((String) options.get("maxResults")); boolean sizeReached = false; boolean hasMorePages = false; LinkedList<String> serializedRrsets = new LinkedList<>(); String lastRecordId = null; for (String recordSetId : fragment.keySet()) { ResourceRecordSet recordSet = fragment.get(recordSetId); if (matchesCriteria(recordSet, name, type)) { if (sizeReached) { // we do not add this, just note that there would be more and there should be a token hasMorePages = true; break; } else { lastRecordId = recordSetId; try { serializedRrsets .addLast(jsonFactory.toString(OptionParsers.extractFields(recordSet, fields))); } catch (IOException e) { return Error.INTERNAL_ERROR.response(String.format( "Error when serializing resource record set in managed zone %s in project %s", zoneName, projectId)); } } } sizeReached = maxResults != null && maxResults.equals(serializedRrsets.size()); } boolean includePageToken = hasMorePages && (fields == null || Arrays.asList(fields).contains("nextPageToken")); return toListResponse(serializedRrsets, "rrsets", lastRecordId, includePageToken); }