Insertion an object into a sorted list
Hello
I have got class MySortedList which encloses List object.
class MySortedList {
private List list = new LinkedList();
public add(Object obj, Comparator cmp) {
Who knows how the add(Object, Comparator) method can be realized better?
All comments...
Why am I using the LinkedList?
It is not in principle. I can change this to
ArrayList, for example.
It is depend on what do I use MySortedList class for.
Can you suggest to use something else?LinkedLists are going to be the slowest way to do this. Even calling contains is slow. You have a sorted list but you have to iterate over all the preceeding elements to get at an element even though you know where it is.
There is also a problem with the general design. someone can call the method once with one Comparator and then again with a completely different comparator. For example, if you add 5 elements with a String comparator that sorts them alphabetically and then with a Comparator that sorts them in reverse alphabetically you could end up with a list like:
z, c, d, e, f, g
then you call it with t and the firs comparator and get:
t, z, d, r, f, g
It's then no longer in order with respect to either comparator and the whole thing is broken. You need to set the Comparator in the constructor.
Use an ArrayList and the code becomes:
public synchronized void add(Object obj)
int index = Collections.binarySearch(list, obj, comparator);
if (index == list.size()) list.add(obj);
else if (index < 0) list.add((index * -1) - 1, obj);
}
Similar Messages
-
How to insert an object into an object array
I have an array of objects and im trying to insert an object into the array at position zero. Does anyone know what method I can use for this?
Hey,
Are u using a normal array or an array list ?
For instance if you are using a normal array and you wnat to store an object of classX it should be something like this:
myArray[0] = new classX(vlaue1, Value2, Value3);this will only work if you have a default constructer for the objects.
I am posting under correction here but this is the basic idea.
Hope it helps :-) -
How To Insert A object into Conext
Hi Techies,
I have 8 tables in my designer
and I have two contexts at designer level
And how to insert a object into a context that is not referencing any table.
For Example I have an object like "rownum" (Which should must be added at Universe level only not at report level). Here this object is not referencing any table and I want this to be used in a query where the remaining objects are coming from the context..
Thanks in Advance..Double-click the Objects and click the TABLES button and select the table you want to associate the object to for the context to work properly (see below).
Regards,
Ajay -
Unable to insert pdf object into 64-bit Word 2010
I have always been able to insert pdf files into word documents. However, when I upgraded to the 64-bit version of Word, I started experiencing the below issue.
My setup is: Windows 7 64-bit, Word 2010 64-bit, Adobe Acrobat 9 Pro v9.4.7.
When I attempt to insert a pdf file into Word, I receive the following message:
"The program used to create this object is AcroExch. That program is either not installed on your computer or it is not responding. To edit this object, install AcroExch or ensure that any dialog boxes in AcroExch are closed."
I have researched this issue a great deal.
Previously, I found a posting which specified some registry keys to delete. I followed these directions and it worked. But, after installing some updates, the issue is back and I am unable to find the post specifying the registry keys to remove.
Any help will be greatly appreciated.
Thanks!
BrandonSolution:
Open Adobe Reader / Pro
Go to Edit àPreferenceà General (LHS)àUncheck “Enable protected mode at startup”.
Adobe Reader’s protected mode will be disabled
Now try inserting Adobe document in Word, it will work. -
Cannot open PDFs inserted as objects into Excel.
Two-part question. I know this has been addressed before, but the solutions are not working for me.
I have Adobe Acrobat 9 Pro and Adobe Reader XI. When inserting a PDF document as an object into Excel, it will not allow me to insert the icon/object from the "Create New" option. I get one of two error messages: 'Cannot insert object' or 'Cannot start the soruce application for this object'. I am able to insert the PDF icon/object if I insert from the "Create from file" option. (Please note I cannot always link to the PDF, as some spreadsheets are sent out externally and will not have access.)
Once I am finally able to insert the document as an object, I can open and view the PDF. However, when I close the spreadsheet and re-open it, if I try to open the PDF document again, I get this error message again: 'Cannot start the soruce application for this object'.
I have changed my preference to disable the Protected Mode at startup and this issue is still happening. VERY frustrating. I never encountered this is past versions of Adobe and all previous suggestions are not fixing the issue. Does anyone have any insight or know of an update to fix this issue? Is this an Adobe issue or a Microsoft Office issue?Hi Jerry,
Can you check the similar thread
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/d554e88c-d72f-46b0-8b1a-2f2024fcb9c0/i-e-8-browser-wont-open-pdf-file-returned-from-sharepoint-2010-search?forum=sharepointadminprevious
My Blog- http://www.sharepoint-journey.com|
If a post answers your question, please click Mark As Answer on that post and Vote as Helpful -
Unable to insert pdf object into ppt or word
I am unable to insert a pdf object into Word or Powerpoint. I have Adobe Reader 9.3 and Windows 7 MS Office 2010 64 bit. Previously, I was able to perform this task without issue with the same software.
For word, I get:
"The program used to create this object is AcroExch. That program is either not installed on your computer or it is not responding. The edit this object install AcroExch or ensure that any dialog boxes in AcroExch are closed".
For Powerpoint, I get:
"The server application, source file, or item can't be found, or returned an unknown error. You mayneed to reinstall the server application."
Was an update sent out that may have caused the issue?
Or is there a solution to resolve the issue? The ony solution I have sound is Disabling Protect Mode which does not apply to this version of Reader.
Any help would be greately appreciated. Thank you.There is another thread on this and seems to be an ongoing issue with neither Microsoft nor Adobe owning up to it. What I did to work-around the issue is create a .zip file of the .pdf file which can then be put into the workd doc as an object file icon. Worked for me. Not the best solution but this has been ongoing since 2011, and this worked.
-
How to insert Transition object into html document
Hello Friends,
I am trying to insert Transition object ( downloaded from
Extension) into HTML document.
I tried Insert -> HTML -> Head Tags -> Transitions,
but after doing all this I am not able to insert
this extension in my document.
As I am beginner to Dreamweaver, Can anyone pls. help me out?
I am using Dreamweaver 8.
Do I need to select <img> tag before inserting
Transition Object?
Pls. pls. help me out.....
Waiting for reply.
Thanks in advance for your help.When I used to do tabs I would set up a page that was as wide as the tab sheet including the tab, then add text frames in each tab position.
-
Unable to insert PDF object into Word 2013
Hi,
While trying to insert PDF (Adobe Reader X 10.1.0) document into Word
(Microsoft office Professional plus 2013 15.0.4420.1017) getting below error.
Error Message: The Program used to create this object is
Acroexch.That program is either not installed on your computer or it is not
responding, to edit this object , install AcroExch to ensure that any dialog
boxes in Acroexch are closed
Also i tried mentioned steps:
Step1: Open Adobe Reader and goto Edit ==> References (ctrl+k).
Step2: In General uncheck the Enable protected mode at startup.
But still getting the same error.
Any suggestion Please!!!!!!!
Thanks in advance.gkrish wrote:
(Adobe Reader X 10.1.0)
I would try to install a newer Reader version; either 10.1.10 or 11.0.07. -
Inserting excel object into powerpoint
I am in BPC for PowerPoint and trying to "Insert BPC for Excel Object"
It comes back as an empty worksheet. No other worksheet works either.
The same file works when I insert it into BPC for Word.
Any suggestions?Hello,
Perhaps I'm misunderstanding your question? Do you want to have a SWF-file, published by Presenter with inserted SWF's created in CP. Because you speak about 'using the Presenter tab', so I suppose you have Adobe Presenter installed. I have inserted quite a lot of CP-SWF's in a PPT, and this works fine (especially after the recent Presenter update), but the result is a SWF-published by Presenter (under the same Presenter tab). You can even choose to control the CP-SWF by its proper playbar or by the playbar of Presenter.
BTW, a user doesn't need to have CP installed to watch a CP-SWF, only the Flash Player.
If this is not the answer you expect, please try to explain somewhat more.
Lilybiri -
Insert multiple objects into variable (array)
Hello,
I need to create PS script to which gets logged on users(get-rdusersession | select UserName), puts them into variable $users=@(user1,user2,...,userN) and runs foreach {something} - something like send message and logoff user. But I cannot get the
output from command get-rdusersession to the variable. Can someone tell, how to do that? Thank you.
Pete
sfsHi Pete,
try this:
$Users = Get-RDUserSession | Select -ExpandProperty UserName
The "-ExpandProperty" Parameter means the select command returns a String with the value that the UserName property on the output of Get-RDUserSession had. Otherwise you get a PSObject that has a UserName property itself, containing that string
(try Piping both versions to the cmdlet Get-Member and see for yourself, both properties and type name).
Cheers,
Fred
Ps.: Try running Get-RDUserSession in your Powershell Console and check whether you actually get any output, in case that's the problem.
There's no place like 127.0.0.1 -
Putting a class of objects in a Linked List?
Hi,
I copied a program from a book and I want to edit it and put studentRecord class in the Linked List. I've tried to play about with datum, but everything I try doesn't work. Can someone help me out? How could I put studentRecord in the LinkedList?
import java.io.*;
class IO
static BufferedReader keyboard = new
BufferedReader(new InputStreamReader(System.in));
static PrintWriter screen = new PrintWriter(System.out, true);
class studentRecord
private String name;
private int IDNumber;
class LinkedList
class Node
protected Object datum;
protected Node link;
public Node() {}
public Node(Object item, Node pointer)
datum = item;
link = pointer;
private Node head;
private Node tail;
private Node temporary;
private int nodeCount = 0;
//constructor
public LinkedList()
head = null;
tail = null;
temporary = null;
//method to insert an object into the linked list
public void insert(Object datum)
if (head == null) // list empty
head = new Node(datum, head);
tail = head;
else
temporary = new Node(datum, temporary);
tail.link = temporary;
tail = temporary;
temporary = null;
nodeCount++;
Full program can be found: http://dil3mma.tripod.com/LinkedList.txt
Thanks in advance.Hi jverd,
Thanks for replying. I've tried to change the program liked you said but there is 1 error I can't seem to fix(Im sure there are more tho). The error is "cannot resolve symbol" I typed in caps the line it happens on so it's easy to see. Any idea what it could be? Is it cause I'm comparing a String with Object?
import java.io.*;
class IO
static BufferedReader keyboard = new
BufferedReader(new InputStreamReader(System.in));
static PrintWriter screen = new PrintWriter(System.out, true);
class sRecord
private String name;
private int IDNumber;
class LinkedList
class Node
protected sRecord datum;
protected Node link;
public Node() {}
public Node(sRecord item, Node pointer)
datum = item;
link = pointer;
private Node head;
private Node tail;
private Node temporary;
private int nodeCount = 0;
//constructor
public LinkedList()
head = null;
tail = null;
temporary = null;
//method to insert an object into the linked list
public void insert(sRecord datum)
if (head == null) // list empty
head = new Node(datum, head);
tail = head;
else
temporary = new Node(datum, temporary);
tail.link = temporary;
tail = temporary;
temporary = null;
nodeCount++;
//method to delete an object from the linked list
public boolean delete(Object scrap)
Node previous = head;
//for every node in the linked list
for (Node current = head; current != null; current = current.link)
//node to be deleted is at the head of the list
if (current.datum.equals(scrap) && previous == current)
head = current.link;
if (head == null) tail = null;
nodeCount--;
return true;
//node to be deleted is after the first node and before the last
else if (current.datum.equals(scrap) && (current.link != null))
previous.link = current.link;
nodeCount--;
return true;
//node to be deleted is at the ned of list
else if (current.datum.equals(scrap) && (current.link == null))
tail = previous;
previous.link = null;
nodeCount--;
return true;
previous = current;
return false;
//method to display the contents of a linked list
public void displayList()
Node temporary = head;
if (head == null)
IO.screen.println("linked list is empty");
return;
while (temporary != null)
IO.screen.println(temporary.datum);
temporary = temporary.link;
//method to return true if the linked list is empty
public boolean isEmpty()
return (nodeCount == 0);
//method to return the number of nodes in the linked list
public int nodes()
return nodeCount;
//method to display a menu to insert data into the linked list
static private char menu()
char response = '\u0000';
IO.screen.println("Do you want to ");
IO.screen.print("nsert, [D]elete, [L]ist, [E]xit? ");
IO.screen.flush();
boolean done=false;
do
try
String data = IO.keyboard.readLine();
response = Character.toUpperCase(data.charAt(0));
done = true;
catch (Exception e)
IO.screen.println("Please input a single character I, D, L or E");
} while (! done);
return response;
static public void main(String[] args) throws IOException
LinkedList list = new LinkedList();
String datum;
char choice;
//get information from menu
choice = menu();
for (;;)
//Menu
switch (choice)
case 'I' :
IO.screen.println("type quit to finish input");
IO.screen.print("Enter a word ");
IO.screen.flush();
datum = IO.keyboard.readLine();
while (! datum.equals("quit"))
THE ERROR HAPPENS HERE ON THIS LINE list.insert(datum.name);
IO.screen.print("Enter another word");
IO.screen.flush();
datum = IO.keyboard.readLine();
break;
case 'D' :
//if list is empty deletion not possible
if (list.isEmpty())
IO.screen.println("linked list is empty");
break;
IO.screen.println("type quit to finish input");
IO.screen.print("Delete? ");
IO.screen.flush();
datum = IO.keyboard.readLine();
while (! datum.equals("quit"))
if (list.delete(datum))
IO.screen.println(datum+" was scrapped!");
//if list is empty deletion is not possible
if (list.isEmpty())
IO.screen.println("linked list is empty");
break;
IO.screen.print("Delete? ");
IO.screen.flush();
datum = IO.keyboard.readLine();
break;
case 'L' :
list.displayList();
IO.screen.println("number of nodes " + list.nodes());
break;
case 'E' : System.exit(0);
//get information from menu
choice = menu(); -
Read Hashmap into a Linked List
Hi,
I have a hashmap containing objects; I want to put those objects into a linked list.
Where do I start? I haven't the foggiest idea....
I suppose I have to iterate through the hashmap and extract the objects and then put them into a linked list.
Does anyone know of a good tutorial for that kind of thing?
Cheers,
DidheI'm no expert on this (far from it), but on looking
at the HashMap and LinkedList API's, there may be
something easy available to you.Yes, another URL to bookmark:
http://java.sun.com/javase/6/docs/api/ -
Delete and insert same Object in one transaction?
Hi all,
Can be possible in one transaction delete and then insert same object into the database?
If I want change PK in some record in DB, then I must delete the Object and then insert new Object (row). And this I want realize in one transaction - Unit of Work.
Is this possible?
Thx advance,
best regards,
KLD
P.S. Sry for my EnglishGenerally not always a good idea, but may be possible. If you are using JPA, you should be able to do a flush() after deleting the object, then re-persist the new one.
For the UnitOfWork API, writeChanges() is the same as flush, but it only allowed to be called once, so you may need to use the RepeatableWriteUnitOfWork, or performDeletesFirst option.
Or just use two separate units of work.
James : http://www.eclipselink.org -
Hello all,
I'm currently studying for a midterm on linked lists and I'm having a little trouble inserting in "order". What I'm trying to do is use a compareTo method to compare serial numbers of items. The compareTo methos is as follows:
public int compareTo(Object obj) {
StoreItem other = (StoreItem) obj;
return serialNumber - other.serialNumber;
And the following is my addItem method....which should simply insert the Node into the list in it's proper place according to it's serial number. Any help would be greatly appreciated:)
public boolean addItem(StoreItem item){
if (item == null)
return false;
else if (first == null)
{first = new Node (item, null);
return true;}
else {
Node p = first;
while (p.next != null && item.compareTo(p.value) > 0){
p = p.next;
p.next = new Node (item, p.next);
return true;
Thanks again!
TylerMy error lies in the "else {" section of the code....The code up to there works fine as I've tried adding one element to an empty list and print it and it works. What doesn't work is when there's already one item in my list and I want to add another, which is what the following code was meant to do:
else {
Node p = first;
while (p.next != null && item.compareTo(p.value) > 0){
p = p.next;
p.next = new Node (item, p.next);
return true;
This code compiles and doesn't give me a runtime error, yet when I execute the program, it only seems to add the first element....
Thanks again for the help:)
Tyler -
Insert ActiveX Object - not in list
Hi, guys.
After one time, I'm not able to install by myself ActiveX controls and embed these controls into ActiveX containers yet. I refer to ActiveX controls that can be embedded into ActiveX containers, not those used to instantiate other applications.
I want a certain ActiveX Control to be displayed in an ActiveX Container on the Front Panel. In this particular case, it's a Mozilla Firefox ActiveX Control. According to http://forums.ni.com/t5/LabVIEW/activex-firefox-and-mozilla/td-p/356235 (see message 5), after getting the component from the link provided and installing it, I should be able to insert onto the empty ActiveX Container by clicking over it and selecting "Insert ActiveX Object...". In this case, "MozillaBrowser class" should appear in the list, but not.
However, if I place a Property Node or Invoke Node without reference on the Block Diagram, click on it, then "Select Class" -> "ActiveX" -> "Browse", I find the class "MozillaControl 1.0 Type Library Version 1.0", that, among others, it contains the class "IWebBrowser2". This class happens to be called "MOZILLACONTROLLib.IWebBrowser2". But, once I have the Property Node or Invoke Node, I can't create the container from it (create control from its reference) neither place an empty ActiveX container and wire its reference to the Property Node.
I also tried registering the ActiveX Control, by typing "regsvr32 <control_name.dll>" in the command prompt, but nothing changes.
But this doesn't happen to me only with this particular ActiveX control. Every time I want to find in the list a certain ActiveX component after installing it, I can't find it, and I end up copying ActiveX container blocks from VI examples I found on the forums... One example is using AcroPDF ActiveX Control.
Any suggestion? Has anybody faced the same problem?
Regards,
Francisco
Attachments:
ActiveX Container.png 26 KB
Property Node.png 35 KBHello,
Probably you can
see the server in the pop-up menu because the server is not in the PC but is in
the registry. Remove the checkbox “Validate Servers” to see if the Mozilla
server appears. According to this LV help link...
http://zone.ni.com/reference/en-XX/help/371361G-01/lvhowto/creating_new_controls_in_a/
... looks like the server is not installed in the PC... or it’s not registered.
Maybe you are looking for
-
New computer with external hard drive...
Current setup has iTunes Library, all files, located on an external hard drive....I'm going to implement a new laptop shortly, and will download the latest version on iTunes when I set it up..... I'll have the destination for music point to that exte
-
Hello, I've bought me an iPod nano but I'm having the problem that I can not upload any songs to it. The only songs I can put on it are songs that iTunes has choosen. When I go to my iPod in iTunes, I see this lock next to how much disk space I have
-
High CPU usage for Mail/Address Book with Exchange/GMail
I reinstalled 10.6 on my MacBook Pro because it since the upgrade from 10.5 performance has been generally lousy and I wanted to make a fresh start. I am finding that my performance problems with Mail (which connects to both Gmail and Exchange) is st
-
How groups are assigned in OBIEE 11g if a user is present in more security
Suppose we have security provider1 & provider2 having the same user. If provider 1 is in top of list and it have group 1 assigned to the user1 , then how can i get group2 assigned to user1 in provider2?
-
My Iphone 5 screen wont turn onj
When i was trying to open an app the screen went black and then the folder screen (where all the apps are) came on and i pushed the ome button and then the screen just turned off. My Iphone 5 is on, working, i can hear all the notifications when they