Java Code Examples for org.apache.commons.lang.ArrayUtils#indexOf()

The following examples show how to use org.apache.commons.lang.ArrayUtils#indexOf() . 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: CubeDesc.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private TblColRef initDimensionColRef(DimensionDesc dim, String colName) {
    TblColRef col = model.findColumn(dim.getTable(), colName);

    // for backward compatibility
    if (KylinVersion.isBefore200(getVersion())) {
        // always use FK instead PK, FK could be shared by more than one lookup tables
        JoinDesc join = dim.getJoin();
        if (join != null) {
            int idx = ArrayUtils.indexOf(join.getPrimaryKeyColumns(), col);
            if (idx >= 0) {
                col = join.getForeignKeyColumns()[idx];
            }
        }
    }

    return initDimensionColRef(col);
}
 
Example 2
Source File: TfMetaUtils.java    From systemds with Apache License 2.0 6 votes vote down vote up
public static int[] parseJsonObjectIDList(JSONObject spec, String[] colnames, String group) 
	throws JSONException
{
	int[] colList = new int[0];
	boolean ids = spec.containsKey("ids") && spec.getBoolean("ids");
	
	if( spec.containsKey(group) && spec.get(group) instanceof JSONArray )
	{
		JSONArray colspecs = (JSONArray)spec.get(group);
		colList = new int[colspecs.size()];
		for(int j=0; j<colspecs.size(); j++) {
			JSONObject colspec = (JSONObject) colspecs.get(j);
			colList[j] = ids ? colspec.getInt("id") : 
				(ArrayUtils.indexOf(colnames, colspec.get("name")) + 1);
			if( colList[j] <= 0 ) {
				throw new RuntimeException("Specified column '" +
					colspec.get(ids?"id":"name")+"' does not exist.");
			}
		}
		
		//ensure ascending order of column IDs
		Arrays.sort(colList);
	}
	
	return colList;
}
 
Example 3
Source File: DisplayOptionsParser.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the first found parameter index of the options.
 */
private int getIntParameter(String[] options, int currentValue, String parameter, String parameterName,
        String deviceAddress) {
    int idx = ArrayUtils.indexOf(options, parameter);
    if (idx != -1) {
        if (currentValue == 0) {
            logger.debug("{} option '{}' found at index {} for remote control '{}'", parameterName, parameter,
                    idx + 1, deviceAddress);
            return idx + 1;
        } else {
            logger.warn("{} option already set for remote control '{}', ignoring '{}'!", parameterName,
                    deviceAddress, parameter);
            return currentValue;
        }
    } else {
        return currentValue;
    }
}
 
Example 4
Source File: CubeDesc.java    From kylin with Apache License 2.0 6 votes vote down vote up
private TblColRef initDimensionColRef(DimensionDesc dim, String colName) {
    TblColRef col = model.findColumn(dim.getTable(), colName);

    // for backward compatibility
    if (KylinVersion.isBefore200(getVersion())) {
        // always use FK instead PK, FK could be shared by more than one lookup tables
        JoinDesc join = dim.getJoin();
        if (join != null) {
            int idx = ArrayUtils.indexOf(join.getPrimaryKeyColumns(), col);
            if (idx >= 0) {
                col = join.getForeignKeyColumns()[idx];
            }
        }
    }

    return initDimensionColRef(col);
}
 
Example 5
Source File: DisplayOptionsParser.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns all possible options from the given datapoint.
 */
private String[] getAvailableOptions(HmChannel channel, String datapointName) {
    HmDatapointInfo dpInfo = HmDatapointInfo.createValuesInfo(channel, datapointName);
    HmDatapoint dp = channel.getDatapoint(dpInfo);
    if (dp != null) {
        String[] options = (String[]) ArrayUtils.remove(dp.getOptions(), 0);
        for (String onOffString : onOff) {
            int onIdx = ArrayUtils.indexOf(options, onOffString);
            if (onIdx != -1) {
                options[onIdx] = datapointName + "_" + onOffString;
            }
        }
        return options;
    }
    return new String[0];
}
 
Example 6
Source File: AccessControlScanOptionsDialog.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
@Override
public void save() {
    // In this case, the 'Save' action corresponds to starting a scan with the specified options
    AccessControlScanStartOptions startOptions = new AccessControlScanStartOptions();
    startOptions.targetContext =
            ((ContextSelectComboBox) getField(FIELD_CONTEXT)).getSelectedContext();
    startOptions.targetUsers = usersSelectTable.getSelectedUsers();
    // If the un-authenticated user was selected, replace it with a 'null' user
    if (startOptions.targetUsers.remove(unauthenticatedUser)) {
        startOptions.targetUsers.add(null);
    }
    startOptions.raiseAlerts = ((JCheckBox) getField(FIELD_RAISE_ALERTS)).isSelected();
    // Just to make sure we have a reference here to MSG_RISK for taking care when refactoring
    // and that this still works if somehow the connection between index and value is lost, we
    // perform a quick search
    @SuppressWarnings("unchecked")
    String selectedAlertRisk =
            (String) ((JComboBox<String>) getField(FIELD_ALERTS_RISK)).getSelectedItem();
    startOptions.alertRiskLevel = ArrayUtils.indexOf(Alert.MSG_RISK, selectedAlertRisk);
    extension.startScan(startOptions);
}
 
Example 7
Source File: BridgeOutputBuilder.java    From pxf with Apache License 2.0 5 votes vote down vote up
/**
 * Breaks raw bytes into lines. Used only for sampling.
 * <p>
 * When sampling a data source, we have to make sure that we deal with
 * actual rows (lines) and not bigger chunks of data such as used by
 * LineBreakAccessor for performance. The input byte array is broken into
 * lines, each one stored in the outputList. In case the read data doesn't
 * end with a line delimiter, which can happen when reading chunks of bytes,
 * the partial line is stored separately, and is being completed when
 * reading the next chunk of data.
 *
 * @param val input raw data to break into lines
 */
void convertTextDataToLines(byte[] val) {
    int len = val.length;
    int start = 0;
    int end = 0;
    byte[] line;
    BufferWritable writable;

    while (start < len) {
        end = ArrayUtils.indexOf(val, DELIM, start);
        if (end == ArrayUtils.INDEX_NOT_FOUND) {
            // data finished in the middle of the line
            end = len;
            isPartialLine = true;
        } else {
            end++; // include the DELIM character
            isPartialLine = false;
        }
        line = Arrays.copyOfRange(val, start, end);

        if (partialLine != null) {
            // partial data was completed
            ((BufferWritable) partialLine).append(line);
            writable = (BufferWritable) partialLine;
            partialLine = null;
        } else {
            writable = new BufferWritable(line);
        }

        if (isPartialLine) {
            partialLine = writable;
        } else {
            outputList.add(writable);
        }
        start = end;
    }
}
 
Example 8
Source File: RestrictionsManager.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public synchronized static void deactivate(Restrictions restriction) {
	for (RestrictionMode mode : RestrictionMode.VALUES) {
		Restrictions[] restrictions = RESTRICTIONS[mode.ordinal()];

		for (int index; (index = ArrayUtils.indexOf(restrictions, restriction)) != -1;) {
			restrictions = (Restrictions[]) ArrayUtils.remove(restrictions, index);
		}

		RESTRICTIONS[mode.ordinal()] = restrictions;
	}
}
 
Example 9
Source File: BURL.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
/** Extracts the host part from a scheme+authority by removing the scheme, the user info and the port number.
 *
 * @param schemeAuthority a scheme+authority.
 * @return the host part.
 */
public static String hostFromSchemeAndAuthority(final byte[] schemeAuthority){
	final int length = schemeAuthority.length;
	final int startOfAuthority = ArrayUtils.indexOf(schemeAuthority, (byte)':') + 3;
	int atPosition;
	for(atPosition = startOfAuthority; atPosition < length; atPosition++) if (schemeAuthority[atPosition] == (byte)'@') break;
	final int startOfHost = atPosition != length ? atPosition + 1 : startOfAuthority;

	int endOfHost;
	for(endOfHost = startOfHost; endOfHost < length; endOfHost++) if (schemeAuthority[endOfHost] == (byte)':') break;
	final char[] host = new char[endOfHost - startOfHost];
	for(int i = startOfHost; i < endOfHost; i++) host[i - startOfHost] = (char)schemeAuthority[i];
	return new String(host);
}
 
Example 10
Source File: RemoteControlOptionParser.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns all possible value items from the remote control.
 */
private String[] getValueItems(String parameterName) {
    DatapointConfig dpConfig = new DatapointConfig(remoteControlAddress, "18", parameterName);
    HmValueItem hmValueItem = context.getStateHolder().getState(dpConfig);
    if (hmValueItem != null) {
        String[] valueList = (String[]) ArrayUtils.remove(hmValueItem.getValueList(), 0);
        int onIdx = ArrayUtils.indexOf(valueList, "ON");
        if (onIdx != -1) {
            valueList[onIdx] = parameterName + "_ON";
        }
        return valueList;
    }
    return new String[0];
}
 
Example 11
Source File: HopRewriteUtils.java    From systemds with Apache License 2.0 4 votes vote down vote up
public static int getValidOpPos( OpOp2 input, OpOp2... validTab ) {
	return ArrayUtils.indexOf(validTab, input);
}
 
Example 12
Source File: Corpus.java    From tassal with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public int getIndexProject(final String project) {
	return ArrayUtils.indexOf(projects, project);
}
 
Example 13
Source File: HopRewriteUtils.java    From systemds with Apache License 2.0 4 votes vote down vote up
public static int getValidOpPos( OpOp2 input, OpOp2... validTab ) {
	return ArrayUtils.indexOf(validTab, input);
}
 
Example 14
Source File: CalUtils.java    From spring-boot with Apache License 2.0 4 votes vote down vote up
public static String getWeekCNName(String weekEnName) {
	return weekCnNameArray[ArrayUtils.indexOf(weekEnNameArray, weekEnName)];
}
 
Example 15
Source File: MultiClassMetrics.java    From Alink with Apache License 2.0 4 votes vote down vote up
private int getLabelIndex(String label){
	int index = ArrayUtils.indexOf(getParams().get(LABEL_ARRAY), label);
	Preconditions.checkArgument(index >= 0, String.format("Not exist label %s", label));
	return index;
}
 
Example 16
Source File: PetFeedCalculator.java    From aion-germany with GNU General Public License v3.0 4 votes vote down vote up
public static PetFeedResult getReward(int fullCount, PetRewards rewardGroup, PetFeedProgress progress, int playerLevel) {
	if (progress.getHungryLevel() != PetHungryLevel.FULL || rewardGroup.getResults().size() == 0) {
		return null;
	}

	int pointsIndex = ArrayUtils.indexOf(fullCounts, (short) fullCount);
	if (pointsIndex == ArrayUtils.INDEX_NOT_FOUND) {
		return null;
	}

	if (progress.isLovedFeeded()) { // for cash feed
		if (rewardGroup.getResults().size() == 1) {
			return rewardGroup.getResults().get(0);
		}
		List<PetFeedResult> validRewards = new ArrayList<PetFeedResult>();
		int maxLevel = 0;
		for (PetFeedResult result : rewardGroup.getResults()) {
			int resultLevel = DataManager.ITEM_DATA.getItemTemplate(result.getItem()).getLevel();
			if (resultLevel > playerLevel) {
				continue;
			}
			if (resultLevel > maxLevel) {
				maxLevel = resultLevel;
				validRewards.clear();
			}
			validRewards.add(result);
		}
		if (validRewards.size() == 0) {
			return null;
		}
		if (validRewards.size() == 1) {
			return validRewards.get(0);
		}
		return validRewards.get(Rnd.get(validRewards.size()));
	}

	int rewardIndex = 0;
	int totalRewards = rewardGroup.getResults().size();
	for (int row = 1; row < pointValues.length; row++) {
		int[] points = pointValues[row];
		if (points[pointsIndex] <= progress.getTotalPoints()) {
			rewardIndex = Math.round((float) totalRewards / (pointValues.length - 1) * row) - 1;
		}
	}

	// Fix rounding discrepancy
	if (rewardIndex < 0) {
		rewardIndex = 0;
	}
	else if (rewardIndex > rewardGroup.getResults().size() - 1) {
		rewardIndex = rewardGroup.getResults().size() - 1;
	}

	return rewardGroup.getResults().get(rewardIndex);
}
 
Example 17
Source File: MultiStepProgressBar.java    From rapidminer-studio with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Returns the step index for the given step name.  If multiple steps have the same name, this method will return
 * the index of the first occurrence.
 *
 * @param stepName
 * 		the step name
 * @return the corresponding step index
 */
public int getIndexForName(String stepName) {
	return ArrayUtils.indexOf(stepNames, stepName);
}
 
Example 18
Source File: ExceptionUtils.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * <p>Tests if the list of method names used in the search for <code>Throwable</code>
 * objects include the given name.</p>
 * 
 * @param methodName  the methodName to search in the list.
 * @return if the list of method names used in the search for <code>Throwable</code>
 *  objects include the given name.
 * @since 2.1
 */
public static boolean isCauseMethodName(String methodName) {
    return ArrayUtils.indexOf(CAUSE_METHOD_NAMES, methodName) >= 0;
}
 
Example 19
Source File: ExceptionUtils.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * <p>Tests if the list of method names used in the search for <code>Throwable</code>
 * objects include the given name.</p>
 * 
 * @param methodName  the methodName to search in the list.
 * @return if the list of method names used in the search for <code>Throwable</code>
 *  objects include the given name.
 * @since 2.1
 */
public static boolean isCauseMethodName(String methodName) {
    synchronized(CAUSE_METHOD_NAMES_LOCK) {
        return ArrayUtils.indexOf(CAUSE_METHOD_NAMES, methodName) >= 0;
    }
}
 
Example 20
Source File: ExceptionUtils.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * <p>Tests if the list of method names used in the search for <code>Throwable</code>
 * objects include the given name.</p>
 * 
 * @param methodName  the methodName to search in the list.
 * @return if the list of method names used in the search for <code>Throwable</code>
 *  objects include the given name.
 * @since 2.1
 */
public static boolean isCauseMethodName(String methodName) {
    return ArrayUtils.indexOf(CAUSE_METHOD_NAMES, methodName) >= 0;
}