LINQ grouping with custom comparer

I'm trying to implement a linq grouping with a custom comparer. I have a datatable, I fill it with data, then I add the datarows to a
List(Of DataRow), then I select all the rows to a IEnumerable(Of Object()). After that, I would like to group the result with a custom comprarer.
This is the code:
Dim result As IEnumerable(Of Object())
Dim dt As New DataTable
Dim indexes As New List(Of Integer)
Dim groupedindexes As New List(Of Integer)
Dim datarows As New List(Of DataRow)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dt.Columns.Add("f1", Type.GetType("System.Char"))
dt.Columns.Add("f2", Type.GetType("System.Char"))
dt.Columns.Add("f3", Type.GetType("System.Char"))
For i = 0 To 100
dt.Rows.Add("a", "b", "c")
Next
indexes.Add(0)
indexes.Add(1)
indexes.Add(2)
groupedindexes.Add(0)
groupedindexes.Add(1)
groupedindexes.Add(2)
For i = 0 To dt.Rows.Count - 1
datarows.Add(dt.Rows(i))
Next
result = datarows.Select(Function(row) indexes.Select(Function(index) row(index)).ToArray)
Dim test = result.GroupBy(Function(row) groupedindexes.Select(Function(grpindex) row(grpindex)).ToArray, New compare)
End Sub
And this is the compare class:
Partial Class compare
Implements System.Collections.Generic.IEqualityComparer(Of Object())
Public Function Equals1(ByVal x() As Object, ByVal y() As Object) As Boolean Implements System.Collections.Generic.IEqualityComparer(Of Object()).Equals
Dim equal As Boolean = True
For i = 0 To x.Count - 1
If x(i) IsNot y(i) Then
equal = False
Exit For
End If
Next
Return equal
End Function
Public Function GetHashCode1(ByVal obj() As Object) As Integer Implements System.Collections.Generic.IEqualityComparer(Of Object()).GetHashCode
Dim hashcode As Integer
For i = 0 To obj.Count - 1
hashcode = hashcode + obj(i).GetHashCode
Next
Return hashcode
End Function
End Class
With the above code, I get all the 101 rows, but I would like to get only one row (a, b, c), since all the rows are the same. Therefore I wrote the custom comparer class. I'm new to this and I'm not sure, that I use it correct.
Can you advise me, how should I modify the code to get only one row?
Thanks.

Try code below.  I use a dictionary to group rows and then filter results to get unique rows.
Module Module1
Sub Main()
Dim dt As New DataTable
Dim dict As Dictionary(Of Integer, List(Of DataRow)) = dt.AsEnumerable() _
.GroupBy(Function(x) x.Field(Of Integer)("Col A"), Function(y) y) _
.ToDictionary(Function(x) x.Key, Function(y) compare(y.ToList()))
End Sub
Function compare(rows As List(Of DataRow)) As List(Of DataRow)
Dim results As New List(Of DataRow)
results.Add(rows.FirstOrDefault)
If (rows.Count > 1) Then
For i = 1 To (rows.Count - 1)
Dim unique As Boolean = True
Dim rowArray() As Object = rows(i).ItemArray
For j = 0 To (results.Count - 1)
Dim oldArray() As Object = results(j).ItemArray
For cols = 0 To (rowArray.Length - 1)
If rowArray(i) <> oldArray(j) Then
unique = False
Exit For
End If
Next cols
If unique = False Then
Exit For
End If
Next j
If unique = True Then
results.Add(rows(i))
End If
Next i
End If
Return results
End Function
End Module
jdweng

Similar Messages

  • Slow performance with custom comparator (AdvancedDataGrid sorting)

    I'm using Flex 3.4.
    I have an advancedDataGrid. Have 2 columns with numbers as data.
    For one column, I do not set any custom comparator function.
    For the other column, I set a custom comparator function which is exactly the same as the default one used by Flex. (The private function SortField.numericCompare).
    For both columns, I set the same data - 3000 Rows with values either 0 or 1.
    When i sort on column1 (the one with custom comparator), the sorting is much slower than on column2 (default Flex comparator).
    I went through the AdvancedDataGrid/SortField source codes but could not see why this could be happening as the comparator functions are the same in both cases.
    Also, I checked out this bug -
    http://bugs.adobe.com/jira/browse/SDK-13118
    But shouldn't this be applicable to both custom and default sorting?
    Can anyone help me out?

    This is the function that i have : (same as the SortField numericCompare function which is the default function which is used if no customCompare is specified.)
            public function numCompare(a:Object, b:Object):int {
                var fa:Number;
                try {
                    fa = _name == null ? Number(a) : Number(a[_name]);
                } catch (error:Error) {
                var fb:Number;
                try {
                    fb = _name == null ? Number(b) : Number(b[_name]);
                } catch (error:Error) {
                return ObjectUtil.numericCompare(fa, fb);
    As per bug, the performance should be slow for lots of items that have same value. But, it should be the same for both the custom compare and the default compare as the custom compare function I'm using is the same as what is used for Flex.

  • Target group with customer and contact person

    Hi experts,
    I want to create a target group with customer data and the names of the main contact person to execute a campaign.
    During execution I need the name of the contact person to personalize my forms, the campaign activity should be connected to the customer (and not the contact person).
    Is there a functionality to solve my problem? (CRM 7.0)
    Thanks in advance.
    Werner

    Hi Werner,.
    I assume you want to select for Organizations (BUT000 Type 2) and you want to see in the Target Group the Contact Persons which are assigned via Relationship to the Orgnizations.
    Create for example a Datasource with  Infoset CRM_MKTTG_BP_ORG, and under Details for Business Partner use BUT000_PER-PARTNER_GUID.
    In Field Function Module maintain CRM_MKTTG_PF_BP_TAB_TO_CP.
    Create an Attribute List an assign the Datasource. After Creating the Target Group you will see the Organizations with all the assigned Contact Persons via Relationsship.
    Regards
    Andreas
    Another Tip: Create a Target Group for Persons, assign it to the Campaign, and now set the B2B Flag. Depending from your SP Level you have to apply a note so that the B2B Flag is visible (1263915)
    If you set the B2B flag you will get Communication Data for letters, for a Call List from the Relationship.
    Regards,
    Andreas
    Edited by: Andreas Pauli on Apr 29, 2009 10:18 AM

  • Clone column groups with custom cells

    I have set up custom bordered cells meaning to copy them along with the border. Instead only the contents are copied, when I paste the columns the borders are ignored. How do I copy and paste blocks of cells including the borders?

    We may do that in two operations.
    • copy then paste the contents
    • use the "Copy Style" button on the source block of cell
    select the destination block (with the correct number of cells) then use the "Paste Style" button.
    These two buttons aren't installed by default so, we must install them by ourself.
    Yvan KOENIG (from FRANCE lundi 9 juin 2008 08:52:15)

  • Customer Account Group with Output Procedure assignment

    Hi Gurus,
    Is there any assignment is possible between Customer Account Group & Output Procedure? What is the function of Output procedure DB0001, I mean how its works. How in Customer Master Output box will get open. Please give details as much as possible.
    Thanks & Regards,
    Savi

    Dear Savi,
    Yes it is possible to assign the output determination procedure to the account group.
    IMG path to assign output determination procedure
    SPRO>Financial accounting>Account recievables and Account payables>Customer accounts>Master data>Preparations for Creating Customer Master Data>Define Account Groups with screen layout (Customers) select account group then go in to details here you can find the field Output determ.proc. under general data tab.
    If you assign the output determination procedure to the account group, the output box will open in the customer master record in the Sales area data as Documents tab here you can enter the output types which are related to you.
    I hope it will help you,
    Regards,
    Murali.

  • Is there an option to import with custom groups in PSE 9's organizer?

    With the Organizer included with PSE7 (and earlier, as I recall), I always used the option Custom Groups (Advanced) in Create Subfolders. This allowed me to easily save imported photos into different folders and naming the files accordingly.
    For example, on one media card I might have some family activities, some Kiwanis activities, and skiing activities. With Custom Groups, I could import them in small groups, with different base names, and so on.
    How do I accomplish those same things in PSE9. It was such a useful feature, Please tell me they did not remove it.
    Thanks!

    As far as adding java script to the generated form you can add a pl/sql code having java script in it for eg below is a sample function
    which has javaScript in it.
    CREATE OR REPLACE FUNCTION sample_javaScript
    RETURN varchar2 IS
    l_string varchar2(1000);
    l_char_en varchar2(1) := chr(38);
    begin
    l_string := '<script language="JavaScript1.1">'||chr(10)
    ||'<!--'||chr(10)
    ||'function getField(form,fieldName,theElement)'||chr(10)
    ||'{ '||chr(10)
    ||'var objName = "";'||chr(10)
    ||'var tmp = ""; '||chr(10)
    ||'var recnummer = 0;'||chr(10)
    ||'var dAction = ""; '||chr(10)
    ||'var sel_idx = 0; '||chr(10)
    ||'var cnt = 0; '||chr(10)
    ||'var instance = 0; '||chr(10)
    ||'var slicedName; '||chr(10)
    ||'var slicedButton; '||chr(10)
    ||'var fillData = new Array(); '||chr(10)
    ||'slicedButton = theElement.name.split("."); '||chr(10)
    ||'recnummer = parseInt(slicedButton[3],10); '||chr(10)
    ||'for (var i = 0; i < form.length; i++) '||chr(10)
    ||'{ '||chr(10)
    ||'slicedName = form.elements.name.split("."); '||chr(10)
    ||'tmp = slicedName[2]; '||chr(10)
    ||'instance = parseInt(slicedName[3],10);'||chr(10)
    ||'if (!tmp) '||chr(10)
    ||'continue; '||chr(10)
    ||'objName = tmp; '||chr(10)
    ||'if (objName == fieldName '
    ||l_char_en||l_char_en||' instance == recnummer) '||chr(10)
    ||'{'||chr(10)
    ||'return form.elements[i].value; '||chr(10)
    ||'} '||chr(10)
    ||'} '||chr(10)
    ||'} '||chr(10)
    ||'//-->'||chr(10)
    ||'</script>'||chr(10);
    return l_string;
    end sample_javaScript;
    Grant this to the schema of the form if they are in different schemas.
    In the last sql section (Before Display of the form) you can simply call this function like this.
    htp.p(schemaName.sample_javaScript);This will place java script at the form level.
    You can similarly write what all javascripting you wish to do at the form level instead of
    element level.For firing of Lovs also you can write code in the java script that will do the required action.

  • Custom comparator with LimitFilter

    When I use a custom comparator with a LimitFilter, the results within the limit are returned first and then the comparator is applied, instead of applying the comparator on the complete result set, and then limit them. Is there a way to achieve the scenario I am expecting?
    Thank is advance

    I am also on coherence version 3.5.2
    1. custom-pof-config.xml:
    <?xml version="1.0"?>
    <!DOCTYPE pof-config SYSTEM "pof-config.dtd">
    <pof-config>
         <user-type-list>
              <include>coherence-pof-config.xml</include>
              <user-type>
                   <type-id>2001</type-id>
                   <class-name>com.biperf.cache.example.CacheItem</class-name>
              </user-type>
              <user-type>
                   <type-id>2002</type-id>
                   <class-name>com.biperf.cache.example.CacheSubItem1</class-name>
              </user-type>
              <user-type>
                   <type-id>2003</type-id>
                   <class-name>com.biperf.cache.example.CacheSubItem2</class-name>
              </user-type>
              <user-type>
                   <type-id>2004</type-id>
                   <class-name>com.biperf.cache.example.CustomFilter1</class-name>
              </user-type>
              <user-type>
                   <type-id>2005</type-id>
                   <class-name>com.biperf.cache.example.CustomComparator1</class-name>
              </user-type>
              <user-type>
                   <type-id>2006</type-id>
                   <class-name>com.biperf.cache.example.CustomProcessor1</class-name>
              </user-type>
         </user-type-list>
         <allow-interfaces>true</allow-interfaces>
         <allow-subclasses>true</allow-subclasses>
    </pof-config>2. Domain objects:
    public class CacheItem extends AbstractEvolvable implements EvolvablePortableObject, java.io.Serializable, com.tangosol.io.pof.PortableObject
      private static final int VERSION = 1;
      private static final long serialVersionUID = -1L;
      private long cacheItemId;
      private Set<CacheSubItem1> item1 = new HashSet<CacheSubItem1>();
      private Set<String> item2 = new HashSet<String>();
      private Set<Long> item3 = new HashSet<Long>();
      public long getCacheItemId()
        return cacheItemId;
      public void setCacheItemId( long cacheItemId )
        this.cacheItemId = cacheItemId;
      public Set<CacheSubItem1> getItem1()
        return item1;
      public void setItem1( Set<CacheSubItem1> item1 )
        this.item1 = item1;
      public Set<String> getItem2()
        return item2;
      public void setItem2( Set<String> item2 )
        this.item2 = item2;
      public Set<Long> getItem3()
        return item3;
      public void setItem3( Set<Long> item3 )
        this.item3 = item3;
      @SuppressWarnings( "unchecked" )
      @Override
      public void readExternal( PofReader reader ) throws IOException
        cacheItemId = reader.readLong( 0 );
        item1 = (Set<CacheSubItem1>)reader.readCollection( 1, item1 );
        item2 = (Set<String>)reader.readCollection( 2, item2 );
        item3 = (Set<Long>)reader.readCollection( 3, item3 );
      @Override
      public void writeExternal( PofWriter writer ) throws IOException
        writer.writeLong( 0, cacheItemId );
        writer.writeCollection( 1, item1 );
        writer.writeCollection( 2, item2 );
        writer.writeCollection( 3, item3 );
      @Override
      public int getImplVersion()
        return VERSION ;
    public class CacheSubItem1 extends AbstractEvolvable implements EvolvablePortableObject, java.io.Serializable, com.tangosol.io.pof.PortableObject
      private static final int VERSION = 1;
      private static final long serialVersionUID = -1L;
      private Map<Integer, CacheSubItem2> item1 = new HashMap<Integer, CacheSubItem2>();
      public Map<Integer, CacheSubItem2> getItem1()
        return item1;
      public void setItem1( Map<Integer, CacheSubItem2> item1 )
        this.item1 = item1;
      @SuppressWarnings( "unchecked" )
      @Override
      public void readExternal( PofReader reader ) throws IOException
        item1 = (Map<Integer, CacheSubItem2>)reader.readMap( 0, item1 );
      @Override
      public void writeExternal( PofWriter writer ) throws IOException
        writer.writeMap( 0, item1 );
      @Override
      public int getImplVersion()
        return VERSION ;
    public class CacheSubItem2 extends AbstractEvolvable implements EvolvablePortableObject, java.io.Serializable, com.tangosol.io.pof.PortableObject
      private static final int VERSION = 1;
      private static final long serialVersionUID = -1L;
      private int value;
      private boolean flag;
      public int getValue()
        return value;
      public void setValue( int value )
        this.value = value;
      public boolean isFlag()
        return flag;
      public void setFlag( boolean flag )
        this.flag = flag;
      @Override
      public void readExternal( PofReader reader ) throws IOException
        value = reader.readInt( 0 );
        flag = reader.readBoolean( 1 );
      @Override
      public void writeExternal( PofWriter writer ) throws IOException
        writer.writeInt( 0, value );
        writer.writeBoolean( 1, flag );
      @Override
      public int getImplVersion()
        return VERSION ;
    public class CustomComparator1 implements java.io.Serializable, Comparator<CacheItem>, com.tangosol.io.pof.PortableObject
      private static final long serialVersionUID = -1L;
      private int sortOrder = 1 ;
      private Integer key ;
      public CustomComparator1(){}
      public CustomComparator1( Integer key )
        this.key = key ;
      @Override
      public int compare( CacheItem item1, CacheItem item2 )
        return sortOrder * ( getValue( item1 ).compareTo( getValue( item2 ) )  ) ;
      private Integer getValue( CacheItem item )
        int value = item.getItem1().iterator().next().getItem1().get( key ).getValue() ;
        return new Integer( value ) ;
      @Override
      public void readExternal( PofReader reader ) throws IOException
        sortOrder = reader.readInt( 0 ) ;
        key = reader.readInt( 1 ) ;
      @Override
      public void writeExternal( PofWriter writer ) throws IOException
        writer.writeInt( 0, sortOrder ) ;
        writer.writeInt( 1, key ) ;
      public void setAscendingOrder()
        sortOrder = 1 ;
      public void setDescendingOrder()
        sortOrder = -1 ;
    public class CustomFilter1 implements Filter, java.io.Serializable, com.tangosol.io.pof.PortableObject
      private static final long serialVersionUID = -1L;
      private Integer key = null ;
      public CustomFilter1(){}
      public CustomFilter1( Integer key )
        super() ;
        this.key = key ;
      @Override
      public boolean evaluate( Object item )
        for( CacheSubItem1 subItem1: ((CacheItem)item).getItem1() )
          CacheSubItem2 subItem2 = subItem1.getItem1().get( key );
          if(null!=subItem2){
            return true ;
        return false ;
      @Override
      public void readExternal( PofReader reader ) throws IOException
        key = reader.readInt( 0 ) ;
      @Override
      public void writeExternal( PofWriter writer ) throws IOException
        writer.writeInt( 0, key ) ;
    public class CustomProcessor1 extends AbstractProcessor implements PortableObject
      private static final long serialVersionUID = -1L;
      private Integer key ;
      private Set<String> item2s = new HashSet<String>();
      public CustomProcessor1(){}
      public CustomProcessor1( Integer key, Set<String> item2s )
        this.key = key ;
        this.item2s = item2s ;
      @Override
      public Object process( com.tangosol.util.InvocableMap.Entry entry )
        if ( !entry.isPresent() )
          return null ;
        CacheItem item = (CacheItem)entry.getValue() ;
        return extract( item ) ;
      public CacheItem extract( CacheItem item )
        CacheItem extract = new CacheItem() ;
        extract.setCacheItemId( item.getCacheItemId() );
        Set<CacheSubItem1> item1s = item.getItem1() ;
        for( CacheSubItem1 item1: item1s )
          extract.getItem1().add( getExtractedItem1( item1 ) ) ;
        for( String item2: item2s )
          if( item.getItem2().contains( item2 ) )
            extract.getItem2().add( item2 );
        return extract ;
      private CacheSubItem1 getExtractedItem1( CacheSubItem1 hydrated )
        CacheSubItem1 extracted = new CacheSubItem1() ;
        extracted.getItem1().put( key, hydrated.getItem1().get( key ) ) ;
        return extracted ;
      public Integer getKey()
        return key;
      public void setKey( Integer key )
        this.key = key;
      public Set< String > getItem2s()
        return item2s;
      public void setItem2s( Set< String > item2s )
        this.item2s = item2s;
      @SuppressWarnings( "unchecked" )
      @Override
      public void readExternal( PofReader reader ) throws IOException
        key = reader.readInt( 0 ) ;
        item2s = (Set<String>)reader.readCollection( 1, item2s );
      @Override
      public void writeExternal( PofWriter writer ) throws IOException
        writer.writeInt( 0, key ) ;
        writer.writeCollection( 1, item2s );
    }3. Cache data loader:
    public class CacheDataLoader
      public static final String BASE_ITEM2_KEY = "12345678901234567890";
      public static final char[] VALID_CHARS =
      {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J',
      'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'T', 'U',
      'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4',
      '5', '6', '7', '8', '9', '0'} ;
      public static final int NUMBER_OF_ITEM2 = 1000 ;
      public static final int NUMBER_OF_ITEM3 = 1000 ;
      public static final int NUMBER_OF_ITEM = 20000;
      public static final int BATCH_LOAD_SIZE = 10000 ;
      public static final int NUMBER_OF_KEYS_PER_SUBITEM1 = 50;
      public static final int MULITPLE_ITEM1_FREQUENCY = 1000 ;
      public static final int NUMBER_OF_MULTIPLE_ITEM1 = 1;
      public static final int MULITPLE_ITEM2_FREQUENCY = 2;
      public static final int NUMBER_OF_MULTIPLE_ITEM2 = 3;
      public static final int MULITPLE_ITEM3_FREQUENCY = 2;
      public static final int NUMBER_OF_MULTIPLE_ITEM3 = 5;
      public static final long BASE_CACHE_ITEM_KEY = 10000000 ;
      public static final long BASE_ITEM3_KEY = 10000000;
      private long item3Count = 0;
      private long item2Count = 0;
      private long cacheItemCount = 0;
      private NamedCache cache = CacheFactory.getCache( "cache-data" ) ;
      public static void main( String[] args )
        CacheDataLoader loader = new CacheDataLoader() ;
        loader.load() ;
        loader.createIndices() ;
      private void createIndices()
        cache.addIndex( new KeyExtractor( IdentityExtractor.INSTANCE ), false, null );
        cache.addIndex( new ReflectionExtractor( "getItem2" ), false, null );
        cache.addIndex( new ReflectionExtractor( "getItem3" ), false, null );
      private void load()
        long start = System.currentTimeMillis();
        cache.clear();
        int iterations = NUMBER_OF_ITEM/BATCH_LOAD_SIZE ;
        for ( int i=0;i<iterations; i++ )
          cache.putAll( getCacheItems( BATCH_LOAD_SIZE ) );
        System.out.println( "CACHE LOAD: Instances: " + cache.size() + " keysize: " + NUMBER_OF_KEYS_PER_SUBITEM1 + " Time: " + ( System.currentTimeMillis() - start ) );
      private Map<Long, CacheItem> getCacheItems( int loadSize )
        Map<Long, CacheItem> cacheItems = new HashMap<Long, CacheItem>() ;
        for( int i=0; i<loadSize; i++)
          CacheItem cacheItem = getCacheItem();
          cacheItems.put( cacheItem.getCacheItemId(), cacheItem ) ;
        return cacheItems ;
      private CacheItem getCacheItem()
        CacheItem cacheItem = new CacheItem();
        cacheItem.setCacheItemId( getNextCacheItemId() );
        cacheItem.setItem1( getItem1() ) ;
        cacheItem.setItem2( getItem2() );
        cacheItem.setItem3( getItem3() );
        return cacheItem;
      private Set<Long> getItem3()
        Set<Long> item3s = new HashSet<Long>() ;
        //First item3
        item3s.add( getNextItem3Id() ) ;
        //Additional item3s
        if( isAdditionalItem3Required() )
          for(int i=0; i<NUMBER_OF_MULTIPLE_ITEM3; ++i){
            item3s.add( getNextItem3Id() ) ;
        return item3s;
      private Set<String> getItem2()
        Set<String> item2s = new HashSet<String>() ;
        //First item2
        item2s.add( getNextItem2Id() ) ;
        //Additional item2s
        if( isAdditionalItem2Required() )
          for(int i=0; i<NUMBER_OF_MULTIPLE_ITEM2; ++i){
            item2s.add( getNextItem2Id() ) ;
        return item2s;
      private Set<CacheSubItem1> getItem1()
        Set<CacheSubItem1> item1s = new HashSet<CacheSubItem1>() ;
        //First item1
        item1s.add( getSubItem1() ) ;
        //Additional item1s
        if( isAdditionalItem1Required() )
          for(int i=0; i<NUMBER_OF_MULTIPLE_ITEM1; ++i){
            item1s.add( getSubItem1() ) ;
        return item1s;
      private CacheSubItem1 getSubItem1()
        CacheSubItem1 item = new CacheSubItem1() ;
        item.setItem1( getSubItemMap( NUMBER_OF_KEYS_PER_SUBITEM1 ) ) ;
        return item;
      private Map<Integer, CacheSubItem2> getSubItemMap( int numberPriceKeys )
        Map<Integer, CacheSubItem2> items = new HashMap<Integer, CacheSubItem2>();
        for ( int x = 0; x < numberPriceKeys; x++ )
          Integer key = x;
          items.put( key, getSubItem2() );
        return items;
      private CacheSubItem2 getSubItem2()
        CacheSubItem2 item = new CacheSubItem2() ;
        item.setFlag( RandomUtils.nextBoolean() ) ;
        item.setValue( getRandomValue() ) ;
        return item;
      private boolean isAdditionalItem1Required()
        return cacheItemCount%MULITPLE_ITEM1_FREQUENCY == 0;
      private boolean isAdditionalItem2Required()
        return cacheItemCount%MULITPLE_ITEM2_FREQUENCY == 0;
      private boolean isAdditionalItem3Required()
        return cacheItemCount%MULITPLE_ITEM3_FREQUENCY == 0;
      private long getNextCacheItemId()
        return BASE_CACHE_ITEM_KEY + (++cacheItemCount);
      private long getNextItem3Id()
        return BASE_ITEM3_KEY + (++item3Count%NUMBER_OF_ITEM3);
      private String getNextItem2Id()
        return BASE_ITEM2_KEY + (++item2Count%NUMBER_OF_ITEM2);
      private int getRandomValue()
        return RandomUtils.nextInt( 10000 ) ;
    }4. Test Case:
    public class TestExampleCache extends TestCase
      public void testLimitFilter1()
        final Integer key = getKey();
        Set<String> item2 = getItem2();
        Set<Long> item3 = getItem3();
        CustomComparator1 comparator = new CustomComparator1(key);
        comparator.setAscendingOrder();
        Filter[] filterArray = { new ContainsAnyFilter( "getItem2", item2 ),
                                 new ContainsAnyFilter( "getItem3", item3 ),
                                 new CustomFilter1( key ) };
        Filter allFilter = new AllFilter( filterArray ) ;
        CustomProcessor1 processor = new CustomProcessor1(key,item2);
        Set<Map.Entry<Long, CacheItem>> result1 = CacheFactory.getCache( "cache-data" ).entrySet( allFilter,comparator );
        for(Map.Entry<Long, CacheItem> entry : result1 ){
          CacheItem item = processor.extract( entry.getValue() );
          System.out.println(item.getCacheItemId()+"-"+item.getItem1().iterator().next().getItem1().values().iterator().next().getValue());
        System.out.println();
      public void testLimitFilter2()
        final Integer key = getKey();
        final int numberOfProducts = 10;
        Set<String> item2 = getItem2();
        Set<Long> item3 = getItem3();
        CustomComparator1 comparator = new CustomComparator1(key);
        comparator.setAscendingOrder();
        Filter[] filterArray = { new ContainsAnyFilter( "getItem2", item2 ),
                                 new ContainsAnyFilter( "getItem3", item3 ),
                                 new CustomFilter1( key ) };
        Filter allFilter = new AllFilter( filterArray ) ;
        LimitFilter limitFilter = new LimitFilter(allFilter, numberOfProducts);
        CustomProcessor1 processor = new CustomProcessor1(key,item2);
        Set<Map.Entry<Long, CacheItem>> result1 = CacheFactory.getCache( "cache-data" ).entrySet( limitFilter,comparator );
        for(Map.Entry<Long, CacheItem> entry : result1 ){
          CacheItem item = processor.extract( entry.getValue() );
          System.out.println(item.getCacheItemId()+"-"+item.getItem1().iterator().next().getItem1().values().iterator().next().getValue());
        System.out.println();
        limitFilter.nextPage();
        Set<Map.Entry<Long, CacheItem>> result2 = CacheFactory.getCache( "cache-data" ).entrySet( limitFilter,comparator );
        for(Map.Entry<Long, CacheItem> entry : result2 ){
          CacheItem item = processor.extract( entry.getValue() );
          System.out.println(item.getCacheItemId()+"-"+item.getItem1().iterator().next().getItem1().values().iterator().next().getValue());
      private Integer getKey()
        return new Integer(10);
      private Set<String> getItem2()
        Set<String> items = new HashSet<String>();
        items.add( "12345678901234567890" + 1 );
        items.add( "12345678901234567890" + 2 );
        items.add( "12345678901234567890" + 3 );
        items.add( "12345678901234567890" + 4 );
        items.add( "12345678901234567890" + 5 );
        items.add( "12345678901234567890" + 6 );
        items.add( "12345678901234567890" + 7 );
        items.add( "12345678901234567890" + 8 );
        items.add( "12345678901234567890" + 9 );
        items.add( "12345678901234567890" + 10 );
        items.add( "12345678901234567890" + 11 );
        items.add( "12345678901234567890" + 12 );
        return items;
      private Set<Long> getItem3()
        Set<Long> items = new HashSet<Long>();
        items.add( new Long(10000001) );
        items.add( new Long(10000002) );
        items.add( new Long(10000003) );
        items.add( new Long(10000004) );
        items.add( new Long(10000005) );
        items.add( new Long(10000006) );
        items.add( new Long(10000007) );
        items.add( new Long(10000008) );
        items.add( new Long(10000009) );
        items.add( new Long(10000010) );
        return items;
    }5. Results:
    a. testLimitFilter1()
    10010001-109
    10002002-121
    10002004-487
    10006003-726
    10008004-762
    10000004-845
    10010003-922
    10014003-1157
    10012002-1426
    10008002-1585
    10002003-1709
    10004004-2004
    10004001-2179
    10018002-2452
    10016004-3073
    10012004-3145
    10008001-3249
    10018001-3270
    10008003-3319
    10016002-3778
    10012001-4256
    10012003-4391
    10002001-4921
    10006002-5072
    10000002-5162
    10016003-5777
    10014004-6068
    10000001-6260
    10000003-6373
    10004002-6615
    10014001-7679
    10006001-7729
    10006004-7794
    10010002-8188
    10010004-8215
    10018004-8258
    10016001-8383
    10018003-8760
    10004003-9652
    10014002-9876
    b. testLimitFilter2()
    Page-1
    10002004-487
    10000004-845
    10012002-1426
    10008002-1585
    10004004-2004
    10018001-3270
    10016003-5777
    10006004-7794
    10016001-8383
    10018003-8760
    Page-2
    10018002-2452
    10008001-3249
    10008003-3319
    10016002-3778
    10012001-4256
    10012003-4391
    10014004-6068
    10000003-6373
    10010002-8188
    10010004-8215
    c. Expected results:
    Page-1
    10010001-109
    10002002-121
    10002004-487
    10006003-726
    10008004-762
    10000004-845
    10010003-922
    10014003-1157
    10012002-1426
    10008002-1585
    Page-2
    10002003-1709
    10004004-2004
    10004001-2179
    10018002-2452
    10016004-3073
    10012004-3145
    10008001-3249
    10018001-3270
    10008003-3319
    10016002-3778
    Edited by: user8065775 on Oct 21, 2009 3:02 PM
    PS : Looks like the following thread addresses the problem that I have mentioned, which has links to download the source code but they do not work. Is there a way that I can access the java source pointed to in the post pointed to by the following link?
    Re: The question about the locking of the cache
    SortByMethodNameAggregator.java
    SortByMethodNameCaller.java
    Can you please email me the code to [email protected]

  • Doubt with Customer pricing group

    Hi ,
              I have  maintained a customer pricing group in customer master. say x is my customer so i maintained  c.p.g as A1(regular cust).  so when ever mr x place an order he gets some discount  which i am maitaining in condition type k020 . so now i create a new material in the same sales area but i dont want to  give Mr x any kind of discount.. not ever k020 disc..  how do i do this ..  becoz by default this cus belongs to group A1.
    Any solution ??
    Edited by: jagadisha14 on Jul 14, 2009 6:16 PM

    Hi jagadisha14,
                  Well, in your case if you don't want to determine in all cases the condition type K020 when your c.p.g is A1 you should create a condition table for that condition type K020 with an additional field to distinguish for which materials you want the discount, this field can be the material pricing group or the material number or other, it should be a field with different value between these material, because the same result as now will be get.
    Example: 
    Material XX             YY
    MPG       B1             B2
    So if you have a condition record for K020
    CPG                A1
    MPG                B1
    The condition K020 will be only determine for material XX.
    On other hand I don't think condition exclusion works in this case because it has other functionality.
    Thanks,
    Mariano.
    Edited by: Mariano Adalberto Sorrentino on Jul 14, 2009 7:47 PM

  • Sorting a Set with a custom Comparator

    Hi,
    I wondered how to sort a Set with a custom Comparator. I know how to do this with a List: Collections.sort(list,new CustomComparator()).
    But how can I do this with a Set?
    Thanks
    Jonny

    If you want to just sort the Set on demand, you'd have to dump its contents into a List, sort the List, then dump its contents back into a LinkedHashSet.
    If you want the set to always be in sorted order, use a SortedSet, such as TreeSet.

  • Customer and customer group with different credit limit.

    HI All,
    we have customers belonging to a group. Every single Customer of the group must have its own credit limit and the group must have another credit limit too. Example.
    Customer 1: Limit u20AC 100.000
    Customer 2: Limit u20AC 350.000
    Customer 3: Limit u20AC 400.000
    Group 1: Limit u20AC 700.000
    I used the customer hierarchy and now each customer have the high-level customer "10000":
    Group 1 = Customer "10000" (Account Group 0012)
    so Customer 1 + customer 2 + customer 3  limit can not exceed limit group 1 (u20AC 700.000)
    How can fix ?
    Thanks in advance.
    Antonio

    thank you for your reply
    in my system, each customer is paying, but the group 1 no. The credit limit is not shared but different. If CLI1 exceeds its limit, I lock the sales orders, but if an individual does not exceed the limit I have to check the sum of CLI1 CLI2 CLI3 exceeds the limit of u20AC 700,000.
    example:
    CLI1: Limit u20AC 100,000
    CLI1: credit exposure u20AC 55,000
    Group 1: Limit u20AC 700,000
    CLI1 CLI2 CLI3: credit exposure u20AC 670,000
    New Customer Order CLI1: value u20AC 35,000
    The sales order is blocked because it does not exceed the limit CLI1 (100,000 u20AC) but exceeds the limit of a Group (700,000 u20AC)
    Thanks
    Antonio

  • Business Partner Creation ( Master Tenant with Customer Account)

    Hello Experts
    Am trying to create a master tenant with a customer account, but as i save the business partner there is no corresponding creation of the master tenant with a customer account in the company code. The system only generates a business partner created. I have cheked the settings on business partner customer and have the correct FI custmer acount to the business partner, have also checked settings on the assignment of the reconciliation account to the BP and again it is compatible with the customer reconciliation account in Financials. I have also the synchronization data to see whether the synchronization object is activated, and it was not activated and i activated it, but still am not able to create a master tenant with customer account.
    Please Experts help me on this am very very  stranded
    Regards
    David Mavi

    Hi David,
                  Following activities are to be done to create customer simultaneously while the creation of business partner.
    Business Partner Number Range: IMG>Flexible Real Estate Management (RE-FX)>Business Partner>Relevant Settings for Business Partner in RE Context>Number Range>Business Partner Number Range
    Define Grouping and number range: IMG>Flexible Real Estate Management (RE-FX)>Business Partner>Relevant Settings for Business Partner in RE Context>Number Range>Define Groupings and Assign Number Ranges
    Also make sure that the customer account group is created with a number range which should be external. The number range for the business partner should be internal.           
    Master Data syncronization: IMG>Cross Application Components>Master Data Synchronization>Customer/Vendor Integration>Business Partner Settings>Settings for Customer Integration>Field Assignment for Customer Integration>Assign Keys>Define Number Assignment for Direction of BP to Customer
    In the settings select the same number range only if the number ranges for the customer account group and BP groups are the same.
    If u have done all these things and still the customer is not getting created then there might be a problem of the mandatory fields. i.e may be in customer account group some fields are mandatory which are not getting copied from the BP. So make all the fields in the customer account group as optional. and try to create new BP again.
    Regards,
    Deepak M

  • Sort order by custom comparable logic

    Hi All,
    Is it possible to sort the records from NamedCache.entrySet() by implementing Comparable<T> in my pojo?
    Thanks,

    user1096084 wrote:
    Thanks for your quick response.
    My requirement is to fetch objects without filter but with custom sort order and
    I couldn't find any method in QueryMap for this purpose.
    What will be result if implement Comparable interface in object?Hi,
    1. You can always use AlwaysFilter.INSTANCE for filtering.
    2. You can use a parallel aggregator to parallelly presort objects and also limit the number of objects you fetch.
    Implementing Comparable with the objects allows you to call entrySet(Filter, Comparator) with null for comparator. The method entrySet() without parameters or the entrySet(Filter) do not sort regardless of whether your objects implement comparable or not.
    Best regards,
    Robert

  • Create Document Set with custom Create Only permission set

    Here is the situation. We have a requirement where my customer wants to create document sets, however, document set/document level permissions are required.
    Setup: We created a new permission level called "Create Only". We then give the user Read and Create only permissions. This allows the user to theoretically create the item. We then run a Workflow on create that Replaces the permissions so that
    you are only allowed to view the ones you created along with other security groups based on their choices in the metadata fields.
    This setup works PERFECTLY when using a List or Form Library.
    However, for the life of me I cannot get it to work for Document Sets. If I have the same setup, I get an Access Denied message. However, it still creates the document set.
    What is weird, I've been playing around with custom permission levels and it seems as though the user has to have EDIT permissions at a minimum in order to create the document set. This will not work for me since I dynamically assign permissions to each
    document set based on what they select.
    As a side note, the only tool I have at my disposal is SharePoint Designer 2010.
    Does anyone know if there is an actual requirement to have EDIT permissions when creating a Document Set? Any input would be greatly appreciated.
    Alternatively, is there a way to setup permissions on a library for all NT Authenticated users so that we can give them the necessary permissions to create the Document Set, but still prevent them from see the other items and then the Workflow would set
    the permissions accordingly?
    I believe the more granular the permissions it uses those permissions instead so would this work?  I have not tested this theory yet.

    Hi,
    According to your description, my understanding is that you want to know if there is an actual requirement to have EDIT permissions when creating a Document Set and is there a way to setup permissions on a library for all NT Authenticated users and prevent
    them from seeing items created by others.
    For the first question, per my knowledge, if a user is given the Add Items permission, he/she can create a document set in SharePoint.
    However, there is an error “access denied” after the document set is created. It is due to the user has no permission to access the page which SharePoint will redirect the user to after finishing creating the document set.
    If the user is also given Edit Items permission, there will be no error when he/she create a document set.
    For the second question, I recommend to follow the link below to
    customize item permissions for each document submitted to a document library and remember to give the
    NT Authenticated users contribute permission.
    http://blogs.technet.com/b/spke/archive/2010/04/09/configure-item-level-permissions-for-document-libraries-sharepoint-2010-edition.aspx
    To grant permission to NT Authenticated users, please refer to the link below:
    http://office.microsoft.com/en-in/sharepoint-server-help/what-happened-to-add-all-authenticated-users-HA101805183.aspx
    Best regards.
    Thanks
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • How to use a custom comparator in a TableSorter?

    Hi,
    I want to use a custom comparator for sorting a table by a specific column.
    As you possibly know, the constructor for the TableSorter class looks like this:
    TableSorter(IWDTable table, IWDAction sortAction, Map comparators);
    As Map is an Interface I chose Hashmap as comparator container. So, I use the put(Key, Value) method to insert my own comparator into the Hashmap in order to deliver this Object to the TableSorter constructor.
    But there is an essential problem:
    I assume, that the column which is to be associated with my comparator is determined by the key of the Map object from the TableSorter constructor.
    Presuming this, <u>what should the map key be/look like?</u>
    An Integer counted from the columns? The column header as String? Whatever? Or am I on the wrong way?
    PS:
    Hours of search did not lead me to some kind of documentation or javadoc of the TableSorter class! This can't be, does someone have a link please?
    Thanks a lot for any help.

    (sorry Mrutyun, this did not help.)
    Ok, I solved it; let me share it with you:
    public class ExampleView
            public static void wdDoModifyView(IPrivateExampleView wdThis, IPrivateExampleView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
                     * A custom Comparator class is used for sorting by Severity.
                     * An Object of it is delivered to an object of a Map class to be delivered to the TableSorter constructor.
                     * The Map class consists of key-value pairs, and the TableSorter must accept the Key of it
                     * because he uses it to assign the mapped Comparator to the column of the table to be sorted!
                     * And this is done with the ID of the Element, which shall be sorted with the Comparator, used as Map Key.
                     * All other columns of the assigned tables will be sorted by default Comparators.
                    IWDTable table = (IWDTable) view.getElement("[TableName]");
                    HashMap tableComps = new HashMap();
                    tableComps.put(view.getElement("[ColumnName]").getId(), new MyComp(wdContext.currentExampleElement())); //The map key value I looked for is the ID of the Element of the Column!
                    wdContext.current/*yourContextNode*/Element().setTableSort(
                            new TableSorter(table, wdThis.wdGetSortTableRowAction(),
                                    tableComps)); //Insert HashMap with the new Comparator
            public void onActionSortTableRow(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
            //@@begin onActionSortTableRow(ServerEvent)
                            wdContext.currentConfigurationElement().getTableSort().sort(wdEvent, wdContext.nodeOpenIncident());
            //@@end
    As you see, the Column which is to be sorted by the custom Comparator "MyComp", is clearly assigned to it. Thus, is will only be used when sorting by this column is done.
    The "inActionSort" method is as usual.
    My Comparator sorts a column which contains variables of a "SimpleType" with an enumeration. (If you need help with this, feel free to write me.) To achieve this, the Comparator needs to know what this SimpleType consists of. That's why I deliver this Element per Constructor to it.
    public class MyComp implements Comparator
         MappedNodeElement element;
         public SeverityComp(I/*one*/Element element)
              this.element = element;
         public SeverityComp(I/*another*/Element element)
              this.element = element;
         public int compare(Object severity1, Object severity2)
    Because MappedNodeElement is such abstract, it can be used by several different Tables, provided they use the same SimpleType.
    Concerning my quest for this resolution, I hope this is helpful.
    null

  • How to create a transaction code for a function group with screen 100 as st

    Hello ,
    I have requirement where I need to create a function group and create screen 100, 200, 300 and include the function in the screens.
    Customer asked me to create a transaction with the screen 100 as the starting screen.
    Can you please let me know how to create a transaction code for a function group with screen 100 as starting screen.
    [ It is not a module pool program ].
    Thanks
    Prashanth.
    Moderator message - Please ask a specific question and do not ask the forum to do your work for you - post locked
    Edited by: Rob Burbank on Jun 2, 2009 11:49 AM

    Go to transaction SE93, enter a transaction code that you want and click on "create". Enter a text and select the "Transaction with Parameters" button. In the Default Values section, enter START_REPORT in the transaction field. Check the "skip initial screen" box. In the Name of Screen field section enter the following lines:
    Name of screen field:                               Value
    D_SREPOVARI-REPORTTYPE                RW
    D_SREPOVARI-REPORT                        ZPCA
    Save and transport accordingly.

Maybe you are looking for

  • IMac 27" 2010 distorted displays -(checkerboard, ⅛ inch square dots, screen artifacts)

    THE ‘FIX’  (kinda/sorta) I own an iMac 27” 2010 Model ID 11,3 with the ATI 5750 (lucky me)  I too suffer(ed) from the checkerboard, distorted screen issue.  THIS is what I did to pretty much eliminate the symptoms so I could reliably use my system: u

  • Authorization Object Error

    Hi All, I added an object M_MATE_WRK in the master role and generated the profile for derived role as well. The necessary derived roles have the object now. When user runs a custom t-code which needs this object the su53 still shows that access for M

  • Java.lang.ClassCastException  in local lookups

    hi, i have written two ejb projects named as proj1 and proj2. i deployed proj1 as EAR1 and proj2 as EAR2.(in same server) in proj1 Sessionbean1  i need to use(lookup) proj2 Sessionbean2 . <b>i have given jndi name for proj2 Sessionbean2 as "jndiproj2

  • DSM Terminator issue -  when exiting, user sees "about blank" screen

    This issue is being experienced by two of our Portal users. When the user exits the portal, they get an "about blank" internet explorer page that is minimized in the Windows taskbar. When viewing the "about blank" page properties, there is no informa

  • HELP! MBP is not starting up with a start up disk

    My MBP was working fine one minute then all of a sudden, I heard constant beeping. After that it didn't shut down unless I pushed the power button. Upon restarting, I saw a question mark in the middle with a grey screen. I tried reinstalling OSX leop