Skip to content

Commit

Permalink
Removes defunct Util class from legacy
Browse files Browse the repository at this point in the history
* Util.java
 * Removes the class and moves its functions over to StringUtilities
  • Loading branch information
Paul Richardson committed Nov 18, 2015
1 parent 0825e30 commit 0e4fe98
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 107 deletions.
Expand Up @@ -474,6 +474,62 @@ public static void main(String[] args) {
System.out.println(" START NAME = " + startName + " UNIQUE NAME = " + newName);
}

/**
* Compares two strings lexicographically.
* The comparison is based on the Unicode value of each character in
* the strings.
* @param str1
* @param str2
*
* @return the value <code>0</code> if the str1 is equal to str2;
* a value less than <code>0</code> if str1
* is lexicographically less than str2;
* and a value greater than <code>0</code> 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() {
}
}
1 change: 1 addition & 0 deletions plugins/org.teiid.designer.legacy/META-INF/MANIFEST.MF
Expand Up @@ -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,
Expand Down
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
Expand Up @@ -13,6 +13,7 @@

import java.io.IOException;
import java.util.ArrayList;
import org.teiid.core.designer.util.StringUtilities;

/**
* @since 8.0
Expand All @@ -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);
Expand Down
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
Expand Up @@ -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;


/**
Expand Down Expand Up @@ -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)
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

This file was deleted.

Expand Up @@ -12,6 +12,7 @@
package org.teiid.designer.core.index;

import java.util.Arrays;
import org.teiid.core.designer.util.StringUtilities;


/**
Expand Down Expand Up @@ -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);
}
}
@@ -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$
}


}
@@ -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

0 comments on commit 0e4fe98

Please sign in to comment.