Determines if the specified field is constrained by a constant range in
this predicate. If so, the method returns that range. If not, the method
returns null.

@param fldName
the name of the field
@return either the constant range or null
179693
public ConstantRange constantRange(String fldName) {
		ConstantRange cr = null;
		for (Term t : terms) {
			Constant c = t.oppositeConstant(fldName);
			if (c != null) {
				Operator op = t.operator(fldName);
				if (op == OP_GT)
					cr = cr == null ? ConstantRange.newInstance(c, false, null,
							false) : cr.applyLow(c, false);
				else if (op == OP_GTE)
					cr = cr == null ? ConstantRange.newInstance(c, true, null,
							false) : cr.applyLow(c, true);
				else if (op == OP_EQ)
					cr = cr == null ? ConstantRange.newInstance(c) : cr
							.applyConstant(c);
				else if (op == OP_LTE)
					cr = cr == null ? ConstantRange.newInstance(null, false, c,
							true) : cr.applyHigh(c, true);
				else if (op == OP_LT)
					cr = cr == null ? ConstantRange.newInstance(null, false, c,
							false) : cr.applyHigh(c, false);
			}
		}
		// validate the constant range
		if (cr != null && cr.isValid()
				&& (cr.hasLowerBound() || cr.hasUpperBound()))
			return cr;
		return null;
	}
626257
private Object getValue(FieldType field, byte[] block)
   {
      Object result = null;

      switch (block[0])
      {
         case 0x07: // Field
         {
            result = getFieldType(block);
            break;
         }

         case 0x01: // Constant value
         {
            result = getConstantValue(field, block);
            break;
         }

         case 0x00: // Prompt
         {
            result = getPromptValue(field, block);
            break;
         }
      }

      return result;
   }
1043353
public Constraint getConstraint(String constraintName) {

        int i = getConstraintIndex(constraintName);

        return (i < 0) ? null
                       : constraintList[i];
    }
362466
private boolean hasConstantField (TypeElement typeElement) {
        VisibleMemberMap visibleMemberMapFields = configuration.getVisibleMemberMap(typeElement,
            VisibleMemberMap.Kind.FIELDS);
        List<Element> fields = visibleMemberMapFields.getLeafMembers();
        for (Element f : fields) {
            VariableElement field = (VariableElement)f;
            if (field.getConstantValue() != null) {
                typeElementsWithConstFields.add(typeElement);
                return true;
            }
        }
        return false;
    }
646127
private static boolean hasRestrictionsOtherThanEnumeration(XsdRestriction restriction){
        return restriction.getMinExclusive() != null || restriction.getMinInclusive() != null ||
                restriction.getMaxExclusive() != null || restriction.getMaxInclusive() != null ||
                restriction.getMaxLength() != null || restriction.getMinLength() != null ||
                restriction.getLength() != null || restriction.getPattern() != null ||
                restriction.getTotalDigits() != null || restriction.getFractionDigits() != null;
    }
994316
public String getValue(final String field)
    {
        FieldValue fieldValue = Iterables.find
        (
            fieldValues,
            new Predicate<FieldValue>()
            {
                @Override
                public boolean apply(FieldValue fv)
                {
                    return fv.getField().equals(field);
                }
            },
            null
        );
        return (fieldValue != null) ? fieldValue.getValue() : null;
    }
1002757
public WebQuery eq(final String field, final Object... values)
	{
		if (values == null)
		{
			add(WQConstraint.eq(field, null));
		}
		else if (values.length == 1)
		{
			add(WQConstraint.eq(field, values[0]));
		}
		else if (values.length > 1)
		{
			final WQGroup or = or();

			for (Object value : values)
				or.eq(field, value);
		}

		return this;
	}


	/**
	 * Assert that a field equals one of the provided values. Implicitly creates a new OR group if multiple values are supplied.
	 * At least one value must be supplied.
	 *
	 * @param field
	 * @param values
	 *
	 * @return
	 */
	public WebQuery eq(final String field, final Collection<?> values)
	{
		if (values == null)
			throw new IllegalArgumentException("Must supply at least one value to .eq when passing a Collection");
		else if (values.size() == 0)
			return eq(field, values.stream().findFirst().get());
		else
		{
			final WQGroup or = or();

			for (Object value : values)
				or.eq(field, value);

			return this;
		}
	}


	public WebQuery neq(final String field, final Object value)
	{
		return add(WQConstraint.neq(field, value));
	}


	public WebQuery isNull(final String field)
	{
		return add(WQConstraint.isNull(field));
	}


	public WebQuery isNotNull(final String field)
	{
		return add(WQConstraint.isNotNull(field));
	}


	public WebQuery lt(final String field, final Object value)
	{
		return add(WQConstraint.lt(field, value));
	}


	public WebQuery le(final String field, final Object value)
	{
		return add(WQConstraint.le(field, value));
	}


	public WebQuery gt(final String field, final Object value)
	{
		return add(WQConstraint.gt(field, value));
	}


	public WebQuery ge(final String field, final Object value)
	{
		return add(WQConstraint.ge(field, value));
	}


	public WebQuery contains(final String field, final Object value)
	{
		return add(WQConstraint.contains(field, value));
	}


	public WebQuery startsWith(final String field, final Object value)
	{
		return add(WQConstraint.startsWith(field, value));
	}


	public WebQuery range(final String field, final Object from, final Object to)
	{
		return add(WQConstraint.range(field, from, to));
	}


	public WebQuery eqRef(final String field, final String field2)
	{
		return add(WQConstraint.eqRef(field, field2));
	}


	public WebQuery neqRef(final String field, final String field2)
	{
		return add(WQConstraint.neqRef(field, field2));
	}


	public WebQuery leRef(final String field, final String field2)
	{
		return add(WQConstraint.leRef(field, field2));
	}


	public WebQuery ltRef(final String field, final String field2)
	{
		return add(WQConstraint.ltRef(field, field2));
	}


	public WebQuery geRef(final String field, final String field2)
	{
		return add(WQConstraint.geRef(field, field2));
	}


	public WebQuery gtRef(final String field, final String field2)
	{
		return add(WQConstraint.gtRef(field, field2));
	}


	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Sub-groups
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


	/**
	 * Construct a new AND group and return it for method chaining
	 *
	 * @return
	 */
	public WQGroup and()
	{
		final WQGroup and = WQGroup.newAnd();

		add(and);

		return and;
	}


	/**
	 * Construct a new OR group and return it for method chaining
	 *
	 * @return
	 */
	public WQGroup or()
	{
		final WQGroup or = WQGroup.newOr();

		add(or);

		return or;
	}


	/**
	 * Construct a new AND group, using the supplier to add the constraints to the group. Returns the original {@link WebQuery}
	 * for method chaining
	 *
	 * @param consumer
	 *
	 * @return
	 */
	public WebQuery and(Consumer<WQGroup> consumer)
	{
		final WQGroup and = and();

		// Let the consumer build their sub-constraints
		if (consumer != null)
			consumer.accept(and);

		return this;
	}


	/**
	 * Construct a new OR group, using the supplier to add the constraints to the group. Returns the original {@link WebQuery}
	 * for
	 * method chaining
	 *
	 * @param consumer
	 *
	 * @return
	 */
	public WebQuery or(Consumer<WQGroup> consumer)
	{
		final WQGroup or = or();


		// Let the consumer build their sub-constraints
		if (consumer != null)
			consumer.accept(or);

		return this;
	}

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Decoding URI Query
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


	/**
	 * Overwrite any fields in this WebQuery using the query defined in the Query String of the provided UriInfo
	 *
	 * @param qs
	 * 		the UriInfo to extract the QueryParameters from
	 *
	 * @return this WebQuery for chaining
	 */
	public WebQuery decode(UriInfo qs)
	{
		return decode(qs.getQueryParameters());
	}


	/**
	 * Overwrite any fields in this WebQuery using the query defined in the provided map
	 *
	 * @param map
	 * 		a map of fields (or control fields) to encoded constraints
	 *
	 * @return this WebQuery for chaining
	 */
	public WebQuery decode(Map<String, List<String>> map)
	{
		WebQuery def = new WebQuery();

		// incoming queries from a map get a default limit set
		def.limit(QUERY_STRING_DEFAULT_LIMIT);

		boolean hasConstraints = false;

		for (Map.Entry<String, List<String>> entry : map.entrySet())
		{
			if (entry.getKey().charAt(0) == '_')
			{
				final WQUriControlField specialField = WQUriControlField.getByName(entry.getKey());

				switch (specialField)
				{
					case OFFSET:
						def.offset(Integer.valueOf(entry.getValue().get(0)));
						break;
					case LIMIT:
						def.limit(Integer.valueOf(entry.getValue().get(0)));
						break;
					case CLASS:
						def.subclass(entry.getValue().toArray(new String[entry.getValue().size()]));
						break;
					case COMPUTE_SIZE:
						def.computeSize(parseBoolean(entry.getValue().get(0)));
						break;
					case LOG_SQL:
						def.logSQL(parseBoolean(entry.getValue().get(0)));
						break;
					case LOG_PERFORMANCE:
						def.logPerformance(parseBoolean(entry.getValue().get(0)));
						break;
					case EXPAND:
						def.expand(entry.getValue().toArray(new String[entry.getValue().size()]));
						break;
					case ORDER:
						def.orderings = entry.getValue().stream().map(WQOrder:: parseLegacy).collect(Collectors.toList());
						break;
					case FETCH:
						// Ordinarily we'd expect a single value here, but allow for multiple values to be provided as a comma-separated list
						def.fetch = entry.getValue().stream().collect(Collectors.joining(","));
						break;
					case DBFETCH:
						def.dbfetch = entry.getValue().stream().collect(Collectors.joining(","));
						break;
					case NAME:
						def.name(entry.getValue().get(0));
						break;
					default:
						throw new IllegalArgumentException("Unknown query field: " +
						                                   specialField +
						                                   " expected one of " +
						                                   WQUriControlField.getAllNames());
				}
			}
			else
			{
				// If this is the first constraint, clear any pre-defined default constraints
				if (!hasConstraints)
				{
					def.constraints.constraints = new ArrayList<>();

					hasConstraints = true;
				}

				if (entry.getValue().size() == 1)
				{
					def.constraints.constraints.add(WQConstraint.decode(entry.getKey(), entry.getValue().get(0)));
				}
				else if (entry.getValue().size() > 0)
				{
					WQGroup group = new WQGroup();

					group.operator = WQGroupType.OR;

					group.constraints = entry
							                    .getValue()
							                    .stream()
							                    .map(value -> WQConstraint.decode(entry.getKey(), value))
							                    .collect(Collectors.toList());

					def.constraints.constraints.add(group);
				}
			}
		}


		return def;
	}


	private static boolean parseBoolean(String value)
	{
		if (StringUtils.equalsIgnoreCase(value, "true") ||
		    StringUtils.equalsIgnoreCase(value, "yes") ||
		    StringUtils.equalsIgnoreCase(value, "on"))
			return true;
		else if (StringUtils.equalsIgnoreCase(value, "false") ||
		         StringUtils.equalsIgnoreCase(value, "no") ||
		         StringUtils.equalsIgnoreCase(value, "off"))
			return false;
		else
			throw new IllegalArgumentException("Cannot parse boolean: " + value);
	}


	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Decoding URI Query
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


	/**
	 * Encode this query to the equivalent (where possible) URI web query
	 *
	 * @return
	 */
	public Map<String, List<String>> encode()
	{
		return WebQueryToQueryStringConverter.convert(this);
	}
}
11561
@Override
	public long getLong(String fldName) throws RemoteException {
		try {
			fldName = fldName.toLowerCase(); // to ensure case-insensitivity
			return (Long) s.getVal(fldName).castTo(BIGINT).asJavaVal();
		} catch (RuntimeException e) {
			rconn.rollback();
			throw e;
		}
	}
669301
@Override
	public boolean hasField(String fldName) {
		return ts.hasField(fldName) || s.hasField(fldName);
	}
1113616
public static ConstraintField getInstance(int value)
   {
      ConstraintField result = null;

      if (value >= 0 && value < FIELD_ARRAY.length)
      {
         result = FIELD_ARRAY[value];
      }

      return (result);
   }
613967
public boolean contains(final CharRange range) {
        Validate.isTrue(range != null, "The Range must not be null");
        if (negated) {
            if (range.negated) {
                return start >= range.start && end <= range.end;
            }
            return range.end < start || range.start > end;
        }
        if (range.negated) {
            return start == 0 && end == Character.MAX_VALUE;
        }
        return start <= range.start && end >= range.end;
    }
359298
private int[] getRange(String field, int min, int max) {
        int[] result = new int[2];
        if (field.contains("*")) {
            result[0] = min;
            result[1] = max - 1;
            return result;
        }
        if (!field.contains("-")) {
            result[0] = result[1] = Integer.valueOf(field);
        } else {
            String[] split = StringUtils.delimitedListToStringArray(field, "-");
            if (split.length > 2) {
                throw new IllegalArgumentException("Range has more than two fields: '" + field + "' in expression \""
                        + this.expression + "\"");
            }
            result[0] = Integer.valueOf(split[0]);
            result[1] = Integer.valueOf(split[1]);
        }
        if (result[0] >= max || result[1] >= max) {
            throw new IllegalArgumentException("Range exceeds maximum (" + max + "): '" + field + "' in expression \""
                    + this.expression + "\"");
        }
        if (result[0] < min || result[1] < min) {
            throw new IllegalArgumentException("Range less than minimum (" + min + "): '" + field
                    + "' in expression \"" + this.expression + "\"");
        }
        return result;
    }
623604
@Override
    public boolean isConst(String name)
    {
        Slot slot = slotMap.query(name, 0);
        if (slot == null) {
            return false;
        }
        return (slot.getAttributes() & (PERMANENT|READONLY)) ==
                                       (PERMANENT|READONLY);

    }
98076
@Override
	public Constant getVal(String fldname) {
		if (groupFlds.contains(fldname))
			return groupVal.getVal(fldname);
		if (aggFns != null)
			for (AggregationFn fn : aggFns)
				if (fn.fieldName().equals(fldname))
					return fn.value();
		throw new RuntimeException("field " + fldname + " not found.");
	}
176089
public boolean isNull()
    {   // Return true if all non null fields have data in them
        int fieldCount = this.getFieldCount();  // BaseField Count
        for (int fieldSeq = DBConstants.MAIN_FIELD; fieldSeq < fieldCount+DBConstants.MAIN_FIELD; fieldSeq++)
        {
            BaseField field = this.getField(fieldSeq);
            if ((!field.isNullable()) && (field.isNull()))
                return true;            // This field can't be null!!!
        }
        return false;   // All fields okay
    }
520214
public Range getRange() {
    Long rangeMin = getRangeMin();
    Long rangeMax = getRangeMax();
    return rangeMin != null || rangeMax != null ? new Range(rangeMin, rangeMax) : null;
  }
502396
@VisibleForTesting
  void rangeSetToByteStringRange(RangeSet<RowKeyWrapper> guavaRangeSet, Query query) {

    for (Range<RowKeyWrapper> guavaRange : guavaRangeSet.asRanges()) {
      // Is it a point?
      if (guavaRange.hasLowerBound() && guavaRange.lowerBoundType() == BoundType.CLOSED
          && guavaRange.hasUpperBound() && guavaRange.upperBoundType() == BoundType.CLOSED
          && guavaRange.lowerEndpoint().equals(guavaRange.upperEndpoint())) {

        query.rowKey(guavaRange.lowerEndpoint().getKey());
      } else {
        ByteStringRange byteRange = ByteStringRange.unbounded();

        // Handle start key
        if (guavaRange.hasLowerBound()) {
          switch (guavaRange.lowerBoundType()) {
            case CLOSED:
              byteRange.startClosed(guavaRange.lowerEndpoint().getKey());
              break;
            case OPEN:
              byteRange.startOpen(guavaRange.lowerEndpoint().getKey());
              break;
            default:
              throw new IllegalArgumentException("Unexpected lower bound type: "
                  + guavaRange.lowerBoundType());
          }
        }

        // handle end key
        if (guavaRange.hasUpperBound()) {
          switch (guavaRange.upperBoundType()) {
            case CLOSED:
              byteRange.endClosed(guavaRange.upperEndpoint().getKey());
              break;
            case OPEN:
              byteRange.endOpen(guavaRange.upperEndpoint().getKey());
              break;
            default:
              throw new IllegalArgumentException("Unexpected upper bound type: " +
                  guavaRange.upperBoundType());
          }
        }
        query.range(byteRange);
      }
    }
  }