Ejemplo n.º 1
0
        } // _Number_Comparable_Impl_


        //public static IComparable<object> getComparable(object o)
        //{
        //    NNumber n = toNumber(o);
        //    return new _Number_Comparable_Impl_(_instance, n);
        //} // getComparable()


        public int Compare(object o1, object o2)
        {
            NNumber n1 = toNumber(o1);
            NNumber n2 = toNumber(o2);

            if (n1 == null && n2 == null)
            {
                return(0);
            }
            if (n1 == null)
            {
                return(-1);
            }
            if (n2 == null)
            {
                return(1);
            }

            if (n1 is NNumber && n2 is NNumber)
            {
                return((n1.asBigInteger()).CompareTo(n2.asBigInteger()));
            }

            //if (n1 is BigDecimal && n2 is BigDecimal) {
            //    return ((BigDecimal)n1).compareTo((BigDecimal)n2);
            //}

            if (NumberComparator.IsIntegerType(n1) && NumberComparator.IsIntegerType(n2))
            {
                return(NInteger.ValueOf(n1).CompareTo(n2.asLong()));
            }

            return(NNumber.ValueOf(n1).CompareTo(n2.asLong()));
        } // Compare()
        public int getJdbcType() // throws IllegalStateException
        {
            string name = this.ToString();

            try
            {
                // We assume that the JdbcTypes class only consists of constant
                // integer types, so we make no assertions here
                FieldInfo[] fields = typeof(JdbcTypes).GetFields();
                for (int i = 0; i < fields.Length; i++)
                {
                    FieldInfo field     = fields[i];
                    string    fieldName = field.Name;
                    if (fieldName.Equals(name))
                    {
                        NInteger value = NInteger.ZERO;
                        field.GetValue(value);
                        return(value);
                    }
                }
                throw new InvalidOperationException("No JdbcType found with field name: " + name);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Could not access fields in JdbcTypes", e);
            }
        } // getJdbcType()
Ejemplo n.º 3
0
        // @Override
        public override int indexOf(SelectItem item)
        {
            if (item == null)
            {
                return(-1);
            }

            if (_selectItemIndexCache == null)
            {
                int concurrency_level = 10;
                int capacity          = base.size();
                _selectItemIndexCache = new ConcurrentDictionary <NInteger, NInteger>(concurrency_level, capacity);
            }

            int      identityCode = item.GetHashCode();
            NInteger index        = _selectItemIndexCache[identityCode];

            if (index == null)
            {
                index = base.indexOf(item);

                if (index != -1)
                {
                    _selectItemIndexCache[identityCode] = index;
                }
            }
            return(index);
        }
 public override string ToString()
 {
     // overridden version of toString() method that uses identity hash code
     // (to prevent hashCode() recursion due to logging!)
     return GetType().Name + "@"
           + NInteger.ToHexString(NSystem.IdentityHashCode(this)); // Integer.toHexString(System.identityHashCode(this));
 }
Ejemplo n.º 5
0
        } // constructor

        #endregion Constructors


        // @Override
        public override int indexOf(Column column)
        {
            if (column == null)
            {
                return(-1);
            }

            if (_columnIndexCache == null)
            {
                _columnIndexCache = new ConcurrentDictionary <NInteger, NInteger>(10, base.size());
            }

            int      identityCode = column.GetHashCode();
            NInteger index        = _columnIndexCache[identityCode];

            if (index == null)
            {
                index = base.indexOf(column);

                if (index != -1)
                {
                    _columnIndexCache[identityCode] = index;
                }
            }
            return(index);
        }
        } // getFirstRow()()

        /**
         * Sets the first row (aka offset) of the query's result. The row number is
         * 1-based, so setting a first row value of 1 is equivalent to not setting
         * it at all..
         *
         * @param firstRow
         *            the first row, where 1 is the first row.
         * @return this query
         */
        public Query setFirstRow(NInteger firstRow)
        {
            if (firstRow != null && firstRow < 1)
            {
                //[J2N] IllegalArgumentException <=> ArgumentException
                throw new ArgumentException("First row cannot be negative or zero");
            }
            _firstRow = firstRow;
            return(this);
        }
Ejemplo n.º 7
0
 private String getSubstring(NInteger from, int to)
 {
     if (from == null)
     {
         return(null);
     }
     if (from.asInt() == to)
     {
         return(null);
     }
     return(_queryString.Substring(from, to));
 }
        } // constructor

        public StyleImpl(bool bold, bool italic, bool underline, NInteger fontSize, SizeUnit fontSizeUnit,
                         TextAlignment alignment, Color backgroundColor, Color foregroundColor)
        {
            _bold            = bold;
            _italic          = italic;
            _underline       = underline;
            _fontSize        = fontSize;
            _fontSizeUnit    = fontSizeUnit;
            _alignment       = alignment;
            _backgroundColor = backgroundColor;
            _foregroundColor = foregroundColor;
        } // constructor
 /**
  * Sets the maximum number of rows to be queried. If the result of the query
  * yields more rows they should be discarded.
  *
  * @param maxRows
  *            the number of desired maximum rows. Can be null (default) for
  *            no limits
  * @return this query
  */
 public Query setMaxRows(NInteger maxRows)
 {
     if (maxRows != null)
     {
         int maxRowsValue = maxRows;
         if (maxRowsValue < 0)
         {
             throw new ArgumentException("Max rows cannot be negative");
         }
     }
     _maxRows = maxRows;
     return(this);
 } // setMaxRows()
Ejemplo n.º 10
0
 private void parseLimitClause(Query query, String limitClause)
 {
     limitClause = limitClause.Trim();
     if (!limitClause.IsEmpty())
     {
         try
         {
             int limit = NInteger.ParseInt(limitClause);
             query.setMaxRows(limit);
         }
         catch (FormatException e)
         {
             throw new QueryParserException("Could not parse LIMIT value: " + limitClause);
         }
     }
 }
Ejemplo n.º 11
0
 private void parseOffsetClause(Query query, String offsetClause)
 {
     offsetClause = offsetClause.Trim();
     if (!offsetClause.IsEmpty())
     {
         try
         {
             int offset = NInteger.ParseInt(offsetClause);
             // ofset is 0-based, but first-row is 1-based
             int firstRow = offset + 1;
             query.setFirstRow(firstRow);
         }
         catch (FormatException e)
         {
             throw new QueryParserException("Could not parse OFFSET value: " + offsetClause);
         }
     }
 }
        }  // find()

        private static Object find(Dictionary <object, object> map, String key, int fromIndex)
        {
            int indexOfDot     = key.IndexOf('.', fromIndex);
            int indexOfBracket = key.IndexOf('[', fromIndex);

            int indexOfEndBracket = -1;
            int arrayIndex        = -1;

            bool hasDot     = indexOfDot != -1;
            bool hasBracket = indexOfBracket != -1;

            if (hasBracket)
            {
                // also check that there is an end-bracket
                indexOfEndBracket = key.IndexOf("]", indexOfBracket);
                hasBracket        = indexOfEndBracket != -1;
                if (hasBracket)
                {
                    String indexString = key.Substring(indexOfBracket + 1, indexOfEndBracket);
                    try
                    {
                        arrayIndex = NInteger.ParseInt(indexString);
                    }
                    catch (FormatException e)
                    {
                        // not a valid array/list index
                        hasBracket = false;
                    }
                }
            }

            if (hasDot && hasBracket)
            {
                if (indexOfDot > indexOfBracket)
                {
                    hasDot = false;
                }
                else
                {
                    hasBracket = false;
                }
            }

            if (hasDot)
            {
                String prefix       = key.Substring(0, indexOfDot);
                Object nestedObject = map[prefix];
                if (nestedObject == null)
                {
                    return(find(map, key, indexOfDot + 1));
                }
                if (nestedObject is Dictionary <String, object> )
                {
                    String remainingPart = key.Substring(indexOfDot + 1);
                    //@SuppressWarnings("unchecked")
                    Dictionary <object, object> nestedMap = (Dictionary <object, object>)nestedObject;
                    return(find(nestedMap, remainingPart));
                }
            }

            if (hasBracket)
            {
                String prefix       = key.Substring(0, indexOfBracket);
                Object nestedObject = map[prefix];
                if (nestedObject == null)
                {
                    return(find(map, key, indexOfBracket + 1));
                }

                String remainingPart = key.Substring(indexOfEndBracket + 1);

                try
                {
                    Object valueAtIndex;
                    if (nestedObject is List <object> )
                    {
                        valueAtIndex = ((List <object>)nestedObject)[arrayIndex];
                    }
                    else if (nestedObject.GetType().IsArray)
                    {
                        valueAtIndex = ((Array)nestedObject).GetValue(arrayIndex);
                    }
                    else
                    {
                        // no way to extract from a non-array and non-list
                        valueAtIndex = null;
                    }

                    if (valueAtIndex != null)
                    {
                        if (remainingPart.StartsWith("."))
                        {
                            remainingPart = remainingPart.Substring(1);
                        }

                        if (remainingPart.IsEmpty())
                        {
                            return(valueAtIndex);
                        }

                        if (valueAtIndex is Dictionary <object, object> )
                        {
                            //@SuppressWarnings("unchecked")
                            Dictionary <object, object> nestedMap = (Dictionary <object, object>)valueAtIndex;
                            return(find(nestedMap, remainingPart));
                        }
                        else
                        {
                            // not traversing any further. Should we want to add
                            // support for double-sided arrays, we could do it here.
                        }
                    }
                }
                catch (NIndexOutOfBoundsException e)
                {
                    return(null);
                }
            }

            return(null);
        }       // find()
Ejemplo n.º 13
0
        } // constructor

        public MutableColumn(String name, ColumnType type, Table table, int columnNumber, NInteger columnSize,
                             String nativeType, Boolean nullable, String remarks, bool indexed, String quote) :
            this(name, type, table, columnNumber, nullable)
        {
            setColumnSize(columnSize);
            setNativeType(nativeType);
            setRemarks(remarks);
            setIndexed(indexed);
            setQuote(quote);
        } // constructor
Ejemplo n.º 14
0
 public MutableColumn setColumnSize(NInteger columnSize)
 {
     _columnSize = columnSize;
     return(this);
 }
        }     // ValueOf()

        public static string ToHexString(NInteger value_arg)
        {
            return(NInteger.ToHexString(value_arg));
        }     // ToHexString()
        }         // constructor

        public static int ValueOf(NInteger value_arg)
        {
            return(value_arg.asInt());
        }     // ValueOf()