Java Code Examples for java.util.AbstractMap#SimpleEntry
The following examples show how to use
java.util.AbstractMap#SimpleEntry .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerStateRepositoryTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test public void testInvokeEntrySet() throws Exception { ServerStateRepository repository = new ServerStateRepository(); repository.invoke(new StateRepositoryOpMessage.PutIfAbsentMessage("foo", "bar", "key1", "value1")); repository.invoke(new StateRepositoryOpMessage.PutIfAbsentMessage("foo", "bar", "key2", "value2")); repository.invoke(new StateRepositoryOpMessage.PutIfAbsentMessage("foo", "bar", "key3", "value3")); EhcacheEntityResponse.MapValue response = (EhcacheEntityResponse.MapValue) repository.invoke( new StateRepositoryOpMessage.EntrySetMessage("foo", "bar")); @SuppressWarnings("unchecked") Set<Map.Entry<String, String>> entrySet = (Set<Map.Entry<String, String>>) response.getValue(); assertThat(entrySet.size(), is(3)); Map.Entry<String, String> entry1 = new AbstractMap.SimpleEntry<>("key1", "value1"); Map.Entry<String, String> entry2 = new AbstractMap.SimpleEntry<>("key2", "value2"); Map.Entry<String, String> entry3 = new AbstractMap.SimpleEntry<>("key3", "value3"); @SuppressWarnings("unchecked") Matcher<Iterable<? extends Map.Entry<String, String>>> matcher = containsInAnyOrder(entry1, entry2, entry3); assertThat(entrySet, matcher); }
Example 2
Source File: Controller.java From kubernetes-client with Apache License 2.0 | 6 votes |
public Controller(Class<T> apiTypeClass, DeltaFIFO<T> queue, ListerWatcher<T, L> listerWatcher, Consumer<Deque<AbstractMap.SimpleEntry<DeltaFIFO.DeltaType, Object>>> processFunc, Supplier<Boolean> resyncFunc, long fullResyncPeriod, OperationContext context, ConcurrentLinkedQueue<SharedInformerEventListener> eventListeners) { this.queue = queue; this.listerWatcher = listerWatcher; this.apiTypeClass = apiTypeClass; this.processFunc = processFunc; this.resyncFunc = resyncFunc; this.fullResyncPeriod = fullResyncPeriod; this.operationContext = context; this.eventListeners = eventListeners; // Starts one daemon thread for reflector this.reflectExecutor = Executors.newSingleThreadScheduledExecutor(); // Starts one daemon thread for resync this.resyncExecutor = Executors.newSingleThreadScheduledExecutor(); }
Example 3
Source File: HttpMetadataParser.java From rawhttp with Apache License 2.0 | 6 votes |
@Nullable private Map.Entry<String, String> parseHeaderField(InputStream inputStream, int lineNumber, BiFunction<String, Integer, RuntimeException> createError) throws IOException { @Nullable String headerName = parseHeaderName(inputStream, lineNumber, createError); if (headerName == null) { return null; } String headerValue = parseHeaderValue(inputStream, lineNumber, createError); return new AbstractMap.SimpleEntry<>(headerName, headerValue); }
Example 4
Source File: DittoMessageMapperTest.java From ditto with Eclipse Public License 2.0 | 6 votes |
private static Map.Entry<ExternalMessage, List<Adaptable>> valid2() { final Map<String, String> headers = new HashMap<>(); headers.put("header-key", "header-value"); headers.put(ExternalMessage.CONTENT_TYPE_HEADER, DittoConstants.DITTO_PROTOCOL_CONTENT_TYPE); final JsonObject json = JsonFactory.newObjectBuilder() .set("path","/some/path") .build(); final List<Adaptable> expected = Collections.singletonList( ProtocolFactory.newAdaptableBuilder(ProtocolFactory.jsonifiableAdaptableFromJson(json)) .build()); final ExternalMessage message = ExternalMessageFactory.newExternalMessageBuilder(headers) .withText(json.toString()) .build(); return new AbstractMap.SimpleEntry<>(message, expected); }
Example 5
Source File: OperationInvocationHandler.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private Map.Entry<URI, EdmOperation> getUnboundOperation( final Operation operation, final List<String> parameterNames) { final EdmEntityContainer container = getClient().getCachedEdm().getEntityContainer(targetFQN); final EdmOperation edmOperation; if (operation.type() == OperationType.FUNCTION) { edmOperation = container.getFunctionImport(operation.name()).getUnboundFunction(parameterNames); } else { edmOperation = container.getActionImport(operation.name()).getUnboundAction(); } final URIBuilder uriBuilder = getClient().newURIBuilder(). appendOperationCallSegment(edmOperation.getName()); return new AbstractMap.SimpleEntry<URI, EdmOperation>(uriBuilder.build(), edmOperation); }
Example 6
Source File: TtlMapState.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private Map.Entry<UK, UV> getUnexpiredAndUpdateOrCleanup(Map.Entry<UK, TtlValue<UV>> e) { TtlValue<UV> unexpiredValue; try { unexpiredValue = getWrappedWithTtlCheckAndUpdate( e::getValue, v -> original.put(e.getKey(), v), originalIterator::remove); } catch (Exception ex) { throw new FlinkRuntimeException(ex); } return unexpiredValue == null ? null : new AbstractMap.SimpleEntry<>(e.getKey(), unexpiredValue.getUserValue()); }
Example 7
Source File: ResponderIdTests.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public Map.Entry<Boolean, String> runTest() { Boolean pass = Boolean.FALSE; String message = null; try { // Test methods for pulling out the underlying // KeyIdentifier object. Note: There is a minute chance that // an RSA public key, once hashed into a key ID might collide // with the one extracted from the certificate used to create // respByKeyId. This is so unlikely to happen it is considered // virtually impossible. KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); kpg.initialize(2048); KeyPair rsaKey = kpg.generateKeyPair(); KeyIdentifier testKeyId = new KeyIdentifier(rsaKey.getPublic()); if (respByKeyId.getKeyIdentifier().equals(testKeyId)) { message = "Unexpected match in ResponderId Key ID"; } else if (respByName.getKeyIdentifier() != null) { message = "Non-null key ID returned from " + "ResponderId constructed byName"; } else { pass = Boolean.TRUE; } } catch (Exception e) { e.printStackTrace(System.out); message = e.getClass().getName(); } return new AbstractMap.SimpleEntry<>(pass, message); }
Example 8
Source File: DeltaFIFO.java From kubernetes-client with Apache License 2.0 | 5 votes |
/** * Keep the one with the most information if both are deletions. * * @param d1 the most one * @param d2 the elder one * @return the most one */ private AbstractMap.SimpleEntry<DeltaType, Object> isDuplicate(AbstractMap.SimpleEntry<DeltaType, Object> d1, AbstractMap.SimpleEntry<DeltaType, Object> d2) { AbstractMap.SimpleEntry<DeltaType, Object> deletionDelta = isDeletionDup(d1, d2); if (deletionDelta != null) { return deletionDelta; } return null; }
Example 9
Source File: Services.java From olingo-odata4 with Apache License 2.0 | 5 votes |
protected Map.Entry<Accept, AbstractUtilities> getUtilities(final String accept, final String format) { Accept acceptType; if (StringUtils.isNotBlank(format)) { try { acceptType = Accept.valueOf(format.toUpperCase()); } catch (Exception e) { acceptType = Accept.parse(format); } } else { acceptType = Accept.parse(accept); } return new AbstractMap.SimpleEntry<Accept, AbstractUtilities>(acceptType, getUtilities(acceptType)); }
Example 10
Source File: IndexTool.java From phoenix with Apache License 2.0 | 4 votes |
public static Map.Entry<Integer, Job> run(Configuration conf, String schemaName, String dataTable, String indexTable, boolean useSnapshot, String tenantId, boolean disableBefore, boolean shouldDeleteBeforeRebuild, boolean runForeground) throws Exception { final List<String> args = Lists.newArrayList(); if (schemaName != null) { args.add("-s"); args.add(schemaName); } args.add("-dt"); args.add(dataTable); args.add("-it"); args.add(indexTable); if (runForeground) { args.add("-runfg"); } if (useSnapshot) { args.add("-snap"); } if (tenantId != null) { args.add("-tenant"); args.add(tenantId); } if (shouldDeleteBeforeRebuild) { args.add("-deleteall"); } args.add("-op"); args.add("/tmp/" + UUID.randomUUID().toString()); if (disableBefore) { PhoenixConfigurationUtil.setDisableIndexes(conf, indexTable); } IndexTool indexingTool = new IndexTool(); indexingTool.setConf(conf); int status = indexingTool.run(args.toArray(new String[0])); Job job = indexingTool.getJob(); return new AbstractMap.SimpleEntry<>(status, job); }
Example 11
Source File: MysqlMutationMapperTest.java From SpinalTap with Apache License 2.0 | 4 votes |
@Test public void testUpdateMutationWithDifferentPK() throws Exception { Serializable[] old = new Serializable[4]; old[0] = 12131L; old[1] = "test_user"; old[2] = 25; old[3] = 0; Serializable[] current = new Serializable[4]; current[0] = 12334L; current[1] = old[1]; current[2] = 26; current[3] = old[3]; Map.Entry<Serializable[], Serializable[]> change = new AbstractMap.SimpleEntry<>(old, current); BinlogEvent event = new UpdateEvent(TABLE_ID, SERVER_ID, TIMESTAMP, BINLOG_FILE_POS, ImmutableList.of(change)); List<? extends Mutation> mutations = eventMapper.map(event); assertEquals(2, mutations.size()); assertTrue(mutations.get(0) instanceof MysqlDeleteMutation); MysqlDeleteMutation deleteMutation = (MysqlDeleteMutation) mutations.get(0); validateMetadata(deleteMutation, 0); Row row = deleteMutation.getRow(); assertEquals(12131L, row.getColumns().get("id").getValue()); assertEquals("test_user", row.getColumns().get("name").getValue()); assertEquals(25, row.getColumns().get("age").getValue()); assertEquals(0, row.getColumns().get("sex").getValue()); assertTrue(mutations.get(1) instanceof MysqlInsertMutation); MysqlInsertMutation insertMutation = (MysqlInsertMutation) mutations.get(1); validateMetadata(insertMutation, 0); row = insertMutation.getRow(); assertEquals(12334L, row.getColumns().get("id").getValue()); assertEquals("test_user", row.getColumns().get("name").getValue()); assertEquals(26, row.getColumns().get("age").getValue()); assertEquals(0, row.getColumns().get("sex").getValue()); }
Example 12
Source File: UnmarkPin.java From WhereAreTheEyes with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected Void doInBackground(MarkData... params) { Location l = params[0].loc; String username = params[0].username; Context context = params[0].context; Activity activity = params[0].activity; if( username.length() == 0 ) return null; if( l == null ) { Log.d("Unmarking", "Location was null!"); return null; // Location data isn't available yet! } try { List<AbstractMap.SimpleEntry> httpParams = new ArrayList<AbstractMap.SimpleEntry>(); httpParams.add(new AbstractMap.SimpleEntry<>("username", username)); httpParams.add(new AbstractMap.SimpleEntry<>("latitude", Double.valueOf(l.getLatitude()).toString())); httpParams.add(new AbstractMap.SimpleEntry<>("longitude", Double.valueOf(l.getLongitude()).toString())); // Vibrate once, let the user know we received the button tap Vibrate.pulse(context); URL url = new URL("https://" + Constants.DOMAIN + "/unmarkPin"); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); try { conn.setReadTimeout(10000); conn.setConnectTimeout(15000); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); OutputStream os = conn.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); writer.write(getQuery(httpParams)); writer.flush(); writer.close(); os.close(); String response = ""; int responseCode = conn.getResponseCode(); if( responseCode == HttpsURLConnection.HTTP_OK ) { String line; BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); while ((line = br.readLine()) != null) { response += line; } } handleResponse(response, context, activity); Log.d("Unmarking", "Unmarked pin, got response: " + response); } finally { conn.disconnect(); } } catch( Exception e ) { Log.e("UnmarkPin", "Error unmarking pin: " + e.getMessage()); Log.e("UnmarkPin", Log.getStackTraceString(e)); } return null; }
Example 13
Source File: Mute.java From BungeeAdminTools with GNU General Public License v3.0 | 4 votes |
public void setMuteMessage(final String messagePattern, final Timestamp expiration){ muteMessage = new AbstractMap.SimpleEntry<String, Timestamp>(messagePattern, expiration); }
Example 14
Source File: CacheGetterFactory.java From simple-robot-core with Apache License 2.0 | 4 votes |
/** * 构建缓存的代理Getter * * @param toCacheGetter getter对象 * @param time 时间类型,可以为null * @param timeTypeGetter 时间获取器与类型获取器,可以通过枚举CacheTypes指定,可以为null */ public static SenderGetList toCacheableGetter(SenderGetList toCacheGetter, Long time, Function<Long, Map.Entry<Supplier<LocalDateTime>, CacheTimeTypes>> timeTypeGetter) { Objects.requireNonNull(toCacheGetter, "GETTER对象自身不可为null"); SenderGetList getter = initLocalGetter(toCacheGetter); //获取类型 CacheTimeTypes type = timeTypeGetter == null ? null : timeTypeGetter.apply(time).getValue(); Supplier<LocalDateTime> timeGetter = timeTypeGetter == null ? null : timeTypeGetter.apply(time).getKey(); //先尝试查询本线程代理对象 ProxyType proxyType = new ProxyType(time, type); //获取缓存Map MethodCacheMap cache = getCacheMap(); Map.Entry<ProxyType, SenderGetList> localCache = LOCAL_PROXY_GETTER.get(); //如果为null,记录值且value值为null if((localCache == null) || (!localCache.getKey().equals(proxyType))){ localCache = new AbstractMap.SimpleEntry<>(proxyType, null); LOCAL_PROXY_GETTER.set(localCache); } //查看是否有getList代理对象 SenderGetList senderGetList = localCache.getValue(); if (senderGetList != null) { return senderGetList; } //构建GETTER的代理对象 SenderGetList proxyCacheGetter = getProxy(getter, SenderGetList.class, (m, o) -> { //如果被忽略,不进行缓存 if(ifIgnore(m)){ return m.invoke(getter, o); } //执行 //先查看是否有缓存值 Object result = cache.get(m); if (result == null) { //没有值,执行方法并获取返回值 result = m.invoke(getter, o); if (time != null) { //有时间 if (timeGetter == null) { //没有时间获取器,默认时间类型为秒 cache.putPlusSeconds(m, result, time); } else { cache.put(m, result, timeGetter.get()); } } else { //如果什么也没有,则此代理默认缓存1小时 cache.putPlusHours(m, result, 1); } } //返回结果 return result; }); //记录本地线程数据 LOCAL_PROXY_GETTER.get().setValue(proxyCacheGetter); return proxyCacheGetter; }
Example 15
Source File: BlockMaterialMap.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@Override public Entry<BlockVector, MaterialData> next() { iter.advance(); return new AbstractMap.SimpleEntry<>(decodePos(iter.key()), decodeMaterial(iter.value())); }
Example 16
Source File: Utils.java From YouTube-In-Background with MIT License | 4 votes |
public static <K, V> Map.Entry<K, V> entry(K key, V value) { return new AbstractMap.SimpleEntry<>(key, value); }
Example 17
Source File: ResourceResolvingStubDownloader.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
@Override public Map.Entry<StubConfiguration, File> downloadAndUnpackStubJar( StubConfiguration config) { registerShutdownHook(); List<RepoRoot> repoRoots = repoRootFunction.apply(stubRunnerOptions, config); List<String> paths = toPaths(repoRoots); List<Resource> resources = resolveResources(paths); if (log.isDebugEnabled()) { log.debug("For paths " + paths + " found following resources " + resources); } if (resources.isEmpty() && this.stubRunnerOptions.isFailOnNoStubs()) { throw new IllegalStateException("No stubs were found on classpath for [" + config.getGroupId() + ":" + config.getArtifactId() + "]"); } final File tmp = TemporaryFileStorage.createTempDir("classpath-stubs"); if (stubRunnerOptions.isDeleteStubsAfterTest()) { tmp.deleteOnExit(); } boolean atLeastOneFound = false; for (Resource resource : resources) { try { String relativePath = relativePathPicker(resource, this.gavPattern.apply(config)); if (log.isDebugEnabled()) { log.debug("Relative path for resource is [" + relativePath + "]"); } if (relativePath == null) { log.warn("Unable to match the URI [" + resource.getURI() + "]"); continue; } atLeastOneFound = true; copyTheFoundFiles(tmp, resource, relativePath); } catch (IOException e) { log.error("Exception occurred while trying to create dirs", e); throw new IllegalStateException(e); } } if (!atLeastOneFound) { log.warn("Didn't find any matching stubs"); return null; } log.info("Unpacked files for [" + config.getGroupId() + ":" + config.getArtifactId() + ":" + config.getVersion() + "] to folder [" + tmp + "]"); return new AbstractMap.SimpleEntry<>(new StubConfiguration(config.getGroupId(), config.getArtifactId(), config.getVersion(), config.getClassifier()), tmp); }
Example 18
Source File: Runner.java From metron with Apache License 2.0 | 4 votes |
public Map.Entry<RunnerOptions, String> of(String value) { if(option.hasArg()) { return new AbstractMap.SimpleEntry<>(this, value); } return new AbstractMap.SimpleEntry<>(this, null); }
Example 19
Source File: CryptoInterface.java From SigFW with GNU Affero General Public License v3.0 | 2 votes |
/** * Method to encrypt TCAP message. * * * @param message SCCP message * @param sccpMessageFactory SCCP message factory * @param publicKey Public Key * @param lmrt Long Message Rule Type, if UDT or XUDT should be send * @return pair<message, lmrt> - message and indicator if UDT or XUDT should be send */ public AbstractMap.SimpleEntry<SccpDataMessage, LongMessageRuleType> tcapEncrypt(SccpDataMessage message, MessageFactoryImpl sccpMessageFactory, PublicKey publicKey, LongMessageRuleType lmr);
Example 20
Source File: MobileCommand.java From java-client with Apache License 2.0 | 2 votes |
/** * This method forms a {@link java.util.Map} of parameters for the * key event invocation. * * @param key code for the key pressed on the device. * @return a key-value pair. The key is the command name. The value is a * {@link java.util.Map} command arguments. */ public static Map.Entry<String, Map<String, ?>> pressKeyCodeCommand(int key) { return new AbstractMap.SimpleEntry<>( PRESS_KEY_CODE, prepareArguments("keycode", key)); }