Same priority items in a priority queue

Hello all,
I am writing a project that uses the PriorityQueue class to sort patients according to their emergency level.
The more urgent is a patient's condition, the higher the priority (Priority 1 = Very Urgent. Priority 10 = Not urgent).
However, there are many patients with the same priority and I would like to process them according to a first-in first-out scheme.
The PriorityQueue class doesn't seem to follow that scheme naturally.
Does anyone have an idea how to solve this problem?
Thanks in advance,
Nader

Thanks for the code. The compound parameter is instructive.
I'm not sure that you've thought it through, though. Declaring
public class OrderedPriorityQueue<T extends OpqComparator<T> & OpqOrderable<T>> extends PriorityQueue<T> { ...}forces an element to be declared
public class Foo extends OpqComparator<Foo>  implements OpqOrderable<Foo>  {...}and then you pass what as a comparator to the OPQ constructor? Apparently null because..
By having OpqOrderable extend Comparable as you suggest, the user is forced to write a compareTo() method. Assuming that he does so correctly, the 'natural ordering' of the class is sufficient to prevent ties. No comparator is needed.
By dropping the Comparable from OpqOrderable and using OpqComparator, the ordering due to the 'order' field is supplied, yet the user must still write essentially the same comparator code. Very little seems to have been achieved, although admittedly it's what I asked for. :) Am I missing something?
Here's what I have now:
public interface OpqOrderable<T> extends Comparable<T> {
     int getOrder();
     void setOrder( int order );
public class OrderedPriorityQueue<T extends OpqOrderable<T>> extends PriorityQueue<T> {
     public OrderedPriorityQueue( int initialCapacity ) {
          super(initialCapacity);
     @Override
    public boolean offer( T o ) {
          if( o instanceof OpqOrderable ) 
               synchronized (this)  {
                    o.setOrder( nextOrdinal++  );  }
        return offer(o);
public class Foo implements OpqOrderable<Foo>  {...}
private OrderedPriorityQueue<Foo> productionQueue = new OrderedPriorityQueue<Foo>( 100 );Thoughts?

Similar Messages

  • Listing Items based on criteria e.g. High Priority Items First.

    Hi,
    One of our customers have a need to List High Priority Items first on the WebTools site.
    Let's take two ItemCodes for example: Printer001, and, Monitor001.
    >> If these two items are included in the same category then Monitor001 will appear before Printer001 as WebTools sorts in alphabetic ascending order;
    >> But, our customer wants Printer001 to appear before Monitor001 as it is an Item higher in priority that Printer001.
    I can think of two possible solutions:
    1/2) Prefix Items with a number or letter to have it appear first in the WebTools default sort order. E.g. Rename "Monitor001" as "AMonitor001". This will not be possible for existing Items in SAP, so it doen't solve the issue,
    Or,
    2/2) Customize the Default WebTools Item List block to sort Items based on a User Define field called "pririty". Which might require a lot of effort.
    Please advise if anyone else has solved similar issue and how.
    Thanks very much for your replies in advance.

    Hey Kafil ... I think you may be stuck modifying the parts list page or creating something from scratch. I'm not aware of an easy way to do this out of the box.

  • Exchange 2010 SP2 RU2 - Indexing backlog reached a critical limit of 48 hours or the number of items in the retry queue is greater than 10000 for one or more databases

    We have been getting intermittent SCOM alarms for our Exchange 2010 MBX server citing "Indexing backlog reached a critical limit of 48 hours or the number of items in the retry queue is greater than 10000 for one or more databases"
    I see events in EventViewer that SCOM is triggering on, but not whats generating the events or how else to test for them.
        get-eventlog -computername SERVERNAME -logname "Application" -after "03/14/2013" | ?{$_.eventid -eq "5604"} | select MachineName,EventID,EntryType,Message | ft -autosize
    One MS Forum post online says it is a bug in RU4, unclear if it may also be a bug in RU2 (our installed version).
        http://social.technet.microsoft.com/Forums/en-US/exchangesvradmin/thread/9dcb3011-9327-4935-9479-62b38a6ddd87
        "I was looking for the same error and found this.. it basically says that this is a bug in RU4 and RU4-v2...and it needs to be removed."
    tests using troubleshooting scripts find no issues with search indexer,
        [PS] C:\Program Files\Microsoft\Exchange Server\V14\scripts>.\Troubleshoot-CI.ps1
        Get-EventLog : No matches found
        At C:\Program Files\Microsoft\Exchange Server\V14\scripts\CITSLibrary.ps1:622 char:40
        + $msftesqlCrashes = get-eventlog <<<< -computername $Server -after $StartTime -logname "Application" -source $msftesqlServiceName | where {$_.eventId
        -eq $msftesqlCrashEventId}
            + CategoryInfo : ObjectNotFound: (:) [Get-EventLog], ArgumentException
            + FullyQualifiedErrorId : GetEventLogNoEntriesFound,Microsoft.PowerShell.Commands.GetEventLogCommand
        Name IsDeadLocked CatalogStatusArray
        SERVERNAME False {DATABASENAME\SERVERNAME, DATABASENAME\S...
        [PS] C:\Program Files\Microsoft\Exchange Server\V14\scripts>
    and tests against searches on each DB themselves show no issues and respond typically within 3 seconds.
        [PS] C:\Program Files\Microsoft\Exchange Server\V14\scripts>Test-ExchangeSearch | ft Server, Database, ServerGuid, ResultFound, SearchTimeInSeconds, Error -AutoSize
        Server Database ServerGuid ResultFound SearchTimeInSeconds Error
        SERVERNAME DATABASENAME b16e3461-257c-40dd-a9ad-99a5f41a927e True 2.937
    I also tried to check the Performance Viewer for the MSExchange Search Indexer and MXExchange Search Indices but am unsure which of the many metrics would indicate this issue.
    We have had no reports of search issues from our users and have been unable to duplicate any impairment in our testing.
    Does anyone else have any suggestions for tests to check or steps to take on this alert? Is it simply a false alarm or a timeout of other sorts during testing? We have 80 DAGs on this server (as well as all our servers, some of which have also reported the
    same alert) and the Test-ExchangeSearch command times out before completely testing all DAGs.

    Hi IAMChrisL,
    Any updates?
    Frank Wang
    TechNet Community Support

  • How do I switch the items in my print queue listed under "wireless" over to the "usb" ?

    I turned off my wireless service, but i still have items in my print queue under "wireless printer" for my HP 3050A.  How do I switch the settings so that it will print using the usb cable (for the same printer)?

    hi there,
    could you provide the community with a little more information to help narrow troubleshooting? What operating system?
    You can say thanks by clicking the Kudos Star in my post. If my post resolves your problem, please mark it as Accepted Solution so others can benefit too.

  • Vendor's same open item selected for payment twice through APP run F110

    Hi,
    In F110 run, specified vendor  number and payment method(Bank Transfer), executed payment run.
    After, say 5 minutes interval again executed F110 for all vendors and except for the above mentioned payment method.
    In the first case, payment document generated, posted and cleared the Vendor open items. Here, the Payment method is B.
    In the second time also, the same open items are selected in the payment run and the payment method D(Cheque payment).
    Payment document generated and is not posted but cheque is generated for the same amount.
    How could it happened?

    Hi,
    In F110 run, specified vendor  number and payment method(Bank Transfer), executed payment run.
    After, say 5 minutes interval again executed F110 for all vendors and except for the above mentioned payment method.
    In the first case, payment document generated, posted and cleared the Vendor open items. Here, the Payment method is B.
    In the second time also, the same open items are selected in the payment run and the payment method D(Cheque payment).
    Payment document generated and is not posted but cheque is generated for the same amount.
    How could it happened?

  • Condition type PB00 and PBXX, coming in the same PO Item

    Hi,
    In the PO (created with reference to Outline Agreement),  condition types PB00 and PBXX are coming in the same line item.
    In the PO output, the PB00 value is also showing up and PBXX value is also showing up. User entered PBXX value as 350000 dollars which is right, however system is picking 1.2 million dollar of PB00 from outline agreement which is not intended here. As a result of that the output going to Vendor is exceeding more than 1.2 million dollar instead of 350,000 dollars. I cannot change or delete any othe condition types.THis is a production problem.
    Has anyone faced this problem. I appreciate your reply in advance.
    Thanks,

    Well, thanks Saurav and Prabhakaran, however the problem still stays.
    The contract is created for services (1 lot), so the dollar amount can vary depending upon the service rendered by the consultant.
    That mean user will only enter the service amount.
    Saurav, system should not copy down PB00, it should come by itself when user enters the specific amount. And it comes from contract. PBXX should only appear if there is no PB00 maintained in the contract. This is not the case. The service amount is maintained in the contract. Also, I don't think that PBXX and PB00 should come in one line item together as normal system behaviour &  as a normal business process too. Moreover, it is not happeniing in the other two line items - line item 20 and line item 30 are fine. The pricing analysis shows both the conditions as found - PB00 and PBXX, so I could not take any clue from analysis too.
    Prabhakaran, system is only behaving incorrectly for line item 10. It is behaving as expected (good ) for other line items and other PO's. So, we cannot touch the pricing procedure as that will affect other line items.
    Regards

  • Particular sales order of the same line item hv created multiple production

    sir,
    I am having a problem in MD04. A particular sales order of the same line item hv created multiple production order.and continously planning is going on... I didn't get why it happens.
    Will u please suggest me what should i do in this case?
    Regards
    Meenu

    Hello sir,
    yes, ofcourse, for the finished material have the BOM with some semifinished productes which are to be produced .
    In co02 , we can go through the collective production order.
    One more thing is that, in the multiple production order date(scheduling date) shows in forward(future dates).
    For ex:09-05-2010.
    Regards
    Meenu

  • How to copy the line item description to other same line items - FBL5N

    Hi All,
    I have an issue while printing the description in the script.In the final internal table there are multiple same line items but the description is comming for the only one line item but my requirement is i want to copy the description text(bseg-sgtxt) to the other same line items also. I trying to use the control break statements but i am not getting the solution.
    can any one please provide me the solution.
    FYI.. please find the attched text doc..in the document the first four lineitems are same but description is comming for only one line item. I want to display the description to all the same line items.
    Thanks in advance.
    Regards,
    koushik

    Hi Bharat,
    Can u just attach the code where populating the internal table with description.
    Regards,
    Shashikanth

  • Cumulative amount in the same line item for the same account

    Hi
    I have an account which appears more than once in the same accounting document.Can I cumulate the amount in the same line item.
    IF it's possible, please how can i do it.
    Thanks in advance

    Hi Maher,
    Assumption:
    You have an accounting document in which more than one line item is there with the different amount. All the other details of the line items are same.
    Solution:
    If you want to make it one line item, key the amounts as zero in other line items and add the value to a single line item.
    Warm regards,
    Murukan Arunachalam

  • Different fonts in same text item....

    Hi Everyone,
    We have a requirement that we should use more than one font in the same text item. We have shortcut to toggle between the fonts (if you are familiar its NUDI used for Kannada Font). So we should make it possible that they can edit both kannada and english in the same field. And, after toggling between the fonts, previously added data should not change.
    Thanks in advance,
    Yathish

    For any fonts you will use you OAS must support it, but as I said in my previous post, you cannot have two different types of fonts in the same text item natively.
    It may be possible if you use a PJC.
    Regards,
    Tony

  • Intercompany billing has 2 line items referring to the same salesorder item

    Hi All,
    I am posting Intercompany billing documents using Idocs. I am using the standard function module that creates INVOICE IDocs, but these Idocs are failing with error text "Document contains same order item more that once".
    The problem lies here, the PO that is been used is a STO (Scheduling Agreement) and the inter company billing the line item has the same material repeated twice but change in the quantity field. So, when I am posting document using Idocs we come across a segment E1EDP01 which has your quantity, weight, line item number and other fields. This segment is getting repeated twice with two different outbound deliveries.
    So, I think the solution is a mixture of both functional and technical....
    So, what I am planning to do here is for this particular material when ever it comes across duplicate entries add all the quantities fields and other numerical fields in the user exit and then refresh the internal table and then enter new entries. This could be done, but I don't know what could be the functional implications if these changes are made.
    Request you all to let me know what exactly needs to done in order to avoid these scenarios.
    Raghuram.

    Hi Raghuram,
    I found a very important SAP Note 103051, details are below.
    An IDoc processed by function module IDOC_INPUT_INVOIC_MM (of category INVOIC01) must not refer to the same purchase order item in several invoice items. This is also valid if for a goods receipt-related invoice verification several delivery notes belong to the same purchase order item.
    Depending on the system settings and the situation, various error messages can occur (for example, FD240 'Order item ... selected more than once' or M8050 'Balance not zero: & debits: & credits: &').
    In this situation module IDOC_INPUT_INVOIC_MRM generates error message M8321 'Document contains same order item more than once'.
    For example, this situation occurs if you work with individual batch valuation and the SD billing document executes a batch split for different batches which belong to the same purchase order item and delivery.
    Other terms
    INVOIC, SAPLIEDI,  M8047, M8, 321
    Reason and Prerequisites
    This is because of the program design.
    Solution
    There is no solution for IDOC_INPUT_INVOIC_MM.
    Module IDOC_INPUT_INVOIC_MRM (only as of Release 4.0) for the logistics invoice verification can distinguish different goods receipts by means of the delivery note number. For this purpose, GR-related invoice verification must be active.
    Owing to this symptom, billing documents for single batch valuation with batch split cannot be settled in MM-EDI inbound processing. The settlement generates exactly the situation described (several invoice items for the same purchase order item). In this case, the only solution is to deactivate the billing of the batch sub-items in SD Customizing and to calculate the main item only.
    Hope this helps.
    Reward if helpful.
    Thanks

  • Error : Document contains same order item more than once in IDOC

    We have Intercompany IDOCs getting created in our system. The
    trigger for this is the Billing Document in the same system in
    differenct company code. The MEssage type being used is INVOIC and the
    basic type is INVOIC01.
    The IDOC is in the status of 51 with the error message
    Document contains same order item more than once
    Message No : M8 321.
    Can anyone tell me why raise this error and how to resolve it?
    Thanks.

    What I have recently learned is that in 6.0 SAP allows the same line item to be on an idoc multiple times.  However, the item has to be GR-based-IV and there has to be a unique entry in the delivery note of the GR.   I have successfully tested this in my development system.  
    What I can't get to work is if the GRs have the same delivery note value.   What I think is happening is these GRs are not unique so SAP cannot match a GR with an IR so it fails with this error. 
    Here are the examples:
    Works 
    GR# A           deliverynote/BOL    "abcd"
    GR# B           deliverynote/BOL     "efgh"
    Invoice idoc
    e1edp02    qualifier 016          abcd
    e1edp02    qualifier 016          efgh
    Doesn't work:
    GR# A           deliverynote/BOL    "abcd"
    GR# B           deliverynote/BOL     "abcd"
    Invoice idoc
    e1edp02    qualifier 016          abcd
    e1edp02    qualifier 016          abcd
    If anyone knows of a way to make the second scenario work, I'd like to hear your solution.
    Thanks
    Sandra

  • Same work item in the work flow is generating 2 mails with a time gap.

    Hi,
    I have a workflow object where,The same work item in the work flow is generating 2 mails with a time gap.
    Please suggest how should I resolve the problem.
    Thanks in advance.

    Hello Rob & Rick,
    Many thanks for your inputs.
    I am working on smartforms for the first time.It still some time till I find a solution with the inputs that you have suggested.
    I will keep this thread posted,& if I am not able to complete the task,i will close the thread.

  • Same line items

    Hi,
         While creating a sales order ,my requirement is that the system should not accept same line item two or more times.
    Eg.,   Line item 10     xyz  material           10 units
             Line item  20    xyz  material            20 units
    In the above scenario system should not accept the second line item and should propose that a line item already exists.
    Regards,
    Phani Prasad.

    But its not a good Habit as while creating a Sales Order , sometimes User put / use the Same material in different Line Items with different Quantity as you would have different Batch with the Same Material.
    Otherwise , you can maintain the same in the User Exit MV45AFZZ with POSNR & MATNR as reference fields as the system will throw an error if it checks the Same material Code in different Line Items.
    Best Regards,
    Ankur

  • TO priority fields to high priority for  special kind of materials.

    Hi,
    Can we automatically set the TO priority fields to high priority for Can we automatically set the TO priority fields to high priority for special kind of materials?
    thanks
    Raj Kiran

    Hi Prashant,
    Is there any way the TO priority can be set to high priority before at the time of TO creation. Becuase the operator has to go through each TO to see if it is a special material which need special attention.
    Can we automate this process a little bit by assigning a high priority to TO(automatically) for these kind of materials or is there any other alternative possible through "Special movement indicators"?

Maybe you are looking for