1

私は、Spring Batch を使用して実装されたデータローダーに取り組んでいます。つまり、複数のフラットファイルを読み取り、処理し、コミット間隔 1000 で pojo のリストをデータベースに書き込みます。
ファイルから読み取られた各行は、処理の結果に設定する必要があるプロパティを含む pojo オブジェクトに変換されます。

180 行の 3 つの列を含むルックアップ テーブルがあります。各列の値を個別のリストに保持し、各 POJO 項目のプロパティと一致する述語でリストを反復処理します。すべてのリストで一致が見つかった場合、プロパティが設定されます。使用する述語は次のとおりです。

public class LogicProcessor<I, O> implements ItemProcessor<I, O> {

    private Map[] params ;

    public void setParams( Map[] params )
    {
        this.params = params;
    }

    public O process(I item) throws Exception 
    {
        System.out.println(params  );

        List container      =  (List) params[1].get("SRVC");
        final List callInd      =  (List) container.get(0);
        final List totaltype        =  (List) container.get(1);
        final List servicetype  =   (List) container.get(2);

        Predicate<I> callIndipredicate = new Predicate<I>() {
            public boolean apply(I input) 
            {
                boolean flag=false;
                for (int i=0;i<callInd.size();i++)
                {
                    if ( "*".equals(callInd.get(i)))
                    {
                        flag= true;
                        break;
                    } else
                    {
                        try 
                        {
                            if (BeanUtils.getProperty(input,"CALLINDICATOR").equals(callInd.get(i)))
                            {
                                flag = true;
                                break;
                            } else
                            {
                                flag= false;
                                break;
                            }
                        } catch (IllegalAccessException e) {
                            e.printStackTrace();
                        } catch (InvocationTargetException e) {
                            e.printStackTrace();
                        } catch (NoSuchMethodException e) {
                            e.printStackTrace();
                        }

                    }
                }
                return flag;
            }
        };

        Predicate<I> totaltyppredicate = new Predicate<I>() {
            public boolean apply(I input) 
            {
                boolean flag=false;
                for (int i=0;i<totaltype.size();i++)
                {
                    try 
                    {
                        if (BeanUtils.getProperty(input,"TOTALTYPE").equals(totaltype.get(i)))
                        {
                            flag = true;
                            break;
                        } else
                        {
                            flag= false;
                            break;
                        }
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    } catch (NoSuchMethodException e) {
                        e.printStackTrace();
                    }
                }
                return flag; 
            }
        };

        Predicate<I>srvctypepredicate = new Predicate<I>() {
            public boolean apply(I input) 
            {
                boolean flag=false;
                for (int i=0;i<servicetype.size();i++)
                {
                    try 
                    {
                        if (BeanUtils.getProperty(input,"SERVICETYPE").equals(servicetype.get(i)))
                        {
                            flag = true;
                            break;
                        } else
                        {
                            flag= false;
                            break;
                        }
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    } catch (NoSuchMethodException e) {
                        e.printStackTrace();
                    }
                }
                return flag;                
            }
        };

        Predicate<I> isFound = Predicates.and(callIndipredicate,totaltyppredicate,srvctypepredicate);
        int preorPost=  Iterables.indexOf(Arrays.asList(item), isFound) ;
        System.out.println(preorPost);
        if (preorPost >=0)
        {
            BeanUtils.setProperty(item, "PREPOST", '0');
        } else
        {
            BeanUtils.setProperty(item, "PREPOST", 'X');
        }
        return (O) item;
    }

}

アイテムをフィルタリングしてグアバを使用して変更するより良い方法はありますか。

4

1 に答える 1

2

Guava: DB ルックアップを行うPredicateでIterables.findを使用します。Functionを使用して結果に変換を適用します。

コモンズ: FilterListIterator (または) をPredicateFilterIteratorと組み合わせて使用​​し、次にTransformIteratorTransformerと組み合わせて使用​​します。

LambdaJについては知りません。

于 2011-10-21T15:20:22.853 に答える