0

Here is my method where im convertng a string to enum for a case statement...

   public int AnalyseRow(String UserName, String SymbolName, Date TransDate, double OpenPrice, double HighPrice, double LowPriceee, double ClosePrice, int Volume, String Splits)
        {
            System.out.println("analyse row detected ........................... X");

            String SLPoint = ""; 
            String SLType = ""; 
            String TLDPoint  = "";
            String TLUPoint = "";
            double STPoint; 
            double LTPoint;
            double MAPoint;

            boolean bTLUIsHorizontal  = false;
            double dPointDef;
            double dHorizontalPoints; 
            boolean TLDHorizontalIsSet  = false;
            boolean TLUHorizontalIsSet  = false;

            double dEntryPrice = 0; 
            double dStopLossPrice = 0;

            List objOpenLTOrders = null; 

            int intOpenLTOrdersCount = 0 ;

            List objLiveLTOrders = null; 

            int intLiveLTOrdersCount=0;

            List objOpenSTOrders=null;

            int intOpenSTOrdersCount=0;

            List objLiveSTOrders=null;
            int intLiveSTOrdersCount=0;
            List objContractSettings=null; 


            double dVolume = 0;
            double dGrossProfit=0;
            double dNetProfit=0;
            double dBrokerageCharge=0;
            double dSpreadCharge=0;

                        for(int i=0; i<count;i++)
                        {
    //                      'MsgBox(objSettingsServiceDataRow.SettingName & " - " & objSettingsServiceDataRow.SettingValue)
                            String caseOf = (settingsBusinessService.readRow(1).getSETTINGNAME());
    //                      Select Case objSettingsServiceDataRow.SettingName
                            EnumRule enum1 = EnumRule.valueOf("caseOf");


                            switch(enum1)
                            {
                                case caseOf:
                                {
                                    if( (settingsBusinessService.GetAllSettings(UserName, settings)).size() != 0)
                                    {
                                        //if (TransDate > tradingBusinessService.GetMaxStockDataTransDate(UserName, SymbolName).AddDays(Double.valueOf((objSettingsServiceDataRow.SettingValue))))
                                        {
                                            SaveLog(UserName, "WARNING DateTime Difference : Difference exceeded specified amount on trans " + SymbolName + " " + TransDate, Now(), 2);
                                            return 1;
                                            //break;
                                        }


                                    }
                                }


 }

My enum class:

package com.ib.client.mts.backend.BusinessService;

public enum EnumRule {

    caseOf, EUR

}

what will be the bean id for this class ? im trying property type but its facing error that i need a constructer where as i never used it ? Is there any speacific bean id type for enum class?

Aritra
  • 163
  • 4
  • 18

1 Answers1

0

EDITED: According to How assign bean's property an Enum value in Spring config file?, you can simply use the enum value:

<bean name="yourBean" class="your.pakage">
   <property name="type" value="EUR" />
</bean>

You can create a Spring bean from a java enum using the static valueOf method as a factory method.

Using your EnumRule:

<bean id="yourBean" class="com.ib.client.mts.backend.BusinessService.EnumRule" factory-method="valueOf">
    <constructor-arg>
        <value>EUR</value>
    </constructor-arg>
</bean>
Community
  • 1
  • 1
jalopaba
  • 8,039
  • 2
  • 44
  • 57