List of usage examples for com.google.common.collect Maps newTreeMap
public static <C, K extends C, V> TreeMap<K, V> newTreeMap(@Nullable Comparator<C> comparator)
From source file:com.palantir.atlasdb.keyvalue.partition.DynamicPartitionMapManager.java
public static void main(String[] args) { System.out.println("AtlasDb Dynamic Partition Map Manager"); System.out.print("Enter PMS Uri to download initial map (empty for empty map): "); final DynamicPartitionMapManager instance; try (Scanner scanner = new Scanner(System.in)) { String initialPmsUri = scanner.nextLine(); if (!initialPmsUri.equals("")) { instance = new DynamicPartitionMapManager(initialPmsUri); } else {//w w w. j a v a 2 s.co m System.out.println("This is new partition map wizard"); System.out.print("replication factor: "); int repf = Integer.parseInt(scanner.nextLine()); System.out.print("read factor: "); int readf = Integer.parseInt(scanner.nextLine()); System.out.print("write factor: "); int writef = Integer.parseInt(scanner.nextLine()); QuorumParameters parameters = new QuorumParameters(repf, readf, writef); NavigableMap<byte[], KeyValueEndpoint> initialRing = Maps .newTreeMap(UnsignedBytes.lexicographicalComparator()); while (initialRing.size() < repf) { System.out.print("kvs URI: "); String kvsUri = scanner.nextLine(); System.out.print("pms URI: "); String pmsUri = scanner.nextLine(); System.out.print("rack: "); String rack = scanner.nextLine(); byte[] key = readKey(scanner); SimpleKeyValueEndpoint kve = SimpleKeyValueEndpoint.create(kvsUri, pmsUri, rack); initialRing.put(key, kve); } DynamicPartitionMapImpl dpmi = DynamicPartitionMapImpl.create(parameters, initialRing, PTExecutors.newCachedThreadPool()); instance = new DynamicPartitionMapManager(dpmi); } boolean exit = false; while (!exit) { System.out.println("Local partition map:"); System.out.println(instance.partitionMap); System.out.println("MAIN MENU"); System.out.println("1. Add endpoint"); System.out.println("2. Remove endpoint"); System.out.println("3. Update local map"); System.out.println("4. Set version (deprecated, test only)"); System.out.println("5. Push local map to Uri"); System.out.println("6. Clear all endpoint kvss"); System.out.println("0. Exit"); System.out.print("Choice: "); try { switch (Integer.parseInt(scanner.nextLine())) { case 1: instance.addEndpointInteractive(scanner); continue; case 2: instance.removeEndpointInteractive(scanner); continue; case 3: instance.updateLocalMapInteractive(scanner); continue; case 4: instance.setVersionInteractive(scanner); continue; case 5: instance.pushToUriInteractive(scanner); continue; case 6: instance.clearAllEndpointKvssInteractive(scanner); continue; case 0: exit = true; continue; } } catch (NumberFormatException e) { e.printStackTrace(System.out); continue; } catch (RuntimeException e) { System.out.println("ERROR DURING OPERATION"); e.printStackTrace(System.out); System.out.println("\n\nReturning to main menu\n\n"); continue; } System.out.println("Unrecognized command."); } } }
From source file:com.metamx.druid.input.Rows.java
public static InputRow toCaseInsensitiveInputRow(final Row row, final List<String> dimensions) { if (row instanceof MapBasedRow) { MapBasedRow mapBasedRow = (MapBasedRow) row; TreeMap<String, Object> caseInsensitiveMap = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER); caseInsensitiveMap.putAll(mapBasedRow.getEvent()); return new MapBasedInputRow(mapBasedRow.getTimestampFromEpoch(), dimensions, caseInsensitiveMap); }/*from w ww . j a v a 2 s. c o m*/ throw new ISE("Can only convert MapBasedRow objects because we are ghetto like that."); }
From source file:org.apache.jackrabbit.oak.plugins.document.CheckpointsHelper.java
public static SortedMap<Revision, Long> getCheckpoints(DocumentNodeStore store) { SortedMap<Revision, Info> checkpoints = store.getCheckpoints().getCheckpoints(); SortedMap<Revision, Long> map = Maps.newTreeMap(checkpoints.comparator()); for (Map.Entry<Revision, Info> entry : checkpoints.entrySet()) { map.put(entry.getKey(), entry.getValue().getExpiryTime()); }// w w w. j a v a2 s. c o m return map; }
From source file:io.druid.data.input.Rows.java
public static InputRow toCaseInsensitiveInputRow(final Row row, final List<String> dimensions) { if (row instanceof MapBasedRow) { MapBasedRow mapBasedRow = (MapBasedRow) row; TreeMap<String, Object> caseInsensitiveMap = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER); caseInsensitiveMap.putAll(mapBasedRow.getEvent()); return new MapBasedInputRow(mapBasedRow.getTimestamp(), dimensions, caseInsensitiveMap); }// www . j av a2 s. co m throw new ISE("Can only convert MapBasedRow objects because we are ghetto like that."); }
From source file:org.terasology.rendering.nui.layers.mainMenu.savedGames.GameProvider.java
public static List<GameInfo> getSavedGames() { Path savedGames = PathManager.getInstance().getSavesPath(); SortedMap<FileTime, Path> savedGamePaths = Maps.newTreeMap(Collections.reverseOrder()); try (DirectoryStream<Path> stream = Files.newDirectoryStream(savedGames)) { for (Path entry : stream) { if (Files.isRegularFile(entry.resolve(GameManifest.DEFAULT_FILE_NAME))) { savedGamePaths.put(Files.getLastModifiedTime(entry.resolve(GameManifest.DEFAULT_FILE_NAME)), entry);//from ww w . ja v a 2 s. co m } } } catch (IOException e) { logger.error("Failed to read saved games path", e); } List<GameInfo> result = Lists.newArrayListWithCapacity(savedGamePaths.size()); for (Map.Entry<FileTime, Path> world : savedGamePaths.entrySet()) { Path gameManifest = world.getValue().resolve(GameManifest.DEFAULT_FILE_NAME); if (!Files.isRegularFile(gameManifest)) { continue; } try { GameManifest info = GameManifest.load(gameManifest); if (!info.getTitle().isEmpty()) { Date date = new Date(world.getKey().toMillis()); result.add(new GameInfo(info, date)); } } catch (IOException e) { logger.error("Failed reading world data object.", e); } } return result; }
From source file:org.thiesen.collections.map.impl.MutableTreeMap.java
public static <K, V> MutableTreeMap<K, V> copyOf(final ISortedMap<K, ? extends V> entries) { return new MutableTreeMap<K, V>(Maps.newTreeMap(entries.asMapView())); }
From source file:com.splicemachine.impl.MockRegionUtils.java
public static HRegion getMockRegion() throws IOException { final Map<byte[], Set<Cell>> rowMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); HRegion fakeRegion = mock(HRegion.class); HRegionInfo fakeInfo = mock(HRegionInfo.class); when(fakeInfo.getStartKey()).thenReturn(HConstants.EMPTY_BYTE_ARRAY); when(fakeInfo.getEndKey()).thenReturn(HConstants.EMPTY_BYTE_ARRAY); when(fakeRegion.getRegionInfo()).thenReturn(fakeInfo); when(fakeRegion.get(any(Get.class))).thenAnswer(new Answer<Result>() { @Override/*from w w w .j a v a 2 s . c o m*/ public Result answer(InvocationOnMock invocationOnMock) throws Throwable { final Get get = (Get) invocationOnMock.getArguments()[0]; Set<Cell> keyValues = rowMap.get(get.getRow()); if (get.hasFamilies()) { Set<Cell> filtered = Sets.filter(keyValues, new Predicate<Cell>() { @Override public boolean apply(@Nullable Cell input) { Map<byte[], NavigableSet<byte[]>> familyMap = get.getFamilyMap(); if (!familyMap.containsKey(input.getFamily())) return false; NavigableSet<byte[]> qualifiers = familyMap.get(input.getFamily()); return qualifiers.contains(input.getQualifier()); } }); List<Cell> kvs = Lists.newArrayList(filtered); return Result.create(kvs); } else if (keyValues != null) { return Result.create(Lists.newArrayList(keyValues)); } else return null; } }); Answer<Void> putAnswer = new Answer<Void>() { @Override public Void answer(InvocationOnMock invocationOnMock) throws Throwable { Put put = (Put) invocationOnMock.getArguments()[0]; Set<Cell> keyValues = rowMap.get(put.getRow()); if (keyValues == null) { keyValues = Sets.newTreeSet(new KeyValue.KVComparator()); rowMap.put(put.getRow(), keyValues); } Map<byte[], List<KeyValue>> familyMap = put.getFamilyMap(); for (List<KeyValue> kvs : familyMap.values()) { for (KeyValue kv : kvs) { boolean ts = !kv.isLatestTimestamp(); kv = ts ? kv : new KeyValue(kv.getRow(), kv.getFamily(), kv.getQualifier(), System.currentTimeMillis(), kv.getValue()); if (keyValues.contains(kv)) { keyValues.remove(kv); } keyValues.add(kv); } } return null; } }; doAnswer(putAnswer).when(fakeRegion).put(any(Put.class)); Answer<Void> deleteAnswer = new Answer<Void>() { @Override public Void answer(InvocationOnMock invocationOnMock) throws Throwable { Delete delete = (Delete) invocationOnMock.getArguments()[0]; Set<Cell> keyValues = rowMap.get(delete.getRow()); if (keyValues == null) return null; //nothing to do, it's already deleted long timestamp = delete.getTimeStamp(); boolean isEmpty = delete.isEmpty(); if (isEmpty) { Iterator<Cell> iter = keyValues.iterator(); while (iter.hasNext()) { Cell kv = iter.next(); if (kv.getTimestamp() == timestamp) iter.remove(); } } else { Map<byte[], List<KeyValue>> deleteFamilyMap = delete.getFamilyMap(); Iterator<Cell> iter = keyValues.iterator(); while (iter.hasNext()) { Cell kv = iter.next(); if (!deleteFamilyMap.containsKey(kv.getFamily())) continue; List<KeyValue> toDelete = deleteFamilyMap.get(kv.getFamily()); if (toDelete.size() > 0) { for (KeyValue toDeleteKv : toDelete) { if (toDeleteKv.getQualifier().length <= 0) { //delete everything if (kv.getTimestamp() == toDeleteKv.getTimestamp()) { iter.remove(); break; } } else if (Bytes.equals(kv.getQualifier(), toDeleteKv.getQualifier())) { if (kv.getTimestamp() == toDeleteKv.getTimestamp()) { iter.remove(); break; } } } } else { if (kv.getTimestamp() == timestamp) iter.remove(); } } } return null; } }; doAnswer(deleteAnswer).when(fakeRegion).delete(any(Delete.class)); when(fakeRegion.getScanner(any(Scan.class))).thenAnswer(new Answer<RegionScanner>() { @Override public RegionScanner answer(InvocationOnMock invocationOnMock) throws Throwable { Scan scan = (Scan) invocationOnMock.getArguments()[0]; return new IteratorRegionScanner(rowMap.values().iterator(), scan); } }); return fakeRegion; }
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.ReflectivePropertyAdapter.java
private static Map<String, PropertyReader> readProperties(TypeLiteral<?> typeLiteral, ProgramValueTypeAdapter adapter) { Map<String, PropertyReader> builder = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER); for (Method method : typeLiteral.getRawType().getMethods()) { if (Object.class.equals(method.getDeclaringClass())) { continue; }/* w w w. j a v a 2s. c om*/ if (Modifier.isStatic(method.getModifiers()) || !Modifier.isPublic(method.getModifiers())) { continue; } if (method.getParameterTypes().length > 0) { continue; } if (method.getName().startsWith("get") && method.getName().length() > 3) { String fieldName = method.getName().substring(3, 4).toLowerCase() + method.getName().substring(4); builder.put(fieldName, new MethodPropertyReader(fieldName, method, adapter.adaptInternal(method.getReturnType()))); } else if (method.getName().startsWith("is") && method.getName().length() > 2 && (Boolean.class.isAssignableFrom(method.getReturnType()) || boolean.class.isAssignableFrom(method.getReturnType()))) { String fieldName = method.getName().substring(2, 3).toLowerCase() + method.getName().substring(3); builder.put(fieldName, new MethodPropertyReader(fieldName, method, adapter.adaptInternal(method.getReturnType()))); } } for (Field field : typeLiteral.getRawType().getFields()) { if (Modifier.isStatic(field.getModifiers()) || !Modifier.isPublic(field.getModifiers())) { continue; } builder.put(field.getName(), new FieldPropertyReader(field, adapter.adaptInternal(field.getType()))); } return builder; }
From source file:com.shigengyu.hyperion.server.RestServer.java
private static Collection<ControllerMethod> extractControllerMethods( Iterable<ResourceProvider> resourceProviders) { TreeMap<String, ControllerMethod> controllerMethods = Maps.newTreeMap(new Comparator<String>() { @Override/*from w w w . j a v a 2 s .c o m*/ public int compare(String first, String second) { return first.compareTo(second); } }); for (ResourceProvider resourceProvider : resourceProviders) { String controllerPath = resourceProvider.getResourceClass().getAnnotation(Path.class).value(); for (Method method : resourceProvider.getResourceClass().getMethods()) { if (!method.isAnnotationPresent(Path.class)) { continue; } String methodPath = method.getAnnotation(Path.class).value(); String httpMethod = null; if (method.isAnnotationPresent(GET.class)) { httpMethod = HttpMethods.GET; } else if (method.isAnnotationPresent(POST.class)) { httpMethod = HttpMethods.POST; } ControllerMethod controllerMethod = new ControllerMethod(httpMethod, controllerPath, methodPath); controllerMethods.put(controllerMethod.getUrl(), controllerMethod); } } return controllerMethods.values(); }
From source file:com.ccreanga.bitbucket.rest.client.http.HttpResponse.java
public HttpResponse(int statusCode, String statusMessage, Map<String, String> headers, String body) { this.statusCode = statusCode; this.statusMessage = statusMessage; this.headers = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER); this.headers.putAll(headers); this.body = body; }