Sort list of objects and Comparator.
Hi. I have a problem with list sorting. There is a class with fields like these id (Long), number (String), operator (String), server (String) port (Integer). I have to sort list of these objects in accordance with the conditions specified by the user.
Conditions for sorting:
1. In the first account of the full compliance of the server name and port value (Object Gateway) specifed by the user.
2. When the server name is correct and the port is different from the standard, then the objects should be placed in ascending order of the port.
3. If the server name does not match the model, the order of the objects must reflect the declining value of a parameter port. If the list contains objects of the same port and different name, the order does not matter.
How should Comparator looks like?
Ok, this is the solution ;]
public class GatewayComparator implements Comparator<Gateway> {
private String server;
private Integer port;
public GatewayComparator(String server, Integer port){
this.server = server;
this.port = port;
public int compare(Gateway o1, Gateway o2) {
int result = 0;
if (o1.getServer().equals(this.server)) {
result = -1;
if (o2.getServer().equals(this.server)) {
result = 1;
if (o1.getServer().equals(this.server) && o2.getServer().equals(this.server)) {
if (o1.getPort().equals(this.port)) {
result = -1;
if (o2.getPort().equals(this.port)) {
result = 1;
} else if (!o1.getPort().equals(this.port) && !o2.getPort().equals(this.port)) {
result = o1.getPort().compareTo(o2.getPort());
} else if (!o1.getServer().equals(this.server) && !o2.getServer().equals(this.server)) {
if (o1.getPort() > o2.getPort()) {
result = -1;
} else if (o1.getPort() < o2.getPort()) {
result = 1;
} else {
result = 0;
return result;
}
Similar Messages
-
How to extract list of object and formula used in variables as Excel for a particular Webi Report
Hi,
Is it possible to get the list of variables and objects, and variable formula used in a webi report extracted in excel or PDF in BO XI R3.1?
Thanks In Advance,
ShenbuHi Shenbaga,
You can try to get this information using the report engine sdks of BusinessObjects which is specific to webi reports.
Please refer to the link to download the dev guide and api referrence for XI 3.1
SAP BusinessObjects BI 3.x and Lower - Developer SDK Library
Refer to the Report Engine Java SDK dev guide and api referrence.
Go through the dev guide in detail and you would be able to use the report engine sdks as per your needs.
Additional Note: There have been changes in report engine sdks from XI 3.1 to BI 4.0 and you would not be able to get all the features available in XI 3.1 report engine sdks in BI 4.0.
Hope this helps.
Regards,
Chandrahas -
How to extract List of Objects and Classes in BO
Hi
I need to get a list of all Classes and Objects in a universe.
Is there a way to extract this list in an excel.
I dont need the PDF file which can be saved from a universe with all the universe information.
I just need a plain excel file with the classes, objects under it, object definitions etc.
Is there a VBA code to do so?
I know there is one to extract the user info from CMS.
Please help.
Thanks in advance.Option Explicit
Dim DesignerApp As Designer.Application
Dim Univ As Designer.Universe
Dim Wksht As Excel.Worksheet
Sub GetInfo()
Set DesignerApp = New Designer.Application
DesignerApp.Visible = True
Call DesignerApp.LoginAs
Set Univ = DesignerApp.Universes.Open
'DesignerApp.Visible = False
Set Wksht = ThisWorkbook.Worksheets("Objects")
Wksht.Unprotect
Wksht.Columns().ClearContents
Wksht.Cells(1, 1) = "Class"
Wksht.Cells(1, 2) = "Objects"
Wksht.Cells(1, 3) = "Table Reference"
Wksht.Cells(1, 4) = "Object Description"
Wksht.Cells(1, 5) = "Object Type"
Wksht.Cells(1, 6) = "Qualification"
Call GetObjectInfo(Univ.Classes, 1)
Wksht.Protect
DesignerApp.Quit
Set DesignerApp = Nothing
End Sub
Private Sub GetObjectInfo(Clss, RowNum As Long)
Dim Cls As Designer.Class
Dim Obj As Designer.Object
For Each Cls In Clss
For Each Obj In Cls.Objects
RowNum = RowNum + 1
Wksht.Cells(RowNum, 1) = Cls.Name
Wksht.Cells(RowNum, 2) = Obj.Name
Wksht.Cells(RowNum, 3) = Obj.Select
Wksht.Cells(RowNum, 4) = Obj.Description
If Obj.Type = 2 Then
Wksht.Cells(RowNum, 5) = "Character"
ElseIf Obj.Type = 3 Then
Wksht.Cells(RowNum, 5) = "Date"
ElseIf Obj.Type = 1 Then
Wksht.Cells(RowNum, 5) = "Number"
Else
Wksht.Cells(RowNum, 5) = "Long Text"
End If
If Obj.Qualification = dsDimensionObject Then Wksht.Cells(RowNum, 6) = "Dimension"
If Obj.Qualification = dsDetailObject Then Wksht.Cells(RowNum, 6) = "Detail"
If Obj.Qualification = dsMeasureObject Then Wksht.Cells(RowNum, 6) = "Measure"
Next Obj
If Cls.Classes.Count > 0 Then
Call GetObjectInfo(Cls.Classes, RowNum)
End If
Next Cls
End Sub
Above is the macro to document BO universes (Classes, Objects, TableName.FieldName, Object description, Object Type and Object Qualification ).
You need to open the excel sheet->Go to TOOLS> MACRO --->VB EDITOR (Alt+F11) and paste this code in MODULE1
To run the macro, You need to press Alt+F8 key and Click RUN button. Then designer window pops out, enter user id and password and select the required universe.
Enjoy Macro -
SQL to list all objects and its depencies
Hi:
I am trying to come up with a SQL script thatt will list the following:
For all ORACLE objects, list all its dependent objects.
In other words, I would like to get a trre-like output containing info on every object with all the other objects that depend on it.
I found a TOAD option for View->Dependencies
which does what i am looking for but unfortunately it falls short of making the output useful.
When I tried this option on the schema "SYSTEM" this is what I got:
+ SYSTEM.AQ$DEF$_AQCALL
+ SYSTEM.AQ$DEF$_AQERROR
+ SYSTEM.AQ$_DEF$_AQCALL_E
+ SYSTEM.AQ$_DEF$_AQERROR_E
+ SYSTEM.DEF$_AQCALL
+ SYSTEM.DEF$_AQERROR
+ SYSTEM.DEF$_PROPAGATOR_TRIG
+ SYSTEM.ORA$_SYS_REP_AUTH
+ SYSTEM.PRODUCT_PRIVS
+ SYSTEM.REPCATLOGTRIG
That is what I need but the problem is that you have to manually click on the "+" to expand the three. For some reason the chose not to provide an "expand" option. If the tree has , say, 100 lines and each line is on average 3-4 levels deep you can imagine how many click one would have to do.
Thanks for any help in advance.
So far it looks like I would have to look at the following:
OBJ$
USER$
DBA_DEPENDEBCIES
DBA_OBJECTS
in order to get what I need but since I am not familiar with the precise meaning of the columns I cannot get any close results.
Thanks for any help you might provide,
Robert YoungHave a look under your oracle_home directory for a file called utldtree.sql. That might give you what you are after.
Regards,
Steve Rooney -
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);
} -
Userdefined Sorting the objects using comparator
Hi All,
I want to display the objects in a userdefined order. I have placed the code snippet below. Kindly help me on this to resolve this issue.
public class ApplicabilityObject1 implements Comparable{
private String str;
public ApplicabilityObject1(String str) {
this.str = str;
public boolean equals(Object obj) {
return getStr().equals(((ApplicabilityObject1)obj).getStr());
public String toString() {
return str;
public String getStr() {
return str;
public void setStr(String str) {
this.str = str;
public int compareTo(Object arg0) {
final int equal = 0;
final int before = -1;
final int after= 1;
int returnvalues = 0;
System.out.println(this);
if ("Mexico"==((ApplicabilityObject1)arg0).getStr())
returnvalues = -1;
else if (((ApplicabilityObject1)arg0).getStr()== "Canada")
returnvalues = 0;
else if (((ApplicabilityObject1)arg0).getStr()== "USA")
returnvalues = 1;
return returnvalues;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/*import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.collections.comparators.FixedOrderComparator;*/
public class SortOrder {
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
APPComparator app1 = new APPComparator();
ApplicabilityObject1 obj1 = new ApplicabilityObject1("Mexico");
ApplicabilityObject1 obj2 = new ApplicabilityObject1("Canada");
ApplicabilityObject1 obj3 = new ApplicabilityObject1("USA");
ApplicabilityObject1 obj4 = new ApplicabilityObject1("Mexico");
ApplicabilityObject1 obj5 = new ApplicabilityObject1("USA");
ApplicabilityObject1 obj6 = new ApplicabilityObject1("USA");
ApplicabilityObject1 obj7 = new ApplicabilityObject1("Mexico");
ApplicabilityObject1 obj8 = new ApplicabilityObject1("Mexico");
ApplicabilityObject1 obj9 = new ApplicabilityObject1("Canada");
List list = new ArrayList();
list.add(obj1);
list.add(obj2);
list.add(obj3);
list.add(obj4);
list.add(obj5);
list.add(obj6);
list.add(obj7);
list.add(obj8);
list.add(obj9);
Collections.sort(list, app1);
System.err.println(list);
System.out.println(Integer.MAX_VALUE);
class APPComparator implements Comparator
ApplicabilityObject1 appO = new ApplicabilityObject1("USA");
@Override
public int compare(Object arg0, Object arg1) {
// TODO Auto-generated method stub
return ((ApplicabilityObject1)arg0).compareTo(arg1);
}I'm expecting the result in the Order of USA, CANADA, MEXICO.
But now the above code giving the result of [USA, USA, USA, Mexico, Canada, Mexico, Mexico, Mexico, Canada]
Kindly help me to resolve this issue.
Thanks in advance,
MaheswaranAn alternative way to reduce the size of your code.
//Un-Compiled
ApplicabilityObject1[] appObs = {
new ApplicabilityObject1("Mexico"),
new ApplicabilityObject1("Canada"),
new ApplicabilityObject1("USA"),
new ApplicabilityObject1("Mexico"),
new ApplicabilityObject1("USA"),
new ApplicabilityObject1("USA"),
new ApplicabilityObject1("Mexico"),
new ApplicabilityObject1("Mexico"),
new ApplicabilityObject1("Canada")};
List list = new ArrayList(Arrays.asList(appObs));Mel -
Insertion sorts and comparable
HI guys. I need to refresh my memory for these two things, Insertion sorts and comparable.
I don't quite understand what is the different between insertion sorts and selection sorts.
And secondary, comparable. What is it for? How does it work? Here is the sample code. All I see is the use of it to call the compareTo method.
public static void main (Comparable[] objects)
for(int index=1; index < objects.length; index++)
Comparable key = objects[index];
int position = index;
//shift larger values to the right
while (position > 0 && objects[position-1].compareTo(key)>0)
objects[position] = objects[position-1];
position--;
}//end while
objects[] = key;
}//end for
Thanks a lot.HI guys. I need to refresh my memory for these two
things, Insertion sorts and comparable.
I don't quite understand what is the different between
insertion sorts and selection sorts. They are different sorting algorithms.
(As you understand, I don't remember much either :) )
You're probably best off by finding a book about it.
And secondary, comparable. What is it for? How does it
work? Here is the sample code. All I see is the use of
it to call the compareTo method.Comparable is an interface that declares the compareTo-method. By using that general method you can write a general sorting method that are independent on what objects are being sorted and how they are being sorted, as long as they implement Comparable. -
Need Help with Array.sort and compare
Hi
I have a big problem, i try to make a java class, where i can open a file and add new words, and to sort them in a right order
Ok everthing works fine, but i get a problem with lower and upper cases.
So i need a comparator, i tried everything but i just dont understand it.
How do i use this with Array.sort??
I hope someone can help meOkay, you want to ignore case when sorting.
There are two possibilities: Truly ignore case, so that any of the following are possible, and which one you'll actually get is undefined, and may vary depending on, say, which order the words are entered in the first place:
English english German german
english English german German
English english german German
english English German german
The second possibility is that you do consider case, but it's of lower priority--it's only considered if the letters are the same. This allows only the first two orderings above.
Either way, you need to write a comparator, and call an Arrays.sort method that takes both array and Comparator.
The first situation is simpler. Just get an all upper or lower case copy of the strings, and then compare thosepublic int compare(Object o1, Object o2) {
String s1 = ((String)o1).toUpper();
String s2 = ((String)o1).toUpper();
return s1.compareTo(s2);
} You'll need to add your own null check if you need one.
For the second way, your comparator will need to iterate over each pair of characters. If the characters are equal, ignoring case, then you compare them based on case. You pick whether upper is greater or less than lower.
Of course, the need to do this assumes that such a method doesn't alrady exist. I don't know of one, but I haven't looked. -
List of obsolete objects and tables
Hi,
Can anyone give the list of obsolete objects and tables from 4.6c to ECC 6.0 upgrade. Also other upgrade issues and solutions faced for ECC 6.0 upgrade.
Thanks in advance.You may have an overview wirth Solution Browser tool (at the solution point of view) in order to compare functionality between your current system and the ERP 2005.
at:
http://solutionbrowser.erp.sap.fmpmedia.com/
You can get the detailed release information from the following link.
http://service.sap.com/releasenotes.
A release note is a brief explanation of new features or changes to the system since the last software release. A release note typically describes a new function or an existing function that has been enhanced or changed.
I hope this helps.
Reward Points If helpful
Regards
Nilesh -
Hi,
I have a MBP 13' Late 2011 and Yosemite 10.10.2 (14C1514).
Until yesterday, I was using Garmin ConnectIQ SDK and all was working fine.
Yesterday, I've updated my system with latest security updates and Xcode updates too (Version 6.2 (6C131e)).
Since, I can't launch the ConnectIQ simulator app, I have this message in console :
8/04/2015 15:19:04,103 mds[38]: There was an error parsing the Info.plist for the bundle at URL Info.plist -- file:///Volumes/Leto/connectiq-sdk-mac-1.1.0_2/ios/ConnectIQ.bundle/
The data couldn’t be read because it isn’t in the correct format.
<CFBasicHash 0x7fa64f44e9a0 [0x7fff7dfc7cf0]>{type = immutable dict, count = 2,
entries =>
0 : <CFString 0x7fff7df92580 [0x7fff7dfc7cf0]>{contents = "NSDebugDescription"} = <CFString 0x7fa64f44f0a0 [0x7fff7dfc7cf0]>{contents = "Unexpected character b at line 1"}
1 : <CFString 0x7fff7df9f5e0 [0x7fff7dfc7cf0]>{contents = "kCFPropertyListOldStyleParsingError"} = Error Domain=NSCocoaErrorDomain Code=3840 "The data couldn’t be read because it isn’t in the correct format." (Conversion of string failed.) UserInfo=0x7fa64f44eda0 {NSDebugDescription=Conversion of string failed.}
I have looked at this file and it looks like a binary plist
bplist00ß^P^V^A^B^C^D^E^F^G^H
^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_ !"$%&'()'+,^[\CFBundleNameWDTXcodeYDTSDKName_^P^XNSHumanReadableCopyrightZDTSDKBuild_^P^YCFBundleDevelopmentRegion_^P^OCFBundleVersi on_^P^SBuildMachineOSBuild^DTPlatformName_^P^SCFBundlePackageType_^P^ZCFBundleShortVersionString_^P^ZCFBundleSupportedPlatforms_^P^]CFBundleInfoDictionaryVersion_^P^RCFBundleE xecutableZDTCompiler_^P^PMinimumOSVersion_^P^RCFBundleIdentifier^UIDeviceFamily_^P^QDTPlatformVersion\DTXcodeBuild_^P^QCFBundleSignature_^P^ODTPlatformBuildYConnectIQT0611[iph oneos8.1o^P-^@C^@o^@p^@y^@r^@i^@g^@h^@t^@ ^@©^@ ^@2^@0^@1^@5^@ ^@G^@a^@r^@m^@i^@n^@.^@ ^@A^@l^@l^@ ^@r^@i^@g^@h^@t^@s^@ ^@r^@e^@s^@e^@r^@v^@e^@d^@.V12B411RenQ1V14C109Xiphoneos TBNDLS1.0¡#XiPhoneOSS6.0YConnectIQ_^P"com.apple.compilers.llvm.clang.1_0S8.1_^P^Tcom.garmin.ConnectIQ¡*^P^AW6A2008aT????^@^H^@7^@D^@L^@V^@q^@|^@<98>^@ª^@À^@Ï^@å^A^B^A^_^A?^AT^ A_^Ar^A<87>^A<96>^Aª^A·^AË^AÝ^Aç^Aì^Aø^BU^B\^B_^Ba^Bh^Bq^Bv^Bz^B|^B<85>^B<89>^B<93>^B¸^B¼^BÓ^BÕ^B×^Bß^@^@^@^@^@^@^B^A^@^@^@^@^@^@^@-^@^@^@^@^@^@^@^@^@^@^@^@^@^@^Bä
I guess it is a normal format but my system seems to be unable to read binary plist ?
I tried some stuff with plutil
plutil -lint Info.plist
Info.plist: Unexpected character b at line 1
Same for convert
plutil -convert xml1 Info.plist
Info.plist: Property List error: Unexpected character b at line 1 / JSON error: JSON text did not start with array or object and option to allow fragments not set.
I also try to download a fresh version of the connectIQ SDK and no changes.
Any idea ?
ThanksStep by step, how did you arrive at seeing this agreement?
-
Problem sorting list with virtual layout = false (and also with true)
Hi,
I've a problem sorting a list... or better... I've a problem showing the sorted list ;-)
I've a list of xml item. The list is shown with an item renderer.
my needs: a button to refresh data and a button to sort data.
useVirtualLayout = false
-> refresh works correctly, sort does not affect the view (even if the list is sorted correctly when printed with trace)
useVirtualLayout = true
-> sort works correctly, refresh reverse the list each time I press it (even if the list remain the same when printed with trace)
does any one have an idea?
thank you!!
MXML
<s:List dataProvider="{xmlListCollection}" width="100%" itemRenderer="myRenderer" minHeight="0" id="test" useVirtualLayout="false" >
<s:layout>
<s:VerticalLayout clipAndEnableScrolling="true"/>
</s:layout>
</s:List>
XML example
<unit sortField1="First Floor" sortField2="7">
<employee>
<id>3040684</id>
<name>PIFFARETTI Vasco</name>
<birthdate>20.05.1983</birthdate>
<beginDate>2012-02-25 08:55:00</beginDate>
<endDate>9999-12-31 00:00:00</endDate>
<annotation/>
</employee>
</unit>You can tell when the scroll position has changed by handling the propertyChange event coming from the DataGroup:
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
creationComplete="list1.dataGroup.addEventListener('propertyChange', handle)">
<fx:Script>
<![CDATA[
import mx.events.PropertyChangeEvent;
private function handle(e:PropertyChangeEvent):void {
if (e.property == 'verticalScrollPosition'){
trace('vsp changed');
if (e.property == 'horizontalScrollPosition'){
trace('hsp changed');
]]>
</fx:Script>
<s:List id="list1" width="100" height="50">
<s:layout>
<s:VerticalLayout />
</s:layout>
<s:dataProvider>
<s:ArrayList>
<fx:String>0</fx:String>
<fx:String>1</fx:String>
<fx:String>2</fx:String>
<fx:String>3</fx:String>
<fx:String>4</fx:String>
<fx:String>5</fx:String>
<fx:String>6</fx:String>
<fx:String>7</fx:String>
</s:ArrayList>
</s:dataProvider>
</s:List>
</s:Application>
You might also want to read and consider voting for http://bugs.adobe.com/jira/browse/SDK-21357 -
Revision: 7916
Author: [email protected]
Date: 2009-06-17 09:04:51 -0700 (Wed, 17 Jun 2009)
Log Message:
Last of the List PARB changes - selectedItems is now a Vector of Objects and selectedIndices is a Vector of Numbers.
Also, put alphabetized spark-manifest correctly after my last checkin.
QA: Yes
Doc: Yes
Checkintests: Pass
Modified Paths:
flex/sdk/trunk/frameworks/projects/flex4/src/spark/components/List.as
flex/sdk/trunk/frameworks/spark-manifest.xmlGordon, it looks like its been a while since you made this post. Not sure how valid it is now... I am particularly interested in the LigatureLevel.NONE value. It seems that it is no longer supported.
How do I turn of ligatures in the font rendering?
My flex project involves trying to match the font rendering of Apache's Batik rendering of SVG and ligatures have been turned off in that codebase. Is there any way (even roundabout) to turn ligatures off in flash?
Thanks,
Om -
Thru OEM get list of queries and their schemas that accessed my objects
Hi,
I have a list of objects on my schema and i need to track the list of sql queries by different users that accessed by object during this time period.
i haven't enabled any auditing yet.
is there any way i can get that list of queries and their schemas that accessed those particular objects during a particular time period through OEM.
Can someone guide me please.
Thanks in advance.
Philip.create a name property in your class and assign a name property to your instances (either in the contructor) and/or using getters/setters. (you'll need a getter anyway.)
-
Cheat Sheet/Listing of Object types and transactions they are available in?
Does anyone know how to obtain a listing of the standard object types and where they would be available?
We have already worked with the Travel Management Trip Docuemnts and I know that object type BUS2089 is available through the Object for Services area of transaction PR05. So we store entries in the TOA01 table for this object and they are available to us in the object services section.
But now we want to leverage the functionality we built and extend it to other areas. But I spent a lot of time today trying to find out what object could be used through transaction IE03 for an equipment record and finally found EQUI. Now I just have to test it out.
I see a lot of standard document types available as well and don't know what they are for - for Plant Maintenance work order notifications object type BUS2038 is there with PMONOTFPAP, PMIDAMAGE and PMIREQUEST already available. I didn't want to create a new one if these are available for work order notification images, etc.
It would be nice if there was a spreadsheet or listing that detailed each object type and where it was used in the system.
(I did try searching but didn't find this question/answer on a broad basis.)Tarun,
Thanks for replying. I think that we are agreeing on the same details, but it doesn't really answer my question.
I guess what I am looking for is if I asked the following question:
What object type is used when populating the object services link from within an equipment record via IE03?
How would you obtain the answer to this question - besides just knowing it?
It's the same way that I know the following:
What object type is used when populating the object services link from within a trip via PR05? --> BUS2089
What object type is used when populating the object services link from within a work order via IW33? --> BUS2007
What object type is used when populating the object services link from within a wo notification via IW23? --> BUS2038
The last two were easy because it prompts you when creating an attachment. The first one someone told me the answer to.
We will be doing image links for many different documents (invoices, journal entries, HR employee records, etc) and I'm just trying to figure out how to know which objects to use. Once I know the object I know how to configure the OAC* tables for use.
Any help is much appreciated.
Thanks! -
How to compare 2 Objects( and )?
Should I write an interface?
Java has 2 interfaces that would be of interest to you.
They both are designed to return an integer that describes the relationship between two objects.
Suppose you have two objects: objectA and objectB
The return value is as following:
if (returnValue < 0) then objectA precedes objectB. (A < B)
if (returnValue > 0) then objectA follows objectB. (A > B)
if (returnValue == 0) then objectA and objectB are equivalent (A == B).
It is up to you to do the comparing and determine which is the correct return value...
Here are the two interfaces:
1) Comparable interface (java.lang.Comparable)
You would use this interface when you have a class that exhibits some natural order..
You add this interface to the class, and, within the class, implement the following method:
public int compareTo( Object obj )
The variable obj in this case refers to the "other" object that you want to compare.
public class MyClass implements Comparable // <--- notice the last two words!!
other methods.
public boolean isTallerThan( MyClass mc )
// just some method i made up to compare...
public int compareTo( Object objectB )
// You are comparing "this" object with the "otherObject"...
// Note that objectA is "this".
MyClass otherObject = (MyClass)objectB;
// Do whatever you need to compare the two.
if (this.isTallerThan(otherObject) )
return -1;
else if ( otherObject.isTallerThan(this) )
return +1;
else
return 0; // they are of equal height...whatever...
2) Comparator interface (java.util.Comparator)
You could use this interface if you have a different set of standards with which to compare two different objects. Usually, it is it's own class, designed for only this purpose. You implement the following method:
public int compare( Object objA, Object objB )
Notice that in this case you have to explicitly pass in both objects to be compared, whereas in the Comparable interface, objA is implicitly assumed to be the object on which the method is called (or as I like to call it, this).
Here is an example:
public class MyComparator implements Comparator
public int compare( Object objA, Object objB )
do whatever comparisons you need to determine whether
objA < objB (-1 is returned)
objA > objB (+1 is returned)
or
objA == ObjB (0 is returned)
Maybe you are looking for
-
Keynote and/or Powerpoint content in Final Cut Pro
Hope this is not a stupid question but if it is please excuse me, I'm rather new to FCP. My colleague wants to produce some webcasts of his business presentations. Normally he uses Powerpoint to illustrate his talks. Is it possible to somehow take th
-
How to create Two Week View of Calendar in Sharepoint 2010.
There is an option of Week View when i am using Calendar web part, it is showing 1 week view. I want to create Two(2) week view of Calendar. How can i create Two week view of Calendar. Please Help. Thanks.
-
Wondering if anyone has had a simlar problem. HH5 installed 16th July all went ok until two days ago, Then at some point overnight the internal power supply failed, Ie no light on the router. Contacted the technical department went through a number o
-
Trial to Full version of FCP X
Am upgrading from trial FCP X to paid version. Will I loose my work in trial version? I downloaded trial via australian account but will be using my italian account to purchase. HELP!!
-
Internet Explorer 5.1 Needs to be replaced?
Greetings all. As of late my Internet Explorer 5.1 has gotten more and more squirelly. More and more pages will not load, either I get a message the URL is not found, or IE hangs and I have to force quit. I have tried clearing cache, erasing cookies,