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:org.apache.mahout.df.split.OptIgSplit.java
protected void computeFrequencies(Data data, int attr, double[] values) { for (int index = 0; index < data.size(); index++) { Instance instance = data.get(index); counts[ArrayUtils.indexOf(values, instance.get(attr))][instance.label]++; countAll[instance.label]++;// w ww.j a v a2 s .c o m } }
From source file:org.apache.ode.daohib.bpel.ql.StateComparator.java
/** * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) *//* w ww . j ava2 s .com*/ public int compare(HProcessInstance o1, HProcessInstance o2) { return multiplier * (ArrayUtils.indexOf(order, o1.getState()) - ArrayUtils.indexOf(order, o2.getState())); }
From source file:org.apache.ojb.broker.core.MtoNBroker.java
/** * Stores new values of a M:N association in a indirection table. * * @param cod The {@link org.apache.ojb.broker.metadata.CollectionDescriptor} for the m:n relation * @param realObject The real object/* w w w . j av a2 s. c om*/ * @param otherObj The referenced object * @param mnKeys The all {@link org.apache.ojb.broker.core.MtoNBroker.Key} matching the real object */ public void storeMtoNImplementor(CollectionDescriptor cod, Object realObject, Object otherObj, Collection mnKeys) { ClassDescriptor cld = pb.getDescriptorRepository().getDescriptorFor(realObject.getClass()); ValueContainer[] pkValues = pb.serviceBrokerHelper().getKeyValues(cld, realObject); String[] pkColumns = cod.getFksToThisClass(); ClassDescriptor otherCld = pb.getDescriptorRepository() .getDescriptorFor(ProxyHelper.getRealClass(otherObj)); ValueContainer[] otherPkValues = pb.serviceBrokerHelper().getKeyValues(otherCld, otherObj); String[] otherPkColumns = cod.getFksToItemClass(); String table = cod.getIndirectionTable(); MtoNBroker.Key key = new MtoNBroker.Key(otherPkValues); if (mnKeys.contains(key)) { return; } /* fix for OJB-76, composite M & N keys that have some fields common find the "shared" indirection table columns, values and remove these from m- or n- side */ for (int i = 0; i < otherPkColumns.length; i++) { int index = ArrayUtils.indexOf(pkColumns, otherPkColumns[i]); if (index != -1) { // shared indirection table column found, remove this column from one side pkColumns = (String[]) ArrayUtils.remove(pkColumns, index); // remove duplicate value too pkValues = (ValueContainer[]) ArrayUtils.remove(pkValues, index); } } String[] cols = mergeColumns(pkColumns, otherPkColumns); String insertStmt = pb.serviceSqlGenerator().getInsertMNStatement(table, pkColumns, otherPkColumns); ValueContainer[] values = mergeContainer(pkValues, otherPkValues); GenericObject gObj = new GenericObject(table, cols, values); if (!tempObjects.contains(gObj)) { pb.serviceJdbcAccess().executeUpdateSQL(insertStmt, cld, pkValues, otherPkValues); tempObjects.add(gObj); } }
From source file:org.apache.sling.resource.collection.impl.ResourceCollectionImpl.java
public void orderBefore(Resource srcResource, Resource destResource) { if (srcResource == null) { throw new IllegalArgumentException("Source Resource can not be null"); }/*w w w . ja v a2s. c o m*/ ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class); String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[] {}); String srcPath = srcResource.getPath(); int srcIndex = ArrayUtils.indexOf(order, srcPath); if (srcIndex < 0) { log.warn("Collection ordering failed, as there is no resource {} in collection {} for destResource", srcPath, getPath()); return; } if (destResource == null) { //add it to the end. order = (String[]) ArrayUtils.remove(order, srcIndex); order = (String[]) ArrayUtils.add(order, srcPath); } else { String destPath = destResource.getPath(); if (destPath.equals(srcPath)) { String message = MessageFormat.format( "Collection ordering failed, as source {0} and destination {1} can not be same", srcPath, destPath); log.error(message); throw new IllegalArgumentException(message); } int destIndex = ArrayUtils.indexOf(order, destPath); if (destIndex < 0) { log.warn("Collection ordering failed, as there is no resource {} in collection {} for destResource", destPath, getPath()); return; } order = (String[]) ArrayUtils.remove(order, srcIndex); if (srcIndex < destIndex) { //recalculate dest index destIndex = ArrayUtils.indexOf(order, destPath); } order = (String[]) ArrayUtils.add(order, destIndex, srcPath); } vm.put(ResourceCollectionConstants.REFERENCES_PROP, order); }
From source file:org.apache.sysml.hops.rewrite.HopRewriteUtils.java
public static int getValidOpPos(OpOp2 input, OpOp2... validTab) { return ArrayUtils.indexOf(validTab, input); }
From source file:org.apache.sysml.runtime.transform.meta.TfMetaUtils.java
/** * TODO consolidate external and internal json spec definitions * /* ww w . j a v a 2 s.co m*/ * @param spec transform specification as json string * @param colnames column names * @param group ? * @return list of column ids * @throws JSONException if JSONException occurs */ public static int[] parseJsonIDList(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)) { //parse attribute-array or plain array of IDs JSONArray attrs = null; if (spec.get(group) instanceof JSONObject) { attrs = (JSONArray) ((JSONObject) spec.get(group)).get(TfUtils.JSON_ATTRS); ids = true; //file-based transform outputs ids w/o id tags } else attrs = (JSONArray) spec.get(group); //construct ID list array colList = new int[attrs.size()]; for (int i = 0; i < colList.length; i++) { colList[i] = ids ? UtilFunctions.toInt(attrs.get(i)) : (ArrayUtils.indexOf(colnames, attrs.get(i)) + 1); if (colList[i] <= 0) { throw new RuntimeException("Specified column '" + attrs.get(i) + "' does not exist."); } } //ensure ascending order of column IDs Arrays.sort(colList); } return colList; }
From source file:org.apache.sysml.runtime.transform.meta.TfMetaUtils.java
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."); }/*from ww w.ja va 2 s . co m*/ } //ensure ascending order of column IDs Arrays.sort(colList); } return colList; }
From source file:org.apache.sysml.runtime.transform.meta.TfMetaUtils.java
/** * Converts transform meta data into an in-memory FrameBlock object. * //w ww .j a va2 s .c o m * @param rows number of rows * @param colnames column names * @param rcIDs recode IDs * @param binIDs binning IDs * @param meta ? * @param mvmeta ? * @return frame block * @throws IOException if IOException occurs */ private static FrameBlock convertToTransformMetaDataFrame(int rows, String[] colnames, List<Integer> rcIDs, List<Integer> binIDs, HashMap<String, String> meta, HashMap<String, String> mvmeta) throws IOException { //create frame block w/ pure string schema ValueType[] schema = UtilFunctions.nCopies(colnames.length, ValueType.STRING); FrameBlock ret = new FrameBlock(schema, colnames); ret.ensureAllocatedColumns(rows); //encode recode maps (recoding/dummycoding) into frame for (Integer colID : rcIDs) { String name = colnames[colID - 1]; String map = meta.get(name); if (map == null) throw new IOException("Recode map for column '" + name + "' (id=" + colID + ") not existing."); InputStream is = new ByteArrayInputStream(map.getBytes("UTF-8")); BufferedReader br = new BufferedReader(new InputStreamReader(is)); Pair<String, String> pair = new Pair<String, String>(); String line; int rpos = 0; while ((line = br.readLine()) != null) { DecoderRecode.parseRecodeMapEntry(line, pair); String tmp = pair.getKey() + Lop.DATATYPE_PREFIX + pair.getValue(); ret.set(rpos++, colID - 1, tmp); } ret.getColumnMetadata(colID - 1).setNumDistinct((long) rpos); } //encode bin maps (binning) into frame for (Integer colID : binIDs) { String name = colnames[colID - 1]; String map = meta.get(name); if (map == null) throw new IOException("Binning map for column '" + name + "' (id=" + colID + ") not existing."); String[] fields = map.split(TfUtils.TXMTD_SEP); double min = UtilFunctions.parseToDouble(fields[1]); double binwidth = UtilFunctions.parseToDouble(fields[3]); int nbins = UtilFunctions.parseToInt(fields[4]); //materialize bins to support equi-width/equi-height for (int i = 0; i < nbins; i++) { String lbound = String.valueOf(min + i * binwidth); String ubound = String.valueOf(min + (i + 1) * binwidth); ret.set(i, colID - 1, lbound + Lop.DATATYPE_PREFIX + ubound); } ret.getColumnMetadata(colID - 1).setNumDistinct((long) nbins); } //encode impute meta data into frame for (Entry<String, String> e : mvmeta.entrySet()) { int colID = ArrayUtils.indexOf(colnames, e.getKey()) + 1; String mvVal = e.getValue().split(TfUtils.TXMTD_SEP)[1]; ret.getColumnMetadata(colID - 1).setMvValue(mvVal); } return ret; }
From source file:org.betaconceptframework.astroboa.engine.jcr.util.JcrValueUtils.java
public static void replaceValue(Node node, ItemQName property, Value newValue, Value oldValue, Boolean isPropertyMultivalued) throws RepositoryException { //Node does not have property if (!node.hasProperty(property.getJcrName())) { //New Value is null. Do nothing if (newValue == null) return; //Determine if property is multiple, if this info is not provided if (isPropertyMultivalued == null) { isPropertyMultivalued = propertyIsMultiValued(node, property); }/* ww w . ja v a2 s . c o m*/ if (isPropertyMultivalued) node.setProperty(property.getJcrName(), new Value[] { newValue }); else node.setProperty(property.getJcrName(), newValue); } else { //Node has property Property jcrProperty = node.getProperty(property.getJcrName()); if (isPropertyMultivalued == null) //Determine by property isPropertyMultivalued = jcrProperty.getDefinition().isMultiple(); if (!isPropertyMultivalued) { if (oldValue == null || (oldValue != null && oldValue.equals(jcrProperty.getValue()))) { //Set newValue only if no old value is provided OR //oldValue is provided and it really exists there jcrProperty.setValue(newValue); } } else { Value[] values = jcrProperty.getValues(); //Remove oldValue if (oldValue != null) { int index = ArrayUtils.indexOf(values, oldValue); if (index == ArrayUtils.INDEX_NOT_FOUND) throw new ItemNotFoundException( "Value " + oldValue.getString() + " in property " + jcrProperty.getPath()); values = (Value[]) ArrayUtils.remove(values, index); } //Add new value if (newValue != null && !ArrayUtils.contains(values, newValue)) values = (Value[]) ArrayUtils.add(values, newValue); //If at the end values array is empty //remove property if (ArrayUtils.isEmpty(values)) { node.setProperty(property.getJcrName(), JcrValueUtils.getJcrNullForMultiValue()); } else { node.setProperty(property.getJcrName(), values); } } } }
From source file:org.braiden.fpm2.crypto.JCEFpmCipher.java
@Override public String decrypt(byte[] key, String encryptedData) throws GeneralSecurityException { byte[] result = decryptRaw(key, encryptedData); int idxOfNil = ArrayUtils.indexOf(result, (byte) 0); return new String(result, 0, idxOfNil >= 0 ? idxOfNil : result.length); }