List of usage examples for org.apache.commons.lang ArrayUtils indexOf
public static int indexOf(boolean[] array, boolean valueToFind, int startIndex)
Finds the index of the given value in the array starting at the given index.
From source file:com.delphix.session.impl.sasl.PlainSaslServer.java
public String[] parse(byte[] message) throws SaslException { // Validate the SASL message PlainSasl.validate(message);/*w ww. j a va2s. co m*/ // Append separator to the end of the message message = ArrayUtils.add(message, PlainSasl.SEPARATOR_BYTE); // Parse the user info formatted as value + SEPARATOR String[] userInfo = new String[3]; byte[] segment; int beginIndex = 0; int endIndex; for (int i = 0; i < userInfo.length; i++) { endIndex = ArrayUtils.indexOf(message, PlainSasl.SEPARATOR_BYTE, beginIndex); if (endIndex < 0) { throw new SaslException("invalid sasl message"); } else { segment = ArrayUtils.subarray(message, beginIndex, endIndex); userInfo[i] = fromUTF(segment); } beginIndex = endIndex + 1; } // Check if there is anything else beyond the last separator if (beginIndex < message.length) { throw new SaslException("invalid sasl message"); } // Validate the user info PlainSasl.validate(userInfo); return userInfo; }
From source file:com.pureinfo.ark.auth2.domain.impl.Auth2MgrImplBase.java
/** * @see com.pureinfo.ark.auth2.domain.IAuth2Mgr#hasRole(com.pureinfo.ark.auth.model.IUser, * java.lang.String)/*ww w . ja va 2 s.co m*/ */ public boolean hasRole(IUser _user, String _sRole) throws PureException { String[] roles = getRoles(_user); return roles != null && ArrayUtils.indexOf(roles, _sRole, 0) >= 0; }
From source file:org.apache.hawq.pxf.service.BridgeOutputBuilder.java
/** * Breaks raw bytes into lines. Used only for sampling. * * 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.// ww w . j a va2 s. co m * * @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; } }
From source file:org.apache.sling.resource.collection.impl.ResourceCollectionImpl.java
/** * {@inheritDoc}//w w w . ja v a 2s . c o m */ public boolean contains(Resource res) { if (res != null) { ValueMap vm = membersResource.adaptTo(ValueMap.class); String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[] {}); int index = ArrayUtils.indexOf(order, res.getPath(), 0); return index >= 0 ? true : false; } return false; }
From source file:org.apache.sling.resource.collection.impl.ResourceCollectionImpl.java
/** * {@inheritDoc}//from www . j av a2 s.c o m */ public boolean remove(Resource res) throws PersistenceException { //remove the resource Resource tobeRemovedRes = findRes(res); if (tobeRemovedRes == null) { return false; } resolver.delete(tobeRemovedRes); //remove from order array ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class); String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[] {}); int index = ArrayUtils.indexOf(order, res.getPath(), 0); order = (String[]) ArrayUtils.remove(order, index); vm.put(ResourceCollectionConstants.REFERENCES_PROP, order); return true; }
From source file:org.jumpmind.symmetric.integrate.AbstractXmlPublisherExtensionPoint.java
protected String toXmlGroupId(String[] columnNames, String[] data, String[] keyNames, String[] keys) { if (groupByColumnNames != null) { StringBuilder id = new StringBuilder(); if (keys != null) { String[] columns = keyNames; for (String col : groupByColumnNames) { int index = ArrayUtils.indexOf(columns, col, 0); if (index >= 0) { id.append(keys[index]); } else { id = new StringBuilder(); break; }/*from w w w . ja v a 2 s .c o m*/ } } if (id.length() == 0) { String[] columns = columnNames; for (String col : groupByColumnNames) { int index = ArrayUtils.indexOf(columns, col, 0); if (index >= 0) { id.append(data[index]); } else { return null; } } } if (id.length() > 0) { return id.toString(); } } else { log.warn( "You did not specify 'groupByColumnNames'. We cannot find any matches in the data to publish as XML if you don't. You might as well turn off this filter!"); } return null; }
From source file:padl.creator.cppfile.eclipse.plugin.internal.Utils.java
static char[][] getQualifiedName(final char[] aName) { final char[] name = Utils.convertSeparators(aName); final List<char[]> parts = new ArrayList<char[]>(); int start = -1; int end = -1; // Yann 2014/06/27: Method names and parameters... // For the case // location(enum QLibraryInfo::LibraryLocation) // I must also end if a parenthesis is before the next separator. while ((end = ArrayUtils.indexOf(name, Utils.SEPARATOR, start)) > -1 && end > ArrayUtils.indexOf(name, '(', start)) { final char[] part = ArrayUtils.subarray(name, start, end); start = end + 1;/*from w ww . ja v a 2 s. c o m*/ parts.add(part); } parts.add(ArrayUtils.subarray(name, start, name.length)); final char[][] qualifiedName = new char[parts.size()][]; parts.toArray(qualifiedName); return qualifiedName; }
From source file:padl.creator.cppfile.eclipse.plugin.internal.Utils.java
static char[][] getQualifiedType(final char[] aName) { final List<char[]> parts = new ArrayList<char[]>(); int start = -1; int end = -1; while ((end = ArrayUtils.indexOf(aName, Utils.SEPARATOR, start)) > -1) { final char[] part = ArrayUtils.subarray(aName, start, end); start = end + 1;/*from ww w. j a v a 2 s.c om*/ parts.add(part); } final char[][] qualifiedName = new char[parts.size()][]; parts.toArray(qualifiedName); return qualifiedName; }
From source file:padl.creator.javafile.eclipse.util.PadlParserUtil.java
/** * Create possibly recursively packages//from w w w . ja v a 2 s . com * * @param aPackageName * @param aCodeLevelModel * @return */ public static IPackage getOrCreatePackage(final char[] aPackageName, final ICodeLevelModel aCodeLevelModel) { IPackage currentPackage = null; int startIndexInclusive = 0; do { int endIndexExclusive = ArrayUtils.indexOf(aPackageName, '.', startIndexInclusive); if (endIndexExclusive == -1) { endIndexExclusive = aPackageName.length; } final char[] tempName = ArrayUtils.subarray(aPackageName, startIndexInclusive, endIndexExclusive); if (currentPackage == null) { currentPackage = PadlParserUtil.createPackage(tempName, aCodeLevelModel); } else { currentPackage = PadlParserUtil.createPackage(tempName, currentPackage, aCodeLevelModel); } startIndexInclusive = endIndexExclusive + 1; } while (startIndexInclusive < aPackageName.length); return currentPackage; }