Example usage for org.apache.commons.lang3 ArrayUtils indexOf

List of usage examples for org.apache.commons.lang3 ArrayUtils indexOf

Introduction

In this page you can find the example usage for org.apache.commons.lang3 ArrayUtils indexOf.

Prototype

public static int indexOf(final boolean[] array, final boolean valueToFind) 

Source Link

Document

Finds the index of the given value in the array.

This method returns #INDEX_NOT_FOUND ( -1 ) for a null input array.

Usage

From source file:FILER.java

public static String getDescription(String query, long Doc_id) throws FileNotFoundException, IOException {
    boolean phrase;
    String description = "";
    String content = "";
    File f = new File("C:\\Users\\mennna\\Documents\\NetBeansProjects\\Search\\" + Doc_id + ".html");
    org.jsoup.nodes.Document doc = Jsoup.parse(f, "UTF-8");
    content = content + " " + doc.text();
    content = content.toLowerCase();/*from   w w  w.ja v  a  2 s  .  co m*/
    if (query.endsWith("\"") == true && query.startsWith("\"") == true) {
        phrase = true;
    } else
        phrase = false;
    int query_length = 0;

    String query_words[] = query.split("\\P{Alpha}+");
    query_length = query_words.length;
    String words[] = content.split("\\P{Alpha}+");
    int index = ArrayUtils.indexOf(words, query_words[0]);
    System.out.println("index " + index);
    int i = 0, start = 0, end = 0;
    if (phrase && query_length > 1) {
        if (index - 10 < 0)
            start = 0;
        else
            start = index - 10;
        if (index + 20 > content.length() - 1)
            end = content.length() - 1;
        else
            end = index + 20;
        for (i = start; i < end; i++) {
            if (query.indexOf(words[i]) != -1) {
                description += "<b> " + words[i] + "</b>";
            } else
                description += " " + words[i];
        }

    } else if (query_length == 1) {
        if (index - 10 < 0)
            start = 0;
        else
            start = index - 10;
        if (index + 20 > content.length() - 1)
            end = content.length() - 1;
        else
            end = index + 20;
        for (i = start; i < end; i++) {
            if (words[i].equals(query)) {
                description += "<b> " + words[i] + "</b>";
            } else {
                description += " " + words[i];
            }
        }
    } else if (!phrase && query_length > 1) {
        if (index - 10 < 0)
            start = 0;
        else
            start = index - 10;
        if (index + 20 > content.length() - 1)
            end = content.length() - 1;
        else
            end = index + 20;
        for (i = start; i < end; i++) {
            if (query.indexOf(words[i]) != -1) {
                description += "<b> " + words[i] + "</b>";
            } else
                description += " " + words[i];
        }
    }
    System.out.println("description  " + description);
    return description;
}

From source file:ivorius.ivtoolkit.blocks.Directions.java

@Nullable
public static Integer getHorizontalClockwiseRotations(ForgeDirection source, ForgeDirection dest,
        boolean mirrorX) {
    if (source == dest)
        return mirrorX && ArrayUtils.contains(Directions.X_AXIS, dest) ? 2 : 0;

    int arrayIndexSrc = ArrayUtils.indexOf(HORIZONTAL, source);
    int arrayIndexDst = ArrayUtils.indexOf(HORIZONTAL, dest);

    if (arrayIndexSrc >= 0 && arrayIndexDst >= 0) {
        int mirrorRotations = mirrorX && ArrayUtils.contains(Directions.X_AXIS, dest) ? 2 : 0;
        return ((arrayIndexSrc - arrayIndexDst + mirrorRotations) + HORIZONTAL.length) % HORIZONTAL.length;
    }//from   ww w .j  a v a  2 s  .  c  o m

    return null;
}

From source file:digest.EncryptPpag.java

public String doEnrypt(String str) {
    char[] arrText = { ' ', 'a', 'A', 'b', 'B', 'c', 'C', 'd', 'D', 'e', 'E', 'f', 'F', 'g', 'G', 'h', 'H', 'i',
            'I', 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N', 'o', 'O', 'p', 'P', 'q', 'Q', 'r', 'R', 's',
            'S', 't', 'T', 'u', 'U', 'v', 'V', 'w', 'W', 'x', 'X', 'y', 'Y', 'z', 'Z', '`', '1', '2', '3', '4',
            '5', '6', '7', '8', '9', '0', '~', '!', '@', '$', '^', '*', '(', ')', '-', '{', '}', '|', '[', ']',
            ':', ';', '<', '>', '?', ',', '.', '/', '_', '=' };
    char[] arr = str.toCharArray();
    int len = arrText.length;
    int lenDouble = len * 2;
    int lenTriple = len * 3;
    char[] arrResult = new char[arr.length];

    for (int i = 0; i < arr.length; i++) {
        int xx = ArrayUtils.indexOf(arrText, arr[i]);
        int rnd = xx + i;
        if (rnd < len) {
            arrResult[i] = arrText[rnd];
        } else if ((rnd >= len) && (rnd < lenDouble)) {
            arrResult[i] = arrText[rnd - len];
        } else if ((rnd >= lenDouble) && (rnd < lenTriple)) {
            arrResult[i] = arrText[rnd - lenDouble];
        } else if (rnd >= lenTriple) {
            arrResult[i] = arrText[rnd - lenTriple];
        }/*w  ww .  j a va2s .com*/
    }

    String result = "";
    for (int i = 0; i < arrResult.length; i++) {
        result = result + arrResult[i];
    }
    return result;
}

From source file:net.minecraftforge.oredict.DyeUtils.java

/**
 * Get the dye metadata from the stack, which can be passed into {@link EnumDyeColor#byMetadata(int)}.
 * @param stack the item stack//from  w  ww.ja  v  a 2 s  .  c om
 * @return an {@link OptionalInt} holding the dye metadata for a dye, or an empty {@link OptionalInt} otherwise
 */
public static OptionalInt metaFromStack(ItemStack stack) {
    if (stack.isEmpty())
        return OptionalInt.empty();
    return Arrays.stream(OreDictionary.getOreIDs(stack)).mapToObj(OreDictionary::getOreName)
            .mapToInt(name -> ArrayUtils.indexOf(dyeOredicts, name)).filter(id -> id >= 0).findFirst();
}

From source file:apexproject.ShoppingCart.java

public void removeTour(int tour) {
    index = ArrayUtils.indexOf(chosenTours, tour);
    if (index >= 0) {
        this.chosenTours = ArrayUtils.remove(chosenTours, index);
        this.nrOfAdults = ArrayUtils.remove(nrOfAdults, index);
        this.nrOfChildren = ArrayUtils.remove(nrOfChildren, index);
        this.hotelPickupRequested = ArrayUtils.remove(hotelPickupRequested, index);
        this.hotelLocation = ArrayUtils.remove(hotelLocation, index);
    }/*ww  w  . j av a2 s .  c  om*/
    //LAGA ETTA
    else if (index < 0) {
        System.out.println("Listinn er tmur!");
    } else {
        System.out.println("Enginn dayTour me etta ID");
    }
}

From source file:ivorius.ivtoolkit.blocks.Directions.java

public static ForgeDirection rotate(ForgeDirection direction, AxisAlignedTransform2D transform) {
    if (direction == UP || direction == DOWN)
        return direction;

    int rotations = transform.getRotation();
    if (transform.isMirrorX() && ArrayUtils.contains(X_AXIS, direction))
        rotations += 2;//from ww  w. j a va  2s .  c  o m
    return HORIZONTAL[(ArrayUtils.indexOf(HORIZONTAL, direction) + rotations) % HORIZONTAL.length];
}

From source file:com.nbt.world.NBTRegion.java

@Override
public int getIndexOfChild(Object child) {
    Object[] children = getChildren();
    return ArrayUtils.indexOf(children, child);
}

From source file:clientapi.value.type.EnumType.java

@Override
public final T peekNext() {
    int index = ArrayUtils.indexOf(values, getValue());
    if (++index >= values.length)
        index = 0;//from ww  w .ja v a2  s  .c  o  m
    return values[index];
}

From source file:clientapi.value.type.EnumType.java

@Override
public final T peekLast() {
    int index = ArrayUtils.indexOf(values, getValue());
    if (--index < 0)
        index = values.length - 1;//from w w  w. j a  va2 s  .  c  om
    return values[index];
}

From source file:clientapi.value.type.MultiType.java

@Override
public final String peekNext() {
    int index = ArrayUtils.indexOf(values, getValue());
    if (++index >= values.length)
        index = 0;/*  ww w.  ja  v  a  2  s .c  o  m*/
    return values[index];
}