Search Results

Search found 163 results on 7 pages for 'linkedlist'.

Page 5/7 | < Previous Page | 1 2 3 4 5 6 7  | Next Page >

  • Which are the best ways to organize view hierarchies in GUI interfaces?

    - by none
    I'm currently trying to figure out the best techniques for organizing GUI view hierarchies, that is dividing a window into several panels which are in turn divided into other components. I've given a look to the Composite Design Pattern, but I don't know if I can find better alternatives, so I'd appreciate to know if using the Composite is a good idea, or it would be better looking for some other techniques. I'm currently developing in Java Swing, but I don't think that the framework or the language can have a great impact on this. Any help will be appreciated. ---------EDIT------------ I was currently developing a frame containing three labels, one button and a text field. At the button pressed, the content inside the text field would be searched, and the results written inside the three labels. One of my typical structure would be the following: MainWindow | Main panel | Panel with text field and labels. | Panel with search button Now, as the title explains, I was looking for a suitable way of organizing both the MainPanel and the other two panels. But here came problems, since I'm not sure whether organizing them like attributes or storing inside some data structure (i.e. LinkedList or something like this). Anyway, I don't really think that both my solution are really good, so I'm wondering if there are really better approaches for facing this kind of problems. Hope it helps

    Read the article

  • Creating a Serializable mock with Mockito error

    - by KwintenP
    I'm trying to create a mock object with Mockito that can be serialized. The object is an interface implementation. When this method is called, I receive an object that I want to pass to another object, hence using the doAnswer(...)-method. This is my code. InterfaceClass obj = mock(InterfaceClass.class, withSettings().serializable()); doAnswer(new Answer<Object>() { public Object answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); //Here I do something with the arguments } }).when(obj).someMethod( any(someObject.class)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = null; try { out = new ObjectOutputStream(bos); out.writeObject(obj); byte[] yourBytes = bos.toByteArray(); } finally { out.close(); bos.close(); } As far as I can tell this should be correct (I'm fairly new to Mockito). But when Serializing my object I get this error: java.io.NotSerializableException: com.trust1t.ocs.signcore.test.InvalidInputTestCase$1 at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1165) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:329) at java.util.concurrent.ConcurrentLinkedQueue.writeObject(ConcurrentLinkedQueue.java:644) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:950) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1482) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1413) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1159) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1535) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1413) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1159) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:329) at java.util.LinkedList.writeObject(LinkedList.java:943) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:950) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1482) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1413) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1159) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1535) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1413) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1159) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1535) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1413) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1159) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1535) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1413) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1159) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1535) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1413) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1159) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:329) at com.trust1t.ocs.signcore.test.InvalidInputTestCase.certificateValidationTest(InvalidInputTestCase.java:117) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) The invalidInputTestCase class is the class containing the test where I'm using this code. It looks as if the mock object references this TestCase somewhere (can't find it though). Am I not correctly implementing this or better ideas to mock?

    Read the article

  • C++ - Unwanted characters printed in output file.

    - by Gabe
    This is the last part of the program I am working on. I want to output a tabular list of songs to cout. And then I want to output a specially formatted list of song information into fout (which will be used as an input file later on). Printing to cout works great. The problem is that tons of extra character are added when printing to fout. Any ideas? Here's the code: void Playlist::printFile(ofstream &fout, LinkedList<Playlist> &allPlaylists, LinkedList<Songs*> &library) { fout.open("music.txt"); if(fout.fail()) { cout << "Output file failed. Information was not saved." << endl << endl; } else { if(library.size() > 0) fout << "LIBRARY" << endl; for(int i = 0; i < library.size(); i++) // For Loop - "Incremrenting i"-Loop to go through library and print song information. { fout << library.at(i)->getSongName() << endl; // Prints song name. fout << library.at(i)->getArtistName() << endl; // Prints artist name. fout << library.at(i)->getAlbumName() << endl; // Prints album name. fout << library.at(i)->getPlayTime() << " " << library.at(i)->getYear() << " "; fout << library.at(i)->getStarRating() << " " << library.at(i)->getSongGenre() << endl; } if(allPlaylists.size() <= 0) fout << endl; else if(allPlaylists.size() > 0) { int j; for(j = 0; j < allPlaylists.size(); j++) // Loops through all playlists. { fout << "xxxxx" << endl; fout << allPlaylists.at(j).getPlaylistName() << endl; for(int i = 0; i < allPlaylists.at(j).listSongs.size(); i++) { fout << allPlaylists.at(j).listSongs.at(i)->getSongName(); fout << endl; fout << allPlaylists.at(j).listSongs.at(i)->getArtistName(); fout << endl; } } fout << endl; } } } Here's a sample of the output to music.txt (fout): LIBRARY sadljkhfds dfgkjh dfkgh 3 3333 3 Rap sdlkhs kjshdfkh sdkjfhsdf 3 33333 3 Rap xxxxx PayröÈöè÷÷(÷H÷h÷÷¨÷È÷èøø(øHøhøø¨øÈøèùù(ùHùhùù¨ùÈùèúú(úHúhúú¨úÈúèûû(ûHûhûû¨ûÈûèüü(üHühüü¨üÈüèýý(ýHýhý ! sdkjfhsdf!õüöýÄõ¼5! sadljkhfds!þõÜö|ö\ þx þ  þÈ þð ÿ ÿ@ ÿh ÿ ÿ¸ ÿà 0 X ¨ Ð ø enter code here enter code here

    Read the article

  • CodePlex Daily Summary for Wednesday, March 16, 2011

    CodePlex Daily Summary for Wednesday, March 16, 2011Popular ReleasesuComponents: uComponents v2.1 RTM: What's new in v2.1? 5 new DataTypes JSON Datasource DropDown Multiple Textstring Similarity Text Image XPath DropDownList Please note that the release of DataType Grid has been postponed until v2.2. 3 new XSLT extensions Media Nodes Search Multi-node tree picker updates XPath start node selectors From Global or Relative start node selectors Max & Min node selection limits Bug fixes If you find a bug or have an issue, please raise a ticket here on CodePlex for us and we'l...Facebook C# SDK: 5.0.6 (BETA): This is seventh BETA release of the version 5 branch of the Facebook C# SDK. Remember this is a BETA build. Some things may change or not work exactly as planned. We are absolutely looking for feedback on this release to help us improve the final 5.X.X release. New in this release: Version 5.0.6 is almost completely backward compatible with 4.2.1 and 5.0.3 (BETA) Bug fixes and helpers to simplify many common scenarios For more information about this release see the following blog posts: F...SQLCE Code Generator: Build 1.0.3: New beta of the SQLCE Code Generator. New features: - Generates an IDataRepository interface that contains the generated repository interfaces that represents each table - Visual Studio 2010 Custom Tool Support Custom Tool: The custom tool is called SQLCECodeGenerator. Write this in the Custom Tool field in the Properties Window of an SDF file included in your project, this should create a code-behind file for the generated data access codeKooboo CMS: Kooboo 3.0 RC: Bug fixes Inline editing toolbar positioning for websites with complicate CSS. Inline editing is turned on by default now for the samplesite template. MongoDB version content query for multiple filters. . Add a new 404 page to guide users to login and create first website. Naming validation for page name and datarule name. Files in this download kooboo_CMS.zip: The Kooboo application files Content_DBProvider.zip: Additional content database implementation of MSSQL,SQLCE, RavenDB ...SQL Monitor - tracking sql server activities: SQL Monitor 3.2: 1. introduce sql color syntax highlighting with http://www.codeproject.com/KB/edit/FastColoredTextBox_.aspxUmbraco CMS: Umbraco 4.7.0: Service release fixing 50+ issues! Getting Started A great place to start is with our Getting Started Guide: Getting Started Guide: http://umbraco.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=197051 Make sure to check the free foundation videos on how to get started building Umbraco sites. They're available from: Introduction for webmasters: http://umbraco.tv/help-and-support/video-tutorials/getting-started Understand the Umbraco concepts: http://umbraco.tv/help-and-support...ProDinner - ASP.NET MVC EF4 Code First DDD jQuery Sample App: first release: ProDinner is an ASP.NET MVC sample application, it uses DDD, EF4 Code First for Data Access, jQuery and MvcProjectAwesome for Web UI, it has Multi-language User Interface Features: CRUD and search operations for entities Multi-Language User Interface upload and crop Images (make thumbnail) for meals pagination using "more results" button very rich and responsive UI (using Mvc Project Awesome) Multiple UI themes (using jQuery UI themes)BEPUphysics: BEPUphysics v0.15.0: BEPUphysics v0.15.0!LiveChat Starter Kit: LCSK v1.1: This release contains couple of new features and bug fixes including: Features: Send chat transcript via email Operator can now invite visitor to chat (pro-active chat request) Bug Fixes: Operator management (Save and Delete) bug fixes Operator Console chat small fixesIronRuby: 1.1.3: IronRuby 1.1.3 is a servicing release that keeps on improving compatibility with Ruby 1.9.2 and includes IronRuby integration to Visual Studio 2010. We decided to drop 1.8.6 compatibility mode in all post-1.0 releases. We recommend using IronRuby 1.0 if you need 1.8.6 compatibility. The main purpose of this release is to sync with IronPython 2.7 release, i.e. to keep the Dynamic Language Runtime that both these languages build on top shareable. This release also fixes a few bugs: 5763 Use...SQL Server PowerShell Extensions: 2.3.2.1 Production: Release 2.3.2.1 implements SQLPSX as PowersShell version 2.0 modules. SQLPSX consists of 13 modules with 163 advanced functions, 2 cmdlets and 7 scripts for working with ADO.NET, SMO, Agent, RMO, SSIS, SQL script files, PBM, Performance Counters, SQLProfiler, Oracle and MySQL and using Powershell ISE as a SQL and Oracle query tool. In addition optional backend databases and SQL Server Reporting Services 2008 reports are provided with SQLServer and PBM modules. See readme file for details.IronPython: 2.7: On behalf of the IronPython team, I'm very pleased to announce the release of IronPython 2.7. This release contains all of the language features of Python 2.7, as well as several previously missing modules and numerous bug fixes. IronPython 2.7 also includes built-in Visual Studio support through IronPython Tools for Visual Studio. IronPython 2.7 requires .NET 4.0 or Silverlight 4. To download IronPython 2.7, visit http://ironpython.codeplex.com/releases/view/54498. Any bugs should be report...XML Explorer: XML Explorer 4.0.2: Changes in 4.0: This release is built on the Microsoft .NET Framework 4 Client Profile. Changed XSD validation to use the schema specified by the XML documents. Added a VS style Error List, double-clicking an error takes you to the offending node. XPathNavigator schema validation finally gives SourceObject (was fixed in .NET 4). Added Namespaces window and better support for XPath expressions in documents with a default namespace. Added ExpandAll and CollapseAll toolbar buttons (in a...Mobile Device Detection and Redirection: 1.0.0.0: Stable Release 51 Degrees.mobi Foundation has been in beta for some time now and has been used on thousands of websites worldwide. We’re now highly confident in the product and have designated this release as stable. We recommend all users update to this version. New Capabilities MappingsTo improve compatibility with other libraries some new .NET capabilities are now populated with wurfl data: “maximumRenderedPageSize” populated with “max_deck_size” “rendersBreaksAfterWmlAnchor” populated ...ASP.NET MVC Project Awesome, jQuery Ajax helpers (controls): 1.7.3: A rich set of helpers (controls) that you can use to build highly responsive and interactive Ajax-enabled Web applications. These helpers include Autocomplete, AjaxDropdown, Lookup, Confirm Dialog, Popup Form, Popup and Pager added interactive search for the lookupWPF Inspector: WPF Inspector 0.9.7: New Features in Version 0.9.7 - Support for .NET 3.5 and 4.0 - Multi-inspection of the same process - Property-Filtering for multiple keywords e.g. "Height Width" - Smart Element Selection - Select Controls by clicking CTRL, - Select Template-Parts by clicking CTRL+SHIFT - Possibility to hide the element adorner (over the context menu on the visual tree) - Many bugfixes??????????: All-In-One Code Framework ??? 2011-03-10: http://download.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=1codechs&DownloadId=216140 ??,????。??????????All-In-One Code Framework ???,??20?Sample!!????,?????。http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=1code&DownloadId=128165 ASP.NET ??: CSASPNETBingMaps VBASPNETRemoteUploadAndDownload CS/VBASPNETSerializeJsonString CSASPNETIPtoLocation CSASPNETExcelLikeGridView ....... Winform??: FTPDownload FTPUpload MultiThreadedWebDownloader...Rawr: Rawr 4.1.0: Note: This release may say 4.0.21 in the version bar. This is a typo and the version is actually 4.1.0, not to be confused with 4.0.10 which was released a while back. Rawr is now web-based. The link to use Rawr4 is: http://elitistjerks.com/rawr.phpThis is the Cataclysm Release. More details can be found at the following link http://rawr.codeplex.com/Thread/View.aspx?ThreadId=237262 As of the 4.0.16 release, you can now also begin using the new Downloadable WPF version of Rawr!This is a Relea...PHP Manager for IIS: PHP Manager 1.1.2 for IIS 7: This is a localization release of PHP Manager for IIS 7. It contains all the functionality available in 56962 plus a few bug fixes (see change list for more details). Most importantly this release is translated into five languages: German - the translation is provided by Christian Graefe Dutch - the translation is provided by Harrie Verveer Turkish - the translation is provided by Yusuf Oztürk Japanese - the translation is provided by Kenichi Wakasa Russian - the translation is provid...TweetSharp: TweetSharp v2.0.0: Documentation for this release may be found at http://tweetsharp.codeplex.com/wikipage?title=UserGuide&referringTitle=Documentation. Beta ChangesAdded user streams support Serialization is not attempted for Twitter 5xx errors Fixes based on feedback Third Party Library VersionsHammock v1.2.0: http://hammock.codeplex.com Json.NET 4.0 Release 1: http://json.codeplex.comNew ProjectsABSC - Automatic Battle System Configurator: ABSC - Automatic Battle System Configurator Este é um aplicativo que auxilia os usuários na configuração de diversos script's de batalha disponíveis atualmente para o Rpg Maker. O aplicativo irá gerar um script com toda a configuração especificada pelo usuário.Active Directory Monkey: Designed for IS support teams to easily reset active directoy passwords.Ag-Light: Artesis projectAnito.ORM: Anito ORMblogengine customizations: Customizations for dotnetblogengineCool Tool: Cool Tool is a Visual studio add-in for generating business entities. Generator provides functionality to be able easily and comfortable generate class elements and implement chosen interfaces. Project is developed in VS 2010 (C# 4.0). Enjoy!csmpfit - A Least Squares Optimization Library in C# (C Sharp): A C# port of the C-based mpfit Levenberg Marquardt solver at Argonne National Labs (http://cow.physics.wisc.edu/~craigm/idl/cmpfit.html), including both desktop .NET and Silverlight project libraries.DirectX 11 Framework for Experimentation: Basic Framework for DirectX 11 (without DXUT) containing basic stuffs like Text Rendering, Quad Render, Model Loading, basic Skinning animation, Shader framework (substitute for the effect API) and lots of random stuffs !!!Doanvien code project: DoanVien code projectdtweet - a dashing way of tweeting: dtweet is developed in ASP.NET MVC 3 RTM (Razor) C# JQuery 1.5.1FormMail.NET: This is a project to support emailing form data from a .NET page, and storing that form data in an XML file.LRU Cache: This project implements the LRU Cache using C#. It uses a Dictionary and a LinkedList. Dictionary ensures fast access to the data, and the linkedlist controls which objects are to be removed first.Magelia WebStore Open-source e-commerce software: Magelia WebStore is a customizable, multilingual and multi-currency open-source e-commerce software for the .net environment. WebStore was developped C# and Aspx and only requires an SQL Server Express. MDA.Net: MDA.Net is the .Net/Silverlight port of mda-vst instruments and effects. Currently it includes just the MDA piano and an overdrive with basic interfaces to build on. Just PM me if you have some time to help - we are in no rush, aim to migrate everything one-by-one. MVC NGShop: NGShop ????????????,????Asp.net MVC 2.0 + Jquery + SQL Server 2008, ???Castle Windsor IOC、entity framework,??????visual studio 2010??,??????vs2010,?????js???。Orchard - Photo Albums module: This module allows you to create photo albums with various effects: lightbox, slideshow, etc. PowerShell Workflow: PowerShell Workflow helps organizations to define their operational processes through the power of Workflow and Powershell. Project Dark: Early version of our project. Made in Torque 3dReFSharp: ReFSharp is pretty printer, analyzing tool and translator source code texts between F#, C# and Java. Current version has full functional pretty printer for F# and pre-alpha translator of C# to F#.Relate Intranet Templates: <project name> is an open source package for EPiServer Relate which creates a foundation for an intranet.Service monitor: Service monitor is a simple utility that lets you monitor and manage the states of services of multiple machines. It allows starting/stopping and restarting. It is Windows 7 UAC aware.Sharp Console: Sharp Console is a Windows Command Line (WCL)alternative written in C#. It targets those who lack access to the WCL or simply wish to use the NET framework instead. It aims to provide the same (and more!) functionality as the WCL. Contribute anything you feel will make it better!Stone2: New version of Stone, but using TFS for versioningStudent Database Management System: Student Database Management System is a sample Online Web based and also desktop application which helps school to maintain their records free online. this project is open source project and Free available for all schools to check and send their response..

    Read the article

  • org.hibernate.MappingException: No Dialect mapping for JDBC type: 2002

    - by Moli
    Hi at all, I'm having a issue trying to get working a JPA nativeQuery. I'm having a org.hibernate.MappingException: No Dialect mapping for JDBC type: 2002 when a try to do a nativeQuery and get a geometry field type. I use oracle and org.hibernatespatial.oracle.OracleSpatial10gDialect. The geom fields is mapped as: @Column(name="geometry") @Type(type = "org.hibernatespatial.GeometryUserType") private Geometry geometry; List<Object> listFeatures= new LinkedList<Object>(); Query query= entityManager.createNativeQuery( "SELECT "+ slots +" , geometry FROM edtem_features feature, edtem_dades dada WHERE" + " feature."+ tematic.getIdGeomField() +" = dada."+ tematic.getIdDataField()+ " AND dada.capesid= "+ tematic.getCapa().getId() + " AND feature.geometriesid= "+ tematic.getGeometria().getId()); listFeatures.addAll( query.getResultList()); Anybody knows a solution? or how to force the type of the geometry to get wroking this... MANY Thanks in advance. Moli

    Read the article

  • How to get predecessor and successors from an adjacency matrix

    - by NickTFried
    Hi I am am trying to complete an assignment, where it is ok to consult the online community. I have to create a graph class that ultimately can do Breadth First Search and Depth First Search. I have been able to implement those algorithms successfully however another requirement is to be able to get the successors and predecessors and detect if two vertices are either predecessors or successors for each other. I'm having trouble thinking of a way to do this. I will post my code below, if anyone has any suggestions it would be greatly appreciated. import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.Queue; import java.util.Stack; public class Graph<T> { public Vertex<T> root; public ArrayList<Vertex<T>> vertices=new ArrayList<Vertex<T>>(); public int[][] adjMatrix; int size; private ArrayList<Vertex<T>> dfsArrList; private ArrayList<Vertex<T>> bfsArrList; public void setRootVertex(Vertex<T> n) { this.root=n; } public Vertex<T> getRootVertex() { return this.root; } public void addVertex(Vertex<T> n) { vertices.add(n); } public void removeVertex(int loc){ vertices.remove(loc); } public void addEdge(Vertex<T> start,Vertex<T> end) { if(adjMatrix==null) { size=vertices.size(); adjMatrix=new int[size][size]; } int startIndex=vertices.indexOf(start); int endIndex=vertices.indexOf(end); adjMatrix[startIndex][endIndex]=1; adjMatrix[endIndex][startIndex]=1; } public void removeEdge(Vertex<T> v1, Vertex<T> v2){ int startIndex=vertices.indexOf(v1); int endIndex=vertices.indexOf(v2); adjMatrix[startIndex][endIndex]=1; adjMatrix[endIndex][startIndex]=1; } public int countVertices(){ int ver = vertices.size(); return ver; } /* public boolean isPredecessor( Vertex<T> a, Vertex<T> b){ for() return true; }*/ /* public boolean isSuccessor( Vertex<T> a, Vertex<T> b){ for() return true; }*/ public void getSuccessors(Vertex<T> v1){ } public void getPredessors(Vertex<T> v1){ } private Vertex<T> getUnvisitedChildNode(Vertex<T> n) { int index=vertices.indexOf(n); int j=0; while(j<size) { if(adjMatrix[index][j]==1 && vertices.get(j).visited==false) { return vertices.get(j); } j++; } return null; } public Iterator<Vertex<T>> bfs() { Queue<Vertex<T>> q=new LinkedList<Vertex<T>>(); q.add(this.root); printVertex(this.root); root.visited=true; while(!q.isEmpty()) { Vertex<T> n=q.remove(); Vertex<T> child=null; while((child=getUnvisitedChildNode(n))!=null) { child.visited=true; bfsArrList.add(child); q.add(child); } } clearVertices(); return bfsArrList.iterator(); } public Iterator<Vertex<T>> dfs() { Stack<Vertex<T>> s=new Stack<Vertex<T>>(); s.push(this.root); root.visited=true; printVertex(root); while(!s.isEmpty()) { Vertex<T> n=s.peek(); Vertex<T> child=getUnvisitedChildNode(n); if(child!=null) { child.visited=true; dfsArrList.add(child); s.push(child); } else { s.pop(); } } clearVertices(); return dfsArrList.iterator(); } private void clearVertices() { int i=0; while(i<size) { Vertex<T> n=vertices.get(i); n.visited=false; i++; } } private void printVertex(Vertex<T> n) { System.out.print(n.label+" "); } }

    Read the article

  • Implementig Java Iterable<E> interface

    - by Metz
    Hi, i wrote this code: public class C1 implements Iterable<NC1> { private LinkedList<NC1> list; public static class NC1 { ... } ... x public Iterator<NC1> iterator() { return list.iterator(); } } but eclipse whines (at the x-ed line): - The return type is incompatible with Iterable<NC1>.iterator() - implements java.lang.Iterable<NC1>.iterator i don't understand where the mistake is. thanks in advance.

    Read the article

  • Include headers in header file?

    - by Mohit Deshpande
    I have several libraries made by myself (a geometry library, a linked list library, etc). I want to make a header file to include them all in one lib.h. Could I do something like this: #ifndef LIB_H_ #define LIB_H_ #include <stdio.h> #include <stdlib.h> #include <linkedlist.h> #include <geometry.h> .... #endif Then I could just reference this one library and actually reference multiple libraries. Is this possible? If not, is there a way around it?

    Read the article

  • One liner for getting a sublist from a Set

    - by yegor256
    Is there a one-liner (maybe from Guava or Apache Collections) that gets a sublist from a set. Internally it should do something like this: public <T> List<T> sublist(Set<T> set, int count) { Iterator<T> iterator = set.iterator(); List<T> sublist = new LinkedList<T>(); int pos = 0; while (iterator.hasNext() && pos++ < count) { sublist.add(iterator.next()); } return sublist; } Obviously, if there are not enough elements it has to return as many as possible.

    Read the article

  • Creating a circually linked list in C#?

    - by Dexter
    What would be the best way to create a circually linked list in C#. Should I derive it from the LinkedList< T collection? I'm planning on creating a simple address book using this Linked List to store my contacts (it's gonna be a suck-y address book, but I don't care cause I'll be the only one to use it). I mainly just want to create the crucially linked list so that I can use it again in other projects. If you don't think the Linked List is the right way to go let me know which way would be better.

    Read the article

  • Benefits of arrays

    - by Vitalii Fedorenko
    As I see it, the advantages of List over array are pretty obvious: Generics provide more precise typing: List<Integer>, List<? extends Number>, List<? super Integer>. List interface has a bunch useful methods: addAll, remove etc. While for arrays all standard operations except get/set must be performed in a procedure manner by passing it to a static method. Collections offer different implementations like ArrayList, LinkedList, unmodifieable and synchronized lists, which can be hidden under common List interface. OOB length control. As disadvantages I can only mention absence of syntactic sugar and runtime type check. At the same time supporting of both structures requires frequent using of asList and toArray methods, which makes code less readable. So I am curious if there are any important benefits of using arrays that I miss.

    Read the article

  • What is the best strategy for populating a TableView from a service?

    - by alrutherford
    I have an application which has a potentially long running background process. I want this process to populate a TableView as results objects are generated. The results objects are added to an observableList and have properties which are bound to the columns in the usual fashion for JavaFX. As an example of this consider the following sample code Main Application import java.util.LinkedList; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class DataViewTest extends Application { private TableView<ServiceResult> dataTable = new TableView<ServiceResult>(); private ObservableList<ServiceResult> observableList; private ResultService resultService; public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) { observableList = FXCollections.observableArrayList(new LinkedList<ServiceResult>()); resultService = new ResultService(observableList); Button refreshBtn = new Button("Update"); refreshBtn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { observableList.clear(); resultService.reset(); resultService.start(); } }); TableColumn<ServiceResult, String> nameCol = new TableColumn<ServiceResult, String>("Value"); nameCol.setCellValueFactory(new PropertyValueFactory<ServiceResult, String>("value")); nameCol.setPrefWidth(200); dataTable.getColumns().setAll(nameCol); // productTable.getItems().addAll(products); dataTable.setItems(observableList); Scene scene = new Scene(new Group()); stage.setTitle("Table View Sample"); stage.setWidth(300); stage.setHeight(500); final VBox vbox = new VBox(); vbox.setSpacing(5); vbox.setPadding(new Insets(10, 0, 0, 10)); vbox.getChildren().addAll(refreshBtn, dataTable); ((Group) scene.getRoot()).getChildren().addAll(vbox); stage.setScene(scene); stage.show(); } } Service public class ResultService extends Service<Void> { public static final int ITEM_COUNT = 100; private ObservableList<ServiceResult> observableList; /** * Construct service. * */ public ResultService(ObservableList<ServiceResult> observableList) { this.observableList = observableList; } @Override protected Task<Void> createTask() { return new Task<Void>() { @Override protected Void call() throws Exception { process(); return null; } }; } public void process() { for (int i = 0; i < ITEM_COUNT; i++) { observableList.add(new ServiceResult(i)); } } } Data public class ServiceResult { private IntegerProperty valueProperty; /** * Construct property object. * */ public ServiceResult(int value) { valueProperty = new SimpleIntegerProperty(); setValue(value); } public int getValue() { return valueProperty.get(); } public void setValue(int value) { this.valueProperty.set(value); } public IntegerProperty valueProperty() { return valueProperty; } } Both the service and the TableView share a reference to the observable list? Is this good practise in JavaFx and if not what is the correct strategy? If you hit the the 'Update' button the list will not always refresh to the ITEM_COUNT length. I believe this is because the observableList.clear() is interfering with the update which is running in the background thread. Can anyone shed some light on this?

    Read the article

  • What is a great resource for learning about the implementation details of .NET generic collections?

    - by Jimmy W
    Hi all, I'm interested in understanding the underlying implementation details of generic collections in .NET. What I have in mind are details such as how the collections are stored, how each member of a collection is accessed by the CLR, etc. For collections that are analogous to traditional data structures, such as LinkedList and Dictionary, I think I have an understanding of what's going on underneath. However, I'm not as certain about collections like List (how is set up such that it is both indexable and expandable?) and SortedList, so any leads as to what I could look up to learn more about them would be greatly appreciated.

    Read the article

  • Getting class Type information for Elements on a collection

    - by DutrowLLC
    I would like to get gain access to the type of Object held in a Collection. Below is a simplified example of when and why I might want to do this. Is this even possible? List<Address> addressList = new LinkedList<Address>(); Main.addElement(addressList); Class Main{ public void addElement(Object inArgument){ List<Object> argument = (List<Object>)inArgument; argument.add( /* WOULD LIKE TO CREATE A NEW OBJECT OF THE APPROPRIATE TYPE HERE, IN THIS CASE, IT WOULD BE OF TYPE: "Address" */ ); } }

    Read the article

  • Check if a class is subclass of another class in Java

    - by craesh
    Hi! I'm playing around with Java's reflection API and trying to handle some fields. Now I'm stuck with identifying the type of my fields. Strings are easy, just do myField.getType().equals(String.class). The same applies for other non-derived classes. But how do I check derived classes? E.g. LinkedList as subclass of List. I can't find any isSubclassOf(...) or extends(...) method. Do I need to walk through all getSuperClass() and find my supeclass by my own? Thanks! craesh

    Read the article

  • Is there a fast concat method for linked list in Java?

    - by rocker
    How can I concat two linked lists in O(1) with Java via jdk, google or apache commons collection or whatever? E.g. in jdk there is only the addAll method which is O(n). Another feature I miss is to concat two lists where each of them could be in inverse order. To illustrate this assume two lists a-b-c and e-f-g could merged into a-b-c-e-f-g a-b-c-g-f-e c-b-a-e-f-g c-b-a-g-f-e Do you know of such a list implemenation or do I have to implement my own linked list? It would be also helpful to know how to tweak existing solutions (e.g. the jdk LinkedList has a lot of private methods only). These features seems to me very obvious, hopefully I am not missing something stupid.

    Read the article

  • how to go the middle of the singularly linked list in one iteration?

    - by u3050
    Recently I have been asked one question that in a singularly linked list how do we go to the middle of the list in one iteration. A --> B --> C --> D (even nodes) for this it should return address which points to B A --> B --> C (odd nodes) for this also it should return address which points to B There is one solution of taking two pointers one moves one time and other moves two times but it does not seem working here LinkedList p1,p2; while(p2.next != null) { p1 = p1.next; p2 = p2.next.next; } System.out.print("middle of the node" + p1.data); //This does not give accurate result in odd and even Please help if anyone has did this before.

    Read the article

  • C++ Generic List Assignment

    - by S73417H
    I've clearly been stuck in Java land for too long... Is it possible to do the C++ equivalent of the following Java code: // Method List<Bar> getBars() { return new LinkedList<Bar>(); } // Assignment statement. List<Foo> stuff = getBars(); Where Foo is a sub-class of Bar. So in C++.... std::list<Bar> & getBars() { std::list<Bar> bars; return bars; } std::list<Foo> stuff = getBars(); Hope that makes sense....

    Read the article

  • odd behavior with java collections of parameterized Class objects

    - by Paul
    Ran into some questionable behavior using lists of parameterized Class objects: ArrayList<Class<String>> classList = new ArrayList<Class<String>>(); classList.add(Integer.class); //compile error Class intClass = Integer.class; classList.add(intClass); //legal apparently, as long as intClass is not parameterized Found the same behavior for LinkedList, haven't tried other collections. Is it like this for a reason? Or have I stumbled on something?

    Read the article

  • Trying to use a list iterator to print out entire linked list in Java. Infinite loop for some reaso

    - by Matt
    I created my list: private static List list = new LinkedList(); and my iterator: ListIterator itr = list.listIterator(); and use this code to try to print out the list... Only problem is, it never comes out of the loop. When it reaches the tail, shouldn't it come out of the loop, because there is no next? Or is it going back to the head like a circular linked list? It is printing so quickly and my computer locks up shortly after, so I can't really tell what is going on. while (itr.hasNext()) System.out.println(itr.next());

    Read the article

  • Add a Component to two different JTabbedPanes

    - by haldean
    I have a LinkedList of Components, each of which I would like to add into two different JTabbedPanes. For some reason, Swing is only letting me put each component into one or the other. The code I'm using is the following: /* The two tab panes */ JTabbedPane leftTabs = new JTabbedPane(); JTabbedPane rightTabs = new JTabbedPane(); for (int i=0; i<tabPanes.size(); i++) { rightTabs.add(tabPanes.get(i)); leftTabs.add(tabPanes.get(i)); } Whichever add call I put last is the one that works; if I add to leftTabs last, then rightTabs ends up empty, and vice-versa. Any ideas on how to get this working? Thanks!

    Read the article

  • add objects with different name through for loop

    - by Gandalf StormCrow
    What is the best way to do the following: List<MyObject> list = new LinkedList<MyObject>(); for(int i=0; i<30;i++) { MyObject o1 = new MyObject(); list.add(o1); } But the things is I don't wanna create objects with same name, I wanna create them with different name like o1,o2,o3,o4,o5,o6,o7,o8,o9,o10 and I wanna add each to the list. What is the best way to do this ?

    Read the article

  • setting up linked list Java

    - by erp
    I'm working on some basic linked list stuff, like insert, delete, go to the front or end of the list, and basically i understand the concept of all of that stuff once i have the list i guess but im having trouble setting up the list. I was wondering of you guys could tell me if im going in the right direction. (mostly just the setup) this is what i have so far: public class List { private int size; private List linkedList; List head; List cur; List next; /** * Creates an empty list. * @pre * @post */ public List(){ linkedList = new List(); this.head = null; cur = head; } /** * Delete the current element from this list. The element after the deleted element becomes the new current. * If that's not possible, then the element before the deleted element becomes the new current. * If that is also not possible, then you need to recognize what state the list is in and define current accordingly. * Nothing should be done if a delete is not possible. * @pre * @post */ public void delete(){ // delete size--; } /** * Get the value of the current element. If this is not possible, throw an IllegalArgumentException. * @pre the list is not empty * @post * @return value of the current element. */ public char get(){ return getItem(cur); } /** * Go to the last element of the list. If this is not possible, don't change the cursor. * @pre * @post */ public void goLast(){ while (cur.next != null){ cur = cur.next; } } /** * Advance the cursor to the next element. If this is not possible, don't change the cursor. * @pre * @post */ public void goNext(){ if(cur.next != null){ cur = cur.next;} //else do nothing } /** * Retreat the cursor to the previous element. If this is not possible, don't change the cursor. * @pre * @post */ public void goPrev(){ } /** * Go to top of the list. This is the position before the first element. * @pre * @post */ public void goTop(){ } /** * Go to first element of the list. If this is not possible, don't change the cursor. * @pre * @post */ public void goFirst(){ } /** * Insert the given parameter after the current element. The newly inserted element becomes the current element. * @pre * @post * @param newVal : value to insert after the current element. */ public void insert(char newVal){ cur.setItem(newVal); size++; } /** * Determines if this list is empty. Empty means this list has no elements. * @pre * @post * @return true if the list is empty. */ public boolean isEmpty(){ return head == null; } /** * Determines the size of the list. The size of the list is the number of elements in the list. * @pre * @post * @return size which is the number of elements in the list. */ public int size(){ return size; } public class Node { private char item; private Node next; public Node() { } public Node(char item) { this.item = item; } public Node(char item, Node next) { this.item = item; this.next = next; } public char getItem() { return this.item; } public void setItem(char item) { this.item = item; } public Node getNext() { return this.next; } public void setNext(Node next) { this.next = next; } } } I got the node class alright (well i think it works alright), but is it necessary to even have that class? or can i go about it without even using it (just curious). And for example on the method get() in the list class can i not call that getItem() method from the node class because it's getting an error even though i thought that was the whole point for the node class. bottom line i just wanna make sure im setting up the list right. Thanks for any help guys, im new to linked list's so bear with me!

    Read the article

  • Probelm with String.split() in java

    - by Matt
    What I am trying to do is read a .java file, and pick out all of the identifiers and store them in a list. My problem is with the .split() method. If you run this code the way it is, you will get ArrayOutOfBounds, but if you change the delimiter from "." to anything else, the code works. But I need to lines parsed by "." so is there another way I could accomplish this? import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.*; public class MyHash { private static String[] reserved = new String[100]; private static List list = new LinkedList(); private static List list2 = new LinkedList(); public static void main (String args[]){ Hashtable hashtable = new Hashtable(997); makeReserved(); readFile(); String line; ListIterator itr = list.listIterator(); int listIndex = 0; while (listIndex < list.size()) { if (itr.hasNext()){ line = itr.next().toString(); //PROBLEM IS HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! String[] words = line.split("."); //CHANGE THIS AND IT WILL WORK System.out.println(words[0]); //TESTING TO SEE IF IT WORKED } listIndex++; } } public static void readFile() { String text; String[] words; BufferedReader in = null; try { in = new BufferedReader(new FileReader("MyHash.java")); //NAME OF INPUT FILE } catch (FileNotFoundException ex) { Logger.getLogger(MyHash.class.getName()).log(Level.SEVERE, null, ex); } try { while ((text = in.readLine()) != null){ text = text.trim(); words = text.split("\\s+"); for (int i = 0; i < words.length; i++){ list.add(words[i]); } for (int j = 0; j < reserved.length; j++){ if (list.contains(reserved[j])){ list.remove(reserved[j]); } } } } catch (IOException ex) { Logger.getLogger(MyHash.class.getName()).log(Level.SEVERE, null, ex); } try { in.close(); } catch (IOException ex) { Logger.getLogger(MyHash.class.getName()).log(Level.SEVERE, null, ex); } } public static int keyIt (int x) { int key = x % 997; return key; } public static int horner (String word){ int length = word.length(); char[] letters = new char[length]; for (int i = 0; i < length; i++){ letters[i]=word.charAt(i); } char[] alphabet = new char[26]; String abc = "abcdefghijklmnopqrstuvwxyz"; for (int i = 0; i < 26; i++){ alphabet[i]=abc.charAt(i); } int[] numbers = new int[length]; int place = 0; for (int i = 0; i < length; i++){ for (int j = 0; j < 26; j++){ if (alphabet[j]==letters[i]){ numbers[place]=j+1; place++; } } } int hornered = numbers[0] * 32; for (int i = 1; i < numbers.length; i++){ hornered += numbers[i]; if (i == numbers.length -1){ return hornered; } hornered = hornered % 997; hornered *= 32; } return hornered; } public static String[] makeReserved (){ reserved[0] = "abstract"; reserved[1] = "assert"; reserved[2] = "boolean"; reserved[3] = "break"; reserved[4] = "byte"; reserved[5] = "case"; reserved[6] = "catch"; reserved[7] = "char"; reserved[8] = "class"; reserved[9] = "const"; reserved[10] = "continue"; reserved[11] = "default"; reserved[12] = "do"; reserved[13] = "double"; reserved[14] = "else"; reserved[15] = "enum"; reserved[16] = "extends"; reserved[17] = "false"; reserved[18] = "final"; reserved[19] = "finally"; reserved[20] = "float"; reserved[21] = "for"; reserved[22] = "goto"; reserved[23] = "if"; reserved[24] = "implements"; reserved[25] = "import"; reserved[26] = "instanceof"; reserved[27] = "int"; reserved[28] = "interface"; reserved[29] = "long"; reserved[30] = "native"; reserved[31] = "new"; reserved[32] = "null"; reserved[33] = "package"; reserved[34] = "private"; reserved[35] = "protected"; reserved[36] = "public"; reserved[37] = "return"; reserved[38] = "short"; reserved[39] = "static"; reserved[40] = "strictfp"; reserved[41] = "super"; reserved[42] = "switch"; reserved[43] = "synchronize"; reserved[44] = "this"; reserved[45] = "throw"; reserved[46] = "throws"; reserved[47] = "trasient"; reserved[48] = "true"; reserved[49] = "try"; reserved[50] = "void"; reserved[51] = "volatile"; reserved[52] = "while"; reserved[53] = "="; reserved[54] = "=="; reserved[55] = "!="; reserved[56] = "+"; reserved[57] = "-"; reserved[58] = "*"; reserved[59] = "/"; reserved[60] = "{"; reserved[61] = "}"; return reserved; } }

    Read the article

  • Problem with boundary collision

    - by James Century
    The problem: When the player hits the left boundary he stops (this is exactly what I want), when he hits the right boundary. He continues until his rectangle's left boundary meets with the right boundary. Outcome: https://www.youtube.com/watch?v=yuJfIWZ_LL0&feature=youtu.be My Code public class Player extends GameObject{ BufferedImageLoader loader; Texture tex = Game.getInstance(); BufferedImage image; Animation playerWalkLeft; private HealthBarManager healthBar; private String username; private int width; private ManaBarManager manaBar; public Player(float x, float y, ObjectID ID) { super(x, y, ID, null); loader = new BufferedImageLoader(); playerWalkLeft = new Animation(5,tex.player[10],tex.player[11],tex.player[12],tex.player[13],tex.player[14],tex.player[15],tex.player[17],tex.player[18]); } public void tick(LinkedList<GameObject> object) { setX(getX()+velX); setY(getY()+velY); playerWalkLeft.runAnimation(); } public void render(Graphics g) { g.setColor(Color.BLACK); FontMetrics fm = g.getFontMetrics(g.getFont()); if(username != null) width = fm.stringWidth(username); if(username != null){ g.drawString(username,(int) x-width/2+15,(int) y); } if(velX != 0){ playerWalkLeft.drawAnimation(g, (int)x, (int)y); }else{ g.drawImage(tex.player[16], (int)x, (int)y, null); } g.setColor(Color.PINK); g.drawRect((int)x,(int)y,33,48); g.drawRect(0,0,(int)Game.getWalkableBounds().getWidth(), (int)Game.getWalkableBounds().getHeight()); } @SuppressWarnings("unused") private Image getCurrentImage() { return image; } public float getX() { return x; } public float getY() { return y; } public void setX(float x) { Rectangle gameBoundry = Game.getWalkableBounds(); if(x >= gameBoundry.getMinX() && x <= gameBoundry.getMaxX()){ this.x = x; } } public void setY(float y) { //IGNORE THE SetY please. this.y = y; } public float getVelX() { return velX; } public void setHealthBar(HealthBarManager healthBar){ this.healthBar = healthBar; } public HealthBarManager getHealthBar(){ return healthBar; } public float getVelY() { return velY; } public void setVelX(float velX) { this.velX = velX; } public void setVelY(float velY) { this.velY = velY; } public ObjectID getID() { return ID; } public void setUsername(String playerName) { this.username = playerName; } public String getUsername(){ return this.username; } public void setManaBar(ManaBarManager manaBar) { this.manaBar = manaBar; } public ManaBarManager getManaBar(){ return manaBar; } public int getLevel(){ return 1; } public boolean isPlayerInsideBoundry(float x, float y){ Rectangle boundry = Game.getWalkableBounds(); if(boundry.contains(x,y)){ return true; } return false; } } What I've tried: - Using a method that checks if the game boundary contains player boundary rectangle. This gave me the same result as what the check statement in my setX did.

    Read the article

< Previous Page | 1 2 3 4 5 6 7  | Next Page >