List of usage examples for org.apache.commons.lang ArrayUtils indexOf
public static int indexOf(boolean[] array, boolean valueToFind)
Finds the index of the given value in the array.
From source file:Main.java
public static void main(String[] args) { String[] colours = { "Red", "Orange", "Yellow", "Green", "Blue", "Violet", "Orange", "Blue" }; boolean contains = ArrayUtils.contains(colours, "Blue"); System.out.println("Contains Blue? " + contains); int indexOfYellow = ArrayUtils.indexOf(colours, "Yellow"); System.out.println("indexOfYellow = " + indexOfYellow); int indexOfOrange = ArrayUtils.indexOf(colours, "Orange"); System.out.println("indexOfOrange = " + indexOfOrange); int lastIndexOfOrange = ArrayUtils.lastIndexOf(colours, "Orange"); System.out.println("lastIndexOfOrange = " + lastIndexOfOrange); }
From source file:ArrayUtilsExampleV1.java
public static void main(String args[]) { long[] longArray = new long[] { 10000, 30, 99 }; String[] stringArray = new String[] { "abc", "def", "fgh" }; long[] clonedArray = ArrayUtils.clone(longArray); System.err.println(ArrayUtils.toString((ArrayUtils.toObject(clonedArray)))); System.err.println(ArrayUtils.indexOf(stringArray, "def")); ArrayUtils.reverse(stringArray);/*ww w. j a v a2s . c o m*/ System.err.println(ArrayUtils.toString(stringArray)); }
From source file:com.cic.datacrawl.ui.Main.java
/** * Main entry point. Creates a debugger attached to a Rhino * {@link com.cic.datacrawl.ui.shell.Shell} shell session. *//*from w ww.jav a 2s . co m*/ public static void main(final String[] args) { if (System.getProperties().get("os.name").toString().toLowerCase().indexOf("linux") >= 0) System.setProperty("sun.awt.xembedserver", "true"); try { String path = null; boolean reflash = true; if (args != null && args.length > 0) { if (args[0].equalsIgnoreCase("-h")) { System.out.println("Command Format: \n" + "\t%JAVA_HOME%\\BIN\\JAVA -jar homepageCatcher.jar " + "[-d config path]\n" + "\t%JAVA_HOME%\\BIN\\JAVA -jar homepageCatcher.jar " + "[-d config path_1;path_2;....;path_n]\n"); } int pathIndex = ArrayUtils.indexOf(args, "-d"); if (pathIndex >= 0) { try { path = args[pathIndex + 1]; File f = new File(path); if (!f.exists()) { LOG.warn("Invalid path of configuration. " + "Using default configuration."); } } catch (Throwable e) { LOG.warn("Invalid path of configuration. " + "Using default configuration."); } } // int reflashIndex = ArrayUtils.indexOf(args, "-r"); // // reflash = new Boolean(args[reflashIndex + 1]).booleanValue(); } if (path == null || path.trim().length() == 0) path = Config.INSTALL_PATH + File.separator + "config" + File.separator + "beans"; LOG.debug("Config Path: \"" + path + "\""); // ?IOC // ???? // ? ApplicationContext.initialiaze(path, reflash); System.setProperty(ApplicationContext.CONFIG_PATH, path); // js??? InitializerRegister.getInstance().execute(); // ??? //VerifyCodeInputDialog.init(); // ?? //initTestData(); // ?GUI Thread thread = new Thread(new Runnable() { @Override public void run() { startupGUI(args); } }); thread.setName("UI_Thread"); thread.start(); } catch (Throwable e) { LOG.error(e.getMessage(), e); } }
From source file:com.marc.lastweek.extractionengine.adapters.EbayAdAdapter.java
public final static NewExternalClassifiedAdTO adapt(EbayAd ebayAd) { long categoryId = EBAY_PISOS_CATEGORIES_TO_LASTWEEK_CATEGORIES[ArrayUtils.indexOf(EBAY_PISOS_CATEGORIES, ebayAd.getCategory().trim())]; Double price = null;/* ww w .j a v a 2 s.c o m*/ try { price = Double.valueOf(ebayAd.getPrice().replaceFirst("EUR", "")); } catch (Exception e) { price = Double.valueOf(0); } Long provinceId = Long.valueOf(1); return new NewExternalClassifiedAdTO(Long.valueOf(categoryId), null, price, ebayAd.getTitle(), ebayAd.getDescription(), null, null, provinceId, Integer.valueOf(ClassifiedAd.SOURCE_EBAY), ebayAd.getUrl(), Integer.valueOf(0), Integer.valueOf(ClassifiedAd.STATE_ACTIVE)); }
From source file:com.bstek.dorado.common.ClientType.java
public static int parseClientTypes(String clientTypes) { int clientTypesValue = 0; if (StringUtils.isNotBlank(clientTypes)) { String[] clientTypeArray = StringUtils.split(clientTypes.toLowerCase(), ",; "); if (ArrayUtils.indexOf(clientTypeArray, DESKTOP_NAME) >= 0) { clientTypesValue += ClientType.DESKTOP; }//from w ww .j a v a 2 s . c o m if (ArrayUtils.indexOf(clientTypeArray, TOUCH_NAME) >= 0) { clientTypesValue += ClientType.TOUCH; } } return clientTypesValue; }
From source file:com.github.geequery.codegen.util.GenUtil.java
public static IClass toWrappedType(String primitive) { int i = ArrayUtils.indexOf(IClass.PRIMITIVE_TYPES, primitive); if (i < 0) throw new IllegalArgumentException("The input type " + primitive + " is not a primitive type!"); return IClassUtil.parse(IClass.WRAPPED_TYPES[i]); }
From source file:com.comcast.video.dawg.controller.house.MetaStbPropComparator.java
/** * {@inheritDoc}//from w w w.j a v a 2s . co m */ @Override public int compare(String o1, String o2) { int order1 = ArrayUtils.indexOf(orderedProps, o1); int order2 = ArrayUtils.indexOf(orderedProps, o2); if (order1 < 0) { if (order2 < 0) { // none have a specified order, order alphabetically return o1.compareTo(o2); } else { // o1 is not ordered but o2 is, o2 should go first return 1; } } else { if (order2 < 0) { // o1 is ordered but o2 is not, o1 should go first return -1; } else { // both are ordered, so order by the order... return order1 - order2; } } }
From source file:gov.nih.nci.cabig.caaers.web.search.CommandToSQL.java
private static AbstractQuery buildAbstractQuery(SearchTargetObject targetObject, List<AdvancedSearchCriteriaParameter> criteriaParameters, String tableAliasForInterventions) throws Exception { String queryClassName = targetObject.getQueryClassName(); AbstractQuery query = (AbstractQuery) Class.forName(queryClassName).newInstance(); List<String> objectsToJoin = new ArrayList<String>(); List<String> objectsInView = new ArrayList<String>(); String[] hqlElements = StringUtils.split(query.getBaseQueryString()); int etIndex = ArrayUtils.indexOf(hqlElements, invokeField(query, targetObject.getTableAlias())); hqlElements[etIndex] = invokeField(query, targetObject.getTableAlias()); String associtedObjectsInQueryString = ""; // check the objects selected in results , and add those objects to query .. for (DependentObject dObject : targetObject.getDependentObject()) { List<ViewColumn> viewColumns = dObject.getViewColumn(); for (ViewColumn viewColumn : viewColumns) { if (viewColumn.isSelected()) { if (!dObject.getClassName().equals(targetObject.getClassName())) { if (!objectsInView.contains(dObject.getClassName())) { objectsInView.add(dObject.getClassName()); if (tableAliasForInterventions != null && dObject.getClassName().equals(INTERVENTION_CLASS_NAME)) { associtedObjectsInQueryString = associtedObjectsInQueryString + " , " + invokeField(query, tableAliasForInterventions); } else { associtedObjectsInQueryString = associtedObjectsInQueryString + " , " + invokeField(query, dObject.getTableAlias()); }/* www . j av a 2 s. co m*/ } } } } } // build base query if (!associtedObjectsInQueryString.equals("")) { associtedObjectsInQueryString = associtedObjectsInQueryString + " from "; hqlElements[etIndex + 1] = associtedObjectsInQueryString; String newQuery = StringUtils.join(hqlElements, " "); query.modifyQueryString(newQuery); } // now we need to check which objects are in search criteria , if objects are in search criteria they will be joined for (AdvancedSearchCriteriaParameter parameter : criteriaParameters) { if (parameter.getAttributeName() != null) { DependentObject dobj = AdvancedSearchUiUtil.getDependentObjectByName(targetObject, parameter.getObjectName()); if (!dobj.getClassName().equals(targetObject.getClassName())) { if (!objectsToJoin.contains(dobj.getClassName())) { String joinMethodName = ""; if (dobj.getJoinByMethod().equals(INTERVENTION_JOIN_INXML) && tableAliasForInterventions != null && dobj.getClassName().equals(INTERVENTION_CLASS_NAME)) { joinMethodName = interventionJoinMethodMap().get(tableAliasForInterventions); } else { joinMethodName = dobj.getJoinByMethod(); } invokeMethod(query, joinMethodName, new Class[0], new Object[0]); objectsToJoin.add(dobj.getClassName()); } } } } //if objectsInView are part of objectsToJoin we are fine .. // if objectsInView are not part of objectsToJoin , means - we need to outerjoin/join on these objects based on <outer-join-required>.. // method with "outer" prfix shud exist for (String viewObj : objectsInView) { if (!objectsToJoin.contains(viewObj)) { DependentObject dobj = AdvancedSearchUiUtil.getDependentObjectByName(targetObject, viewObj); if (dobj.isOuterJoinRequired()) { invokeMethod(query, OUTER_JOIN_PREFIX + dobj.getJoinByMethod(), new Class[0], new Object[0]); } else { String joinMethodName = ""; if (dobj.getJoinByMethod().equals(INTERVENTION_JOIN_INXML) && tableAliasForInterventions != null && dobj.getClassName().equals(INTERVENTION_CLASS_NAME)) { joinMethodName = interventionJoinMethodMap().get(tableAliasForInterventions); } else { joinMethodName = dobj.getJoinByMethod(); } invokeMethod(query, joinMethodName, new Class[0], new Object[0]); } } // sometimes view attributes needs some default filtering also , like study identifiers .. DependentObject dobj1 = AdvancedSearchUiUtil.getDependentObjectByName(targetObject, viewObj); List<ViewColumn> vcs = dobj1.getViewColumn(); for (ViewColumn vc : vcs) { if (vc.isSelected() && vc.getFilterMethod() != null) { invokeMethod(query, vc.getFilterMethod(), new Class[0], new Object[0]); } } } // add filters for (AdvancedSearchCriteriaParameter parameter : criteriaParameters) { if (parameter.getAttributeName() != null) { String filterMethodName = parameter.getFilterByMethodInQueryClass(); if (parameter.getAttributeName().equals(STUDY_THERAPY_CODE_FIELD_NAME)) { filterMethodName = interventionFilterMethodMap().get(tableAliasForInterventions); } Class[] par = new Class[2]; Object[] obj = new Object[2]; if (parameter.getDataType().equals("String")) { par[0] = String.class; obj[0] = parameter.getValue(); } else if (parameter.getDataType().equals("Integer")) { par[0] = Integer.class; obj[0] = Integer.parseInt(parameter.getValue()); } else if (parameter.getDataType().equals("boolean")) { par[0] = Boolean.TYPE; obj[0] = Boolean.parseBoolean(parameter.getValue()); } else { continue; } par[1] = String.class; obj[1] = parameter.getPredicate(); //Method mthd = query.getClass().getMethod(filterMethodName,par); //mthd.invoke(query,obj); invokeMethod(query, filterMethodName, par, obj); } } return query; }
From source file:com.opengamma.analytics.math.curve.DoublesCurveInterpolatedAnchor.java
/** * Constructor.//from w ww . j av a2 s . c o m * @param xData The x data without the anchor. * @param yData The y data. * @param anchor The anchor point. Should not be in xData. * @param interpolator The interpolator. * @param name The curve name. * @return The curve. */ public static DoublesCurveInterpolatedAnchor from(double[] xData, double[] yData, double anchor, Interpolator1D interpolator, String name) { ArgumentChecker.notNull(xData, "X data"); int xLength = xData.length; ArgumentChecker.notNull(yData, "Y data"); ArgumentChecker.isTrue(xLength == yData.length, "Data of incorrect length."); double[] xExtended = new double[xLength + 1]; double[] yExtended = new double[xLength + 1]; System.arraycopy(xData, 0, xExtended, 0, xLength); xExtended[xLength] = anchor; System.arraycopy(yData, 0, yExtended, 0, xLength); ParallelArrayBinarySort.parallelBinarySort(xExtended, yExtended); int anchorIndex = ArrayUtils.indexOf(xExtended, anchor); return new DoublesCurveInterpolatedAnchor(xExtended, yExtended, anchorIndex, interpolator, name); }
From source file:at.tuwien.ifs.feature.ContentType.java
public static ContentType parse(String s) { String[] parts = s.split("-", 2); String subType = parts.length > 1 ? parts[1] : null; int indexOf = ArrayUtils.indexOf(contentTypes, new ContentType(parts[0], subType)); if (indexOf != -1) { return contentTypes[indexOf]; } else {//from w w w.ja v a 2 s .c o m // check if we know the main type alone indexOf = ArrayUtils.indexOf(contentTypes, new ContentType(parts[0], null)); if (indexOf != -1) { return contentTypes[indexOf]; } else { Logger.getLogger("at.tuwien.ifs.somtoolbox") .warning("Unknown content type '" + s + "', known values are " + Arrays.toString(contentTypes) + ". Defaulting to '" + UNKNOWN + "'."); return UNKNOWN; } } }