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

📄 sqlchar.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				}			}			// Trim if appropriate			if (start == tmpValue.length())			{				tmpValue = "";			}			else if (start > 0)			{				tmpValue = tmpValue.substring(start);			}		}		// Trim trailing characters if appropriate		if (trimType == TRAILING)		{			int start = tmpValue.length();			// Find the 1st character which doesn't get trimmed			for ( ; start > 0; start--)			{				boolean found = false;				for (int index = 0; index < trimChars.length; index++)				{					if (tmpValue.charAt(start - 1) == trimChars[index])					{						found = true;						break;					}				}				if (! found)				{					break;				}			}			// Trim if appropriate			if (start == 0)			{				tmpValue = "";			}			else if (start < tmpValue.length())			{				tmpValue = tmpValue.substring(0, start);			}		}				result.setValue(tmpValue);		return result;	}	/** @see StringDataValue#upper 	 *	 * @exception StandardException		Thrown on error	 */	public StringDataValue upper(StringDataValue result)							throws StandardException	{		if (result == null)		{			result = (StringDataValue) getNewNull();		}		if (this.isNull())		{			result.setToNull();			return result;		}				String upper = getString();		upper = upper.toUpperCase(getLocale());		result.setValue(upper);		return result;	}	/** @see StringDataValue#lower 	 *	 * @exception StandardException		Thrown on error	 */	public StringDataValue lower(StringDataValue result)							throws StandardException	{		if (result == null)		{			result = (StringDataValue) getNewNull();		}		if (this.isNull())		{			result.setToNull();			return result;		}				String lower = getString();		lower = lower.toLowerCase(getLocale());		result.setValue(lower);		return result;	}	/*	 * DataValueDescriptor interface	 */	/** @see DataValueDescriptor#typePrecedence */	public int typePrecedence()	{		return TypeId.CHAR_PRECEDENCE;	}	/**	 * Compare two Strings using standard SQL semantics.	 *	 * @param op1				The first String	 * @param op2				The second String	 *	 * @return  -1 - op1 <  op2	 * 			 0 - op1 == op2	 *			 1 - op1 > op2	 */	protected static int stringCompare(String op1, String op2)	{		int			posn;		char		leftchar;		char		rightchar;		int			leftlen;		int			rightlen;		int			retvalIfLTSpace;		String		remainingString;		int			remainingLen;		/*		** By convention, nulls sort High, and null == null		*/		if (op1 == null || op2 == null)		{			if (op1 != null)	// op2 == null				return -1;			if (op2 != null)	// op1 == null				return 1;			return 0;			// both null		}		/*		** Compare characters until we find one that isn't equal, or until		** one String or the other runs out of characters.		*/		leftlen = op1.length();		rightlen = op2.length();		int shorterLen = leftlen < rightlen ? leftlen : rightlen;		for (posn = 0; posn < shorterLen; posn++)		{			leftchar = op1.charAt(posn);			rightchar = op2.charAt(posn);			if (leftchar != rightchar)			{				if (leftchar < rightchar)					return -1;				else					return 1;			}		}		/*		** All the characters are equal up to the length of the shorter		** string.  If the two strings are of equal length, the values are		** equal.		*/		if (leftlen == rightlen)			return 0;		/*		** One string is shorter than the other.  Compare the remaining		** characters in the longer string to spaces (the SQL standard says		** that in this case the comparison is as if the shorter string is		** padded with blanks to the length of the longer string.		*/		if (leftlen > rightlen)		{			/*			** Remaining characters are on the left.			*/			/* If a remaining character is less than a space, return -1 (op1 < op2) */			retvalIfLTSpace = -1;			remainingString = op1;			posn = rightlen;			remainingLen = leftlen;		}		else		{			/*			** Remaining characters are on the right.			*/			/* If a remaining character is less than a space, return 1 (op1 > op2) */			retvalIfLTSpace = 1;			remainingString = op2;			posn = leftlen;			remainingLen = rightlen;		}		/* Look at the remaining characters in the longer string */		for ( ; posn < remainingLen; posn++)		{			char	remainingChar;			/*			** Compare the characters to spaces, and return the appropriate			** value, depending on which is the longer string.			*/			remainingChar = remainingString.charAt(posn);			if (remainingChar < ' ')				return retvalIfLTSpace;			else if (remainingChar > ' ')				return -retvalIfLTSpace;		}		/* The remaining characters in the longer string were all spaces,		** so the strings are equal.		*/		return 0;	}	/** 	 * Compare two SQLChars.  This method will be overriden in the	 * National char wrappers so that the appropriate comparison	 * is done.	 *	 * @exception StandardException		Thrown on error	 */	 protected int stringCompare(SQLChar char1, SQLChar char2)		 throws StandardException	 {		 return stringCompare(char1.getCharArray(), char1.getLength(), 							  char2.getCharArray(), char2.getLength());	 }	/**	 * Compare two Strings using standard SQL semantics.	 *	 * @param op1				The first String	 * @param op2				The second String	 *	 * @return  -1 - op1 <  op2	 * 			 0 - op1 == op2	 *			 1 - op1 > op2	 */	protected static int stringCompare(char[] op1, int leftlen, char[] op2, int rightlen)	{		int			posn;		char		leftchar;		char		rightchar;		int			retvalIfLTSpace;		char[]		remainingString;		int			remainingLen;		/*		** By convention, nulls sort High, and null == null		*/		if (op1 == null || op2 == null)		{			if (op1 != null)	// op2 == null				return -1;			if (op2 != null)	// op1 == null				return 1;			return 0;			// both null		}		/*		** Compare characters until we find one that isn't equal, or until		** one String or the other runs out of characters.		*/		int shorterLen = leftlen < rightlen ? leftlen : rightlen;		for (posn = 0; posn < shorterLen; posn++)		{			leftchar = op1[posn];			rightchar = op2[posn];			if (leftchar != rightchar)			{				if (leftchar < rightchar)					return -1;				else					return 1;			}		}		/*		** All the characters are equal up to the length of the shorter		** string.  If the two strings are of equal length, the values are		** equal.		*/		if (leftlen == rightlen)			return 0;		/*		** One string is shorter than the other.  Compare the remaining		** characters in the longer string to spaces (the SQL standard says		** that in this case the comparison is as if the shorter string is		** padded with blanks to the length of the longer string.		*/		if (leftlen > rightlen)		{			/*			** Remaining characters are on the left.			*/			/* If a remaining character is less than a space, return -1 (op1 < op2) */			retvalIfLTSpace = -1;			remainingString = op1;			posn = rightlen;			remainingLen = leftlen;		}		else		{			/*			** Remaining characters are on the right.			*/			/* If a remaining character is less than a space, return 1 (op1 > op2) */			retvalIfLTSpace = 1;			remainingString = op2;			posn = leftlen;			remainingLen = rightlen;		}		/* Look at the remaining characters in the longer string */		for ( ; posn < remainingLen; posn++)		{			char	remainingChar;			/*			** Compare the characters to spaces, and return the appropriate			** value, depending on which is the longer string.			*/			remainingChar = remainingString[posn];			if (remainingChar < ' ')				return retvalIfLTSpace;			else if (remainingChar > ' ')				return -retvalIfLTSpace;		}		/* The remaining characters in the longer string were all spaces,		** so the strings are equal.		*/		return 0;	}	/**	 * Compare a localized string with this one.	 *	 * @param str2              The other string	 *	 * @return  -1 - this <  str2	 * 			 0 - this == str2	 *			 1 - this > str2	 */	protected int stringCollatorCompare(SQLChar str2) 		throws StandardException	{			CollationKey ckey1 = this.getCollationKey();		CollationKey ckey2 = str2.getCollationKey();				/*		** By convention, nulls sort High, and null == null		*/		if (ckey1 == null || ckey2 == null)		{			if (ckey1 != null)	// str2 == null				return -1;			if (ckey2 != null)	// this == null				return 1;			return 0;			// both == null		}		return ckey1.compareTo(ckey2);	}			protected CollationKey getCollationKey() throws StandardException	{		char tmpCharArray[];		if (cKey != null)			return cKey;		if (rawLength == -1)		{			/* materialize the string if input is a stream */			tmpCharArray = getCharArray();			if (tmpCharArray == null)				return null;		}				int lastNonspaceChar = rawLength;		while (lastNonspaceChar > 0 && 			   rawData[lastNonspaceChar - 1] == '\u0020')			lastNonspaceChar--;			// count off the trailing spaces.		RuleBasedCollator rbc = getLocaleFinder().getCollator();				cKey = rbc.getCollationKey(new String(rawData, 0, lastNonspaceChar));		return cKey;	}	/*	 * String display of value	 */	public String toString()	{		if (isNull()) {			return "NULL";		}		if ((value == null) && (rawLength != -1)) {			return new String(rawData, 0, rawLength);		}		if (stream != null) {			try {				return getString();			} catch (Exception e) {				return e.toString();			}		}		return value;	}	/*	 * Hash code	 */	public int hashCode()	{		try {			if (getString() == null)			{				return 0;			}		}		catch (StandardException se)		{			if (SanityManager.DEBUG)				SanityManager.THROWASSERT("Unexpected exception " + se);			return 0;		}		/* value.hashCode() doesn't work because of the SQL blank padding behavior		 * We want the hash code to be based on the value after the 		 * trailing blanks have been trimmed.  Calling trim() is too expensive		 * since it will create a new object, so here's what we do:		 *		o  Walk from the right until we've found the 1st		 *		   non-blank character.		 *		o  Add up the characters from that character to the 1st in		 *		   the string and return that as the hash code.		 */		int index;		int hashcode = 0;		// value will have been set by the getString() above		String lvalue = value;		// Find 1st non-blank from the right		for (index = lvalue.length() - 1; 		     index >= 0 && lvalue.charAt(index) == ' '; 			 index--)		{			;		}		// Build the hash code		for ( ; index >= 0; index--)		{			hashcode += lvalue.charAt(index);		}		return hashcode;	}	/**	 * Implementation of hashCode() for the national character types,	 * put here to make it accessible to all the national types.	 */	protected int nationalHashCode()	{		CollationKey tmpCKey = null;		try		{			tmpCKey = getCollationKey();		}		catch (StandardException se)		{			if (SanityManager.DEBUG)			{				SanityManager.THROWASSERT("Un

⌨️ 快捷键说明

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