小编Mat*_*rog的帖子

是否有标准的Java List实现,不允许向其添加null?

说我有一个List,我知道我永远不想添加null它.如果我向它添加null,则意味着我犯了一个错误.因此,每次我打电话,list.add(item)我都会打电话if (item == null) throw SomeException(); else list.add(item);.是否存在List为我这样做的现有类(可能在Apache Commons或其他内容中)?

类似的问题:帮助删除Java列表中的空引用?但我不想删除所有空值,我想确保它们从未被添加到第一位.

java collections null list

25
推荐指数
4
解决办法
4万
查看次数

如果TortoiseSVN中的某些文件被标记为"已删除"而其他文件被"删除(+)"并带有加号,这意味着什么?

我即将在TortoiseSVN中做一个提交,涉及重新安排很多文件和目录.在"提交"窗口中,有几个文件的文本状态为"已删除"或"已添加",但其他文件状态为"已删除(+)"或"已添加(+)"的文件.(+)是什么意思?

(对于一个加号来说谷歌很难,而且"加号"这个词在蓝色叠加图标上显示了大量的点击,意思是"添加")

svn tortoisesvn file delete-file

24
推荐指数
2
解决办法
9618
查看次数

22
推荐指数
3
解决办法
5416
查看次数

程序员一周应花多少时间在编码和学习上花费多少时间

我是大学毕业生.我想知道我应该花多少时间在编码和学习上.

time

18
推荐指数
5
解决办法
7501
查看次数

FireBug的console.log()和console.debug()有什么区别?

一个非常简单的代码来说明差异.

var x = [0, 3, 1, 2];
console.debug('debug', x);
console.log('log', x);
// above display the same result
x.splice(1, 2);
// below display kind of a different result
console.debug('debug', x);
console.log('log', x);
Run Code Online (Sandbox Code Playgroud)

alt text http://sixbytesunder.com/stuff/firebug_console.png

javascript值完全相同,但console.log()显示它与应用splice()方法之前有点不同.因为这个我失去了几个小时,因为我认为拼接是有趣的使我的阵列多维或其他东西.

我只是想知道为什么这样的工作.有人知道吗?:)

javascript console firefox firebug

16
推荐指数
1
解决办法
7128
查看次数

SensorEventListener位于单独的线程中

这似乎是一个基本的问题,但在搜索了一段时间并使用它之后,我已经到了可以欣赏一些帮助的地步.我想让一个SensorEventListener在一个与UI不同的线程中运行,这样当事件进入时需要进行的计算不会减慢UI的速度.

我最近的尝试看起来像:

class SensorThread extends Thread {
    SensorManager mSensorManager;
    Sensor mSensor;

    public void run() {
        Log.d( "RunTag", Thread.currentThread().getName() ); // To display thread
        mSensorManager = (SensorManager)getSystemService( SENSOR_SERVICE  );
        mSensor = mSensorManager.getDefaultSensor( Sensor.TYPE_ACCELEROMETER );
        MySensorListener msl = new MySensorListener();
        mSensorManager.registerListener(msl, mSensor, SensorManager.SENSOR_DELAY_UI );
    }

    private class MySensorListener implements SensorEventListener {
        public void onAccuracyChanged (Sensor sensor, int accuracy) {}
        public void onSensorChanged(SensorEvent sensorEvent) {
            Log.d( "ListenerTag", Thread.currentThread().getName() ); // To display thread
        }
    }
Run Code Online (Sandbox Code Playgroud)

在活动(或服务)onCreate()中,我创建了一个SensorThread对象并调用其start()方法.正如您所料,调试日志显示新线程中的"RunTag"条目.但onSensorChanged()的"ListenerTag"正在主线程中运行,即使它的对象在新线程中实例化.我该如何改变?

events android

15
推荐指数
3
解决办法
1万
查看次数

通知服务中的android内存泄漏

我有一个服务,它会创建一个通知,然后定期用某些信息更新它.电话崩溃并重新启动大约12分钟后,我认为这是由于以下代码中的内存泄漏导致我如何更新通知,有人请检查/建议我是否是这种情况和我我做错了.

的onCreate:

mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Run Code Online (Sandbox Code Playgroud)

createNotification:

private void createNotification() {
  Intent contentIntent = new Intent(this,MainScreen.class);
  contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
  PendingIntent appIntent =PendingIntent.getActivity(this,0, contentIntent, 0);

  contentView = new RemoteViews(getPackageName(), R.layout.notification);
  contentView.setImageViewResource(R.id.image, R.drawable.icon);
  contentView.setTextViewText(R.id.text, "");

  notification = new Notification();
  notification.when=System.currentTimeMillis();
  notification.contentView = contentView;
  notification.contentIntent = appIntent;
}
Run Code Online (Sandbox Code Playgroud)

updateNotification:

private void updateNotification(String text){
  contentView.setTextViewText(R.id.text, text);
  mNotificationManager.notify(0, notification);
}
Run Code Online (Sandbox Code Playgroud)

提前致谢.

notifications android memory-leaks notificationmanager

14
推荐指数
1
解决办法
4751
查看次数

Java中的@XmlElementRefs和@XmlElementRef注释

有些人可以向我解释一下是做什么的

@XmlElementRefs
Run Code Online (Sandbox Code Playgroud)

@XmlElementRef
Run Code Online (Sandbox Code Playgroud)

注释在Java中意味着什么是它们的用途..

编辑: @skaffman

好吧,假设我有一个这样的集合

@XmlElementRefs({
    @XmlElementRef(name="ElementA", type=ClassA),
    @XmlElementRef(name="ElementB", type=ClassB) }
)

List<Object> items;
Run Code Online (Sandbox Code Playgroud)

现在我如何访问此列表中的每个元素?以下代码是否正确?

for (int j = 0; j < items.size(); ++j) {
    if (items.get(i).getClass().equals(ClassA)) {
        // perform ClassA specific processing:
    } else if (items.get(i).getClass().equals(ClassB)) {
        // perform ClassB specific processing:
    }
}
Run Code Online (Sandbox Code Playgroud)

这是正确的方法吗?有没有更好的方法来执行每个类特定的处理?我的意思是有办法避免这些if else结构吗?

java xml jaxb

13
推荐指数
1
解决办法
1万
查看次数

TortoiseSVN提交快捷方式

每当我需要提交文件时,我发现它很乏味.进程转到Windows资源管理器窗口,右键单击目录,然后单击"提交"...然后是tortoisesvn提交窗口.

有人知道这样做的任何捷径吗?也许按键盘快捷键提交而不必右键单击目录然后单击提交?

感谢您节省我的工作效率!

svn tortoisesvn

13
推荐指数
2
解决办法
6236
查看次数

在xhtml + xml页面中替换document.write()

我为一家公司工作,该公司编写的软件客户端网站嵌入了<script language ="JavaScript"src = .....等等.我们非常依赖document.write将元素写入页面.由于某种原因,我们的一个客户选择使用内容类型"application/xhtml + xml",这使得document.write()在chrome中无法使用.

我理解为什么会这样,并且符合DOM的代码应该创建每个元素,设置其属性,如果需要填充文本节点,将文本节点附加到其父节点,将父节点附加到某个页面元素....

但是什么是一个好的解决方法,不需要所有这些垃圾?其中的write()有很多元素,如果我们制作节点并将它们固定在一起,就像Knex或Legos或者你有什么,那么生成的代码将是可怕的.

编辑:尝试使用CDATA,但即使这行也被我们的脚本嵌入在同一页面上的xhtml解析器类似地谴责:

<script language="text/javascript"><![CDATA[document.write('hi');]]></script>
Run Code Online (Sandbox Code Playgroud)

javascript xhtml google-chrome document.write

13
推荐指数
1
解决办法
4812
查看次数