复制 OrderByElement

@param orig       原 OrderByElement
@param expression 新 OrderByElement 的排序要素
@return 复制的新 OrderByElement
346532
protected OrderByElement cloneOrderByElement(OrderByElement orig, Expression expression) {
        OrderByElement element = new OrderByElement();
        element.setAsc(orig.isAsc());
        element.setAscDescPresent(orig.isAscDescPresent());
        element.setNullOrdering(orig.getNullOrdering());
        element.setExpression(expression);
        return element;
    }
48734
public static ParenthesizedExpression parenthesizeAndReplace(Expression expression) {
    ParenthesizedExpression newExpr = new ParenthesizedExpression();
    expression.replaceWith(newExpr);
    newExpr.setExpression(expression);
    return newExpr;
  }
842117
protected ElemTemplateElement getElemFromExpression(Expression expr)
  {
  	ExpressionNode parent = expr.exprGetParent();
  	while(null != parent)
  	{
  		if(parent instanceof ElemTemplateElement)
  			return (ElemTemplateElement)parent;
  		parent = parent.exprGetParent();
  	}
  	throw new RuntimeException(XSLMessages.createMessage(XSLTErrorResources.ER_ASSERT_NO_TEMPLATE_PARENT, null));
  	// "Programmer's error! expr has no ElemTemplateElement parent!");
  }
598543
public Object resolveExpression(String expression) {
    if (StringUtils.isBlank(expression)) {
      return null;
    }

    interpreter.getContext().addResolvedExpression(expression.trim());

    try {
      String elExpression = EXPRESSION_START_TOKEN + expression.trim() + EXPRESSION_END_TOKEN;
      ValueExpression valueExp = expressionFactory.createValueExpression(elContext, elExpression, Object.class);
      Object result = valueExp.getValue(elContext);

      validateResult(result);

      return result;

    } catch (PropertyNotFoundException e) {
      interpreter.addError(new TemplateError(ErrorType.WARNING, ErrorReason.UNKNOWN, ErrorItem.PROPERTY, e.getMessage(), "", interpreter.getLineNumber(), interpreter.getPosition(), e,
          BasicTemplateErrorCategory.UNKNOWN, ImmutableMap.of("exception", e.getMessage())));
    } catch (TreeBuilderException e) {
      int position = interpreter.getPosition() + e.getPosition();
      // replacing the position in the string like this isn't great, but JUEL's parser does not allow passing in a starting position
      String errorMessage = StringUtils.substringAfter(e.getMessage(), "': ").replaceFirst("position [0-9]+", "position " + position);
      interpreter.addError(TemplateError.fromException(new TemplateSyntaxException(expression.substring(e.getPosition() - EXPRESSION_START_TOKEN.length()),
          "Error parsing '" + expression + "': " + errorMessage, interpreter.getLineNumber(), position, e)));
    }
    catch (ELException e) {
      if (e.getCause() != null && e.getCause() instanceof DeferredValueException) {
        throw (DeferredValueException) e.getCause();
      }
      if (e.getCause() != null && e.getCause() instanceof TemplateSyntaxException) {
        interpreter.addError(TemplateError.fromException((TemplateSyntaxException) e.getCause()));
      }
      else if (e.getCause() != null && e.getCause() instanceof InvalidInputException) {
        interpreter.addError(TemplateError.fromInvalidInputException((InvalidInputException) e.getCause()));
      }
      else if (e.getCause() != null && e.getCause() instanceof InvalidArgumentException) {
        interpreter.addError(TemplateError.fromInvalidArgumentException((InvalidArgumentException) e.getCause()));
      }
      else {
        interpreter.addError(TemplateError.fromException(new TemplateSyntaxException(expression, e.getMessage(), interpreter.getLineNumber(), e)));
      }
    }
    catch (DisabledException e) {
      interpreter.addError(new TemplateError(ErrorType.FATAL, ErrorReason.DISABLED, ErrorItem.FUNCTION, e.getMessage(), expression, interpreter.getLineNumber(), interpreter.getPosition(), e));
    } catch (UnknownTokenException e) {
      // Re-throw the exception because you only get this when the config failOnUnknownTokens is enabled.
      throw e;
    } catch (DeferredValueException e) {
      // Re-throw so that it can be handled in JinjavaInterpreter
      throw e;
    } catch (InvalidInputException e) {
      interpreter.addError(TemplateError.fromInvalidInputException(e));
    } catch (InvalidArgumentException e) {
      interpreter.addError(TemplateError.fromInvalidArgumentException(e));
    } catch (Exception e) {
      interpreter.addError(TemplateError.fromException(new InterpretException(
          String.format("Error resolving expression [%s]: " + getRootCauseMessage(e), expression), e, interpreter.getLineNumber(), interpreter.getPosition())));
    }

    return null;
  }
128166
@NonNull
    public ArrayExpressionSatisfies in(@NonNull Expression expression) {
        if (expression == null) {
            throw new IllegalArgumentException("expression cannot be null.");
        }
        return new ArrayExpressionSatisfies(type, variable, expression);
    }
1027612
function orderBy(expression) {

        //Check arguments
        if (!expression)
            throw new Error("Expression is invalid");
		
		//Define sort action estracting values from objects
		var sortAction = function(a, b){
		
			//Get value for "a" and "b" element
			var aValue = expression(a);
			var bValue = expression(b);
		
			//Check if one element is greater then the second one
			if(aValue < bValue) return -1;
			if(aValue > bValue) return 1;
			return 0;
		};
		
		//Copy array in order to avoid modifications on original
		var outData = [];
		for(var i = 0; i < this.items.length; i++){
			outData.push(this.items[i]);
		}

        //Define output array
        var sortedData = outData.sort(sortAction);
        
        //Return for chaining
        return new jslinq(sortedData);
    }
26042
public static Expression<?> orderBy(List<OrderSpecifier<?>> args) {
        return operation(Object.class, Ops.ORDER, ConstantImpl.create(args));
    }
192048
function (item, expression) {
            var ret = 1,
                operator = expression.operator;

            if (expression instanceof Query.Where) {
                if (operator === "or") {
                    ret = 0;
                }
                var tmp;
                for (var i = 0; i < expression.expressions.length; i++) {
                    tmp = this._filterItem(item, expression.expressions[i]);
                    if (operator === "and") {
                        ret = ret * tmp;
                    } else if (operator === "or" && tmp) {
                        return 1;
                    } else if (operator === "not") {
                        return tmp ? 0 : 1;
                    }
                }
            } else if (expression instanceof Query.Comparator) {
                // TODO: add type check
                var value = expression.value,
                    field = expression.field,
                    itemValue = this._getValueForItemField(item, field);

                if (typeof(itemValue) === "undefined") {
                    return 0;
                }

                switch (operator) {
                    case "eql":
                        return itemValue == value;
                    case "gt":
                        return itemValue > value;
                    case "lt":
                        return itemValue < value;
                    case "gte":
                        return itemValue >= value;
                    case "lte":
                        return itemValue <= value;
                    case "in":
                        if (!(itemValue instanceof Array)) {
                            itemValue = [itemValue];
                        }
                        for (var j = 0; j < itemValue.length; j++) {
                            for (var k in value) {
                                if (value.hasOwnProperty(k)) {
                                    if (itemValue[j] == value[k]) {
                                        return 1;
                                    }
                                }
                            }
                        }
                        return 0;
                    case "between":
                        return itemValue >= value[0] && itemValue <= value[1];
                    case "like":
                        return new RegExp(value, "i").test(itemValue);
                    case "ne":
                        return itemValue != value;
                    default :
                        return 1;
                }

            }

            return ret;
        }
644801
private static void addOrder(PersistentEntity entity,
                                 CriteriaQuery query,
                                 From queryRoot,
                                 CriteriaBuilder criteriaBuilder,
                                 String sort, String order, boolean ignoreCase) {
        if (sort.equalsIgnoreCase(entity.getIdentity().getName())) {
            Expression path = queryRoot;

            if (ignoreCase) {
                path = criteriaBuilder.upper(path);
            }
            if (DynamicFinder.ORDER_DESC.equals(order)) {
                query.orderBy(criteriaBuilder.desc(path));
            } else {
                query.orderBy(criteriaBuilder.asc(path));
            }
        } else {
            Expression path = queryRoot.get(sort);

            if (ignoreCase) {
                path = criteriaBuilder.upper(path);
            }
            if (DynamicFinder.ORDER_DESC.equals(order)) {
                query.orderBy(criteriaBuilder.desc(path));
            } else {
                query.orderBy(criteriaBuilder.asc(path));
            }
        }
    }
540513
private void processOrderByClause(TermsBuilder termsBuilder, Expression orderByExpression,
            Expression groupByClause, EntityMetadata entityMetadata)
    {
        Expression orderByClause = (OrderByClause) orderByExpression;
        OrderByItem orderByItems = (OrderByItem) ((OrderByClause) orderByClause).getOrderByItems();

        if (orderByClause instanceof CollectionExpression
                || !(orderByItems.getExpression().toParsedText().equalsIgnoreCase(groupByClause.toParsedText())))
        {
            logger.error("Order by and group by on different field are not supported simultaneously");
            throw new UnsupportedOperationException(
                    "Order by and group by on different field are not supported simultaneously");
        }

        String ordering = orderByItems.getOrdering().toString();
        termsBuilder.order(Terms.Order.term(!ordering.equalsIgnoreCase(Expression.DESC)));
    }
1236177
public static Element getElementByXPath(String expression, Object source) {
		return (Element) getNodeByXPath(expression, source);
	}
321491
@Nullable
  public ExpressionTreeElement addTreeElement(@Nonnull final ExpressionTreeElement element) {
    assertNotEmptySlot();
    assertNotNull("The element is null", element);

    final int newElementPriority = element.getPriority();

    ExpressionTreeElement result = this;

    final ExpressionTreeElement parentTreeElement = this.parentTreeElement;

    final int currentPriority = getPriority();

    if (newElementPriority < currentPriority) {
      if (parentTreeElement == null) {
        element.addTreeElement(this);
        result = element;
      } else {
        result = parentTreeElement.addTreeElement(element);
      }
    } else if (newElementPriority == currentPriority) {
      if (parentTreeElement != null) {
        parentTreeElement.replaceElement(this, element);
      }
      if (element.nextChildSlot >= element.childElements.length) {
        throw new PreprocessorException("[Expression]Can't process expression item, may be wrong number of arguments", this.sourceString, this.includeStack, null);
      }
      element.childElements[element.nextChildSlot] = this;
      element.nextChildSlot++;
      this.parentTreeElement = element;
      result = element;
    } else if (isFull()) {
      final int lastElementIndex = getArity() - 1;

      final ExpressionTreeElement lastElement = childElements[lastElementIndex];
      if (lastElement.getPriority() > newElementPriority) {
        element.addElementToNextFreeSlot(lastElement);
        childElements[lastElementIndex] = element;
        element.parentTreeElement = this;
        result = element;
      }

    } else {
      addElementToNextFreeSlot(element);
      result = element;
    }
    return result;
  }
75059
public <R> AnimaQuery<T> order(TypeFunction<T, R> function, OrderBy orderBy) {
        String columnName = AnimaUtils.getLambdaColumnName(function);
        return order(columnName, orderBy);
    }
787048
function singleOrDefault(expression) {

		//Define output
		var outData;
		
		//If there's no expression
		if (!expression){
		
			//Just assign current items
			outData = this.items;
		}
		else{
		
			//Otherwise apply where condition
			outData = jslinq(this.items)
				.where(expression)
				.toList();
		}
	
        //If output list does not contains element, return null
        if (outData.length === 0)
            return null;

        //If contains just one element, returns element
        if (outData.length == 1)
            return outData[0];

        //If contains more than one element, throws
        throw new Error("Sequence contains " + outData.length + " matching elements");
    }
1046377
public static OrderByClause getOrderByClause(JPQLExpression jpqlExpression)
    {
        OrderByClause orderByClause = null;

        if (hasOrderBy(jpqlExpression))
        {
            orderByClause = (OrderByClause) ((SelectStatement) jpqlExpression.getQueryStatement()).getOrderByClause();
        }
        return orderByClause;
    }
1141234
public static <E extends Comparable<? super E>> AbstractGroupExpression<E, SortedSet<E>> sortedSet(Expression<E> expression) {
        return GSet.createSorted(expression);
    }
504956
public OptionalSyntax where(Expression<?>... expression) {
		for (Expression<?> exp : expression) {
			getMessage().getOptional().add(exp.toString());
			LOG.debug("expression: " + exp);
		}
		QueryMessage mess = getMessage();
		return new OptionalSyntax(mess);
	}