コード例 #1
0
        /// <summary>
        /// Returns the data that should be placed in the JTable at the given row
        /// and column. </summary>
        /// <param name="row"> the row for which to return data. </param>
        /// <param name="col"> the column for which to return data.  This is base 0. </param>
        /// <returns> the data that should be placed in the JTable at the given row and col. </returns>
        public virtual object getValueAt(int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }
            StateMod_DiversionRight dr = (StateMod_DiversionRight)_data.get(row);

            switch (col)
            {
            case COL_RIGHT_ID:
                return(dr.getID());

            case COL_RIGHT_NAME:
                return(dr.getName());

            case COL_STRUCT_ID:
                return(dr.getCgoto());

            case COL_ADMIN_NUM:
                return(dr.getIrtem());

            case COL_DCR_AMT:
                return(new double?(dr.getDcrdiv()));

            case COL_ON_OFF:
                return(new int?(dr.getSwitch()));

            default:
                return("");
            }
        }
コード例 #2
0
        /// <summary>
        /// Compares this object to another StateMod_Data object based on the sorted
        /// order from the StateMod_Data variables, and then by irtem and dcrdiv, in that order. </summary>
        /// <param name="data"> the object to compare against. </param>
        /// <returns> 0 if they are the same, 1 if this object is greater than the other object, or -1 if it is less. </returns>
        public virtual int CompareTo(StateMod_Data data)
        {
            int res = base.CompareTo(data);

            if (res != 0)
            {
                return(res);
            }

            StateMod_DiversionRight right = (StateMod_DiversionRight)data;

            res = _irtem.CompareTo(right.getIrtem());
            if (res == 0)
            {
                double dcrdiv = right.getDcrdiv();
                if (dcrdiv == _dcrdiv)
                {
                    return(0);
                }
                else if (_dcrdiv < dcrdiv)
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            }
            else
            {
                return(res);
            }
        }
        /// <summary>
        /// Returns the data that should be placed in the JTable at the given row
        /// and column. </summary>
        /// <param name="row"> the row for which to return data. </param>
        /// <param name="col"> the column for which to return data.  This is base 0. </param>
        /// <returns> the data that should be placed in the JTable at the given row and col. </returns>
        public virtual object getValueAt(int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }
            StateMod_DiversionRight dr = (StateMod_DiversionRight)_data.get(row);

            // necessary for table models that display rights for 1+ diversions,
            // so that the -1st column (ID) can also be displayed.  By doing it
            // this way, code can be shared between the two kinds of table models
            // and less maintenance is necessary.
            if (!__singleDiversion)
            {
                col--;
            }

            switch (col)
            {
            case COL_DIVERSION_ID:
                return(dr.getCgoto());

            case COL_RIGHT_ID:
                return(dr.getID());

            case COL_RIGHT_NAME:
                return(dr.getName());

            case COL_STRUCT_ID:
                return(dr.getCgoto());

            case COL_ADMIN_NUM:
                return(dr.getIrtem());

            case COL_DCR_AMT:
                return(new double?(dr.getDcrdiv()));

            case COL_ON_OFF:
                return(new int?(dr.getSwitch()));

            default:
                return("");
            }
        }
コード例 #4
0
        /// <summary>
        /// Checks the data to make sure that all the data are valid. </summary>
        /// <returns> 0 if the data are valid, 1 if errors exist and -1 if non-fatal errors
        /// exist. </returns>
        private int checkInput()
        {
            string routine = "StateMod_Diversion_Right_JFrame.checkInput";

            System.Collections.IList v = __worksheet.getAllData();

            int size = v.Count;
            StateMod_DiversionRight right = null;
            string warning = "";
            string id;
            string name;
            string divID;
            string adminNum;
            int    fatalCount = 0;

            for (int i = 0; i < size; i++)
            {
                right = (StateMod_DiversionRight)(v[i]);

                id       = right.getID();
                name     = right.getName();
                divID    = right.getCgoto();
                adminNum = right.getIrtem();

                if (id.Length > 12)
                {
                    warning += "\nDiversion right ID (" + id + ") is "
                               + "longer than 12 characters.";
                    fatalCount++;
                }

                if (id.IndexOf(" ", StringComparison.Ordinal) > -1 || id.IndexOf("-", StringComparison.Ordinal) > -1)
                {
                    warning += "\nDiversion right ID (" + id + ") cannot "
                               + "contain spaces or dashes.";
                    fatalCount++;
                }

                if (name.Length > 24)
                {
                    warning += "\nDiversion name (" + name + ") is "
                               + "longer than 24 characters.";
                    fatalCount++;
                }

                if (divID.Length > 12)
                {
                    warning += "\nDiversion ID associated with right ("
                               + divID + ") is longer than 12 characters.";
                }

                if (!StringUtil.isDouble(adminNum))
                {
                    warning += "\nAdministration number (" + adminNum + ") is not a number.";
                    fatalCount++;
                }

                // decreed amount is not checked to be a double because that
                // is enforced by the worksheet and its table model

                // on/off is not checked to be an integer because that is
                // enforced by the worksheet and its table model
            }
            // REVISIT - if daily time series are supplied, check for time series
            // and allow creation if not available.
            if (warning.Length > 0)
            {
                warning += "\nCorrect or Cancel.";
                Message.printWarning(1, routine, warning, this);
                if (fatalCount > 0)
                {
                    // Fatal errors...
                    Message.printStatus(1, routine, "Returning 1 from checkInput()");
                    return(1);
                }
                else
                {         // Nonfatal errors...
                    Message.printStatus(1, routine, "Returning -1 from checkInput()");
                    return(-1);
                }
            }
            else
            {     // No errors...
                Message.printStatus(1, routine, "Returning 0 from checkInput()");
                return(0);
            }
        }
コード例 #5
0
        /// <summary>
        /// Writes a list of StateMod_Diversion objects to a list file.  A header is
        /// printed to the top of the file, containing the commands used to generate the
        /// file.  Any strings in the body of the file that contain the field delimiter will be wrapped in "...". </summary>
        /// <param name="filename"> the name of the file to which the data will be written. </param>
        /// <param name="delimiter"> the delimiter to use for separating field values. </param>
        /// <param name="update"> whether to update an existing file, retaining the current
        /// header (true) or to create a new file with a new header. </param>
        /// <param name="data"> the list of objects to write. </param>
        /// <param name="newComments"> comments to add at the top of the file (e.g., command file, HydroBase version). </param>
        /// <exception cref="Exception"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeListFile(String filename, String delimiter, boolean update, java.util.List<StateMod_DiversionRight> data, java.util.List<String> newComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_DiversionRight> data, IList <string> newComments)
        {
            string routine = "StateMod_DiversionRight.writeListFile";
            int    size    = 0;

            if (data != null)
            {
                size = data.Count;
            }

            IList <string> fields = new List <string>();

            fields.Add("ID");
            fields.Add("Name");
            fields.Add("StationID");
            fields.Add("AdministrationNumber");
            fields.Add("Decree");
            fields.Add("OnOff");

            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = StateMod_DataSet.COMP_DIVERSION_RIGHTS;
            string   s       = null;

            for (int i = 0; i < fieldCount; i++)
            {
                s          = fields[i];
                names[i]   = StateMod_Util.lookupPropValue(comp, "FieldName", s);
                formats[i] = StateMod_Util.lookupPropValue(comp, "Format", s);
            }

            string oldFile = null;

            if (update)
            {
                oldFile = IOUtil.getPathUsingWorkingDir(filename);
            }

            int j = 0;
            StateMod_DiversionRight right             = null;
            IList <string>          commentIndicators = new List <string>(1);

            commentIndicators.Add("#");
            IList <string> ignoredCommentIndicators = new List <string>(1);

            ignoredCommentIndicators.Add("#>");
            string[]      line   = new string[fieldCount];
            StringBuilder buffer = new StringBuilder();
            PrintWriter   @out   = null;

            try
            {
                // Add some basic comments at the top of the file.  Do this to a copy of the
                // incoming comments so that they are not modified in the calling code.
                IList <string> newComments2 = null;
                if (newComments == null)
                {
                    newComments2 = new List <string>();
                }
                else
                {
                    newComments2 = new List <string>(newComments);
                }
                newComments2.Insert(0, "");
                newComments2.Insert(1, "StateMod diversion rights as a delimited list file.");
                newComments2.Insert(2, "");
                @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentIndicators, ignoredCommentIndicators, 0);

                for (int i = 0; i < fieldCount; i++)
                {
                    if (i > 0)
                    {
                        buffer.Append(delimiter);
                    }
                    buffer.Append("\"" + names[i] + "\"");
                }

                @out.println(buffer.ToString());

                for (int i = 0; i < size; i++)
                {
                    right = data[i];

                    line[0] = StringUtil.formatString(right.getID(), formats[0]).Trim();
                    line[1] = StringUtil.formatString(right.getName(), formats[1]).Trim();
                    line[2] = StringUtil.formatString(right.getCgoto(), formats[2]).Trim();
                    line[3] = StringUtil.formatString(right.getIrtem(), formats[3]).Trim();
                    line[4] = StringUtil.formatString(right.getDcrdiv(), formats[4]).Trim();
                    line[5] = StringUtil.formatString(right.getSwitch(), formats[5]).Trim();

                    buffer = new StringBuilder();
                    for (j = 0; j < fieldCount; j++)
                    {
                        if (j > 0)
                        {
                            buffer.Append(delimiter);
                        }
                        if (line[j].IndexOf(delimiter, StringComparison.Ordinal) > -1)
                        {
                            line[j] = "\"" + line[j] + "\"";
                        }
                        buffer.Append(line[j]);
                    }

                    @out.println(buffer.ToString());
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Writes a diversion rights file. </summary>
        /// <param name="infile"> the original file </param>
        /// <param name="outfile"> the new file to write </param>
        /// <param name="theRights"> a Vector of StateMod_DiversionRight objects to right </param>
        /// <param name="newComments"> new comments to add to the header </param>
        /// <param name="useOldAdminNumFormat"> whether to use the old admin num format or not </param>
        /// <exception cref="Exception"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeStateModFile(String infile, String outfile, java.util.List<StateMod_DiversionRight> theRights, java.util.List<String> newComments, boolean useOldAdminNumFormat) throws Exception
        public static void writeStateModFile(string infile, string outfile, IList <StateMod_DiversionRight> theRights, IList <string> newComments, bool useOldAdminNumFormat)
        {
            IList <string> commentIndicators = new List <string>(1);

            commentIndicators.Add("#");
            IList <string> ignoredCommentIndicators = new List <string>(1);

            ignoredCommentIndicators.Add("#>");
            PrintWriter @out    = null;
            string      routine = "StateMod_DiversionRight.writeStateModFile";

            Message.printStatus(2, routine, "Writing diversion rights to: " + outfile);

            try
            {
                @out = IOUtil.processFileHeaders(IOUtil.getPathUsingWorkingDir(infile), IOUtil.getPathUsingWorkingDir(outfile), newComments, commentIndicators, ignoredCommentIndicators, 0);

                string iline;
                string cmnt     = "#>";
                string format_0 = null;
                if (useOldAdminNumFormat)
                {
                    format_0 = "%-12.12s%-24.24s%-12.12s%-12.12s    %8.2F%8d";
                }
                else
                {
                    format_0 = "%-12.12s%-24.24s%-12.12s%16.16s%8.2F%8d";
                }
                StateMod_DiversionRight right = null;
                IList <object>          v     = new List <object>(6);

                // print out the non-permanent header
                @out.println(cmnt);
                @out.println(cmnt + "***************************************************");
                @out.println(cmnt + " StateMod Direct Diversion Rights File");
                @out.println(cmnt);
                @out.println(cmnt + "     format:  (a12, a24, a12, f16.5, f8.2, i8)");
                @out.println(cmnt);
                @out.println(cmnt + "     ID       cidvri:  Diversion right ID ");
                @out.println(cmnt + "     Name      named:  Diversion right name");
                @out.println(cmnt + "     Struct    cgoto:  Direct Diversion Structure ID associated with this right");
                @out.println(cmnt + "     Admin #   irtem:  Administration number");
                @out.println(cmnt + "                       (small is senior).");
                @out.println(cmnt + "     Decree   dcrdiv:  Decreed amount (cfs)");
                @out.println(cmnt + "     On/Off   idvrsw:  Switch 0 = off, 1 = on");
                @out.println(cmnt + "                       YYYY = on for years >= YYYY.");
                @out.println(cmnt + "                       -YYYY = off for years > YYYY.");
                @out.println(cmnt);
                @out.println(cmnt + "   ID            Name              Struct            Admin #   Decree  On/Off");
                @out.println(cmnt + "EndHeader");
                @out.println(cmnt + "---------eb----------------------eb----------eb--------------eb------eb------e");

                int num = 0;
                if (theRights != null)
                {
                    num = theRights.Count;
                }
                for (int i = 0; i < num; i++)
                {
                    right = (StateMod_DiversionRight)theRights[i];
                    if (right == null)
                    {
                        continue;
                    }
                    v.Clear();
                    v.Add(right.getID());
                    v.Add(right.getName());
                    v.Add(right.getCgoto());
                    v.Add(right.getIrtem());
                    v.Add(new double?(right.getDcrdiv()));
                    v.Add(new int?(right.getSwitch()));
                    iline = StringUtil.formatString(v, format_0);
                    @out.println(iline);
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }