本文整理了Java中io.airlift.slice.Slice.indexOf()
方法的一些代码示例,展示了Slice.indexOf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Slice.indexOf()
方法的具体详情如下:
包路径:io.airlift.slice.Slice
类名称:Slice
方法名:indexOf
[英]Returns the index of the first occurrence of the pattern with this slice. If the pattern is not found -1 is returned. If patten is empty, zero is returned.
[中]返回此切片模式第一次出现的索引。如果找不到模式,则返回-1。如果patten为空,则返回零。
代码示例来源:origin: prestodb/presto
@Description("returns index of first occurrence of a substring (or 0 if not found)")
@ScalarFunction("strpos")
@LiteralParameters({"x", "y"})
@SqlType(StandardTypes.BIGINT)
public static long stringPosition(@SqlType("varchar(x)") Slice string, @SqlType("varchar(y)") Slice substring)
{
if (substring.length() == 0) {
return 1;
}
int index = string.indexOf(substring);
if (index < 0) {
return 0;
}
return countCodePoints(string, 0, index) + 1;
}
代码示例来源:origin: io.airlift/slice
public static void assertIndexOf(Slice data, Slice pattern, int offset, int expected)
{
assertEquals(data.indexOf(pattern, offset), expected);
assertEquals(data.indexOfBruteForce(pattern, offset), expected);
}
代码示例来源:origin: prestodb/presto
private static List<Long> getSyncPositionsBruteForce(RcFileReader recordReader, File file)
{
Slice slice = Slices.allocate((int) file.length());
try (InputStream in = new FileInputStream(file)) {
slice.setBytes(0, in, slice.length());
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
List<Long> syncPositionsBruteForce = new ArrayList<>();
Slice sync = Slices.allocate(SIZE_OF_INT + SIZE_OF_LONG + SIZE_OF_LONG);
sync.setInt(0, -1);
sync.setBytes(SIZE_OF_INT, recordReader.getSync());
long syncPosition = 0;
while (syncPosition >= 0) {
syncPosition = slice.indexOf(sync, (int) syncPosition);
if (syncPosition > 0) {
syncPositionsBruteForce.add(syncPosition);
syncPosition++;
}
}
return syncPositionsBruteForce;
}
代码示例来源:origin: airlift/slice
public static void assertIndexOf(Slice data, Slice pattern, int offset, int expected)
{
assertEquals(data.indexOf(pattern, offset), expected);
assertEquals(data.indexOfBruteForce(pattern, offset), expected);
}
代码示例来源:origin: prestodb/presto
int entryEnd = string.indexOf(entryDelimiter, entryStart);
if (entryEnd >= 0) {
keyValuePair = string.slice(entryStart, entryEnd - entryStart);
int keyEnd = keyValuePair.indexOf(keyValueDelimiter);
if (keyEnd >= 0) {
int valueStart = keyEnd + keyValueDelimiter.length();
Slice value = keyValuePair.slice(valueStart, keyValuePair.length() - valueStart);
if (value.indexOf(keyValueDelimiter) >= 0) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Key-value delimiter must appear exactly once in each entry. Bad input: '" + keyValuePair.toStringUtf8() + "'");
代码示例来源:origin: airlift/slice
public static void assertIndexOf(Slice data, Slice pattern)
{
int index;
List<Integer> bruteForce = new ArrayList<>();
index = 0;
while (index >= 0 && index < data.length()) {
index = data.indexOfBruteForce(pattern, index);
if (index >= 0) {
bruteForce.add(index);
index++;
}
}
List<Integer> indexOf = new ArrayList<>();
index = 0;
while (index >= 0 && index < data.length()) {
index = data.indexOf(pattern, index);
if (index >= 0) {
indexOf.add(index);
index++;
}
}
assertEquals(bruteForce, indexOf);
}
代码示例来源:origin: prestodb/presto
int entryEnd = string.indexOf(entryDelimiter, entryStart);
if (entryEnd >= 0) {
keyValuePair = string.slice(entryStart, entryEnd - entryStart);
int keyEnd = keyValuePair.indexOf(keyValueDelimiter);
if (keyEnd < 0) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Key-value delimiter must appear exactly once in each entry. Bad input: " + keyValuePair.toStringUtf8());
Slice key = keyValuePair.slice(0, keyEnd);
Slice value = keyValuePair.slice(valueStart, keyValuePair.length() - valueStart);
if (value.indexOf(keyValueDelimiter) >= 0) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Key-value delimiter must appear exactly once in each entry. Bad input: " + keyValuePair.toStringUtf8());
代码示例来源:origin: io.airlift/slice
public static void assertIndexOf(Slice data, Slice pattern)
{
int index;
List<Integer> bruteForce = new ArrayList<>();
index = 0;
while (index >= 0 && index < data.length()) {
index = data.indexOfBruteForce(pattern, index);
if (index >= 0) {
bruteForce.add(index);
index++;
}
}
List<Integer> indexOf = new ArrayList<>();
index = 0;
while (index >= 0 && index < data.length()) {
index = data.indexOf(pattern, index);
if (index >= 0) {
indexOf.add(index);
index++;
}
}
assertEquals(bruteForce, indexOf);
}
代码示例来源:origin: prestodb/presto
int matchIndex = string.indexOf(delimiter, previousIndex);
代码示例来源:origin: prestodb/presto
int splitIndex = string.indexOf(delimiter, index);
代码示例来源:origin: prestodb/presto
int indexBuffer = 0;
while (index < str.length()) {
int matchIndex = str.indexOf(search, index);
代码示例来源:origin: airlift/slice
/**
* Returns the index of the first occurrence of the pattern with this slice.
* If the pattern is not found -1 is returned. If patten is empty, zero is
* returned.
*/
public int indexOf(Slice slice)
{
return indexOf(slice, 0);
}
代码示例来源:origin: io.airlift/slice
/**
* Returns the index of the first occurrence of the pattern with this slice.
* If the pattern is not found -1 is returned. If patten is empty, zero is
* returned.
*/
public int indexOf(Slice slice)
{
return indexOf(slice, 0);
}
代码示例来源:origin: qubole/presto-udfs
private static long stringPosition(Slice string, Slice substring)
{
if (substring.length() == 0) {
return 1L;
}
else {
int index = string.indexOf(substring);
return index < 0 ? 0L : (long) (SliceUtf8.countCodePoints(string, 0, index) + 1);
}
}
代码示例来源:origin: uk.co.nichesolutions.presto/presto-main
@Description("returns index of first occurrence of a substring (or 0 if not found)")
@ScalarFunction("strpos")
@SqlType(StandardTypes.BIGINT)
public static long stringPosition(@SqlType(StandardTypes.VARCHAR) Slice string, @SqlType(StandardTypes.VARCHAR) Slice substring)
{
if (substring.length() == 0) {
return 1;
}
int index = string.indexOf(substring);
if (index < 0) {
return 0;
}
return countCodePoints(string, 0, index) + 1;
}
代码示例来源:origin: prestosql/presto
@Description("returns index of first occurrence of a substring (or 0 if not found)")
@ScalarFunction("strpos")
@LiteralParameters({"x", "y"})
@SqlType(StandardTypes.BIGINT)
public static long stringPosition(@SqlType("varchar(x)") Slice string, @SqlType("varchar(y)") Slice substring)
{
if (substring.length() == 0) {
return 1;
}
int index = string.indexOf(substring);
if (index < 0) {
return 0;
}
return countCodePoints(string, 0, index) + 1;
}
代码示例来源:origin: io.prestosql/presto-rcfile
private static List<Long> getSyncPositionsBruteForce(RcFileReader recordReader, File file)
{
Slice slice = Slices.allocate((int) file.length());
try (InputStream in = new FileInputStream(file)) {
slice.setBytes(0, in, slice.length());
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
List<Long> syncPositionsBruteForce = new ArrayList<>();
Slice sync = Slices.allocate(SIZE_OF_INT + SIZE_OF_LONG + SIZE_OF_LONG);
sync.setInt(0, -1);
sync.setBytes(SIZE_OF_INT, recordReader.getSync());
long syncPosition = 0;
while (syncPosition >= 0) {
syncPosition = slice.indexOf(sync, (int) syncPosition);
if (syncPosition > 0) {
syncPositionsBruteForce.add(syncPosition);
syncPosition++;
}
}
return syncPositionsBruteForce;
}
代码示例来源:origin: prestosql/presto
private static List<Long> getSyncPositionsBruteForce(RcFileReader recordReader, File file)
{
Slice slice = Slices.allocate((int) file.length());
try (InputStream in = new FileInputStream(file)) {
slice.setBytes(0, in, slice.length());
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
List<Long> syncPositionsBruteForce = new ArrayList<>();
Slice sync = Slices.allocate(SIZE_OF_INT + SIZE_OF_LONG + SIZE_OF_LONG);
sync.setInt(0, -1);
sync.setBytes(SIZE_OF_INT, recordReader.getSync());
long syncPosition = 0;
while (syncPosition >= 0) {
syncPosition = slice.indexOf(sync, (int) syncPosition);
if (syncPosition > 0) {
syncPositionsBruteForce.add(syncPosition);
syncPosition++;
}
}
return syncPositionsBruteForce;
}
代码示例来源:origin: io.prestosql/presto-main
@Description("returns index of first occurrence of a substring (or 0 if not found)")
@ScalarFunction("strpos")
@LiteralParameters({"x", "y"})
@SqlType(StandardTypes.BIGINT)
public static long stringPosition(@SqlType("varchar(x)") Slice string, @SqlType("varchar(y)") Slice substring)
{
if (substring.length() == 0) {
return 1;
}
int index = string.indexOf(substring);
if (index < 0) {
return 0;
}
return countCodePoints(string, 0, index) + 1;
}
代码示例来源:origin: com.facebook.presto/presto-rcfile
private static List<Long> getSyncPositionsBruteForce(RcFileReader recordReader, File file)
{
Slice slice = Slices.allocate((int) file.length());
try (InputStream in = new FileInputStream(file)) {
slice.setBytes(0, in, slice.length());
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
List<Long> syncPositionsBruteForce = new ArrayList<>();
Slice sync = Slices.allocate(SIZE_OF_INT + SIZE_OF_LONG + SIZE_OF_LONG);
sync.setInt(0, -1);
sync.setBytes(SIZE_OF_INT, recordReader.getSync());
long syncPosition = 0;
while (syncPosition >= 0) {
syncPosition = slice.indexOf(sync, (int) syncPosition);
if (syncPosition > 0) {
syncPositionsBruteForce.add(syncPosition);
syncPosition++;
}
}
return syncPositionsBruteForce;
}
内容来源于网络,如有侵权,请联系作者删除!