我有一个Map作为语法Map<String, String> testMap = new HashMap<String, String>();.在此地图中可以有1000个数据.
当我的应用程序需要新的数据列表时,我必须清除Map.但是当我看到Map.clear()的代码为
/**
* Removes all of the mappings from this map.
* The map will be empty after this call returns.
*/
public void clear() {
modCount++;
Entry[] tab = table;
for (int i = 0; i < tab.length; i++)
tab[i] = null;
size = 0;
}
Run Code Online (Sandbox Code Playgroud)
我意识到clear方法循环n次(其中n是Map中的数据).所以我认为可以有一种方法来重新定义Map,因为testMap = new HashMap<String, String>();
之前使用的Map将是Garbage收集的.
但我不确定这将是一个好方法.我正在研究移动应用程序.
你能指导我吗?
是否可以定义用于开发Google Glass应用程序的Android虚拟设备(直到这些设备可以广泛使用)?
我有一个工作流方法,并在发生错误时抛出异常.我想将报告指标添加到我的工作流程中.在下面的finally块中,有没有办法判断try/catch块中的一个方法是否引发了异常?
我可以添加自己的catch/throw代码,但更喜欢更清晰的解决方案,因为这是我在项目中重用的模式.
@Override
public void workflowExecutor() throws Exception {
try {
reportStartWorkflow();
doThis();
doThat();
workHarder();
} finally {
/**
* Am I here because my workflow finished normally, or because a workflow method
* threw an exception?
*/
reportEndWorkflow();
}
}
Run Code Online (Sandbox Code Playgroud) 是否可以从.ebextensions配置文件引用PARAM1/PARAM2等容器环境属性.如果是这样,怎么样?我试过$ PARAM1,但它似乎是一个空值.
我想设置在启动时的主机名包含DEV,QA和PROD,我通过PARAM1环境变量传递给我的容器.
commands:
01-set-correct-hostname:
command: hostname myappname{$PARAM1}.com
Run Code Online (Sandbox Code Playgroud) 在iPhone上,本地谷歌地图应用程序拦截并加载maps.google.com网址.我想在Android上做同样的事情,但谷歌地图正在浏览器中加载.
因此,在网页中,是否可以在Android Google地图应用中打开此网址http://maps.google.com/maps?saddr=brighton&daddr=timbuktu?
我从这个问题中看到你可以通过Intent从另一个应用程序中完成.你能从浏览器触发这些Intent吗?
编辑 - 在进一步测试中,我发现系统会提示用户在浏览器或地图应用中打开链接,以获取到maps.google.maps的标准html链接:
<a href="http://maps.google.com/maps?saddr=brighton&daddr=timbuktu">show route</a>
Run Code Online (Sandbox Code Playgroud)
我遇到了问题因为我使用javascript通过Location API回调设置window.location.href(所以我可以获取用户的位置,然后打开地图).我为此打开了一个错误报告.
我在MySQL中有下表,记录每天发生的事件的事件计数
event_date event_count
2011-05-03 21
2011-05-04 12
2011-05-05 12
Run Code Online (Sandbox Code Playgroud)
我希望能够通过日期范围和星期几来有效地查询.例如 - "5月的星期二什么是event_count?"
目前,event_date字段是日期类型.MySQL中是否有任何函数可以按星期几查询此列,还是应该在表中添加另一列来存储星期几?
该表将保存数十万行,因此如果有选择,我将选择最有效的解决方案(而不是最简单的解决方案).
我正在使用Angular和Bootstrap,使用nav选项卡控件来切换div的可见性.在一个div中,我有一个大的img(建筑物的CAD绘图).然后我还在图像上叠加标记.我想根据图像宽度和图像naturalWidth缩放标记的x/y位置.我正在使用resize指令来检测更改并更新我的范围.
我的问题是,如果用户使用CAD img切换标签并切换回div,则在我调整浏览器大小之前不会进行刷新(或者如果我按下Mac上的CMD键,则会令人惊讶).
是否有角度方式触发resize事件以强制重新计算我的标记.或者是否有一个我可以点击的事件在完全显示时会被触发?
或者我应该采取更精确的角度方法?
这是HTML,我写的resize指令在标签上.
<div id="imageDiv" style="position: relative;" ng-show="selectedLocation" >
<img ng-src="../maps/image/{{selectedLocation}}"
style=" max-width: 100%; max-height: auto; border:solid 1px black" resize imageonload />
</div>
Run Code Online (Sandbox Code Playgroud)
这是resize指令(改编自http://jsfiddle.net/jaredwilli/SfJ8c/)
directive('resize', function($window) {
return function(scope, element) {
var w = angular.element($window);
scope.imgCadImage = element;
scope.getWindowDimensions = function() {
return {
'h' : scope.imgCadImage[0].width,
'w' : scope.imgCadImage[0].height
};
};
scope.$watch(scope.getWindowDimensions, function(newValue, oldValue) {
if (scope.imgCadImage[0].naturalWidth)
scope.imgScale = newValue.w / scope.imgCadImage[0].naturalWidth;
else
scope.imgScale = 1;
console.log("watched resize event - scale = "+scope.imgScale)
scope.updateCADMarkersAfterResize(); …Run Code Online (Sandbox Code Playgroud) 我正在使用JAXB/Jersey(1.3)在REST API中将java转换为json.我正在返回的java类是:
public class MyClass {
List<String> myTags;
public List<String> getMyTags() {
return myTags;
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果列表myTags中只有一个元素,那么数据将转换为json作为字符串对象,而不是字符串数组.也就是说,我得到:
{
"myTags": "myString"
}
Run Code Online (Sandbox Code Playgroud)
我想要的是:
{
"myTags": ["myString"]
}
Run Code Online (Sandbox Code Playgroud)
有谁知道什么?
我有关于HTML5地理定位功能的问题.我使用下面的代码来获取位置数据.我使用"enableHighAccuracy:false"选项来使用基于Cell的GPS功能.准确度很低但响应速度太快.但有些人总是在手机上使用内置GPS,因此这段代码对他们不起作用.如果我将accurency选项更改为"enableHighAccuracy:true",则它适用于他们.但这次,代码仅使用内置GPS.不是基于CELL的GPS.
问题 - >我怎么能这样做:首先,尝试从内置GPS获取超时(例如5000ms)的位置如果此时无法获得位置只需查找基于单元格的位置超时(例如10000ms)如果位置不能在这个时候得到,返回一条错误信息.
这是我现在使用的代码.
提前致谢.
function getLocationfromGoogle() {
navigator.geolocation.getCurrentPosition(
function(pos) {
$("#lat_field").val(pos.coords.latitude);
$("#long_field").val(pos.coords.longitude);
var geocoder = new google.maps.Geocoder();
var latLng = new google.maps.LatLng(pos.coords.latitude,pos.coords.longitude);
geocoder.geocode({ 'latLng': latLng}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//console.log(results[0].formatted_address);
$("#adresim").val(results[0].formatted_address);
}
else {
alert('Google convertion is not succesfully done.');
}
});
},function error(msg){
alert('Please enable your GPS position future.');
},{maximumAge:600000, timeout:5000, enableHighAccuracy: false}
);
}
Run Code Online (Sandbox Code Playgroud) android ×3
java ×2
angularjs ×1
browser ×1
charts ×1
collections ×1
exception ×1
geolocation ×1
google-glass ×1
html5 ×1
javascript ×1
jaxb ×1
jersey ×1
mysql ×1
performance ×1