package com.alibaba.druid.sql.ast;

import java.util.Comparator;

public class SQLExprComparor implements Comparator<SQLExpr> {
   public static final SQLExprComparor instance = new SQLExprComparor();

   public int compare(SQLExpr a, SQLExpr b) {
      return compareTo(a, b);
   }

   public static int compareTo(SQLExpr a, SQLExpr b) {
      if (a == null && b == null) {
         return 0;
      } else if (a == null) {
         return -1;
      } else if (b == null) {
         return 1;
      } else {
         return a.getClass() == b.getClass() && a instanceof Comparable ? ((Comparable)a).compareTo(b) : a.getClass().getName().compareTo(b.getClass().getName());
      }
   }
}
