Constructor  that takes Comparator parameter

Hello,
How would you implement a new Constructor for a class that takes a Comparator<> parameter?

MindGames wrote:
Hello,
How would you implement a new Constructor for a class that takes a Comparator<> parameter?The same way, you'd implement a new Constructor that takes any other parameter.
What's the problem? Where are you stuck?

Similar Messages

  • Creating a generic class with a constructor that takes an array of objects

    I am relatively new to java and want to build a quick utility class that can generate a Run Length Encoding of any object. The idea is to take an array of objects of type "O" and then encode a string of objects that are "equal" to each other as an integer that counts the number of such equal instances and a single copy of the instance. This has the potential to very quickly reduce the size of some objects that I want to store. I would like to implement this class as a generic.
    public class RunLengthEncoding<O> {
         private class RLEPair {
              private int length;
              private O object;
         public RunLengthEncoding(O[]) {
    }As you can see, I need to make a constructor that takes an array of type "O". Is this possible to do? I can't seem to find the right syntax for it.
    Thanks,
    Sean

    Sorry. Obvious answer:
    public RunLengthEncoding(O[] oarray) {Again, sorry for the noise.

  • Initializing instance variables in a constructor that are used by super()

    I have a class that extends a standard class (ie JButton, but it doesn't matter what class). The constructor takes a parameter that I set to an instance variable. There is an overloaded method of the standard class that needs to use the variable.
    My problem is that since I must call super() first, my instance variable is not yet set, so when my overloaded method is called by the constructor it is unable to see the paramater value. How can my method see this value?
    public class MyClass extends somejavaclass {
    MyClass(int x) {
    super();
    myInt = x;
    // This overrides something in somejavaclass and is called by the constructor
    public void aJavaMethod() {
    // do some logic with myInt, but it has not been set to my paramater value
    int myInt;
    }

    If the variable in question is an object reference,
    you could compare it to null. A true result would tell
    you that it hadn't been initialized yet, and you could
    write code to behave accordingly (for example calling
    the init() method to do the initialization).That's a good solution but what if the instance in question is set in the sub-classes constructor?
    This is a very annoying feature of Java, and one that
    I have had to work around on several occasions. And as
    far as I'm concerned it's an unnecessary feature: why
    shouldn't a class be able to initialize its variables
    before it calls the superclass's constructor? Other OO
    languages permit that.I've wondered this also. I'd always assumed it was a way to make sure the super-class was completely initialized before anything tries to use it esp. to make sure the Object() constructor is finished before anything else happens.
    How is this dealt with in C++ or does it just leave open potential for errors?

  • Problem calling a method which takes a parameter from a table

    Hi guys,
    I'm very new to jsf and hope you can help me out.
    On my page i'm generating a list, which is working fine. now i want to add some commandLinks to the list entries. on click, i want to execute a bean method, which takes a parameter from the list, generates a picture and displays it on my page.
    here's a piece of code thats already working:
    <rich:dataTable var="data" value="#{pathwayBean.orgList}">
    <rich:columnGroup>     
            <rich:column>     
               <h:outputText value="#{data.name}" />
         </rich:column>
    </rich:columnGroup>
    </rich:dataTable>now, i want to replace the outputText with a commandLink, and execute a method with {data.id} as parameter. Unfortunately, the commandLink property "action" can only call bean methods with no parameter, or is that wrong?
    Thanks in advance,
    Alex

    use actionlistener.
    here a typical code that works fine for me:
    (JSF 1.2)
    //Java
    private Integer selectedItemId=null;
         public void selectItem(ActionEvent event) {
              // Find the UIParameter component by expression
              UIParameter component = (UIParameter) event.getComponent().findComponent("itemId");
              // parse the value of the UIParameter component
              try {
                   selectedItemId = Integer.parseInt(component.getValue().toString());
                   // find itemBean here using selectedItemId
              } catch (Exception e) {
                   logger.error(e, e);
              logger.info(" +++ selectedItemId =" + selectedItemId);
         public String viewItem() {
                 //create view beans here
                 return "itemView";//return appropriate view.
    //JSF
    <h:column>
                             <h:commandLink     id="View"
                                                 action="#{itemListBean.viewItem}"
                                                       actionListener="#{itemListBean.selectItem}">
                                  <h:outputText value="select"/>
                                  <f:param id="itemId" name="itemId" value="#{itemBean.id}"/>
                             </h:commandLink>
                     </h:column>

  • How to write a method that takes two arguments of same type

    Hi,
    I seldom do anything "advanced" in generics, but I've done my reading, and thought that I had an understanding of the basics, but I'm stuck on this. How do I write a method that takes two arguments that must be of exact same type.
    I've tried something like:
    public class GenericsTest1 {
        public static <T> void compare(T first, T second) {
    }But the compare method can in this case be called with e.g.
    String arg1 = null;
    Long arg2 = null;
    compare(arg1, arg2);I can restrict the call to something like GenericsTest1.<Long>compare(arg1, arg2), but I don't want to do it in the location that calls the method, and the method can still be invoked with subclasses of the specified type. E.g. this is valid (but I don't want it to be valid):
    Number arg1 = null;
    Long arg2 = null;
    GenericsTest1.<Number>compare(arg1, arg2);So I then changed the method into something like this:
    public class GenericsTest2 {
        public static <T, E extends T> void compare(T first, E second) {
    }It feels like I'm half way there now. Compare can't be called with e.g:
    Long arg1 = null;
    Number arg2 = null;
    compare(arg1, arg2);But this is still valid:
    Number arg1 = null;
    Long arg2 = null;
    compare(arg1, arg2);Hmm... So what to do? I only want the method to be callable when arg1 and arg2 is of exact same type. Everything else should give a compilation error.
    Kaj
    Ps. No, I don't have a need for this, I'm just curious.

    dannyyates wrote:
    I haven't gone through everything you've written, but I would expect that in the first instance, it's inferred <T> to be Object. This is a good reason to parameterise the class rather than the method wherever that makes sense.Thanks for you reply, but as I said this isn't related to anything that I'm going to use. I just want to know if it ca ben done with a static method and generics.
    Kaj

  • Bind ADF table to EJB method that takes a argument (operation)

    Hi Oracles
    I can bind a ADF table to a EJB method that takes no arguments, and then JDeveloper calls the method a accessor. I would like to bind another ADF table to another EJB method that takes a argument, but there I have some problems. First of all JDeveloper will not allow this, can I work around that? Then obviously I have to pass the argument to this EJB method some how..?
    Do you guys have any way of fixing this? Is the only way to not bind the ADF table, and do it in code in the background, and how do I do this?
    Best regards
    Søren

    Thank you!
    I found it, and if I drag it to my JSP, it gives me these options:
    - Create Methods
    - ADF Link
    - ADF Button
    - ADF Menu Item
    - ADF Toolbar Button
    - ADF Image Link
    - Create Parameters
    - ADF Parameter Form
    I have one ADF table that is bound to a data control, and based on the selection on this table, I would like to show data in another table based on a EJB method that takes a id from the selected object from the first table. Either on the same JSP or on another JSP, whatever is easiests.
    Can you help me do this? Then I hope I learn something in the process :)
    Best regards
    Søren

  • IView takes query parameter

    Is there a way to create an iView that takes in query string parameter? for example,
    I have a URL like this
    http://www.someserver.com/abc.jsp?client_id=12345
    Can the client_id be a parameter that get passed to the iView at run time?
    Thanks

    Hi,
    Can refer to the following :
    [Set user Language in URL IView;
    [http://help.sap.com/saphelp_nw04/helpdata/en/d3/ab0b5decd045e482d0deae9f9c90d5/frameset.htm]
    Regards,
    Dhruv Shah

  • Nested If condition in Routine - Literals that take up more than one line

    Hi All,
           I am writing following code at object level of routine but its giving following exception: Please help me on this.
    Exception:
    E:Literals that take up more than one line not permitted.
    CODE:
    IF SOURCE_FIELDS-/BIC/TOTAL >= 900.
        RESULT = 'A.
    ELSEIF SOURCE_FIELDS-/BIC/TOTAL >= 800 AND SOURCE_FIELDS-/BIC/TOTAL < 900.
        RESULT = 'B.
    ELSEIF SOURCE_FIELDS-/BIC/TOTAL >= 700 AND SOURCE_FIELDS-/BIC/TOTAL < 800.
        RESULT = 'C.
    ELSEIF SOURCE_FIELDS-/BIC/TOTAL >= 600 AND SOURCE_FIELDS-/BIC/TOTAL < 700.
        RESULT = 'D'.
    ELSEIF SOURCE_FIELDS-/BIC/TOTAL >= 500 AND SOURCE_FIELDS-/BIC/TOTAL < 600.
        RESULT = 'E'.
    ELSEIF SOURCE_FIELDS-/BIC/TOTAL >= 400 AND SOURCE_FIELDS-/BIC/TOTAL < 500.
        RESULT = 'F.
    ELSEIF SOURCE_FIELDS-/BIC/TOTAL >= 350 AND SOURCE_FIELDS-/BIC/TOTAL < 400.
        RESULT = 'G.
    ELSEIF SOURCE_FIELDS-/BIC/TOTAL >= 300 AND SOURCE_FIELDS-/BIC/TOTAL < 350.
        RESULT = 'H.
    ELSEIF SOURCE_FIELDS-/BIC/TOTAL >= 200 AND SOURCE_FIELDS-/BIC/TOTAL < 300.
        RESULT = 'I.
    ELSEIF SOURCE_FIELDS-/BIC/TOTAL >= 0 AND SOURCE_FIELDS-/BIC/TOTAL < 200.
        RESULT = 'J.
    ENDIF.
    Thanks in advance.
    Anitha.B

    Hi Anitha
    Just check
    RESULT = 'A.
    ELSEIF SOURCE_FIELDS-/BIC/TOTAL >= 800 AND SOURCE_FIELDS-/BIC/TOTAL < 900.
    RESULT = 'B.
    ELSEIF SOURCE_FIELDS-/BIC/TOTAL >= 700 AND SOURCE_FIELDS-/BIC/TOTAL < 800.
    RESULT = 'C.
    Whether it needs to be under two quotes. I feel one is missing. it should be 'A' and not just 'A.
    Regards
    Sriram

  • How To Handle DB That Takes Time To Open

    I am using DAO to link sql server tables into mdb.  With one database I have it takes roughly 60 seconds for the database to become available to link in the table.  When I open the database normally (w/o code) it takes about 5 seconds for the Database
    pane to be displayed, and this database has a form load on database open, and that takes about 50 seconds to actually pop-up.  I have been using Thread.Sleep() to combat this, but wanted to see if their is a better way to handle a bugger database.  This
    is my current code, does anyone have a better solution or code tweaks to handle this better?
    namespace TestLinkTable
    public partial class Form1 : System.Windows.Forms.Form1
    private DAO.Database dd;
    private DAO.DBEngine db = new DAO.DBEngine();
    private stat string dbolocation = "C:\\Testing\\database1.mdb";
    private DAO.TableDef tdf1;
    private static string SQLName = "dbo.MasterTable";
    private static string AccessName = "MasterTable"
    private static string SQLConnectionString = "";
    private void btnOpenDatabase_Click()
    dd = db.OpenDatabase(dbolocation);
    Thread.Sleep(6000);
    tdf1 = dd.CreateTableDef(AccessName);
    tdf1.Connect = SQLConnectionString;
    tdf1.SourceTableName = SQLName;
    dd.TableDefs.Append(tdf1);

    I implemented your code and I like the fact that it keeps the form available to still use if need be, but is their a way to keep the timer ticking so the elapsedtime on the form is updated and it doesn't just stop updating while this intensive database is
    in process of updating?  This is the syntax I have right now
    namespace TestLinkTable
    public partial class Form1 : System.Windows.Forms.Form1
    private DAO.Database dd;
    private DAO.DBEngine db = new DAO.DBEngine();
    private stat string dbolocation = "C:\\Testing\\database1.mdb";
    private DAO.TableDef tdf1;
    private static string SQLName = "dbo.MasterTable";
    private static string AccessName = "MasterTable"
    private static string SQLConnectionString = "";
    private Stopwatch sw = new Stopwatch();
    private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
    public Form1()
    backgroundWorker1.WorkerReportsProgress = true;
    backgroundWorker1.WorkerSupportsCancellation = false;
    backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
    backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
    timer.Tick += timer1_Tick;
    private void btnOpenDatabase_Click()
    sw.Restart();
    timer.Start();
    backgroundWorker1.RunWorkerAsync();
    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    System.Threading.Tasks.Task.Factory.StartNew(() =>
    dd = db.OpenDatabase(dbolocation);
    }).ContinueWith((t) =>
    Thread.Sleep(6000);
    tdf1 = dd.CreateTableDef(AccessName);
    tdf1.Connect = SQLConnectionString;
    tdf1.SourceTableName = SQLName;
    dd.TableDefs.Append(tdf1);
    //More going on here....
    timer.Stop();
    private void timer1_Tick(object sender, EventArgs e)
    txt_TimeElapsed.Text = sw.Elapsed.ToString("mm\\:ss\\.ff");

  • I have a keynote presentation that includes a significant amount of video.  When I edit the keynote slides (not the video slides) how can I save the changes without re-saving the videos (because that takes a VERY long time)?

    I have a keynote presentation that includes a significant amount of video.  When I edit the keynote slides (not the video slides) how can I save the changes without re-saving the videos (because that takes a VERY long time)?  I edit the presentation depending on the audience to which I am presenting.

    If you add a new  slide with just a text box (therefore a very small amount of data),  to an existing presentation then save,  Keynote will only save the new content to the file,  it wont save  pre-existing content as its already included in the file.
    The time  taken to "save" will be very much shorter than a "save as" when all of the existing content is saved again.

  • How do I create a 1d array that takes a single calculation and insert the result into the first row and then the next calculation the next time the loop passes that point and puts the results in thsecond row and so on until the loop is exited.

    The attached file is work inprogress, with some dummy data sp that I can test it out without having to connect to equipment.
    The second tab is the one that I am having the problem with. the output array from the replace element appears to be starting at the index position of 1 rather than 0 but that is ok it is still show that the new data is placed in incrementing element locations. However the main array that I am trying to build that is suppose to take each new calculation and place it in the next index(row) does not ap
    pear to be working or at least I am not getting any indication on the inidcator.
    Basically what I am attempting to do is is gather some pulses from adevice for a minute, place the results for a calculation, so that it displays then do the same again the next minute, but put these result in the next row and so on until the specifiied time has expired and the loop exits. I need to have all results displayed and keep building the array(display until, the end of the test)Eventually I will have to include a min max section that displays the min and max values calculated, but that should be easy with the min max function.Actually I thought this should have been easy but, I gues I can not see the forest through the trees. Can any one help to slear this up for me.
    Attachments:
    regulation_tester_7_loops.vi ‏244 KB

    I didn't really have time to dig in and understand your program in depth,
    but I have a few tips for you that might things a bit easier:
    - You use local variables excessively which really complicates things. Try
    not to use them and it will make your life easier.
    - If you flowchart the design (very similar to a dataflow diagram, keep in
    mind!) you want to gather data, calculate a value from that data, store the
    calculation in an array, and loop while the time is in a certain range. So
    theres really not much need for a sequence as long as you get rid of the
    local variables (sequences also complicate things)
    - You loop again if timepassed+1 is still less than some constant. Rather
    than messing with locals it seems so much easier to use a shiftregister (if
    absolutely necessary) or in this case base it upon the number of iterations
    of the loop. In this case it looks like "time passed" is the same thing as
    the number of loop iterations, but I didn't check closely. There's an i
    terminal in your whileloop to read for the number of iterations.
    - After having simplified your design by eliminating unnecessary sequence
    and local variables, you should be able to draw out the labview diagram.
    Don't try to use the "insert into array" vis since theres no need. Each
    iteration of your loop calculates a number which goes into the next position
    of the array right? Pass your result outside the loop, and enable indexing
    on the terminal so Labview automatically generates the array for you. If
    your calculation is a function of previous data, then use a shift register
    to keep previous values around.
    I wish you luck. Post again if you have any questions. Without a more
    detailed understanding of your task at hand it's kind of hard to post actual
    code suggestions for you.
    -joey
    "nelsons" wrote in message
    news:[email protected]...
    > how do I create a 1d array that takes a single calculation and insert
    > the result into the first row and then the next calculation the next
    > time the loop passes that point and puts the results in thsecond row
    > and so on until the loop is exited.
    >
    > The attached file is work inprogress, with some dummy data sp that I
    > can test it out without having to connect to equipment.
    > The second tab is the one that I am having the problem with. the
    > output array from the replace element appears to be starting at the
    > index position of 1 rather than 0 but that is ok it is still show that
    > the new data is placed in incrementing element locations. However the
    > main array that I am trying to build that is suppose to take each new
    > calculation and place it in the next index(row) does not appear to be
    > working or at least I am not getting any indication on the inidcator.
    >
    > Basically what I am attempting to do is is gather some pulses from
    > adevice for a minute, place the results for a calculation, so that it
    > displays then do the same again the next minute, but put these result
    > in the next row and so on until the specifiied time has expired and
    > the loop exits. I need to have all results displayed and keep building
    > the array(display until, the end of the test)Eventually I will have to
    > include a min max section that displays the min and max values
    > calculated, but that should be easy with the min max function.Actually
    > I thought this should have been easy but, I gues I can not see the
    > forest through the trees. Can any one help to slear this up for me.

  • Just updated I pad 2 and some of my apps are dim and say waiting Is that something that takes a long time or does it mean something didn't work

    Just updated my I pad 2 and some of my apps are dim and say waiting. Is this something that takes a long time or could something be wrong?

    That means they are in the queue to be updated.
    If everything is working it will depend on the speed of your wifi connection as to how long it takes.

  • Hi everybody, we have some hi8 tapes that we wish to put onto our apple. however the hi8 camcorder no longer works! is there a machine that takes the hi8 tapes and plugs into the apple. help!cheers

    hi everybody,
    we have some hi8 tapes that we would like to put onto our computer. however the camcorder no longer works. Does anyone know if there is a machine that takes hi8 tapes which we can plug into our apple? or if there is a way of getting around this problem?
    cheers

    Why not just purchase a used camcorder on eBay?  Another option would be to use a Hi8 to DVD Transfer service such as http://www.memoryhub.com/convert/hi8-to-dvd

  • ABAP program to take input parameter from variant, execute KSB1 and export

    Hi Friends,
    My client asking  change request in CO
    The Change request is "ABAP program to take input parameter from variant, execute KSB1 and export the output into an excel sheet and park the document in a designated location"
    Pls let me know  actually i am a FICO consultant what i can do in this change request
    Thanks,
    Santi

    Hi
    First I dont you would need to create a ABAP to generate the report in Excel.
    You can look at this option. Execute the report Go to->Change Layout, Click on the view option, On the Preferred View Select Microsoft Excel, Save the layout, provide a layout name with /XYZ.
    Now when you want to execute KSB1 with excel, just execute KSB1 with /XYZ layout, it would open in Excel, export to which ever location you want.
    Or just simply save the report as Excel using the Excel button on the tool bar.
    Regards,
    Suraj

  • When I click on anything in the F/fox newsletter that takes me to Google Play, it shows it in French. I have a French ISP but my registered preference is for

    When I click on anything in the F/fox newsletter that takes me to Google Play, it shows it in French. I have a French ISP but my registered preference is for English. What do I do to have Google Play material appear in English ?
    Thanks and regards

    If you are logged in to your Google account, I would expect the page to use your preference set here:
    https://www.google.com/settings/language
    If you are not logged in, Google settings/preferences usually are retained using a cookie. I can't tell which cookie is relevant.
    I noticed a language selector on the support page:
    https://support.google.com/googleplay/?hl=en
    Maybe setting that once will help?

Maybe you are looking for

  • My HP 5610V all-in-one is no longer recognized by any pc as a working equipment.

    My HP Officejet 5610v All-in-One is no longer recognized by any of my pc's.  When I plug it in to another pc it says that the device is not recognized or malfunctioning.  All the local or off line functions of the printer, such as copy and fax is wor

  • Nokia N95 and HBH-DS970 BT headset not working

    Hi, I read on the web and reviews about DS970 working with N95 but for me it pairs fine but when it gets to the connect part it fails. I have the latest firmware version v 10.0.018 (i think). So far i'm impressed by the phone but i REALLY hoped to us

  • Apache can't start.

    I installed apache but it isn't want to start: # /etc/rc.d/httpd stop :: Stopping HTTP Daemon [DONE] [root@myhost ~]# /etc/rc.d/httpd stop :: Stopping HTTP Daemon [DONE] [root@myhost ~]# /etc/rc.d/httpd start :: Starting HTTP Daemon [FAIL] What is th

  • LSMW (SAP-ABAP)

    Hi,     i m wroking on lsmw but no idea abt where i sd write code for particular field. can anyone tell me the solution for it ??? Thx and Regds, bobby

  • Why can't I download adobe flash player on my mac?

    Hi, I tried it many times, to download adobe flash player onto my Mac, and the first two of the process work, however, the third steps fails. I need adobe flash player in order to listen music, and watch videos, and it would be nice if someone could