How to return a non const value?

Hi,
I would like one of my methods to return a date object that should not be modified. How do I enforce this? I could create a 2nd object duplicating the original and return it, so any changes to the returned object will not mess up the original, but there must be a better way. What is it?
Thanks,
Carlo

That, sadly won't work because I still need to be able to modify the date internally to the class, just when I return it in a getter I want to enforce non modifyability.
Following is the code. Look at the getNextTime() method, this is the method that returns the date object that I want to enforce being non modifyable.
import java.util.GregorianCalendar;
import java.util.Timer;
import java.util.TimerTask;
import java.util.HashMap;
import java.util.Date;
* Any ClockListener may register itself with this object to be notified at
* specified times. This may for example be usefull for a job that needs to
* be run at certain times or time intervals.
* To schedule notifications:
* 1. Create the class that implements the ClockListener interface.
* 2. Add this class as a listener to the clock, using one of the schedule
*    methods.
* To stop notification:
* 1. Use remove method.
* To change a notification schedule
* 1. Reschedule the listener. If added previously the instance will
*    automatically be rescheduled.
* NOTE: The granularity of this timer is 1 minute. All timers will fire on
*       the minute, even if scheduled mid-way a minute.
* @see com.sorenson.utils.ClockListener
* @author carlo
* @since  Nov 21, 2001 - 9:49:31 AM
public class Clock
    private HashMap mSchedules;
    private HashMap mReminders;
    private static Clock mInstance = null;
    public static Clock getInstance()
        if (null == mInstance)
            mInstance = new Clock();
        return mInstance;
    private Clock()
        mSchedules = new HashMap();
        mReminders = new HashMap();
     * Every (minute) th minute(s)
    public void scheduleInterval(ClockListener listener, int minute)
        addSchedule(listener, -1, -1, -1, minute);
     * Every day at (hour):(minute)
    public void scheduleDaily(ClockListener listener, int hour, int minute)
        addSchedule(listener, -1, -1, hour, minute);
     * Every week on the (dayOfWeek) day at (hour):(minute)
    public void scheduleWeekly(ClockListener listener, int dayOfWeek, int hour, int minute)
        addSchedule(listener, -1, dayOfWeek, hour, minute);
     * Every month on the (dayofMonth) day at (hour):(minute)
    public void scheduleMonthly(ClockListener listener, int dayOfMonth, int hour, int minute)
        addSchedule(listener, dayOfMonth, -1, hour, minute);
    public Date getNextTime(ClockListener listener)
        return ((Schedule)mSchedules.get(listener)).mNextTime.getTime();
    private void addSchedule(ClockListener listener, int dayOfMonth , int dayOfWeek, int hour, int minute)
        // check for existance
        if (null != mSchedules.get(listener))
            remove(listener);
        // create a schedule for the listener based upon the specified parameters
        Schedule schedule = new Schedule(dayOfMonth, dayOfWeek, hour, minute);
        // link the listener to the schedule and store
        mSchedules.put(listener, schedule);
        // create a reminder for the next wake up time and store
        mReminders.put(listener, new Reminder(listener, schedule.updateNext()));
    public void remove(ClockListener listener)
        // cancel the current reminder
        ((Reminder)mReminders.get(listener)).cancel();
        // remove the schedule for the listener
        mSchedules.remove(listener);
        // remove the canceled reminder for the listener
        mReminders.remove(listener);
    private void wakeUp(ClockListener listener)
        // remove the old reminder
        mReminders.remove(listener);
        // create a new reminder with the next scheduled wake up time
        mReminders.put(listener, new Reminder(listener, ((Schedule)mSchedules.get(listener)).updateNext()));
        // notify listener
        listener.onWakeUpCall();
     * Defines a wake up schedule for a clock listener
    private class Schedule
        // the next date/time the listener for this schedule needs to be notified
        GregorianCalendar mNextTime;
        // schedule rule variables
        int mDayOfMonth;
        int mDayOfWeek;
        int mHour;
        int mMinute;
        Schedule(int dayOfMonth , int dayOfWeek, int hour, int minute)
            // set the initial next time to right now,
            mNextTime = BasicHelper.getGMTGregorianCalendar();
            mNextTime.set(GregorianCalendar.SECOND, 0);
            // save the schedule rules
            mDayOfMonth = dayOfMonth;
            mDayOfWeek = dayOfWeek;
            mHour = hour;
            mMinute = minute;
        long updateNext()
            // once a month
            if (-1 != mDayOfMonth)
                nextMonth();
            // once a week
            else if (-1 != mDayOfWeek)
                nextWeek();
            // once a day
            else if (-1 != mHour)
                nextDay();
            // every so many minutes
            else
                nextSoManyMinutes();
            // return the time in ms between the current time and the next scheduled wake up time
            return mNextTime.getTime().getTime() - BasicHelper.getGMTGregorianCalendar().getTime().getTime();
        private void nextMonth()
            mNextTime.add(GregorianCalendar.HOUR_OF_DAY, mHour - mNextTime.get(GregorianCalendar.HOUR_OF_DAY));
            mNextTime.add(GregorianCalendar.MINUTE, mMinute - mNextTime.get(GregorianCalendar.MINUTE));
            mNextTime.add(GregorianCalendar.DATE, mDayOfMonth - mNextTime.get(GregorianCalendar.DAY_OF_MONTH));
            // skip to next month if next time in the past
            if (BasicHelper.getGMTGregorianCalendar().after(mNextTime))
                mNextTime.add(GregorianCalendar.MONTH, 1);
        private void nextWeek()
            mNextTime.add(GregorianCalendar.HOUR_OF_DAY, mHour - mNextTime.get(GregorianCalendar.HOUR_OF_DAY));
            mNextTime.add(GregorianCalendar.MINUTE, mMinute - mNextTime.get(GregorianCalendar.MINUTE));
            mNextTime.add(GregorianCalendar.DATE, mDayOfWeek - mNextTime.get(GregorianCalendar.DAY_OF_WEEK));
            // skip to next week if next time in the past
            if (BasicHelper.getGMTGregorianCalendar().after(mNextTime))
                mNextTime.add(GregorianCalendar.DATE, 7);
        private void nextDay()
            GregorianCalendar newTime = new GregorianCalendar(
                    mNextTime.get(GregorianCalendar.YEAR),
                    mNextTime.get(GregorianCalendar.MONTH),
                    mNextTime.get(GregorianCalendar.DATE),
                    mHour,
                    mMinute);
            if (newTime.after(mNextTime))
                mNextTime = newTime;
            else
                newTime.roll(GregorianCalendar.DATE, true); // rolls one day ahead
                mNextTime = newTime;
        private void nextSoManyMinutes()
            mNextTime.add(GregorianCalendar.MINUTE, mMinute);
     * Internal class used to set reminders for the wake up schedules of the listeners
    private class Reminder
        Timer mTimer;
        ClockListener mListener;
        Reminder(ClockListener listener, long ms)
            mListener = listener;
            mTimer = new Timer();
            mTimer.schedule(new RemindTask(), ms);
        void cancel()
            mTimer.cancel();
        class RemindTask extends TimerTask
            public void run()
                // Terminate the timer thread
                mTimer.cancel();
                // Wake up the listener
                Clock.this.wakeUp(mListener);

Similar Messages

  • How to return more than one value from a  function

    hello everybody,
    Can anyone tell me how to return more than a single value from a function, the problem is i have 4 points,
    2 points form one line ,another 2 points form 2nd line ,each point is 3 dimensional(x,y,z coorinates) so i will pass these values to func(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4), i will find the point of intersecton of two lines and i will get it as x,y,z , now how to return these 3 coordinates,usually the function returns only one value, please help me to solve it out.
    Thanks.

    I think the easiest way or trick here is (easiest isn't always the best as we know, but atleast this one will work) to create simple data array. and pass that. Create an array with:
    <code>
    class justArray {
    int x=0
    int y=0;
    int z= 0;
    ...somewhere
    justArray[] points= new justArray[4];
    points[0].x= ..
    points[0].y= ..
    points[0].z= ..
    points[1].x= ..
    return points[]
    </code>

  • How to find first non zero value from the numeric value or string?

    Hiii, Every body
              I have one numeric indicator in which some valuse is coming with the decimal value, lets say 0.00013, now i want to find the first non-zero value from this numeric indicator, then what should i do to do so? i have converted it in the string, but i could not find any method to find first non-zero value from that string or either from the numeric indicator????
          Can you please help me, how to do it? i have attached the vi and write all the description inside.
    Thanks in Advance,
    Nisahnt
    Attachments:
    Find first nonzero.vi ‏20 KB

    Just convert it to an exponential string and take the first character .
    Message Edited by altenbach on 05-10-2006 08:00 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    FisrstNonzeroChar.png ‏3 KB
    FindFirstNonzeroCharacter.vi ‏20 KB

  • How to output only non-existing values

    If I have a table say Employee and has values for EmployeeNum as 1111, 2222, 3333 and I have a query like this. SELECT EMPLOYEENUM FROM EMPLOYEE WHERE EMPLOYEENUM IN (4444, 66666, 1111)
    Now, this will only return 1111. But, I want to find out values that are not in the table. So, I want to output 4444, 66666.
    How can this be done. Please suggest?

    This is called anti join...
    SELECT *
       FROM TABLE(sys.odcivarchar2list(4444, 66666, 1111)) t
      WHERE NOT EXISTS
      ( SELECT 1 FROM EMPLOYEE d WHERE d.EMPLOYEENUM = t.column_value
      )Ravi Kumar

  • How to return more than one value through RECORD TYPE from function

    Hi friends,
    i m ew in oracle forms. i want to return the two values at a time from a function but can't,Please help me. my codding is as following
    Thanks in advance.
    FUNCTION Fun_Choose_Right_cast(v_post_no payroll.post_register.post_no%TYPE) RETURN RECORD IS --here is the error 
    v_return_char CHAR NOT NULL := 'X';
    TYPE row_no_record_type IS RECORD
         (v_row_id NUMBER(3)NOT NULL := 0,
         v_char CHAR NOT NULL := 'X');
    row_no_record row_no_record_type;
    BEGIN
    IF v_post_no = 1 THEN
         IF TRUNC(v_post_no*0.15) >= 1 THEN
              row_no_record_type.v_row_id := v_post_no;
              v_char := 'A';
              --v_return_char := 'A';
         END IF;
         IF TRUNC(v_post_no*0.075) >= 1 THEN
              row_no_record_type.v_row_id := v_post_no;
              v_char := 'B';
              --v_return_char := 'B';
         END IF;
         IF TRUNC(v_post_no*0.275) >= 1 THEN
              row_no_record_type.v_row_id := v_post_no;
              v_char := 'C';
              --v_return_char := 'C';
         END IF;
         IF row_no_record_type.v_row_id = 0 AND v_char = 'X' THEN
              row_no_record_type.v_row_id := v_post_no;
              v_char := 'D';
         --IF v_return_char = 'X' THEN 
              --v_return_char := 'D';
         END IF;
    ELSIF(v_post_no BETWEEN 2 AND 100) THEN
         IF TRUNC(v_post_no*0.15) > TRUNC((v_post_no-1)*0.15) THEN
              row_no_record_type.v_row_id := v_post_no;
              v_char := 'A';
              --v_return_char := 'A';
         END IF;
         IF TRUNC(v_post_no*0.075) > TRUNC((v_post_no-1)*0.075) THEN
              IF TRUNC(v_post_no*0.15) > TRUNC((v_post_no-1)*0.15) THEN
                   row_no_record_type.v_row_id := v_post_no-1;
                   v_char := 'B';
                   --v_return_char := 'A';
              ELSE
                   row_no_record_type.v_row_id := v_post_no;
                   v_return_char := 'B';
              END IF;
         END IF;
         IF TRUNC(v_post_no*0.275) > TRUNC((v_post_no-1)*0.275) THEN
              row_no_record_type.v_row_id := v_post_no;
              v_char := 'C';
              --v_return_char := 'C';
         END IF;
         IF row_no_record_type.v_row_id = 0 AND v_char = 'X' THEN
              row_no_record_type.v_row_id := v_post_no;
              v_char := 'D';
         --IF v_return_char = 'X' THEN 
              --v_return_char := 'D';
         END IF;
         END IF;
    RETURN row_no_record;
    END;

    Posting your Oracle version is immensely helpful when asking questions (different version = different answers / functionality available).
    select * from v$version;Also, using tags will preserve the formatting of your code.
    You should likely read (a lot) about  [http://www.stanford.edu/dept/itss/docs/oracle/10g/appdev.101/b10807/05_colls.htm]
    Basically, you would need to create a PL/SQL record and reference that, OR you could create a SQL type.
    If you're looking for a 'simple' way to return many single values (no arrays) then your best bet would be a procedure with multiple OUT parameters.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Output parameters or how to return more than one value

    My RMI server retrieves a list of Strings from the database. I need to return a status code int and an array of Strings to the RMI client. Does anybody have any ideas on how to do this. The only way I have come up with is to return an array of Strings using the first array position as the status code. But this is very ugly. There doesn't seem to be any way to have output parameters. I can use "output parameters" with code that lies in the same app by using wrapper classes or arrays but this does not really apply to a client and server running on different machines. Any ideas?

    Well, my general reaction is that you don't need a status code. (You can instead throw an exception if the status is anything but "OK".)
    However, on the assumption that you really DO need the status, then some alternatives are
    o Return an object that has a status code and an array as member variables.
    o In the call, pass in an object that the server can fill in with the array of strings. have the function return the status code.

  • How to return quotes with varchar2 value

    Hello-
    I'm writing a function and need to add quotes to either side of a varchar2 db value
    i.e. column value is Financial Trx, I need it to be 'Financial Trx'
    I'd be grateful for any ideas on how to do this -
    Many thanks in advance-
    amanda

    John, good point. Here is another way to get the single quotes that may or may not seem cleaner
    UT1> l
    1 select chr(39)||fld4||chr(39) as Word
    2 ,chr(39)||fld3||chr(39) as Oradate
    3* from marktest where fld1 = 8
    UT1> /
    WORD ORADATE
    'fraction' '25-JUL-03'
    When used in plsql code a variable can be given the value of a single quote, chr(39) and concatenated to the column values instead of repeatedly calling the function.
    HTH -- Mark D Powell --

  • How to view variable and constant value

    Hi there,
    I try to view a variable in sql plus command line and oracle xe object browser. The following is a small code to assign a value to a variable from an existing column name id that has value 4567 from table airplane. I'm a newbie, so pardon my ignorance:
    declare new_num number;
    begin
    select id into new_num from airplane where id=4567;
    end;
    Questions:
    1. Anything wrong with the code?
    2. How can I view it via sql plus command line?
    3. Can I view it from Oracle XE object browser gui?
    Regards,
    Valerie

    you use variable command to declare my_var as a global variableActually Toon used a BIND variable in his example, see:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch5.htm#sthref1118
    Is this a SQL or PL/SQL command? Bind variables can (should) be used by SQL*Plus and in PL/SQL.
    Check the docs.
    Can I view it via oracle xe object browser?I have no clue, don't know the 'Oracle XE Object Browser'.

  • How to return more then one value in OC4J

    Hi,
    do I really need to create a serializable object + interface with an reader and writer to pass more then 2 variables back to the client ?
    Must this object a java bean ?
    .. or does anybody know an easier way to solve this problems.
    greetings
    Mike

    What is your client, and what are you using on the server? Are you trying to return values from a servlet to a web page, or from a servlet to a JSP, or from a EJB to a Java client?
    John H. Hi John
    We have some services currentliy implementet as PL/SQL stored Procedures on Oracle. They are now accessable with DCE and C-clients.
    The task is now to implement the services as Web-Services with SOAP. For that we want to use the OC4J. - as an SOAP Server.
    But unforunatly the only examples I found are returning only one parameter.
    The Java books learned me to create a class and an interface to pass more parameter to the client. This interface should be inherit from Serializable.
    The compiler is happy, the deployment is ok. But when I try to get the wsdl and stub I get something like: "must be an bean" or "have to be a reader and write property.
    From my point of view this looks very complicated. I want to use SOAP and therefore all parameters should be passed with one call and the parameter should be explained in the WSDL so that they could be used independed of the programming language and plattform.
    When I implement the read and write methods I will pass the parameters in one stream. When I only use Java I think this is a solution - but what is with C or other languages.
    Ciao Mike

  • How to return the same SUM value from two tables

    Hello,
    I have the following data:
    SQL> SELECT * FROM t1;
         T1_ID   T1_VALUE
             1        500
             1        500
    SQL> SELECT * FROM t2;
         T2_ID   T2_VALUE
             1       1000
    SQL> SELECT t1_id, SUM(t1_value), SUM(t2_value)
      2    FROM t1, t2
      3   WHERE t1_id = t2_id
      4   GROUP BY t1_id;
         T1_ID SUM(T1_VALUE) SUM(T2_VALUE)
             1          1000          2000How is it possible that SUM(T2_VALUE) returns also 1000.
    Thank you

    Here's one way:
    with t1 as (select 1 t1_id, 500 t1_value from dual union all
                select 1 t1_id, 500 t1_value from dual),
         t2 as (select 1 t2_id, 1000 t2_value from dual)
    select t3.t3_id, t3.t3_sum, t4.t4_sum
    from   (select t1_id t3_id, sum(t1_value) t3_sum from t1
            group by t1_id) t3,
           (select t2_id t4_id, sum(t2_value) t4_sum from t2
            group by t2_id) t4
    where  t3.t3_id = t4.t4_id

  • How to Return only alpha-numeric Values

    In my query, I want to return only records for which data in a specific column is alpha-numeric. Any records having this field as NULL, or containing symbols, I want to exclude. What's the best way to do this?
    Thanks,
    Brice

    select str from tab1
    where str is not null
    and translate(str, '_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','_') is null
    /Regards
    Dmytro

  • How to Get ZERO and Non-ZERO Values in rowcount using Group by?

    Dear All,
    How can I get Non-ZERO and ZERO row count values in SQL using Group by? I can get non-zero values but when I want NULL should be returned to non-zero values it is ignoring ZERO values in output?
    Any hint?
    Thanks
    GQ

    Hi,
    Something like
    select count(case col
                    when 0
                    then 1
                  end) zero_count,
           count(case nvl(col,1)
                    when 0
                    then null
                    else 1
                  end) nonzero_countRegards
    Peter

  • Query only non numeric values in a column

    How to query only non numeric values in a cloumn.
    For example:
    Table1 has a column1(col1)
    Values:
    Row Value
    1 27376
    2 47D99
    3 83039
    4 DKFI*
    5 3J6
    Query should retrieve only rows(2,4,5).
    Thanks! for help
    Murali

    Version 2(PL/SQL) above is not clear enough, It can be tuned to the following:
    -- Create a function
    Create or replace function IsVARCHAR(pCol VARCHAR2) return VARCHAR2
    AS
    vNumber NUMBER := 0;
    begin
      vNumber := to_number(pCol);
      RETURN NULL;
    Exception
      When Others Then
        RETURN pCol;
    End;
    -- To See VARCHAR values (alpha-numeric) only!
    SELECT col1 FROM tab1
    WHERE IsVARCHAR(col1) IS NOT NULL;
    -- To See NUMBER values only!
    SELECT col1 FROM tab1
    WHERE IsVARCHAR(col1) IS NULL;Versatility here with PL/SQL, but I personally like SQL versions.
    Thx,
    SriDHAR

  • Return all the column values using the F4IF_INT_TABLE_VALUE_REQUEST

    Hi,
    How to return all the column values using the F4IF_INT_TABLE_VALUE_REQUEST?
    For example : if the row has 3 columns then after selecting the particular row, the RETURN_TAB internal table should contain all the three column values.
    Regards,
    Raghu

    Hi,
       Try the following...
    DATA : it_fields like help_value occurs 1 with header line.
    data: begin of w_vbap,
            vbeln      like vbap-vbeln,    
            posnr      like vbap-posnr,   
            werks      like vbap-werks,  
          end of w_vbap.
    data: i_vbap   like w_vbap   occurs 0 with header line,
             w_fields type help_value,
          i_dfies type table of dfies,
          i_return_tab type table of ddshretval with header line,
          i_field  type dfies.
      select vbeln posnr werks
          from vbap into table i_vbap up to 5 rows.
    if sy-subrc = 0.
       sort i_vbap by vbeln.
    endif.
      clear it_fields[] , it_fields.
      it_fields-tabname = c_vbap.
      it_fields-fieldname = 'VBELN'.
      it_fields-selectflag = c_on.
      append it_fields.
      it_fields-tabname = c_vbap.
      it_fields-fieldname = 'POSNR'.
      it_fields-selectflag = space.
      append it_fields.
      it_fields-tabname = c_vbap.
      it_fields-fieldname = 'WERKS'.
      it_fields-selectflag = space.
      append it_fields.
      loop at it_fields into w_fields.
        i_field-tabname   = w_fields-tabname.
        i_field-fieldname = w_fields-fieldname.
        i_field-keyflag   = w_fields-selectflag.
        append i_field to i_dfies.
      endloop.
      call function 'F4IF_INT_TABLE_VALUE_REQUEST'
        exporting
          retfield               = 'VBELN'
         window_title           = 'Select'
        tables
          value_tab              = i_vbap
          field_tab                = i_dfies
          return_tab             = i_return_tab
       exceptions
         parameter_error        = 1
         no_values_found        = 2
         others                 = 3
      read table i_return_tab into w_return_tab index 1.
      if sy-subrc = 0.
      endif.
    Regards,
    Srini.

  • Stored procedure: how to return multline table

    Environment: SQL Server 2008 R2, Windows
    Tools: MSMS 2008 R2
    Code:
    CREATE PROCEDURE [dbo].[Cleanup]
    (@id CHAR(12)
    ,@Date DATETIME
    ,@ID int OUT
    ,@Ln_ID CHAR(10) OUT
    ,@qcdate DATETIME OUT
    ,@P4 VARCHAR(8000)OUT
    ,@P9 VARCHAR(8000) OUT
    ,@P11 VARCHAR(8000) OUT
    ) WITH ENCRYPTION
    AS
    BEGIN
    Update Table_mocha
    SET P4=Replace(PE4,RTRIM(Cast(Q_ID as varchar(10))), '')
    where id=@id and order_dt=@Date
    Update Table_mocha
    SET P4 = NullIf(P4,'')
    where id=@id and order_dt=@Date
    Update Table_mocha
    SET P4=LTRIM(RTRIM(P4))
    where id=@id and order_dt=@Date
    SELECT @id=id, ln_id=@ln_id,@p4=p4, @p9=P9,@p11=P11
    where id=@id and order_dt=@Date
    Problem: having three updates would cause the database to lock. How would I pass input paramaters for those three updates in SP. How would I update multiple tables, how to avoid database lock, how to return multi-statment table - value (display
    table contains multiple records)

    I prefer to use different stored procedures to do different things.
    CREATE PROCEDURE [dbo].usp_updatedata
    (@id CHAR(12)
    ,@Date DATETIME
    AS
    BEGIN
    Update Table_mocha
    SET P4=LTRIM(RTRIM(Nullif(Replace(PE4,RTRIM(Cast(Q_ID as varchar(10))), ''),'')))
    where id=@id and order_dt=@Date
    End
    CREATE PROCEDURE [dbo].usp_getData
    (@id CHAR(12)
    ,@Date DATETIME
    AS
    BEGIN
    SET NOCOUNT ON;
    SELECT id, ln_id,p4, P9,P11
    where id=@id and order_dt=@Date
    End

Maybe you are looking for