⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utilities.java

📁 JoSQL 1.5的源代码。JoSQL(SQL for Java Objects)为Java开发者提供运用SQL语句来操作Java对象集的能力.利用JoSQL可以像操作数据库中的数据一样对任何Java
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	{	    return ((Comparable) o1).compareTo ((Comparable) o2);	}	// Force a string comparison.	String s1 = o1.toString ();	String s2 = o2.toString ();	return s1.compareTo (s2);    }    public static boolean isGTEquals (Object o1,				      Object o2)    {	return Utilities.matches (o1,				  o2,				  false,				  Utilities.GTE,				  false);    }    public static boolean isLTEquals (Object o1,				      Object o2)    {	return Utilities.matches (o1,				  o2,				  false,				  Utilities.LTE,				  false);    }    public static boolean isEquals (Object o1,				    Object o2)    {	return Utilities.compare (o1,				  o2) == 0;    }    public static Double getDoubleObject (Object o)    {	return new Double (Utilities.getDouble (o));    }    public static double getDouble (Object o)    {	return ((Number) o).doubleValue ();    }    public static boolean isNumber (Object o)    {	if (o == null)	{	    return false;	}	return Utilities.pCNames.containsKey (o.getClass ().getName ());    }    public static boolean isNumber (Class c)    {	return Utilities.pCNames.containsKey (c.getName ());    }    public static String formatSignature (String  name,					  Class[] ps)    {	StringBuffer buf = new StringBuffer (name);	buf.append ("(");		if (ps != null)	{	    for (int i = 0; i < ps.length; i++)	    {		    		buf.append (ps[i].getName ());				if (i < (ps.length - 1))		{		    buf.append (",");		    		}			    }	    	}		buf.append (")");		return buf.toString ();    }    public static boolean matchLikePattern (List    p,					    Object  lhs,					    boolean not,					    boolean ignoreCase)    {	if (lhs instanceof Collection)	{	    return Utilities.matchLikePattern (p,					       (Collection) lhs,					       not,					       ignoreCase);	}	boolean v = Utilities.matchLikePattern (p,						lhs,						ignoreCase);	if ((!v)	    &&	    (not)	   )	{	    return true;	}	if ((v)	    &&	    (not)	   )	{	    return false;	}	return v;    }    public static boolean matchLikePattern (List       p,					    Collection lhs,					    boolean    not,					    boolean    ignoreCase)    {	if (lhs instanceof List)	{	    int s = lhs.size () - 1;	    List l = (List) lhs;	    for (int i = s; i > -1; i--)	    {		Object o = l.get (i);		if (!Utilities.matchLikePattern (p,						 o,						 ignoreCase))		{		    if (not)		    {			return true;		    }		    return false;		}	    }	    if (not)	    {		return false;	    }	    return true;	}	Iterator iter = lhs.iterator ();	while (iter.hasNext ())	{	    Object o = iter.next ();	    if (!Utilities.matchLikePattern (p,					     o,					     ignoreCase))	    {		if (not)		{		    return true;		}		return false;	    }	}		if (not)	{	    return false;	}	return true;    }    public static boolean matchLikePattern (List    p,					    Object  o,					    boolean ignoreCase)    {	if (o == null)	{	    return false;	}	String st = o.toString ();		if (ignoreCase)	{	    st = st.toLowerCase ();	}	return Utilities.matchLikePattern (p,					   st);    }    public static boolean matchLikePattern (List    p,					    String  value)    {	if (value == null)	{	    return false;	}        boolean accept = true;        String c = null;        String pm = null;        int currPos = 0;        int cmdPos = 0;	int s = p.size ();        while (cmdPos < s)        {            c = (String) p.get (cmdPos);            pm = (String) p.get (cmdPos + 1);            if (c.equals (Utilities.F))            {                // if we are to find 'anything'                // then we are done                if (pm.equals (Utilities.A))                {                    break;                }                // otherwise search for the param                // from the curr pos                int nextPos = value.indexOf (pm, 					     currPos);                if (nextPos >= 0)                {                    // found it                    currPos = nextPos + pm.length ();                } else {                    accept = false;		    break;                }            } else {                if (c.equals (Utilities.E))                {                    // if we are to expect 'nothing'                    // then we MUST be at the end of the string                    if (pm.equals (Utilities.N))                    {                        if (currPos != value.length ())                        {                            accept = false;                        }                        // since we expect nothing else,                        // we must finish here                        break;                    } else {                         // otherwise, check if the expected string                        // is at our current position                        int nextPos = value.indexOf (pm, 						     currPos);                        if (nextPos != currPos)                        {                            accept = false;                            break;                        }                        // if we've made it this far, then we've                        // found what we're looking for                        currPos += pm.length ();                    }                }            }            cmdPos += 2;        }	return accept;    }    public static boolean matchLikePattern (List    p,					    String  value,					    boolean not)    {	boolean accept = Utilities.matchLikePattern (p,						     value);	if (not)	{	    return !accept;	}	return accept;    }    public static List getLikePattern (String value,				       String wildcard)    {	List p = new ArrayList ();        StringTokenizer t = new StringTokenizer (value, 						 wildcard, 						 true);        String tok = null;        while (t.hasMoreTokens ())        {            tok = t.nextToken ();            if (tok.equals (wildcard))            {                p.add (Utilities.F);                if (t.hasMoreTokens ())                {                    tok = t.nextToken ();                    p.add (tok);                } else {                    p.add (Utilities.A);                }            } else {                p.add (Utilities.E);                p.add (tok);            }        }        if ((tok == null)	    ||	    (!tok.equals (wildcard))	   )	            {            p.add (Utilities.E);            p.add (Utilities.N);        }	return p;    }    public static String stripQuotes (String s)    {	if (s == null)	{	    return s;	}	if (((s.charAt (0) == '\'')	     &&	     (s.charAt (s.length () - 1) == '\'')	    )	    ||	    ((s.charAt (0) == '"')	     &&	     (s.charAt (s.length () - 1) == '"')	    )	   )	{ 	    return s.substring (1,				s.length () - 1);	}	return s;    }    public static void getMethods (Class  c,				   String name,				   int    mods,				   List   ms)    {	if (c == null)	{	    return;	}	Method[] meths = c.getDeclaredMethods ();	for (int i = 0; i < meths.length; i++)	{	    Method m = meths[i];	    if ((m.getName ().equals (name))		&&		((m.getModifiers () & mods) == mods)	       )	    {		if (!ms.contains (m))		{		    // This is one.		    ms.add (m);		}	    }	}		// Now get all the super-classes.	Class sup = c.getSuperclass ();	if (sup != null)	{	    Utilities.getMethods (sup,				  name,				  mods,				  ms);	}	// Now work up through the super-classes/interfaces.	Class[] ints = c.getInterfaces ();	for (int i = 0; i < ints.length; i++)	{	    Class in = ints[i];	    Utilities.getMethods (in,				  name,				  mods,				  ms);	}    }    public static int matchMethodArgs (Class[] args,				       Class[] compArgs)    {	if ((compArgs == null)	    &&	    (args == null)	   )	{	    return 2;	}	if ((compArgs == null)	    &&	    (args.length == 0)	   )	{	    return 2;	}	if ((compArgs == null)	    &&	    (args.length > 0)	   )	{	    return 0;	}	if (args.length != compArgs.length)	{	    return 0;	}	// The score here helps in argument resolution, a more specific argument	// match (that is NOT expression in the method args) will score higher and	// thus is a better match.	int score = 0;	for (int i = 0; i < args.length; i++)	{	    Class c = args[i];	    // See if the arg is object, which means "I can accept any type".	    if (c.getClass ().getName ().equals (Object.class.getName ()))	    {		score += 1;		continue;	    }	    Class cc = compArgs[i];	    if (cc == null)	    {		// Can't match this arg.		continue;	    } else {		if (c.isAssignableFrom (cc))		{		    score += 2;		    continue;		}	    }	    if ((Utilities.isNumber (cc))		&&		(Utilities.isNumber (c))	       )	    {		score += 1;		// This matches...		continue;	    }	    if ((Utilities.isPrimitiveClass (c))		&&		(Utilities.isPrimitiveClass (cc))	       )	    {		// It is a primitive class as well, so now see if they are compatible.		if (Utilities.getPrimitiveClass (c).isAssignableFrom (Utilities.getPrimitiveClass (cc)))		{		    score += 1;		    // They are assignable...		    continue;		}	    }	    // See if the type is an object... this "may" mean	    // that we can match and it may not, it will be determined at runtime.	    if (cc.getName ().equals (Object.class.getName ()))	    {		score += 1;		continue;	    }	    // If we are here then we can't match this arg type...	    // No point checking any further...	    return 0;	}	// All args can be matched.	return score;    }     public static Object[] convertArgs (Object[] args,					Class[]  argTypes)    {	if (args == null)	{	    return args;	}	Object[] nargs = new Object [args.length];	for (int i = 0; i < argTypes.length; i++)	{	    if (Utilities.isNumber (argTypes[i]))	    {		Class c = Utilities.getObjectClass (argTypes[i]);		// This arg is a number, need to now convert to the type in the args.		Number arg = (Number) args[i];		if (Double.class.isAssignableFrom (c))		{		    nargs[i] = arg;		    continue;		}		if (Short.class.isAssignableFrom (c))		{		    nargs[i] = new Short (arg.shortValue ());		    continue;		}		if (Integer.class.isAssignableFrom (c))		{		    nargs[i] = new Integer (arg.intValue ());		    continue;		}		if (Long.class.isAssignableFrom (c))		{		    nargs[i] = new Long (arg.longValue ());		    continue;		}		if (Float.class.isAssignableFrom (c))		{		    nargs[i] = new Float (arg.floatValue ());		    continue;		}		if (Byte.class.isAssignableFrom (c))		{		    nargs[i] = new Byte (arg.byteValue ());		    continue;		}	    } else {		nargs[i] = args[i];	    }	}	return nargs;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -