Java Code Examples for org.apache.commons.lang3.ArrayUtils#INDEX_NOT_FOUND

The following examples show how to use org.apache.commons.lang3.ArrayUtils#INDEX_NOT_FOUND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CellSpaceBodyList.java    From notreal2d with MIT License 6 votes vote down vote up
@Nonnull
private static Body[] addBodyToCell(@Nullable Body[] cellBodies, @Nonnull Body body) {
    if (cellBodies == null) {
        return new Body[] {body};
    }

    int bodyIndex = ArrayUtils.indexOf(cellBodies, body);
    if (bodyIndex != ArrayUtils.INDEX_NOT_FOUND) {
        throw new IllegalStateException("Can't add Body {id=" + body.getId() + "} to index.");
    }

    int bodyCount = cellBodies.length;
    Body[] newCellBodies = new Body[bodyCount + 1];
    System.arraycopy(cellBodies, 0, newCellBodies, 0, bodyCount);
    newCellBodies[bodyCount] = body;
    return newCellBodies;
}
 
Example 2
Source File: CellSpaceBodyList.java    From notreal2d with MIT License 6 votes vote down vote up
@Nullable
private static Body[] removeBodyFromCell(@Nonnull Body[] cellBodies, @Nonnull Body body) {
    int bodyIndex = ArrayUtils.indexOf(cellBodies, body);
    if (bodyIndex == ArrayUtils.INDEX_NOT_FOUND) {
        throw new IllegalStateException("Can't remove Body {id=" + body.getId() + "} from index.");
    }

    int bodyCount = cellBodies.length;
    if (bodyCount == 1) {
        return null;
    }

    Body[] newCellBodies = new Body[bodyCount - 1];
    System.arraycopy(cellBodies, 0, newCellBodies, 0, bodyIndex);
    System.arraycopy(cellBodies, bodyIndex + 1, newCellBodies, bodyIndex, bodyCount - bodyIndex - 1);
    return newCellBodies;
}
 
Example 3
Source File: CSVMatrixReader.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
@Override
public String[] read() throws IOException, NoSuchElementException {

    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    
    String[] values = reader.getValues();
    readRecord();

    lineNumber++;

    // drop all values after last non-empty cell
    // otherwise a lot of empty (but styled) cells will be returned
    int lastNonEmptyCellIdx = ArrayUtils.INDEX_NOT_FOUND;

    for (int i = values.length - 1; i >= 0; i--) {
        if (StringUtils.isNotBlank(values[i])) {
            lastNonEmptyCellIdx = i;
            break;
        }
    }

    if(lastNonEmptyCellIdx == ArrayUtils.INDEX_NOT_FOUND) {
        return ArrayUtils.EMPTY_STRING_ARRAY;
    }

    if(values.length != lastNonEmptyCellIdx + 1) {
        values = Arrays.copyOf(values, lastNonEmptyCellIdx + 1);
    }

    for (int i=0; i<values.length; i++) {
        values[i] = values[i].trim();
    }

    return values;
}
 
Example 4
Source File: BaseWorkTime.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean inDefinedHoliday(Calendar c) {
	if (ArrayUtils.isNotEmpty(this.definedHolidays)) {
		if (ArrayUtils.indexOf(this.definedHolidays,
				DateFormatUtils.format(c, DATEPARTFORMATPATTERN[0])) > ArrayUtils.INDEX_NOT_FOUND) {
			return true;
		}
	}
	return false;
}
 
Example 5
Source File: BaseWorkTime.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean inDefinedWorkday(Calendar c) {
	if (ArrayUtils.isNotEmpty(this.definedWorkdays)) {
		if (ArrayUtils.indexOf(this.definedWorkdays,
				DateFormatUtils.format(c, DATEPARTFORMATPATTERN[0])) > ArrayUtils.INDEX_NOT_FOUND) {
			return true;
		}
	}
	return false;
}
 
Example 6
Source File: BaseWorkTime.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
private boolean inDefinedWeekends(Calendar c) {
	if (ArrayUtils.indexOf(this.definedWeekends, c.get(Calendar.DAY_OF_WEEK)) > ArrayUtils.INDEX_NOT_FOUND) {
		return true;
	}
	return false;
}
 
Example 7
Source File: Direction.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public static float direction8ToRadians(int direction) {
  int i = ArrayUtils.indexOf(DIRS_8M, direction);
  if (i == ArrayUtils.INDEX_NOT_FOUND) return 0;
  return RADIANS_8[i];
}