Implement Comparable with multiple arguments
Is there a way of implementing Comparable<> with multiple different arguments to the Comparable generics?
For example:
public class Foo<K, V> implements Comparable<K>,
Comparable<V>
}The compiler complains with the error: "The interface Comparable cannot be implemented more than once with different arguments: Comparable<K> and Comparable<V>"
Clearly, this cannot be done exactly like this, so I'm wondering if there is a different way of accomplishing the same functionality.
Edited by: mgolowka on Apr 24, 2008 12:22 PM
I'm working on creating a generic binary search tree. Currently I have this:
public class BinarySearchTree<T extends Comparable<T>> implements Collection<T>
}With the add() function, I can simply do add(T) that will use T's compareTo(T) method to find its place in the tree, however with the remove() and get() functions that I want to have would require an input of T, which isn't what I'm entirely looking for. I could change this to have a key/value pair so it's functionality is like a set, but I'm not sure if that's the best course of action. I could make it implement Map<K, V> to get that functionality...
There is no time limit on this project as it is a part of a personal project.
Similar Messages
-
Implementing Comparable for multiple types
I am currently refactoring some legacy code to make use of Java 5's generics, and I ran into a problem.
Foo extends Parent and implements Comparable. Bar is a sibling of Foo and does not implement Comparable. Now, in the legacy code, Foo is Comparable to both Foo and Bar, and in order to use generics, I have to specify a single class or use wild cards with "extends". I know I could resolve this problem by using <? extends Parent>, but I am reluctant to do this, because Foo and Bar also have about 30 other siblings.
Is there anyway that I can use generics and only let the two classes, Foo and Bar be Comparable to Foo?I quite don't get what the legacy code does. If Bar does not implement comparable, how is Foo comparable to Bar? I think, this quite violates the rules for implementing Comparable.
You don't have to implement an additional class, though, but might work with an interface, which both Foo and Bar implement and which extends Comparable on the interface.
Maybe I should give an abstract example on my confusing statement. :)
interface FooBar extends Comparable<FooBar> { ...}
class Foo implements FooBar { ... }
class Bar implements FooBar { ... } -
Cfexecute with multiple arguments
Hello,
I'm trying to encrypt a file with CFEXECUTE, using OpenSSL. When I run the code in the command prompt, it works fine and the new encrypted file appears in the correct folder. Also, I can run CFEXECUTE with OpenSSL with just one argument and it works fine. ie arguments="version". But the following does not return a value, nor does it create the new folder:
<cfexecute name = "C:\Program Files (x86)\GnuWin32\bin\openssl"
arguments = "aes-256-cbc -a -salt -in ""C:\Users\Dev2\Documents\My Stuff\OpenSSL\secrets.txt"" -out ""C:\Users\Dev2\Documents\My Stuff\OpenSSL\secrets2.txt"""
variable = "result"
timeout = "5">
</cfexecute>
<cfdump var="#result#">
Any ideas?
PeteBYW,
This runs fine:
<cfexecute name = "C:\Program Files (x86)\GnuWin32\bin\openssl"
arguments = "list-standard-commands"
variable = "result"
timeout = "5">
</cfexecute>
<cfdump var="#result#">
and so does this:
<cfexecute name = "C:\Program Files (x86)\GnuWin32\bin\openssl"
arguments = "version"
variable = "result"
timeout = "5">
</cfexecute>
<cfdump var="#result#">
Maybe someone has a multiple argument example of CFEXECUTE that runs fine.
I'd be interested to know.
Pete -
Event Handlers which trigger functions with multiple arguments
I am playing two video clips back to back. I have a few
things which I need to do in between clips, so what I am doing for
each is adding a handler for VideoEvent.COMPLETE, at which time i
want to call a function which takes multiple arguments, like this:
video.addEventListener(VideoEvent.COMPLETE,
myFunction("1","2","3"));
private function myFunction(var1:String, var2:String,
var3:String):void
video.removeEventListeners(VideoEvent.COMPLETE, myFunction);
I've already figured out that getting rid of event handlers
that trigger anonymous functions is impossible. Please don't tell
me that it's impossible to remove them if functions require more
than 0 arguments..."muskiemania" <[email protected]> wrote in
message
news:gc0pk0$jfb$[email protected]..
>I am playing two video clips back to back. I have a few
things which I need
>to
> do in between clips, so what I am doing for each is
adding a handler for
> VideoEvent.COMPLETE, at which time i want to call a
function which takes
> multiple arguments, like this:
>
> video.addEventListener(VideoEvent.COMPLETE,
myFunction("1","2","3"));
>
> private function myFunction(var1:String, var2:String,
var3:String):void
> {
> video.removeEventListeners(VideoEvent.COMPLETE,
myFunction);
> }
>
> I've already figured out that getting rid of event
handlers that trigger
> anonymous functions is impossible. Please don't tell me
that it's
> impossible to
> remove them if functions require more than 0
arguments...
Any function that you add via addEventListener should expect
exactly ONE
argument, the event. And 99.958% of the time, you can take
that event
object and figure out exactly what you need to know.
HTH;
Amy -
Implementing Comparable with Generics
Hi,
I would like to implement a generic class containing two elements that would be sorted according to the second element. I get a compilation error on the last line of the code.
public class Pair <T , U> implements Comparable
private final T first;
private final U second;
public Pair( T f, U s )
this.first = f;
this.second = s;
public Pair () {
this.first = null;
this.second = null;
public T getFirst()
return first;
public U getSecond()
return second;
@Override
public int compareTo(Object oth) {
if ( this == oth ) {
return 0;
if ( oth == null ) {
throw new NullPointerException();
if(!(getClass().isInstance( oth ))) {
throw new IllegalArgumentException();
Pair<T, U> other = this.getClass().cast( oth );
if(this.getSecond() == other.getSecond()) {
return 0;
else {
//The following line does not compile
return (this.getSecond() > other.getSecond()) ? 1 : -1;
}How do I ensure that the second object U implements the comparable interface. If I do something like
public class Pair <T , U implements Comparable> implements Comparableit does not compile?
Thank you for your ideas.
O.O.edit: scratch that
How about:
public class Pair <T , U extends Comparable<U>> implements Comparable<Pair<T, U>>
public int compareTo(Pair<T, U> oth) {
else {
return (this.getSecond().compareTo(other.getSecond()));
}Edited by: Encephalopathic on Jul 11, 2008 5:23 PM -
Call apt with multiple arguments
Is it possible to call apt inside a java class and pass multiple .class files?
For example:
String[] args = new String[5];
args[0] = "-nowarn";
args[1] = "-XclassesAsDecls";
args[2] = "-classpath";
args[3] = System.getProperty("java.class.path");
args[4] = "packageName.FirstClass packageName.SecondClass";
return Main.process(new MyAnnotationProcessorFactory(),args);Result of the above example is:
error: Could not find class file for packageName.FirstClass packageName.SecondClass
1 errorThe class path contains classes that we need.
This example works:
String[] args = new String[6];
args[0] = "-nowarn";
args[1] = "-XclassesAsDecls";
args[2] = "-classpath";
args[3] = System.getProperty("java.class.path");
args[4] = "packageName.FirstClass";
args[5] = "packageName.SecondClass";
return Main.process(new IapiAnnotationProcessorFactory(),args);I replaced args[4] = "packageName.FirstClass packageName.SecondClass"; with a
args[4] = "packageName.FirstClass";
args[5] = "packageName.SecondClass"; -
Applescript with multiple arguments
AFAIK, Terminal.app does not accept arguments. So, I need for AppleScript to accept some arguments, then open Terminal to run them. Something like this:
tell application "Terminal"
activate
set shell to do script arg1 arg2 arg3 in window 1
end tell
All I've been able to accomplish is:
tell application "Terminal"
activate
set shell to do script arg1 in window 1
end tell
Help please?OK I have no idea how anyone is posting code now with this new ASC software but I can;t get it to work no matter what I do.
If I make two changes to your code I get the following output in the Terminal window, which seems to be what you want.
Last login: Thu Jul 3 07:59:35 on console
LIBMACLAPcaggiano ~ %
LIBMACLAPcaggiano ~ % /Applications/adbFire/adb -s 192.168.1.196 shell
zsh: no such file or directory: /Applications/adbFire/adb
LIBMACLAPcaggiano ~ %
The changes were (for testing)
set daddr to "192.168.1.196"
hardcoding in the ip address rather then getting it setting it from argv. I'm a bit confused you show a run handler, how is the script being called?
And second
set shell to do script "/Applications/adbFire/adb -s" & space & daddr & space & " shell" in window 1
adding the -s right to the program string.
One last thing I run zsh not sure if that has any bearing here.
I suppose a screen shot is better then nothing
Actually you can pair down the command to
set shell to do script "/Applications/adbFire/adb -s " & daddr & " shell" in window 1
no real need for the & space in there -
How to implement Om with multiple companycodes for multiple countries?
can anyone help me.
I think your question is not sufficient, give some more information so as to help you...
Simply, start creating org-units Country wise and Join the org-units with appropriate relationship.
If there are too many objects, then try using LSMW method and upload.
Experts, please correct if am wrong. -
JNI callback funtion with multiple arguments
Hi,
Is it possible to return more than one argument in java callback function.
for single arg return, I am using below function in my C code.
jmethodID mid = (*env)->GetMethodID(env, cls, "callback", "(I)V");
(*env)->CallVoidMethod(env, obj, mid, depth);
what are the changes require to return more than one arg?
Thanks in Advance
AshwaniIs it possible to return more than one argument in java callback function.Of course. A 'callback function' is just a method like any other.
what are the changes require to return more than one arg?1. Adjust the method declaration in the class you are calling.
2. Compile the class.
3. Run javap -s to see the new signature.
4. Adjust the signature in GetMethod() accordingly in your code.
5. Adjust the CallVoidMethod() call to pass the necessary parameters. -
Hi Crystal gurus.
I'm having the report which consist of more that 500 rows , so therefore I decided to implement "Format with multiple rows" feature, which is available in Section Expert area. Everything is just fine, I'm getting multiple columns, but how to suppress the header which is not needed for the last page, because the records are only in the first column.
I can easily copy/paste the header as such, but I do not know how to suppress it. Tried to search here, but found nothing.
Many thanks in advance McmerphyIf it truely is the last page of the report, you could try a conditional suppression where pagenumber = totalpagecount. But this would always suppress the header selected for suppression, and if you should get another column on the last page, it will still suppress.
Debi -
Examples/Demos of APEX applications with Master with Multiple Details.
Trying to get my head round the way to best method/approach to present / allow a user to select / maintain a Master table and then maintain multiple Detail tables that are for the current Master. Typically in my Forms days I would have used tab canvases as placeholders for maintaining the related individual detail table rows. But in the APEX world tabs are used as top level page navigational items. Are there any demos, tutorials or articles on how to implement Master with multiple Details using simple APEX pages with minimal bespoke HTML and Javascript intervention.
Hi Leo,
I have been trying for the similar example (Master with multiple details) for long time.
But i did not get the solution. Can you please share the solution to my emaid address [email protected]
Thanks in advance.
Sutha -
How can I compare single value with multiple value...
Hello,
I want to compare one value with multiple values, how can it possible ?
Here in attachment I tried to design same logic but I got problem that when I entered value in y that is compared with only minimum value of x, I don't want that I want to compare y value with all the x value and then if y is less then x while loop should be stop.
I want to do so because in my program some time I didn't get result what I want, for example x values is 4,5,6,7,8 and y value is suppose 6 then while loop should be stop but here it consider only minimum number and its 4 here so while loop is not stop even y is less then 7 and 8. So I want to compare y value with all the entered values of x and if y is less then any of x values then while loop should be stop and led should be ON.
Please guide me how can I do so.....
Solved!
Go to Solution.
Attachments:
COMPARISON.vi 8 KBAnkitRamani wrote:
Thank you very mach for your help..
may be i have solved this ....i have made one change in my vi that instead of min. i select max and max. value is compare with the value of y and then if y is less then the max. while loop will be stop other wise its run continuously.
this is working fine...
any ways thanks again for your help and time...
I have to agree with Lewis - his way is more efficient.
Bill
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all. -
Compare date with implements Comparator
I have a DefaultListModel (mode) staffed with EMPL (id, name, startingDate). I would like to sort the defaultListModel accourding to the dob. for this I do the following:
Object[] contents = model.toArray();
Arrays.sort(contents, new ComparatorDate());
model.copyInto(contents);the comparator: ComparatorDate
public class ComparatorDate implements Comparator
public int compare(Object o1, Object o2)
Empl a = (Empl ) o1;
Empl b = (Empl ) o2;
Date d1 = a.getStartDate();
Date d2 = b.getStartDate();
return (d1.getDate()-d2.getDate());
}when debugging I realize the dates are diff but the d1.getDate()=1 and d2.getDate()=1 ??? how come? the result are not what expected.
any idea?getDate() tells you the day of the month. Both your dates are apparently on the first of some month. Since Date implements Comparable, why not just do return d1.compareTo(d2)
-
NamedQuery problem- single argument compared to multiple columns
Hello,
I'm not sure if this issue is a bug or if I'm misinterpreting the API. I'm trying to execute a text search query against multiple columns in the same table via EJB 3.0, e.g.
select object(o) from Location o where o.city LIKE :searchString OR o.county LIKE :searchString"So, a single text argument is compared to multiple fields- but I keep getting an exception that the number of supplied arguments (one) does not match the number of required arguments (one- even though it's ID is referenced twice). Is there a separate syntax for repeating arguments in EQL (EJB 3.0, JDeveloper 10.1.3)? Is it not supported?
I get around the issue by just specifying a Query at runtime, but I'd prefer --if possible-- to create a NamedQuery instead.
Any help would be appreciated. Take care.Should the EJBQL statement be
select object(o) from Location o where o.city LIKE :?1 OR o.county LIKE :?2 -
Hi there
I have read a few BC forum articles on this subject, but none seem to have clarified whether a drop shipping eCommerce solution with MULTIPLE suppliers can truly be implemented successfully in BC.
In particluar, my concern is with splitting up ONE online order with products from MULTIPLE suppliers ... and split up the order into its individual supplier components and thereby calculate freight costs for each of the suppliers i.e. the freight cost should really be calculated for each of the suppliers SEPERATELY and not for the order as a whole.
Forum post http://forums.adobe.com/message/4881302#4881302 addresses this issue and Liam Dilley [as always] kindly responded. But his response indicates this is not possible with BC.
If this is the case, drop shipping in BC is quite useless unless:
1. you had only one supplier
2. or, you somehow restricted each order placed to products from only one supplier - which I am unsure is even possible even with JQuery
Any feedback from the community would be most appreciated.
Regards
GavinYou have two requirements:
1. Once ordered, split the order into suppliers, contact the supplier of the product, give the information of the order to the customer. Supplier ships it. This could be done manually but a pain in the ***. I would assume you want it automated.
2. When ordering, multiple products require mutliple shipping rates. As the shipping from location could be different for each product you can't just use the ship from one location option.
Solutions:
1. This is the easier one, you record the supplier in the product via a form or in the product item itself. If you wanted to automate here you could via API, if you wanted to do it manually you also could.
2. Shipping calulator, to make things easier you would have to do everything by weight. Use Javascript to remove the default shipping option on the checkout page, pass all the items in the shopping cart. Use a lookup table function in Javascript "item name to weight" then have another function item to (from) shipping location. Work out the shipping and display it and force change with Javascript BC's shipping price (so the customer pays the correct amount).
Like Liam says, it's not something BC does too well at the moment and the above solution is more of a workaround but does work.
Maybe you are looking for
-
How can I get from what I have ti what I want. I am a new Apple user and appreciate detailed instructions. Thank You
-
AFS Inventory Management in BI
HI All Can anyone provide me material step by step process for AFS Inventory Management in BI? Praveen
-
ABAP User Roles and Query for accessing particular T- codes and Reports
dear Gurus I have one problem, i want to know about ABAP User Query ,i have one requirement my user wants to Lock all the HR Std versus Customized reports in T- code SQ01,other department peoples also see the Payslips and Hr personal reports which is
-
Large number of http posts navigating between forms
Hi, i'm not really a forms person (well not since v3/4 running character mode on a mainframe!), so please be patient if I'm not providing the most useful information. An oracle forms 10 system that I have fallen into supporting has to me very poor pe
-
Hi All, I have a table with 2 columns, let say ID as Int and TimeField as Varchar(8) ID TimeField 1 1:15 2 8:45 3 12:30 4 10:00 5 8:30 I want leading 0 to be added before the timefield for the Id's=1,2 and 5 My output should loo