Java Code Examples for com.beust.jcommander.internal.Maps#newHashMap()
The following examples show how to use
com.beust.jcommander.internal.Maps#newHashMap() .
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: ZxingUtils.java From wish-pay with Apache License 2.0 | 6 votes |
/** * 将内容contents生成长为width,宽为width的图片,返回刘文静 */ public static ServletOutputStream getQRCodeImge(String contents, int width, int height) throws IOException { ServletOutputStream stream = null; try { Map<EncodeHintType, Object> hints = Maps.newHashMap(); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); hints.put(EncodeHintType.CHARACTER_SET, "UTF8"); BitMatrix bitMatrix = new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, width, height, hints); MatrixToImageWriter.writeToStream(bitMatrix, "png", stream); return stream; } catch (Exception e) { log.error("create QR code error!", e); return null; } finally { if (stream != null) { stream.close(); } } }
Example 2
Source File: AlarmExpressionTest.java From monasca-common with Apache License 2.0 | 6 votes |
public void shouldParseDeterministicExpression() { final Map<String, String> dimensions = Maps.newHashMap(); final ArrayList<AlarmExpression> expressions = Lists.newArrayList( new AlarmExpression("count(log.error{},deterministic,20) > 5") ); final MetricDefinition metricDefinition = new MetricDefinition("log.error", dimensions); final AlarmSubExpression logErrorExpr = new AlarmSubExpression( AggregateFunction.COUNT, metricDefinition, AlarmOperator.GT, 5, 20, 1, true // each expression is deterministic ); for (final AlarmExpression expr : expressions) { final List<AlarmSubExpression> subExpressions = expr.getSubExpressions(); assertTrue(expr.isDeterministic()); // each expression is deterministic assertEquals(1, subExpressions.size()); assertEquals(subExpressions.get(0), logErrorExpr); } }
Example 3
Source File: JawbonePhysicalActivityDataPointMapperUnitTests.java From shimmer with Apache License 2.0 | 6 votes |
@Test public void asDataPointsShouldReturnCorrectMissingSensedDataPoints() { List<DataPoint<PhysicalActivity>> dataPoints = mapper.asDataPoints(singletonList(responseNode)); PhysicalActivity expectedPhysicalActivity = new PhysicalActivity.Builder("Bike") .setDistance(new LengthUnitValue(METER, 6318.2688961)) .setEffectiveTimeFrame( TimeInterval.ofEndDateTimeAndDuration(OffsetDateTime.parse("2015-04-29T16:07:07-04:00"), new DurationUnitValue(SECOND, 343))) .setCaloriesBurned(new KcalUnitValue(KILOCALORIE, 27.16863765916)) .build(); assertThat(dataPoints.get(1).getBody(), equalTo(expectedPhysicalActivity)); DataPointHeader testDataPointHeader = dataPoints.get(1).getHeader(); Map<String, Object> testProperties = Maps.newHashMap(); testProperties.put(HEADER_EXTERNAL_ID_KEY, "SbiOBJjJJk8n2xLpNTMFng12pGRjX-qe"); testProperties.put(HEADER_SOURCE_UPDATE_KEY, "2015-04-29T20:07:56Z"); testProperties.put(HEADER_SCHEMA_ID_KEY, PhysicalActivity.SCHEMA_ID); testDataPointHeader(testDataPointHeader, testProperties); }
Example 4
Source File: AlarmSqlImplTest.java From monasca-thresh with Apache License 2.0 | 6 votes |
@Test(groups = "orm") public void checkComplexMetrics() { final Alarm newAlarm = new Alarm(alarmDef, AlarmState.ALARM); for (final String hostname : Arrays.asList("vivi", "eleanore")) { for (final String metricName : Arrays.asList("cpu", "load")) { final Map<String, String> dimensions = Maps.newHashMap(); dimensions.put("first", "first_value"); dimensions.put("second", "second_value"); dimensions.put("hostname", hostname); final MetricDefinition md = new MetricDefinition(metricName, dimensions); newAlarm.addAlarmedMetric(new MetricDefinitionAndTenantId(md, TENANT_ID)); } } dao.createAlarm(newAlarm); final Alarm found = dao.findById(newAlarm.getId()); // Have to check both ways because there was a bug in AlarmDAOImpl and it showed up if both // ways were tested assertTrue(newAlarm.equals(found)); assertTrue(found.equals(newAlarm)); }
Example 5
Source File: FuzzyMap.java From muJava with Apache License 2.0 | 6 votes |
private static <V> V findAbbreviatedValue(Map<? extends IKey, V> map, IKey name, boolean caseSensitive) { String string = name.getName(); Map<String, V> results = Maps.newHashMap(); for (IKey c : map.keySet()) { String n = c.getName(); boolean match = (caseSensitive && n.startsWith(string)) || ((! caseSensitive) && n.toLowerCase().startsWith(string.toLowerCase())); if (match) { results.put(n, map.get(c)); } } V result; if (results.size() > 1) { throw new ParameterException("Ambiguous option: " + name + " matches " + results.keySet()); } else if (results.size() == 1) { result = results.values().iterator().next(); } else { result = null; } return result; }
Example 6
Source File: AliPayUtil.java From wish-pay with Apache License 2.0 | 6 votes |
/** * 获取阿里支付链接的所有参数列表 * * @param request * @return */ public static Map<String, String> getAlipayNotify(HttpServletRequest request) { Map<String, String> params = Maps.newHashMap(); Map requestParams = request.getParameterMap(); for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext(); ) { String name = iter.next(); String[] values = (String[]) requestParams.get(name); String valueStr = ""; for (int i = 0; i < values.length; i++) { valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ","; } //乱码解决,这段代码在出现乱码时使用。如果mysign和sign不相等也可以使用这段代码转化 //valueStr = new String(valueStr.getBytes("ISO-8859-1"), "gbk"); params.put(name, valueStr); } return params; }
Example 7
Source File: ZxingUtils.java From wish-pay with Apache License 2.0 | 6 votes |
/** * 将内容contents生成长为width,宽为width的图片,图片路径由imgPath指定 */ public static File getQRCodeImge(String contents, int width, int height, String imgPath) { try { Map<EncodeHintType, Object> hints = Maps.newHashMap(); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); hints.put(EncodeHintType.CHARACTER_SET, "UTF8"); BitMatrix bitMatrix = new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, width, height, hints); File imageFile = new File(imgPath); writeToFile(bitMatrix, "png", imageFile); return imageFile; } catch (Exception e) { log.error("create QR code error!", e); return null; } }
Example 8
Source File: DistributedWorkersEnsemble.java From openmessaging-benchmark with Apache License 2.0 | 6 votes |
@Override public void createConsumers(ConsumerAssignment overallConsumerAssignment) { List<List<TopicSubscription>> subscriptionsPerConsumer = ListPartition.partitionList( overallConsumerAssignment.topicsSubscriptions, consumerWorkers.size()); Map<String, ConsumerAssignment> topicsPerWorkerMap = Maps.newHashMap(); int i = 0; for (List<TopicSubscription> tsl : subscriptionsPerConsumer) { ConsumerAssignment individualAssignement = new ConsumerAssignment(); individualAssignement.topicsSubscriptions = tsl; topicsPerWorkerMap.put(consumerWorkers.get(i++), individualAssignement); } List<CompletableFuture<Void>> futures = topicsPerWorkerMap.keySet().stream().map(consumer -> { try { return sendPost(consumer, "/create-consumers", writer.writeValueAsBytes(topicsPerWorkerMap.get(consumer))); } catch (Exception e) { CompletableFuture<Void> future = new CompletableFuture<>(); future.completeExceptionally(e); return future; } }).collect(toList()); FutureUtil.waitForAll(futures).join(); }
Example 9
Source File: DistributedWorkersEnsemble.java From openmessaging-benchmark with Apache License 2.0 | 6 votes |
@Override public void createProducers(List<String> topics) { List<List<String>> topicsPerProducer = ListPartition.partitionList(topics, producerWorkers.size()); Map<String, List<String>> topicsPerProducerMap = Maps.newHashMap(); int i = 0; for (List<String> assignedTopics : topicsPerProducer) { topicsPerProducerMap.put(producerWorkers.get(i++), assignedTopics); } // Number of actually used workers might be less than available workers numberOfUsedProducerWorkers = i; List<CompletableFuture<Void>> futures = topicsPerProducerMap.keySet().stream().map(producer -> { try { return sendPost(producer, "/create-producers", writer.writeValueAsBytes(topicsPerProducerMap.get(producer))); } catch (Exception e) { CompletableFuture<Void> future = new CompletableFuture<>(); future.completeExceptionally(e); return future; } }).collect(toList()); FutureUtil.waitForAll(futures).join(); }
Example 10
Source File: WechatServiceAPI.java From seezoon-framework-all with Apache License 2.0 | 6 votes |
/** * h5 js api ticket * * @return */ public String getJsApiTicket() { String token = this.getToken(); Assert.hasLength(token,"token 为null"); Map<String,String> params = Maps.newHashMap(); params.put("access_token",token); params.put("type","jsapi"); String cachedTicket = valueOperations.get("wx_js_ticket"); Long expire = valueOperations.getOperations().getExpire("wx_js_ticket", TimeUnit.SECONDS); if (StringUtils.isNotEmpty(cachedTicket) && expire > 3600) {//缓存两小时,剩余时间小于1小时就重新拿 return cachedTicket; } else { JsApiTicket jsApiTicket = HttpRequestUtils.doGet("https://api.weixin.qq.com/cgi-bin/ticket/getticket", params,JsApiTicket.class); if (jsApiTicket.isSuccess()) { valueOperations.set("wx_js_ticket", jsApiTicket.getTicket(),7200,TimeUnit.SECONDS); return jsApiTicket.getTicket(); } else { throw new ServiceException(jsApiTicket.getErrmsg()); } } }
Example 11
Source File: WechatServiceAPI.java From seezoon-framework-all with Apache License 2.0 | 6 votes |
/** * 获取接口操作token * @return */ public String getToken() { Map<String,String> params = Maps.newHashMap(); params.put("grant_type","client_credential"); params.put("appid",appId); params.put("secret",appsecret); String cachedToken = valueOperations.get("wx_token"); Long expire = valueOperations.getOperations().getExpire("wx_token", TimeUnit.SECONDS); if (StringUtils.isNotEmpty(cachedToken) && expire > 3600) {//缓存两小时,剩余时间小于1小时就重新拿 return cachedToken; } else { Token token = HttpRequestUtils.doGet("https://api.weixin.qq.com/cgi-bin/token", params,Token.class); if (token.isSuccess()) { valueOperations.set("wx_token", token.getAccess_token(),7200,TimeUnit.SECONDS); return token.getAccess_token(); } else { throw new ServiceException(token.getErrmsg()); } } }
Example 12
Source File: WechatServiceAPI.java From seezoon-framework-all with Apache License 2.0 | 6 votes |
/** * author token 换取用户信息 * @param accessToken * @return */ public UserInfo userinfo(AuthAccessToken accessToken) { Assert.notNull(accessToken,"accessToken 为null"); Assert.hasLength(accessToken.getAccess_token(),"accessToken 为空"); Assert.hasLength(accessToken.getOpenid(),"openid 为空"); Map<String,String> params = Maps.newHashMap(); params.put("access_token",accessToken.getAccess_token()); params.put("openid",accessToken.getOpenid()); params.put("lang","zh_CN"); params.put("grant_type","authorization_code"); UserInfo userInfo = HttpRequestUtils.doGet("https://api.weixin.qq.com/sns/userinfo", params,UserInfo.class); if (userInfo.isSuccess()) { return userInfo; } else { throw new ServiceException(accessToken.getErrmsg()); } }
Example 13
Source File: WechatServiceAPI.java From seezoon-framework-all with Apache License 2.0 | 5 votes |
/** * h5 auth code 换取auth token * @param code * @return */ public AuthAccessToken getUserInfoByCode(String code) { Assert.hasLength(code,"code 为空"); Map<String,String> params = Maps.newHashMap(); params.put("appid",appId); params.put("secret",appsecret); params.put("code",code); params.put("grant_type","authorization_code"); AuthAccessToken accessToken = HttpRequestUtils.doGet("https://api.weixin.qq.com/sns/oauth2/access_token", params, AuthAccessToken.class); if (accessToken.isSuccess()) { return accessToken; } else { throw new ServiceException(accessToken.getErrmsg()); } }
Example 14
Source File: WechatServiceAPI.java From seezoon-framework-all with Apache License 2.0 | 5 votes |
/** * 小程序登录获取 * @param code * @return */ public JsCode2session jscode2session(String code) { Assert.hasLength(code,"code为空"); Map<String,String> params = Maps.newHashMap(); params.put("appid",mappId); params.put("secret",mappsecret); params.put("js_code",code); params.put("grant_type","authorization_code"); JsCode2session code2session = HttpRequestUtils.doGet("https://api.weixin.qq.com/sns/jscode2session", params, JsCode2session.class); if (code2session.isSuccess()) { return code2session; } else { throw new ServiceException(code2session.getErrmsg()); } }
Example 15
Source File: CompilingTestBase.java From yql-plus with Apache License 2.0 | 5 votes |
public void init(Module... modules) { if(modules == null) { modules = new Module[0]; } this.metricModule = new JavaTestModule.MetricModule(); injector = Guice.createInjector(Iterables.concat(ImmutableList.<Module>of(new CompilingTestModule()), Arrays.asList(modules))); source = injector.getInstance(ASMClassSource.class); scope = new GambitSource(source); this.modules = Maps.newLinkedHashMap(); this.views = Maps.newHashMap(); this.sources = Maps.newLinkedHashMap(); }
Example 16
Source File: WechatServiceAPI.java From seezoon-framework-all with Apache License 2.0 | 5 votes |
/** * h5 需要js 的签名参数 * @param url * @return */ public Map<String,Object> getJsConfig(String url){ Assert.hasLength(url,"url 为null"); String noncestr = WxUtils.createNoncestr(); long timestamp = WxUtils.createTimestamp(); String jsapiTicket = getJsApiTicket(); String signature = WxUtils.jsSignature(noncestr, timestamp, jsapiTicket, url); Map<String,Object> config = Maps.newHashMap(); config.put("noncestr", noncestr); config.put("timestamp", timestamp); config.put("signature", signature); config.put("appId", appId); return config; }
Example 17
Source File: JCommander.java From muJava with Apache License 2.0 | 5 votes |
/** * Create the ParameterDescriptions for all the \@Parameter found. */ private void createDescriptions() { m_descriptions = Maps.newHashMap(); for (Object object : m_objects) { addDescription(object); } }
Example 18
Source File: ShapefileQueryOutputFormat.java From geowave with Apache License 2.0 | 4 votes |
@Override public void output(final ResultSet results) { int geometryColumn = -1; for (int i = 0; i < results.columnCount(); i++) { if (Geometry.class.isAssignableFrom(results.columnType(i))) { geometryColumn = i; break; } } if (geometryColumn < 0) { throw new RuntimeException( "Unable to output results to a shapefile without a geometry column."); } final SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(); ftb.setCRS(results.getCRS()); ftb.setName(typeName); for (int i = 0; i < results.columnCount(); i++) { final AttributeTypeBuilder atb = new AttributeTypeBuilder(); atb.setBinding(results.columnType(i)); atb.nillable(true); if (i == geometryColumn) { ftb.add(atb.buildDescriptor("the_geom")); } else { ftb.add(atb.buildDescriptor(results.columnName(i))); } } final SimpleFeatureType sft = ftb.buildFeatureType(); final SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(sft); final AtomicLong nextId = new AtomicLong(0L); final Iterator<SimpleFeature> features = Iterators.transform(results, r -> { sfb.reset(); for (int i = 0; i < results.columnCount(); i++) { sfb.add(r.columnValue(i)); } final SimpleFeature feature = sfb.buildFeature(Long.toString(nextId.incrementAndGet())); return feature; }); final FileDataStoreFactorySpi factory = FileDataStoreFinder.getDataStoreFactory("shp"); final File file = new File(outputFile); final Map<String, Serializable> params = Maps.newHashMap(); final Transaction transaction = new DefaultTransaction("Write Results"); try { params.put("url", file.toURI().toURL()); final DataStore dataStore = factory.createNewDataStore(params); dataStore.createSchema(sft); final SimpleFeatureStore store = (SimpleFeatureStore) dataStore.getFeatureSource(dataStore.getTypeNames()[0]); store.setTransaction(transaction); final SimpleFeatureCollection featureCollection = DataUtilities.collection(new SimpleFeatureIterator() { @Override public boolean hasNext() { return features.hasNext(); } @Override public SimpleFeature next() throws NoSuchElementException { return features.next(); } @Override public void close() {} }); store.addFeatures(featureCollection); transaction.commit(); } catch (final Exception e) { try { transaction.rollback(); } catch (final IOException ioe) { throw new RuntimeException("Encountered an error when rolling back transaction", ioe); } throw new RuntimeException( "Encountered an error when writing the features to the file: " + e.getMessage(), e); } }