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:adalid.core.EntityAtlas.java
@SuppressWarnings("deprecation") void initialiseFields(Class<?> clazz) { track("initialiseFields", _declaringArtifact, clazz.getSimpleName()); Class<?> c;/*www. j a va2 s . c o m*/ int d, r; String name; String key; String pattern = "there are several fields for operation {0}"; String message; Class<?> type; Class<?> decl; Class<?> operationClass; Field operationField; int modifiers; boolean restricted; Object o; int depth = _declaringArtifact.depth(); int round = _declaringArtifact.round(); Class<?>[] classes = new Class<?>[] { Property.class, Key.class, Tab.class, View.class, Instance.class, NamedValue.class, Expression.class, Transition.class, Operation.class, Trigger.class }; Class<?> dac = _declaringArtifact.getClass(); Class<?> top = Entity.class; int i = ArrayUtils.indexOf(classes, clazz); if (i != ArrayUtils.INDEX_NOT_FOUND) { c = classes[i]; for (Field field : XS1.getFields(dac, top)) { field.setAccessible(true); logger.trace(field); name = field.getName(); type = field.getType(); decl = field.getDeclaringClass(); if (!c.isAssignableFrom(type)) { continue; } if (c.equals(Expression.class) && Property.class.isAssignableFrom(type)) { continue; } // TODO: extension handling if (field.isAnnotationPresent(Extension.class) && Entity.class.isAssignableFrom(type)) { // if (!dac.equals(decl) || !dac.isAssignableFrom(type)) { // continue; // } continue; } modifiers = type.getModifiers(); if (NamedValue.class.isAssignableFrom(type) || Expression.class.isAssignableFrom(type)) { restricted = false; } else { restricted = type.isInterface() || Modifier.isAbstract(modifiers); } restricted = restricted || !Modifier.isPublic(modifiers); if (restricted) { continue; } modifiers = field.getModifiers(); restricted = Modifier.isPrivate(modifiers); if (restricted) { continue; } restricted = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers); if (restricted) { continue; } if (Operation.class.isAssignableFrom(type)) { key = type.getSimpleName(); operationClass = _operationClasses.get(key); if (operationClass != null) { operationField = _operationFields.get(key); if (operationField == null) { _operationFields.put(key, field); } else { message = MessageFormat.format(pattern, operationClass.getName()); logger.warn(message); TLC.getProject().getParser().increaseWarningCount(); } } } String errmsg = "failed to create a new instance of field \"" + field + "\" at " + _declaringArtifact; try { o = field.get(_declaringArtifact); if (o == null) { logger.debug(message(type, name, o, depth, round)); o = XS1.initialiseField(_declaringArtifact, field); if (o == null) { logger.debug(message(type, name, o, depth, round)); // throw new RuntimeException(message(type, name, o, depth, round)); } else { logger.debug(message(type, name, o, depth, round)); field.set(_declaringArtifact, o); } } } catch (IllegalArgumentException | IllegalAccessException ex) { throw new InstantiationRuntimeException(errmsg, ex); } } } }
From source file:adalid.core.Operation.java
void initialiseFields(Class<?> clazz) { Class<?> c;/*from w w w . j a v a2s. com*/ int d, r; String name; Class<?> type; int modifiers; boolean restricted; Object o; int depth = depth(); int round = round(); Class<?>[] classes = new Class<?>[] { Parameter.class, Expression.class }; Class<?> dac = getClass(); Class<?> top = Operation.class; int i = ArrayUtils.indexOf(classes, clazz); if (i != ArrayUtils.INDEX_NOT_FOUND) { c = classes[i]; for (Field field : XS1.getFields(dac, top)) { field.setAccessible(true); logger.trace(field); name = field.getName(); type = field.getType(); if (!c.isAssignableFrom(type)) { continue; } modifiers = type.getModifiers(); if (type.isInterface() && Expression.class.isAssignableFrom(type)) { restricted = false; } else { restricted = Modifier.isAbstract(modifiers); } restricted = restricted || !Modifier.isPublic(modifiers); if (restricted) { continue; } modifiers = field.getModifiers(); restricted = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers); if (restricted) { continue; } String errmsg = "failed to create a new instance of field \"" + field + "\" at " + this; try { o = field.get(this); if (o == null) { logger.debug(message(type, name, o, depth, round)); o = XS1.initialiseField(this, field); if (o == null) { logger.debug(message(type, name, o, depth, round)); // throw new RuntimeException(message(type, name, o, depth, round)); } else { logger.debug(message(type, name, o, depth, round)); field.set(this, o); } } } catch (IllegalArgumentException | IllegalAccessException ex) { throw new InstantiationRuntimeException(errmsg, ex); } } } }
From source file:com.opengamma.integration.coppclark.CoppClarkHolidayFileReader.java
private void parseFinancialCentersFile() throws IOException { System.out.println("Parse financial centres"); Map<String, HolidayDocument> combinedMap = new HashMap<String, HolidayDocument>(512); for (InputStream stream : getFinancialCentresStreams()) { Map<String, HolidayDocument> fileMap = new HashMap<String, HolidayDocument>(512); @SuppressWarnings("resource") CSVReader reader = new CSVReader(new InputStreamReader(new BufferedInputStream(stream))); // header String[] row = reader.readNext(); final int ccIdx = ArrayUtils.indexOf(row, "CenterID"); final int isoCountryIdx = ArrayUtils.indexOf(row, "ISOCountryCode"); final int unlocodeIdx = ArrayUtils.indexOf(row, "UN/LOCODE"); final int eventDateIdx = ArrayUtils.indexOf(row, "EventDate"); // data/*from w ww. ja v a2 s. co m*/ while ((row = reader.readNext()) != null) { String ccId = row[ccIdx].trim(); String countryISO = row[isoCountryIdx].trim(); String unlocodePart = row[unlocodeIdx].trim(); ExternalId regionId = ExternalSchemes.coppClarkRegionId(countryISO + unlocodePart); String eventDateStr = row[eventDateIdx]; LocalDate eventDate = LocalDate.parse(eventDateStr, DATE_FORMAT); HolidayDocument doc = fileMap.get(ccId); if (doc == null) { doc = new HolidayDocument(new ManageableHoliday(HolidayType.BANK, regionId, EMPTY_DATE_LIST)); doc.setProviderId(ExternalId.of(COPP_CLARK_SCHEME, ccId)); fileMap.put(ccId, doc); } doc.getHoliday().getHolidayDates().add(eventDate); } merge(combinedMap, fileMap); } mergeWithDatabase(combinedMap); }
From source file:com.contrastsecurity.ide.eclipse.ui.internal.preferences.ContrastPreferencesPage.java
private TableViewer createTableViewer(Composite composite) { TableViewer tableViewer = new TableViewer(composite, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); tableViewer.getTable().setLayoutData(gd); tableViewer.getTable().setHeaderVisible(true); tableViewer.getTable().setLinesVisible(true); tableViewer.setContentProvider(ArrayContentProvider.getInstance()); TableLayout layout = new TableLayout(); tableViewer.getTable().setLayout(layout); TableColumn orgNameColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); orgNameColumn.setText("Organization"); orgNameColumn.setWidth(180);/*from w w w.j a v a 2 s .c om*/ String[] list = ContrastCoreActivator.getOrganizationList(); tableViewer.setInput(list); if (list.length > 0) { String orgName = ContrastCoreActivator.getDefaultOrganization(); if (orgName != null && !orgName.isEmpty()) { tableViewer.getTable().setSelection(ArrayUtils.indexOf(list, orgName)); } else { tableViewer.getTable().setSelection(0); } } return tableViewer; }
From source file:gda.util.exafs.Element.java
/** * @param edgeName// w w w. j a v a2 s.c o m * @return core hole level in eV */ public double getCoreHole(String edgeName) { int index = ArrayUtils.indexOf(edgeNames, edgeName); if (index >= 0) { return getCorehole(index); } return Double.NaN; }
From source file:com.apigee.callout.httpsignature.SignatureVerifierCallout.java
public ExecutionResult execute(MessageContext msgCtxt, ExecutionContext exeCtxt) { String varName;// w ww . j av a 2s.c om String varprefix = "httpsig"; ExecutionResult result = ExecutionResult.ABORT; Boolean isValid = false; try { varName = varprefix + "_error"; msgCtxt.setVariable(varName, null); // 1. retrieve and parse the full signature header payload HttpSignature sigObject = getFullSignature(msgCtxt); // 2. get the required algorithm, if specified, // and check that the actual algorithm in the sig is as required. String actualAlgorithm = sigObject.getAlgorithm(); String requiredAlgorithm = getRequiredAlgorithm(msgCtxt); varName = varprefix + "_requiredAlgorithm"; msgCtxt.setVariable(varName, requiredAlgorithm); if (!HttpSignature.supportedAlgorithms.containsKey(requiredAlgorithm)) { throw new Exception("unsupported algorithm: " + requiredAlgorithm); } if (!actualAlgorithm.equals(requiredAlgorithm)) { throw new Exception("algorithm used in signature (" + actualAlgorithm + ") is not as required (" + requiredAlgorithm + ")"); } // 3. if there are any headers that are configured to be required, // check that they are all present in the sig. String[] requiredHeaders = getRequiredHeaders(msgCtxt); if (requiredHeaders != null) { varName = varprefix + "_requiredHeaders"; msgCtxt.setVariable(varName, StringUtils.join(requiredHeaders, " ")); String[] actualHeaders = sigObject.getHeaders(); int i; for (i = 0; i < actualHeaders.length; i++) { actualHeaders[i] = actualHeaders[i].toLowerCase(); } for (i = 0; i < requiredHeaders.length; i++) { String h = requiredHeaders[i].toLowerCase(); if (ArrayUtils.indexOf(actualHeaders, h) < 0) { throw new Exception("signature is missing required header (" + h + ")."); } } } // 4. Verify that the date skew is within compliance long maxTimeSkew = getMaxTimeSkew(msgCtxt); if (maxTimeSkew > 0L) { long t1 = getRequestSecondsSinceEpoch(msgCtxt); long t2 = (new Date()).getTime() / 1000; // seconds since epoch long diff = Math.abs(t2 - t1); varName = varprefix + "_timeskew"; msgCtxt.setVariable(varName, Long.toString(diff)); if (diff > maxTimeSkew) { // fail. throw new Exception("date header exceeds max time skew (" + diff + ">" + maxTimeSkew + ")."); } } // 5. finally, verify the signature EdgeHeaderProvider hp = new EdgeHeaderProvider(msgCtxt); KeyProvider kp = new KeyProviderImpl(msgCtxt); SigVerificationResult verification = sigObject.verify(actualAlgorithm, hp, kp); isValid = verification.isValid; varName = varprefix + "_signingBase"; msgCtxt.setVariable(varName, verification.signingBase.replace('\n', '|')); result = ExecutionResult.SUCCESS; } catch (Exception e) { //e.printStackTrace(); varName = varprefix + "_error"; msgCtxt.setVariable(varName, e.getMessage()); varName = varprefix + "_stacktrace"; msgCtxt.setVariable(varName, ExceptionUtils.getStackTrace(e)); result = ExecutionResult.ABORT; } varName = varprefix + "_isValid"; msgCtxt.setVariable(varName, isValid); return result; }
From source file:net.sf.firemox.clickable.target.card.CardFactory.java
/** * Return the IdCard value from it's key name. * // ww w . j a va2 s. c o m * @param idCardName * the IdCard non-translated name * @return the IdCard value from it's key name. <code>-1</code> if the given * name does not exist. */ public static int getIdCard(String idCardName) { final int index = ArrayUtils.indexOf(exportedIdCardNames, idCardName); if (index != -1) { return exportedIdCardValues[index]; } return -1; }
From source file:com.bstek.dorado.data.method.MethodAutoMatchingUtils.java
private static MethodDescriptor describMethodIfMatching(Method method, String[] requiredParameterNames, String[] optionalParameterNames, String[] extraParameterNames) throws SecurityException, NoSuchMethodException { String[] methodParameterNames = getParameterNames(method); if (methodParameterNames.length > requiredParameterNames.length + optionalParameterNames.length) { return null; }//from w w w . j a v a 2 s .c o m int rate = 1000; int[] argIndexs = new int[methodParameterNames.length]; for (int i = 0; i < argIndexs.length; i++) { argIndexs[i] = -1; } for (int i = 0; i < requiredParameterNames.length; i++) { int index = ArrayUtils.indexOf(methodParameterNames, requiredParameterNames[i]); if (index < 0) { return null; } argIndexs[index] = i; } for (int i = 0; i < argIndexs.length; i++) { if (argIndexs[i] == -1) { String parameterName = methodParameterNames[i]; int index = ArrayUtils.indexOf(optionalParameterNames, parameterName); if (index < 0) { index = ArrayUtils.indexOf(extraParameterNames, parameterName); if (index >= 0) { argIndexs[i] = requiredParameterNames.length + optionalParameterNames.length + index; rate += 90; continue; } return null; } argIndexs[i] = requiredParameterNames.length + index; rate += 100; } } return new MethodDescriptor(method, argIndexs, rate); }
From source file:com.opengamma.integration.coppclark.CoppClarkHolidayFileReader.java
private void parseExchangeSettlementFile() throws IOException { System.out.println("Parse exchange settlements"); Map<String, HolidayDocument> combinedMap = new HashMap<String, HolidayDocument>(512); for (InputStream stream : getExchangeSettlementStreams()) { Map<String, HolidayDocument> fileMap = new HashMap<String, HolidayDocument>(512); @SuppressWarnings("resource") CSVReader reader = new CSVReader(new InputStreamReader(new BufferedInputStream(stream))); // header String[] row = reader.readNext(); final int ccIdx = ArrayUtils.indexOf(row, "CenterID"); final int isoMICCodeIdx = ArrayUtils.indexOf(row, "ISO MIC Code"); final int eventDateIdx = ArrayUtils.indexOf(row, "EventDate"); // data//from w w w.ja v a2 s . c om while ((row = reader.readNext()) != null) { String ccId = row[ccIdx].trim(); String isoMICCode = row[isoMICCodeIdx].trim(); ExternalId micId = ExternalSchemes.isoMicExchangeId(isoMICCode); String eventDateStr = row[eventDateIdx]; LocalDate eventDate = LocalDate.parse(eventDateStr, DATE_FORMAT); HolidayDocument doc = fileMap.get(ccId); if (doc == null) { doc = new HolidayDocument( new ManageableHoliday(HolidayType.SETTLEMENT, micId, EMPTY_DATE_LIST)); doc.setProviderId(ExternalId.of(COPP_CLARK_SCHEME, ccId)); fileMap.put(ccId, doc); } doc.getHoliday().getHolidayDates().add(eventDate); } merge(combinedMap, fileMap); } mergeWithDatabase(combinedMap); }
From source file:com.splicemachine.db.impl.sql.compile.TableElementList.java
/** * Fill in the ColumnInfo[] for this table element list. * /*w ww . j a v a 2s . co m*/ * @param colInfos The ColumnInfo[] to be filled in. * * @return int The number of constraints in the create table. */ public int genColumnInfos(ColumnInfo[] colInfos, ResultColumnList partitionedColumnList) throws StandardException { int numConstraints = 0; int size = size(); String[] columnNames = partitionedColumnList == null ? new String[0] : partitionedColumnList.getColumnNames(); for (int index = 0; index < size; index++) { if (((TableElementNode) elementAt(index)).getElementType() == TableElementNode.AT_DROP_COLUMN) { String columnName = ((TableElementNode) elementAt(index)).getName(); colInfos[index] = new ColumnInfo(columnName, td.getColumnDescriptor(columnName).getType(), null, null, null, null, null, ColumnInfo.DROP, 0, 0, 0, ArrayUtils.indexOf(columnNames, columnName)); break; } if (!(elementAt(index) instanceof ColumnDefinitionNode)) { if (SanityManager.DEBUG) { SanityManager.ASSERT(elementAt(index) instanceof ConstraintDefinitionNode, "elementAt(index) expected to be instanceof " + "ConstraintDefinitionNode"); } /* Remember how many constraints we've seen */ numConstraints++; continue; } ColumnDefinitionNode coldef = (ColumnDefinitionNode) elementAt(index); // // Generated columns may depend on functions mentioned in their // generation clauses. // ProviderList apl = null; ProviderInfo[] providerInfos = null; if (coldef.hasGenerationClause()) { apl = coldef.getGenerationClauseNode().getAuxiliaryProviderList(); } if (apl != null && apl.size() > 0) { DependencyManager dm = getDataDictionary().getDependencyManager(); providerInfos = dm.getPersistentProviderInfos(apl); } colInfos[index - numConstraints] = new ColumnInfo(coldef.getColumnName(), coldef.getType(), coldef.getDefaultValue(), coldef.getDefaultInfo(), providerInfos, (UUID) null, coldef.getOldDefaultUUID(), coldef.getAction(), (coldef.isAutoincrementColumn() ? coldef.getAutoincrementStart() : 0), (coldef.isAutoincrementColumn() ? coldef.getAutoincrementIncrement() : 0), (coldef.isAutoincrementColumn() ? coldef.getAutoinc_create_or_modify_Start_Increment() : -1), -1); /* Remember how many constraints that we've seen */ if (coldef.hasConstraint()) { numConstraints++; } } return numConstraints; }