根据Java中的元素属性将列表拆分为多个子列表

有没有办法将列表拆分为多个列表? 根据元素的特定条件将列表分成两个或多个列表。 final List answerRows= getAnswerRows(………); final AnswerCollection answerCollections = new AnswerCollection(); answerCollections.addAll(answerRows); The AnswerRow has properties like rowId, collectionId 基于collectionId我想创建一个或多个AnswerCollections

无法通过GCM获取我的InstanceID

我正在尝试首次在我的应用程序中实现GCM,所以我按照这些步骤操作,并且出现了一个错误,导致我的应用程序无法在我的sv中获得注册令牌。 它说: 09-30 23:05:52.196 31461-31514/com.comgonzalovillarbaribus E/GMPM﹕ getGoogleAppId failed with status: 10 09-30 23:05:52.200 31461-31514/com.comgonzalovillarbaribus E/GMPM﹕ Uploading is not possible. App measurement disabled 我不知道问题是什么,我的清单是正确的,我的GCM_SENDER_ID 。 这是我要求我的令牌的地方: // Set GCM if (checkPlayServices()) { InstanceID instanceID = InstanceID.getInstance(this); String token = null; try { token = instanceID.getToken(Constants.GCM_SENDER_ID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); sendRegistrationToServer(token); } catch (IOException e) { e.printStackTrace(); } } […]

资源.wav中的Javaexception读取流

我猜我的代码没问题,我的.jar文件也可以使用里面的.wav。但是当我尝试使用getResourceAsStream加载它时,我得到一个错误.. 这是我的错误: java.io.IOException: mark/reset not supported at java.util.zip.InflaterInputStream.reset(Unknown Source) at java.io.FilterInputStream.reset(Unknown Source) at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unkno wn Source) at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source) at operation.MainWindowOperations.prepareAudio(MainWindowOperations.java :92) at operation.MainWindowOperations.(MainWindowOperations.java:81) at graphics.LaunchGraphics.(LaunchGraphics.java:25) at run.RunApp.main(RunApp.java:14) 这是我的代码: private void prepareAudio() { try { InputStream is = this.getClass().getClassLoader().getResourceAsStream(“beep.wav”); inputStream = AudioSystem.getAudioInputStream(is); clip = AudioSystem.getClip(); clip.open(inputStream); } catch (Exception ex) { ex.printStackTrace(); } } 有人能帮我吗? […]

方法参考中的类型推断

我最近把手放在Java 8上并尝试使用方法参考。 我正在尝试不同类型的方法引用,并陷入“引用特定类型的任意对象的实例方法”类型中。 String[] arr = {“First”, “Second”, “Third”, “Fourth”}; Arrays.sort(arr, String::compareToIgnoreCase); 这非常有效。 但是当我尝试通过其类型引用用户定义类的方法时: Demo2[] arr = {a, b}; Arrays.sort(arr, Demo2::compare); 这将编译时错误显示为“无法从静态上下文引用非静态方法”。 这是Demo2类: public class Demo2 implements Comparator { Integer i; Demo2(Integer i1){ i = i1; } public Integer getI() { return i; } @Override public int compare(Demo2 o1, Demo2 o2) { return o1.getI().compareTo(o2.getI()); } […]

如何查看IntelliJ IDEA用于编译代码的javac命令?

当我在IntelliJ IDEA中编写Java代码并运行它时,IntelliJ编译Java文件,提取类文件,然后运行类文件。 如何查看IntelliJ运行的javac命令行。 我问它所以我可以看到IntelliJ是否在javac命令中添加了一些标志。

是否有与Eclipse片段项目相同的BundleActivator?

我正在构建一个Eclipse插件,它在常规插件项目中提供了一组核心function。 我通过片段项目提供的可选function。 但我需要片段在启动时使用主插件注册自己。 我不能在片段项目中拥有Bundle-Activator。 所以我想知道是否有一些替代机制来声明我可以挂钩的入口点或某些回调? 如果除了将片段项目转换为常规插件项目之外没有其他选择,那么我需要注意一个缺点吗? 这是我根据接受的答案使用的解决方案: final IExtensionRegistry registry = Platform.getExtensionRegistry(); final IExtensionPoint extensionPoint = registry.getExtensionPoint(“myextensionid”); final IExtension[] extensions = extensionPoint.getExtensions(); for (int j = 0; j < extensions.length; ++j) { final IConfigurationElement[] points = extensions[j].getConfigurationElements(); for (int i = 0; i < points.length; ++i) { if ("myelementname".equals(points[i].getName())) { try { final Object objImpl= […]

使用jax-rs发送临时文件

我试图用jax-rs发送一个临时文件,并在下载完成后删除临时文件。 为此,我将InputSream子类化,以便在流关闭后得到通知。 这是我到目前为止: @GET @Path(“download/{fileName}”) public Response downloadFile(@PathParam(“fileName”) String fileName) { InputStream inputStream = new InputStreamWithFileDeletion(new getFile(filename)); Response.ResponseBuilder response = Response.ok((Object) file); response.header(“Content-Disposition”, “attachment; filename=”+”fileName”+”.xls”); return response.build(); } InputStreamWithFileDeletion: public class InputStreamWithFileDeletion extends FileInputStream { File f; public InputStreamWithFileDeletion(File file) throws FileNotFoundException { super(file); f = file; } @Override public void close() throws IOException { […]

在Android ScrollView中禁用“flinging”?

当你在Android中有一个ScrollView时,你可以通过向上或向下推动ScrollView来快速ScrollView ,但我不希望这个启用。 有没有办法禁用投掷?

在Crouton Library中滚动文本

可以在Github上找到crouton库。我的问题是,如果可以使Crouton中的文本水平滚动显示。 在TextView中,可以这样做: android:singleLine=”true” android:ellipsize=”marquee” android:marqueeRepeatLimit =”marquee_forever” android:scrollHorizontally=”true” android:focusable=”true” android:focusableInTouchMode=”true” 但这在Crouton中也有可能吗? 我感谢每一个帮助/回答!

在Vaadin 7中调用VaadinSession getAttribute时需要锁定

我知道调用setAttribute( link )时有必要,但getAttirbute呢? 它是否正确? public Object getMyAttribute() { return VaadinSession.getCurrent().getAttribute(“myAttribute”); } 还是需要锁定? public Object getMyAttribute() { try { VaadinSession.getCurrent().getLockInstance().lock(); return VaadinSession.getCurrent().getAttribute(“myAttribute”); } finally { VaadinSession.getCurrent().getLockInstance().unlock(); } }