From 0e4fe98ea26af7567585c5f46287b3837c59db8e Mon Sep 17 00:00:00 2001 From: Paul Richardson
0
if the str1 is equal to str2;
+ * a value less than 0
if str1
+ * is lexicographically less than str2;
+ * and a value greater than 0
if str1 is
+ * lexicographically greater than str2.
+ */
+ public static int compare(char[] str1, char[] str2) {
+ int len1 = str1.length;
+ int len2 = str2.length;
+ int n = Math.min(len1, len2);
+ int i = 0;
+ while (n-- != 0) {
+ char c1 = str1[i];
+ char c2 = str2[i++];
+ if (c1 != c2) {
+ return c1 - c2;
+ }
+ }
+ return len1 - len2;
+ }
+
+ /**
+ * Returns the length of the common prefix between s1 and s2.
+ * @param s1
+ * @param s2
+ * @return length of the prefix
+ */
+ public static int prefixLength(char[] s1, char[] s2) {
+ int len = 0;
+ int max = Math.min(s1.length, s2.length);
+ for (int i = 0; i < max && s1[i] == s2[i]; ++i)
+ ++len;
+ return len;
+ }
+
+ /**
+ * Returns the length of the common prefix between s1 and s2.
+ * @param s1
+ * @param s2
+ * @return length of the prefix
+ */
+ public static int prefixLength(String s1, String s2) {
+ int len = 0;
+ int max = Math.min(s1.length(), s2.length());
+ for (int i = 0; i < max && s1.charAt(i) == s2.charAt(i); ++i)
+ ++len;
+ return len;
+ }
+
private StringUtilities() {
}
}
diff --git a/plugins/org.teiid.designer.legacy/META-INF/MANIFEST.MF b/plugins/org.teiid.designer.legacy/META-INF/MANIFEST.MF
index 3a25c1a477..1c7253ea62 100644
--- a/plugins/org.teiid.designer.legacy/META-INF/MANIFEST.MF
+++ b/plugins/org.teiid.designer.legacy/META-INF/MANIFEST.MF
@@ -10,6 +10,7 @@ Require-Bundle: org.jdom;bundle-version="[1.1.1,2.0.0)",
org.teiid.designer.modeshape;bundle-version="[9.0.2,10.0.0)",
org.teiid.designer.spi;bundle-version="[9.0.2,10.0.0)",
org.teiid.core.designer;bundle-version="[9.0.2,10.0.0)",
+ org.teiid.core.designer;bundle-version="[9.0.2,10.0.0)",
org.eclipse.core.runtime;bundle-version="[3.10.0,4.0.0)"
Export-Package:
org.teiid.designer.common.namedobject,
diff --git a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/BlocksIndexInput.java b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/BlocksIndexInput.java
index aac689c4d2..bfa8f0c9b8 100644
--- a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/BlocksIndexInput.java
+++ b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/BlocksIndexInput.java
@@ -18,6 +18,7 @@
import java.util.HashMap;
import org.teiid.core.designer.util.CharOperation;
import org.teiid.core.designer.util.LRUCache;
+import org.teiid.designer.legacy.Messages;
/**
* This input is used for reading indexes saved using a BlocksIndexOutput.
@@ -217,7 +218,7 @@ public void open() throws IOException {
if (!isOpen()) {
raf = new SafeRandomAccessFile(indexFile, "r"); //$NON-NLS-1$
String sig = raf.readUTF();
- if (!sig.equals(IIndexConstants.SIGNATURE)) throw new IOException(Util.bind("exception.wrongFormat")); //$NON-NLS-1$
+ if (!sig.equals(IIndexConstants.SIGNATURE)) throw new IOException(Messages.wrongFormat); //$NON-NLS-1$
int summaryBlockNum = raf.readInt();
raf.seek(summaryBlockNum * (long)IIndexConstants.BLOCK_SIZE);
summary = new IndexSummary();
diff --git a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/FileListBlock.java b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/FileListBlock.java
index dd44fde065..e8ceda3082 100644
--- a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/FileListBlock.java
+++ b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/FileListBlock.java
@@ -13,6 +13,7 @@
import java.io.IOException;
import java.util.ArrayList;
+import org.teiid.core.designer.util.StringUtilities;
/**
* @since 8.0
@@ -38,7 +39,7 @@ public boolean addFile( IndexedFile indexedFile ) {
offset += 4;
}
String path = indexedFile.getPath();
- int prefixLen = prevPath == null ? 0 : Util.prefixLength(prevPath, path);
+ int prefixLen = prevPath == null ? 0 : StringUtilities.prefixLength(prevPath, path);
int sizeEstimate = 2 + 2 + (path.length() - prefixLen) * 3;
if (offset + sizeEstimate > blockSize - 2) return false;
field.putInt2(offset, prefixLen);
diff --git a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/GammaCompressedIndexBlock.java b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/GammaCompressedIndexBlock.java
index d7e71a2691..2ca1bf5551 100644
--- a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/GammaCompressedIndexBlock.java
+++ b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/GammaCompressedIndexBlock.java
@@ -12,6 +12,7 @@
package org.teiid.designer.core.index;
import java.io.UTFDataFormatException;
+import org.teiid.core.designer.util.StringUtilities;
/**
* Uses prefix coding on words, and gamma coding of document numbers differences.
@@ -46,7 +47,7 @@ public boolean addEntry(WordEntry entry) {
}
protected void encodeEntry(WordEntry entry, char[] prevWord, CodeByteStream codeStream) {
char[] word= entry.getWord();
- int prefixLen= prevWord == null ? 0 : Math.min(Util.prefixLength(prevWord, word), 255);
+ int prefixLen= prevWord == null ? 0 : Math.min(StringUtilities.prefixLength(prevWord, word), 255);
codeStream.writeByte(prefixLen);
codeStream.writeUTF(word, prefixLen, word.length);
int n= entry.getNumRefs();
diff --git a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/IndexSummary.java b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/IndexSummary.java
index aa67c2cf4b..a36d3de7d2 100644
--- a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/IndexSummary.java
+++ b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/IndexSummary.java
@@ -14,8 +14,8 @@
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
-
import org.teiid.core.designer.util.CharOperation;
+import org.teiid.core.designer.util.StringUtilities;
/**
@@ -131,7 +131,7 @@ public int getBlockNumForWord(char[] word) {
while (min <= max) {
int mid= (min + max) / 2;
FirstWordInBlock entry= (FirstWordInBlock) firstWordsInBlocks.get(mid);
- int compare= Util.compare(word, entry.word);
+ int compare= StringUtilities.compare(word, entry.word);
if (compare == 0)
return entry.blockNum;
if (compare < 0)
diff --git a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/MergeFactory.java b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/MergeFactory.java
index daf61b43db..38f6f768d7 100644
--- a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/MergeFactory.java
+++ b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/MergeFactory.java
@@ -13,6 +13,7 @@
import java.io.IOException;
import java.util.Map;
+import org.teiid.core.designer.util.StringUtilities;
/**
* A mergeFactory is used to merge 2 indexes into one. One of the indexes
@@ -172,7 +173,7 @@ protected void mergeReferences() throws IOException {
else if (word2 == null)
compare= -1;
else
- compare= Util.compare(word1.getWord(), word2.getWord());
+ compare= StringUtilities.compare(word1.getWord(), word2.getWord());
if (compare < 0) {
word1.mapRefs(mappingOld);
mergeOutput.addWord(word1);
diff --git a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/Util.java b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/Util.java
deleted file mode 100644
index 03f74dd831..0000000000
--- a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/Util.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * MetaMatrix, Inc - repackaging and updates for use as a metadata store
- *******************************************************************************/
-package org.teiid.designer.core.index;
-
-import java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-/**
- * @since 8.0
- */
-public class Util {
-
- private Util() {
- }
-
- /* Bundle containing messages */
- protected static ResourceBundle bundle;
- private final static String bundleName = "com.metamatrix.core.index.i18n"; //$NON-NLS-1$
-
- /**
- * Lookup the message with the given ID in this catalog
- */
- public static String bind(String id) {
- return bind(id, (String[]) null);
- }
- /**
- * Lookup the message with the given ID in this catalog and bind its
- * substitution locations with the given string values.
- */
- public static String bind(String id, String[] arguments) {
- if (id == null)
- return "No message available"; //$NON-NLS-1$
- String message = null;
- try {
- message = bundle.getString(id);
- } catch (MissingResourceException e) {
- // If we got an exception looking for the message, fail gracefully by just returning
- // the id we were looking for. In most cases this is semi-informative so is not too bad.
- return "Missing message: " + id + " in: " + bundleName; //$NON-NLS-2$ //$NON-NLS-1$
- }
- return MessageFormat.format(message, (Object[])arguments);
- }
-
- /**
- * Compares two strings lexicographically.
- * The comparison is based on the Unicode value of each character in
- * the strings.
- *
- * @return the value 0
if the str1 is equal to str2;
- * a value less than 0
if str1
- * is lexicographically less than str2;
- * and a value greater than 0
if str1 is
- * lexicographically greater than str2.
- */
- public static int compare(char[] str1, char[] str2) {
- int len1= str1.length;
- int len2= str2.length;
- int n= Math.min(len1, len2);
- int i= 0;
- while (n-- != 0) {
- char c1= str1[i];
- char c2= str2[i++];
- if (c1 != c2) {
- return c1 - c2;
- }
- }
- return len1 - len2;
- }
-
- /**
- * Returns the length of the common prefix between s1 and s2.
- */
- public static int prefixLength(char[] s1, char[] s2) {
- int len= 0;
- int max= Math.min(s1.length, s2.length);
- for (int i= 0; i < max && s1[i] == s2[i]; ++i)
- ++len;
- return len;
- }
- /**
- * Returns the length of the common prefix between s1 and s2.
- */
- public static int prefixLength(String s1, String s2) {
- int len= 0;
- int max= Math.min(s1.length(), s2.length());
- for (int i= 0; i < max && s1.charAt(i) == s2.charAt(i); ++i)
- ++len;
- return len;
- }
-}
diff --git a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/WordEntry.java b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/WordEntry.java
index 9db604dda3..fe1519d233 100644
--- a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/WordEntry.java
+++ b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/core/index/WordEntry.java
@@ -12,6 +12,7 @@
package org.teiid.designer.core.index;
import java.util.Arrays;
+import org.teiid.core.designer.util.StringUtilities;
/**
@@ -164,6 +165,6 @@ public String toString() {
}
@Override
public int compareTo(WordEntry other) {
- return Util.compare(this.fWord, other.fWord);
+ return StringUtilities.compare(this.fWord, other.fWord);
}
}
diff --git a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/legacy/Messages.java b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/legacy/Messages.java
new file mode 100644
index 0000000000..76f695530e
--- /dev/null
+++ b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/legacy/Messages.java
@@ -0,0 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source.
+*
+* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
+*
+* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
+*/
+package org.teiid.designer.legacy;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+*
+*/
+public class Messages extends NLS {
+
+ public static String wrongFormat;
+
+ public static String blockSizeExceeded;
+
+ static {
+ NLS.initializeMessages(Messages.class.getPackage().getName() + ".messages", Messages.class); //$NON-NLS-1$
+ }
+
+
+}
diff --git a/plugins/org.teiid.designer.legacy/src/org/teiid/designer/legacy/messages.properties b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/legacy/messages.properties
new file mode 100644
index 0000000000..e4b1d3dcc1
--- /dev/null
+++ b/plugins/org.teiid.designer.legacy/src/org/teiid/designer/legacy/messages.properties
@@ -0,0 +1,8 @@
+# JBoss, Home of Professional Open Source.
+#
+# See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
+#
+# See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
+
+blockSizeExceeded=Index creation failure: Entry cannot be added to index since its size exceeds the block size
+wrongFormat=Index cannot be read since it does not conform to the correct format
\ No newline at end of file