All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.amygdalum.util.text.ByteUtils Maven / Gradle / Ivy

Go to download

Searching and Matching Strings with efficient algorithms: - Knuth-Morris-Pratt - Shift-And/Or - Boyer-Moore-Horspool - Sunday (QuickSearch) - BNDM - BOM - Aho-Corasick - Set-Horspool - Wu-Manber - Set-BOM

There is a newer version: 0.4.4
Show newest version
package net.amygdalum.util.text;

import java.util.List;

public final class ByteUtils {

	private ByteUtils() {
	}

	public static byte[] revert(byte[] bytes) {
		final int ri = bytes.length - 1;
		byte[] reversebytes = new byte[bytes.length];
		for (int i = 0; i < reversebytes.length; i++) {
			reversebytes[i] = bytes[ri - i];
		}
		return reversebytes;
	}

	public static int lastIndexOf(byte[] pattern, byte[] block) {
		nextPos: for (int i = pattern.length - block.length; i >= 0; i--) {
			for (int j = block.length - 1; j >= 0; j--) {
				if (pattern[j + i] == block[j]) {
					continue;
				} else {
					continue nextPos;
				}
			}
			return i;
		}
		return -1;
	}

	public static int minLength(List patterns) {
		int len = Integer.MAX_VALUE;
		for (byte[] pattern : patterns) {
			if (pattern.length < len) {
				len = pattern.length;
			}
		}
		return len;
	}

	public static int maxLength(List patterns) {
		int len = Integer.MIN_VALUE;
		for (byte[] pattern : patterns) {
			if (pattern.length > len) {
				len = pattern.length;
			}
		}
		return len;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy