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)

Similar Messages

  • How to compare date and time together

    Hi,
    How to compare Date and Time together?
    For example in a database table there are two fields rundate and runtime.  I want to compare these two with perticular date and time in the program.  Like, I want to pull all the records where the records's date and time are less than a perticular date and time in the program.
    Hope the question is clear...
    Thanks.
    Kavita

    Hi Kavita
    There is no as such Date and Time Comparision FM in Standard SAP  But You can define your own like this
    <b>FUNCTION ZAV4_COMPAREDATETIME.
    ""Lokale Schnittstelle:
    *"  IMPORTING
    *"     REFERENCE(DATE1) TYPE  DATS
    *"     REFERENCE(TIME1) TYPE  TIMS
    *"     REFERENCE(DATE2) TYPE  DATS
    *"     REFERENCE(TIME2) TYPE  TIMS
    *"  EXPORTING
    *"     VALUE(TWOISMORETOPICAL) TYPE  C
      twoismoretopical = ''.
      if date2 > date1.
        twoismoretopical = 'X'.
      else.
         if date2 = date1 and time2 > time1.
           twoismoretopical = 'X'.
         endif.
      endif.
    ENDFUNCTION.</b>
    Regards
    Mithlesh

  • How to compare char and numc in select query

    Hi  Experts,
    I am using For all entries  to combine two tables.
    I want to fetch the data from these tables.
    The field in one table char, and in another the field is numc.
    1st Query from table BDCP2  and get the tabkey value is like (2000000000000000000086200000000000000000000)
    2nd query     For all entries found,
    query table ESTMJ with the following parameter.
         ESTMJ-RECN = BDCP2-TABKEY+3(20)
    1.TABKEY         CHAR     254
    2.RECN         NUMC     20     
    How to compare these two ?
    Regards,
    Bindhu Priya.

    for  two fields numc & char , please check out their Conversion routine in their respective Database table.
    1st in SE11-> enter table names in different sessions. and check out the data domain used by this fields
    In their respective domains of fields, click on tab 'DEFINITIONS', then check out the conversion routines in Output Characteristics of the Data Domain of field
    From my point of view, both the Conversion routines should be the same.
    If Conversion Routines are not there, then insert suitable Conversion routine for both the fields domain
    For help for for conversion routines:
    conversion routine
    http://help.sap.com/saphelp_46c/helpdata/en/cf/21ee19446011d189700000e8322d00/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/35/26b217afab52b9e10000009b38f974/content.htm
    http://abaplovers.blogspot.com/2008/03/conversion-routines-in-sap.html
    hope this solution could solve your issue..
    <begging removed by moderator>
    Gaur Mayank
    Edited by: Gaur Mayank on Nov 5, 2011 10:40 AM
    Edited by: Thomas Zloch on Nov 6, 2011 3:59 PM

  • How to compare objects between systems

    Hi,
    At the moment I am busy activating business content in BW for an SAP IS-U project. Here I encounter the following problem:
    In the past others have been activating business content objects and they have assigned a developer class to it. Then they decided they did not need those objects and they deleted their transports.
    Now when I want to transport objects to the acceptance environment quite often transports fail due to missing objects (which have never been transported). The automated activation does not include these dependent objects, as it thinks they are already available.
    Is there a way to compare two systems to see which objects are missing and need transporting (without sifting through each InfoObject/transfer rule etc by hand to check its existence)?
    Preferrably I would like to know table names so I can compare SE16 lists, but other suggestions are also more than welcome.
    Otherwise an easy way to see the technical names of those objects so that I can add them manually to a transport request?
    Thank you very much,
    Crispian

    Hi Crispian,
    Welcome to SDN!!
    You can use the following tables for comparing:
    RSDIOBJ - For info-objects
    RSDCUBE - For Cubes
    RSDAREA - InfoAreas
    RSDCHA - Characteristic Catalog
    RSDCUBEIOBJ - Objects per InfoCube (where-used list)
    RSDIOBC - InfoObject catalogs
    RSDIOBCIOBJ - InfoObjects in InfoObject catalogs
    RSDKYF - Key figures
    RSIS - InfoSource (transaction data)
    RSTSRULES - Transfer structure transfer rules
    RSDODSO - ODS
    Hope this helps.
    Bye
    Dinesh
    <i>Assigning point to the helpful answers is the way of saying thanks in SDN. you can assign points by clicking on the appropriate radio button displayed next to the answers for your question. yellow for 2, green for 6 points(2)and blue for 10 points and to close the question and marked as problem solved. closing the threads which has a solution will help the members to deal with open issues with out wasting time on problems which has a solution and also to the people who encounter the same porblem in future. This is just to give you information as you are a new user.</i>
    Message was edited by: Dinesh Lalchand

  • How to find objects and classes

    hi
    any notes or path on objects and classes on crm?

    Hi Kumara
    I beleive your talking about the Classification system.
    To get to this go here: SPRO->IMG->Cross-Application Components - -> Classification System - -> Classes - -> Maintain Object Keys
    This will give a list of Tables which are currently set with Object Keys, you may need to add a new table and configure.
    Next
    To get to this go here: SPRO->IMG->Cross-Application Components - -> Classification System - -> Classes - -> Maintain Object Types and Class Types
    Here you assign a Class Type to Link your Table from the previous step, this class new Class Type will be used with a New Class to created in the following steps.
    Goto Transaction CT04 - Create Characteristics
    Here you create effectively attributes of a Class (Fields)
    Goto Transaction CL01 - Create New Class
                              or CL02 - Maintain Class
    Create a new class linked to your Class Type from previous steps
    On the Char.. Tab you can add the new Characteristics created in the previous step to your new Class.
    Based on the Object Key from the first step, these new attributes shoulds all now link together. If the key is of type 'RAW'  (Binary) it may not be possible to link correctly, therefore some ABAP maybe required to create the link, depending on your application.
    Hope this helps.
    <b>Reward with points if useful.</b>
    Regards
    Arden

  • How to Compare day and night based on current time

    Hi,
    Day starts 08:00 -18:00(start time-end time)
    Night starts 18:00-08:00(st-et)
    for day it's easy I compare current time between st and et in logs table.
    for night if I use the same the process it falls after midnight coz current time is not in between st and et. 
    Example : 00:00 between 18:00 and 08:00.
    To over come above I stared comparing with datetime.
    for day it's fine.
    for night , it inserts one log at 18:00 and updates till 23:59, after 00:00 it's not updating and adds new record then problem starts.
    can anyone give me some idea how to handle this please?
    Cheers :)

    create table #t (st time, et time)
    insert into #t values ('08:00','18:00')
    insert into #t values ('18:00','08:00')
    declare @time time='00:00';
    select st, et from #t
    where case when @time='00:00' then '23:59'
    else @time end >st and et< st
    or @time between st and et
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to slice object and stroke with knife tool?

    I am trying to slice an object into 2 pieces using the knife tool. The problem is that both cut pieces retain a complete stroke outlining the object rather than a cut stroke. How do I slice the object in half and get the effect of cutting thru the stroke as well? Thanks!

    I don't believe you can do this in a single operation. You'll need to knife the object, then select the newly created segment on each object with the direct selection tool, then delete to open each path.
    But this is likely to cause another problem: once you delete the path segment that you knifed through, the object's fill will form a straight edge from one open end point to the other. IOW, you'll lose any curvature you might have created with the knife.
    There may be another way; others who are more adept will be along to offer it I'm sure.

  • LR 4.2 - how to compare master and soft proof copy?

    Hello Everyone,
    I'd like to use the soft proofing function in LR 4.2 to preview the print output and I'd like to use it to apply some corrections to the pictures before printing them, in order they look like I originally meant them to look like, but I'm experiencing some troubles, possibly caused by the used workflow (I'm not a pro, but my environment is calibrated properly).
    My workflow is:
    1. I import all fotos and apply some changes so that the fotos look like I want them to be (this is the master)
    2. As I want to print them I use the soft proofing function and load the target icc profile with which I create a soft proof copy. Sometimes I notice that the differences between master and soft proof copy are quite drammatic, especially with regards to contrast, vibrance of colors and sometimes also regarding the brightness.
    3. My target is now to adapt the soft proof copy so that it looks like the master (as I wanted the foto to look like), but I can't find any proper way to do so, because:
         - I can't find a (semi-)automated way to adapt the soft proof copy so that it "looks" like the master copy
         - in the Develop module I can't find a way to display both the master foto and the soft proof copy besides each other to compare them, in order to apply changes to the soft proof copy only so that it "looks" like the master.
    The only way I found so far is to switch back and forth bewteen master and soft proof copy to compare them (to be able to apply the needed changes to the soft proof copy), but this is pretty painful, as the fotos don't load immediately, but it always takes some seconds and I have to 'remember' how the master looks like.
    I'm not sure whether I'm doing something terribly wrong, but unfotunately I didn't find any answers to this specific issue so far, that's why I'm writing here.
    Hope you can point me to a solution,
    Regards,
    Plasma2k

    Activate softproofing with your choice of output profile (this can include proofing a web output colourspace such as sRGB).
    Press Y to show a split before/after view (if your Toolbar is not open, press T to open that - this gives different kinds of split view options).
    You will now see a comparison of the un-proofed and proofed appearances of this current image.
    If you then make any develop adjustment from this mode, e.g. to make these two appearances more similar, you are then prompted to create a new proofing (virtual) copy as necessary - which can store these corrective adjustments independently of the main adjustments.
    The before/after view then switches to show a comparison between your starting image (shown without softproofing) against your print-adjusted proof version (shown with softproofing).

  • How to compare New and Old long text at PO Line Item

    Hi all,
    I am Using user exit "EXIT_SAPMM06E_013". In user exit i am trying to compare the old and new values of PO maintain at item level. All this values, i am getting in X and Y structures in user exit
    For long text there is no Such structures. When i am trying to fetch the details from FM Read_Text to fetch this values, Every time i am getting old values. Since new values has not yet been store to database.
    Is there any way through which i can compare the old and new values of item Long text.
    Thanks in advance,
    Regards,
    Vikram Singh.

    Hi Vikram,
    Iam not sure though, did you chekced EXIT_SAPMM06E_022 if it helps you in anyway.
    Regards,
    Swarna Munukoti

  • Create Objects and Attachments

    Hi All,
    I want to know how to create Objects and Attachments  in Workflow as in case of Customized WF . As for Purchase Order Release I can see the Click on the Link and Display the Document. How it get done?
    Help Me
    Thanks

    Hello Munish,
    First goto SWO1 to create objects.(custom).
    Second you can copy std. WF and enhance it for your requiremet.
    in custom BO you can write method and in that you can call your form59.
    from swel you can find which std. B.O. is used for PO Release.
    Hope magic works,
    Regards,
    Purvesh.

  • Convert String Object to Comparable Object

    Getting all types of warnings in Eclipse when I try to cast. I have a method that wants to accept a Comparable<Object> and I would like to pass in a string, float, or integer, and make sure of the Comparable interface.

    EJP wrote:
    Try Comparable<?>. If that doesn't work please post some code.I will continue this thread then.
    inserInSubTree() is to take an attribute and compare it to another using Comparable.
    Here is my code:
    private PrimaryIndexNode insertInSubtree(Comparable<?> newAttribute,
                                            int newByteIndex, PrimaryIndexNode subTreeRoot)
              if (subTreeRoot == null)
                   return new PrimaryIndexNode(newAttribute, newByteIndex, null, null);
              else if(newAttribute.compareTo(subTreeRoot.attribute) < 0)
                   subTreeRoot.leftLink = insertInSubtree(newAttribute,
                                                      newByteIndex, subTreeRoot.leftLink);
                   return subTreeRoot;
              else
                   subTreeRoot.rightLink = insertInSubtree(newAttribute,
                                                      newByteIndex, subTreeRoot.rightLink);
                   return subTreeRoot;
         }I am unfamiliar with generics or the proper use of Comparable. what I desire to do is compare any object for ordering it and subsequently inserting it into a binary tree. I figured Comparable could do this and with auto up and down boxing I can do this for primitives and objects.
    However, unfamiliarity with what I need to do and having no clear example in my resources has left me without remedy.

  • Comparing characeristics and Keyfigures in SAP R/3 for Gap analysis

    How to compare characteristics and keyfigures with SAP R/3 tables and fields .
    Is there any standard method is there or standard table is there.We are doing Gap Analysis for comparing this one.Please send anyone.
    Sridhar

    check following blogs if they help you:
    /people/sap.user72/blog/2005/09/05/sap-bw-and-business-content-datasources-in-pursuit-of-the-origins
    /people/swapna.gollakota/blog/2008/01/14/one-stage-stop-to-know-all-about-bw-extractors-part1

  • Comparing CO and FI totals (Reconciliation)

    Hello!
    I need to find a way how to compare CO and FI totals for every cost element /  account. Actually, totals for account may be taken from FS10N, but getting totals for cost elements is still very long process.
    The only way I found is using report S_ALR_87013603 CO/FI Reconciliation, but I have some troubles with it. First, I can see data just for CO-module; FI column is empty. Second, when the table is formed, what does double-clicking on a line do? I suppose it allows seeing the detailed description for every cost element, but it still shows nothing after 2 hours after I double-clicked on it.
    So, these are my questions:
    1. Is there any other way of comparing totals of CO and FI other than running S_ALR_87013603 ?
    2. If this report is the only way, how can I see data for FI module if it's empty in the report?
    3. Is it possible to get a detailed description of costs for every cost element in this report by double-clicking on it?
    Thanks everyone in advance!
    Alexander.

    Hello Alex
    There are two reports  are available KE5Z and 2KEE, if u want compare the line item wise you can utilise the KE5Z or otherwise only summary for each cost element or account go for 2KEE
    With the above two reports only we are comparing the FI with CO with profit center wise etc.,
    Regards
    Madhav

  • Directly access specified item in Compare-object results

    I have done a Compare-Object and assigned the results to the array variable $NeedToConform. I can iterate through the variable with foreach ($Item in $NeedToConform) and get $Item.SideIndicator, but in my case I already have the item in question in $Package,
    and I need to get at the SideIndicator of that specific item. Basically $NeedToConform.$Package.SideIndicator, but that doesn't work. I tried using a dictionary instead of an array, with no joy. 
    Is there a trick here, or should I just punt and step through the array each time?
    EDIT: Damn, why do I so often find a solution right after posting the question. And why don't I learn and post the question sooner, so I'll find the solution sooner? ;) Anyway, this works.
    if ($NeedToConform[[array]::indexof($NeedToConform,$Package)].SideIndicator -eq '<=')
    I just wonder, is indexof really just a convenience method that iterates for me? If I might have a hundred or more results in the $NeedToConform array, and I might need to test against a hundred values for $Package, do I have any performance implications
    to worry about?
    Gordon

    mjolinor,
    my failure with Dictionary was on multiple fronts.
    One, you need to compare two dictionaries. But one of my objects needs to be ordered, and it needs to work in v2, so an ordered dictionary isn't an option. I may have been able to get it to work, but indexof works with the array, so that is my solution for
    now. But I am flagging this to come back to for review down the road. Always something new to learn.
    Thanks!
    Gordon
    You can have an ordered dictionary in V2:
    $OrderedHT = New-Object collections.specialized.ordereddictionary
    You just didn't see it used very often because you couldn't use it to create an object very easily.  The -properties parameter of New-Object would only take a generic/unordered dictionary as an argument.
    They fixed that in V3, along with adding the type accelerator ([ordered]) to make it easier to create an ordered dictionary.
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • What is authorization object and how to create it for a table

    Hi All,
    What is authorization object and how to create it for a table?
    Thanks

    Hi
    Authorization
    For authorization checks, there are many ways of linking authorization objects with user actions in an SAP system. The following discusses three possibilities in the context of ABAP programming.
    Authorization Check for Transactions
    You can directly link authorization objects with transaction codes. You can enter values for the fields of an authorization object in the transaction maintenance. Before the transaction is executed, the system compares these values with the values in the user master record and only starts the transaction if the appropriate authorization exists.
    Authorization Check for ABAP Programs
    For ABAP programs, the two objects S_DEVELOP (program development and program execution) and S_PROGRAM (program maintenance) exist. They contains a field P_GROUP that is connected with the program attribute authorization group. Thus, you can assign users program-specific authorizations for individual ABAP programs.
    Authorization Check in ABAP Programs
    A more sophisticated, user-programmed authorization check is possible using the Authority-Check statement. It allows you to check the entries in the user master record for specific authorization objects against any other values. Therefore, if a transaction or program is not sufficiently protected or not every user that is authorized to use the program can also execute all the actions, this statement must be used.
    AUTHORITY-CHECK OBJECT object
                            ID name1 FIELD f1
                            ID name2 FIELD f2
                            ID namen FIELD fn.
    object is the name of an authorization object. With name1, name2 ... , and so on, you must list all fields of the authorization object object. With  f1, f2 ... , and so on, you must specify the values that the system is to check against the entries in the relevant authorization of the user master record. The AUTHORITY-CHECK statement searches for the specified object in the user profile and checks the useru2019s authorizations for all values of f1, f2 ... . You can avoid checking a field name1, name2 ... by replacing FIELD f1  FIELD f2 with DUMMY.
    After the FIELD addition, you can only specify an elementary field, not a selection table. However, there are function modules available that execute the AUTHORITY-CHECK statement for all values of selection tables. The AUTHORITY-CHECK statement is supported by a statement pattern.
    Only if the user has all authorizations, is the return value sy-subrc of the AUTHORITY-CHECK statement set to 0. The most important return values are:
    ·        0: The user has an authorization for all specified values.
    ·        4: The user does not have the authorization.
    ·        8: The number of specified fields is incorrect.
    ·        12: The specified authorization object does not exist.
    A list of all possible return values is available in the ABAP keyword documentation. The content of sy-subrc has to be closely examined to ascertain the result of the authorization check and react accordingly.
    REPORT demo_authorithy_check.
    PARAMETERS pa_carr LIKE sflight-carrid.
    DATA wa_flights LIKE demo_focc.
    AT SELECTION-SCREEN.
      AUTHORITY-CHECK OBJECT 'S_CARRID'
                      ID 'CARRID' FIELD pa_carr
                      ID 'ACTVT' FIELD '03'.
      IF sy-subrc = 4.
        MESSAGE e045(sabapdocu) WITH pa_carr.
      ELSEIF sy-subrc <> 0.
        MESSAGE e184(sabapdocu) WITH text-010.
      ENDIF.
    START-OF-SELECTION.
      SELECT  carrid connid fldate seatsmax seatsocc
        FROM  sflight
        INTO  CORRESPONDING FIELDS OF wa_flights
        WHERE carrid = pa_carr.
        WRITE: / wa_flights-carrid,
                 wa_flights-connid,
                 wa_flights-fldate,
                 wa_flights-seatsmax,
                 wa_flights-seatsocc.
      ENDSELECT.
    Regards
    Hitesh

Maybe you are looking for

  • The best audio interface with Mac Mini using new & existing equipment?

    Hi, I got my existing set-up back in 2003. I'm now about to update it. I've talked to Apple Technical Support re which computer is best for me. Some important questions remain in terms of the audio interface or sound bridge I should use. I've detaile

  • IP Report not input enabled

    Hi Experts, I have done the below activities to make an IP report for manual planning. 1)Creation of real time cube and made is available for planning by setting. 2)Created aggregation level on around 7Characteristics & 4Key figures. 3)Created a Bex

  • IC error: "No root trees assigned to the profile found"

    problem in interaction center - > user gets error message "No root trees assigned to the profile found" when clicks on action box tab Could you please tell me what causes this issue? Thank you very much!

  • I lost all my data after installing ApplCare Protection Plan

    I just recently adopted my first IMac. Everything was going along fine until I installed the AppleCare Protection Plan and I lost all my emails, addresses, pictures. I tried uninstalling but nothing. Is there a way to retrieve my lost data? Thanks.

  • How to change Valid to date in BOM

    Hi Sap experts I have two questions: 1. How to change the valid to date in BOM for either header or component material. 2. If the answer of the above question is NO, then from where the system takes the value for valid to date in BOM. If its default,