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:com.opengamma.integration.coppclark.CoppClarkHolidayFileReader.java
private void parseExchangeTradingFile() throws IOException { System.out.println("Parse exchange trading"); Map<String, HolidayDocument> combinedMap = new HashMap<String, HolidayDocument>(512); for (InputStream stream : getExchangeTradingStreams()) { 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 .j a v a 2s . c o m 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.TRADING, 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.kylinolap.metadata.model.cube.CubeDesc.java
private void initDimensionColumns(Map<String, TableDesc> tables) { // fill back ColRefDesc for (DimensionDesc dim : dimensions) { TableDesc dimTable = tables.get(dim.getTable()); JoinDesc join = dim.getJoin();//from w w w . j av a2s . c o m ArrayList<TblColRef> dimColList = new ArrayList<TblColRef>(); ArrayList<TblColRef> hostColList = new ArrayList<TblColRef>(); // dimension column if (dim.getColumn() != null) { if ("{FK}".equals(dim.getColumn())) { for (TblColRef ref : join.getForeignKeyColumns()) { TblColRef inited = initDimensionColRef(ref); dimColList.add(inited); hostColList.add(inited); } } else { TblColRef ref = initDimensionColRef(dimTable, dim.getColumn()); dimColList.add(ref); hostColList.add(ref); } } // hierarchy columns if (dim.getHierarchy() != null) { for (HierarchyDesc hier : dim.getHierarchy()) { TblColRef ref = initDimensionColRef(dimTable, hier.getColumn()); hier.setColumnRef(ref); dimColList.add(ref); } if (hostColList.isEmpty()) { // the last hierarchy could serve // as host when col is // unspecified hostColList.add(dimColList.get(dimColList.size() - 1)); } } TblColRef[] dimCols = (TblColRef[]) dimColList.toArray(new TblColRef[dimColList.size()]); dim.setColumnRefs(dimCols); // lookup derived columns TblColRef[] hostCols = (TblColRef[]) hostColList.toArray(new TblColRef[hostColList.size()]); String[] derived = dim.getDerived(); if (derived != null) { String[][] split = splitDerivedColumnAndExtra(derived); String[] derivedNames = split[0]; String[] derivedExtra = split[1]; TblColRef[] derivedCols = new TblColRef[derivedNames.length]; for (int i = 0; i < derivedNames.length; i++) { derivedCols[i] = initDimensionColRef(dimTable, derivedNames[i]); } initDerivedMap(hostCols, DeriveType.LOOKUP, dim, derivedCols, derivedExtra); } // FK derived column if (join != null) { TblColRef[] fk = join.getForeignKeyColumns(); TblColRef[] pk = join.getPrimaryKeyColumns(); for (int i = 0; i < fk.length; i++) { int find = ArrayUtils.indexOf(hostCols, fk[i]); if (find >= 0) { TblColRef derivedCol = initDimensionColRef(pk[i]); initDerivedMap(hostCols[find], DeriveType.PK_FK, dim, derivedCol); } } for (int i = 0; i < pk.length; i++) { int find = ArrayUtils.indexOf(hostCols, pk[i]); if (find >= 0) { TblColRef derivedCol = initDimensionColRef(fk[i]); initDerivedMap(hostCols[find], DeriveType.PK_FK, dim, derivedCol); } } } } }
From source file:com.yaodu.framework.controller.product.ProductSearchController.java
private List<ProductBascInfo> getRecentlyViewedList(HttpServletRequest request) { List<ProductBascInfo> recentlyViewedList = null; if (null != request) { Cookie[] cookie = request.getCookies(); if (null == cookie) { return recentlyViewedList; }/*from w w w . ja va2 s .c om*/ for (int i = 0; i < cookie.length; i++) { Cookie cook = cookie[i]; if (cook.getName().equalsIgnoreCase("relatedProducts")) { // ? if (!"".equals(cook.getValue().toString())) { final String[] arrs = cook.getValue().split("\\|"); recentlyViewedList = productSolrjSearchService.findProductsByIds(arrs); Collections.sort(recentlyViewedList, new Comparator<ProductBascInfo>() { public int compare(ProductBascInfo p1, ProductBascInfo p2) { return Integer.valueOf(ArrayUtils.indexOf(arrs, p1.getnId())) .compareTo(ArrayUtils.indexOf(arrs, p2.getnId())); } }); } break; } } } return recentlyViewedList; }
From source file:fr.inria.atlanmod.neoemf.datastore.estores.impl.DirectWriteHbaseResourceEStoreImpl.java
@Override public int indexOf(InternalEObject object, EStructuralFeature feature, Object value) { NeoEMFEObject neoEMFEObject = NeoEMFEObjectAdapterFactoryImpl.getAdapter(object, NeoEMFEObject.class); String[] array = (String[]) getFromTable(neoEMFEObject, feature); if (array == null) { return -1; }//from www . ja v a2s .c o m if (feature instanceof EAttribute) { return ArrayUtils.indexOf(array, serializeValue((EAttribute) feature, value)); } else { NeoEMFEObject childEObject = NeoEMFEObjectAdapterFactoryImpl.getAdapter(value, NeoEMFEObject.class); return ArrayUtils.indexOf(array, childEObject.neoemfId()); } }
From source file:com.bstek.dorado.idesupport.initializer.CommonRuleTemplateInitializer.java
protected List<AutoChildTemplate> getChildTemplatesBySubNode(RuleTemplate ruleTemplate, TypeInfo typeInfo, String propertyName, XmlSubNode xmlSubNode, TypeInfo propertyTypeInfo, InitializerContext initializerContext) throws Exception { List<AutoChildTemplate> childTemplates = new ArrayList<AutoChildTemplate>(); boolean aggregated = xmlSubNode.aggregated(); Class<?> propertyType = null; if (propertyTypeInfo != null) { propertyType = propertyTypeInfo.getType(); aggregated = propertyTypeInfo.isAggregated(); }/* w w w . ja v a 2 s. c om*/ Set<Class<?>> implTypes = ClassUtils.findClassTypes(xmlSubNode.implTypes(), propertyType); for (Class<?> implType : implTypes) { if (implType.equals(typeInfo.getType())) { continue; } boolean isPublic = true; XmlNode implXmlNode = implType.getAnnotation(XmlNode.class); if (implXmlNode != null && ArrayUtils.indexOf(implType.getDeclaredAnnotations(), implXmlNode) >= 0 && !implXmlNode.isPublic()) { if (ArrayUtils.indexOf(xmlSubNode.implTypes(), implType.getName()) < 0) { continue; } else { isPublic = false; } } AutoChildTemplate childTemplate = getChildNodeByBeanType(null, xmlSubNode, aggregated, implType, "protected", initializerContext); if (childTemplate != null) { childTemplate.setPublic(isPublic); childTemplates.add(childTemplate); } } if (propertyType != null) { XmlNode implXmlNode = propertyType.getAnnotation(XmlNode.class); if (implXmlNode == null || implXmlNode.isPublic()) { AutoChildTemplate childTemplate = getChildNodeByBeanType(StringUtils.capitalize(propertyName), xmlSubNode, aggregated, propertyType, null, initializerContext); if (childTemplate != null) { childTemplates.add(childTemplate); } } } XmlNodeWrapper wrapper = xmlSubNode.wrapper(); String wrapperName = wrapper.nodeName(); if (StringUtils.isNotEmpty(wrapperName)) { List<AutoChildTemplate> wrapperTemplates = new ArrayList<AutoChildTemplate>(); AutoRuleTemplate wrapperRuleTemplate = new AutoRuleTemplate("Wrapper." + wrapper.nodeName()); wrapperRuleTemplate.setLabel(StringUtils.defaultIfEmpty(wrapper.label(), wrapper.nodeName())); if (StringUtils.isNotEmpty(wrapper.icon())) { wrapperRuleTemplate.setIcon(wrapper.icon()); } wrapperRuleTemplate.setNodeName(wrapper.nodeName()); for (ChildTemplate childTemplate : childTemplates) { wrapperRuleTemplate.addChild(childTemplate); } AutoChildTemplate wrapperChildTemplate = new AutoChildTemplate(wrapperName, wrapperRuleTemplate, xmlSubNode); wrapperChildTemplate.setFixed(wrapper.fixed()); wrapperTemplates.add(wrapperChildTemplate); return wrapperTemplates; } else { return childTemplates; } }
From source file:com.google.gdt.eclipse.designer.model.widgets.cell.ColumnInfo.java
@Override protected void refresh_finish() throws Exception { super.refresh_finish(); String cellTypeName = null;/*w ww . ja va 2 s .c o m*/ // if anonymous, then it was mocked as TextColumn if (getCreationSupport().getNode() instanceof ClassInstanceCreation) { ClassInstanceCreation creation = (ClassInstanceCreation) getCreationSupport().getNode(); if (creation.getAnonymousClassDeclaration() != null) { ITypeBinding anonymousBinding = AstNodeUtils.getTypeBinding(creation); ITypeBinding superBinding = anonymousBinding.getSuperclass(); String superName = AstNodeUtils.getFullyQualifiedName(superBinding, false); if ("com.google.gwt.user.cellview.client.Column".equals(superName)) { Expression cellExpression = DomGenerics.arguments(creation).get(0); cellTypeName = AstNodeUtils.getFullyQualifiedName(cellExpression, false); } } } // get Cell from Column instance if (cellTypeName == null) { Object cell = ReflectionUtils.invokeMethod2(getObject(), "getCell"); Class<?> cellClass = cell.getClass(); cellTypeName = ReflectionUtils.getCanonicalName(cellClass); } // use icon which corresponds to the Cell type if (cellTypeName != null) { int index = ArrayUtils.indexOf(CELL_TYPES, cellTypeName); if (index != ArrayUtils.INDEX_NOT_FOUND) { m_specialIcon = getCreationIcon(CELL_IDS[index]); } } }
From source file:com.smartmarmot.common.Configurator.java
public DBConn[] rebuildDBList(DBConn[] _dbc) { try {/*from w w w . j a v a 2 s . com*/ verifyConfig(); String[] localdblist = this.getDBList(); String[] remotedblist = new String[_dbc.length]; for (int i = 0; i < _dbc.length; i++) { remotedblist[i] = _dbc[i].getName(); } Collection<DBConn> connections = new ArrayList<DBConn>(); for (int j = 0; j < localdblist.length; j++) { if (ArrayUtils.contains(remotedblist, localdblist[j])) { DBConn tmpDBConn; tmpDBConn = _dbc[ArrayUtils.indexOf(remotedblist, localdblist[j])]; connections.add(tmpDBConn); } if (!ArrayUtils.contains(remotedblist, localdblist[j])) { /* * adding database */ SmartLogger.logThis(Level.INFO, "New database founded! " + localdblist[j]); DBConn tmpDBConn = this.getDBConnManager(localdblist[j]); if (tmpDBConn != null) { connections.add(tmpDBConn); } } } for (int x = 0; x < _dbc.length; x++) { if (!ArrayUtils.contains(localdblist, _dbc[x].getName())) { SmartLogger.logThis(Level.WARN, "Database " + _dbc[x].getName() + " removed from configuration file"); /** * removing database */ // _dbc[x].closeAll(); SmartLogger.logThis(Level.WARN, "Database " + _dbc[x].getName() + " conections closed"); _dbc[x] = null; } } DBConn[] connArray = (DBConn[]) connections.toArray(new DBConn[0]); return connArray; } catch (Exception ex) { SmartLogger.logThis(Level.ERROR, "Error on Configurator while retriving the databases list " + Constants.DATABASES_LIST + " error:" + ex); return _dbc; } }
From source file:com.smartmarmot.orabbix.Configurator.java
public DBConn[] rebuildDBList(DBConn[] _dbc) { try {/* ww w . j a va2s . com*/ verifyConfig(); String[] localdblist = this.getDBList(); String[] remotedblist = new String[_dbc.length]; for (int i = 0; i < _dbc.length; i++) { remotedblist[i] = _dbc[i].getName(); } Collection<DBConn> connections = new ArrayList<DBConn>(); for (int j = 0; j < localdblist.length; j++) { if (ArrayUtils.contains(remotedblist, localdblist[j])) { DBConn tmpDBConn; tmpDBConn = _dbc[ArrayUtils.indexOf(remotedblist, localdblist[j])]; connections.add(tmpDBConn); } if (!ArrayUtils.contains(remotedblist, localdblist[j])) { /* * adding database */ SmartLogger.logThis(Level.INFO, "New database founded! " + localdblist[j]); DBConn tmpDBConn = this.getConnection(localdblist[j]); if (tmpDBConn != null) { connections.add(tmpDBConn); } } } for (int x = 0; x < _dbc.length; x++) { if (!ArrayUtils.contains(localdblist, _dbc[x].getName())) { SmartLogger.logThis(Level.WARN, "Database " + _dbc[x].getName() + " removed from configuration file"); /** * removing database */ // _dbc[x].closeAll(); _dbc[x].getSPDS().close(); SmartLogger.logThis(Level.WARN, "Database " + _dbc[x].getName() + " conections closed"); _dbc[x] = null; } } DBConn[] connArray = (DBConn[]) connections.toArray(new DBConn[0]); return connArray; } catch (Exception ex) { SmartLogger.logThis(Level.ERROR, "Error on Configurator while retriving the databases list " + Constants.DATABASES_LIST + " error:" + ex); return _dbc; } }
From source file:com.novartis.opensource.yada.QueryManager.java
/** * Populates the data and parameter storage in the query object, using values passed in request object * @since 4.0.0/*from ww w . ja v a 2s . co m*/ * @param yq * the query object to be processed * @return {@code yq}, now endowed with metadata * @throws YADAFinderException * when the name of the query in {@code yq} can't be found in the * YADA index * @throws YADAQueryConfigurationException * the the YADA request is malformed * @throws YADAUnsupportedAdaptorException when the adaptor attached to the query object can't be found or instantiated * @throws YADAResourceException when the query {@code q} can't be found in the index * @throws YADAConnectionException when a connection pool or string cannot be established */ YADAQuery endowQuery(YADAQuery yq) throws YADAQueryConfigurationException, YADAResourceException, YADAUnsupportedAdaptorException, YADAConnectionException { int index = 0; if (getJsonParams() != null) index = ArrayUtils.indexOf(getJsonParams().getKeys(), yq.getQname()); yq.addRequestParams(this.yadaReq.getRequestParamsForQueries(), index); yq.setAdaptorClass(this.qutils.getAdaptorClass(yq.getApp())); if (RESTAdaptor.class.equals(yq.getAdaptorClass()) && this.yadaReq.hasCookies()) { for (String cookieName : this.yadaReq.getCookies()) { for (Cookie cookie : this.yadaReq.getRequest().getCookies()) { if (cookie.getName().equals(cookieName)) { yq.addCookie(cookieName, Base64.encodeBase64String(Base64.decodeBase64(cookie.getValue().getBytes()))); } } } } //TODO handle missing params exceptions here, throw YADARequestException //TODO review instances where YADAQueryConfigurationException is thrown this.qutils.setProtocol(yq); yq.setAdaptor(this.qutils.getAdaptor(yq.getAdaptorClass(), this.yadaReq)); yq.setConformedCode(this.qutils.getConformedCode(yq.getYADACode())); for (int row = 0; row < yq.getData().size(); row++) { // TODO perhaps move this functionality to the deparsing step? yq.addDataTypes(row, this.qutils.getDataTypes(yq.getYADACode())); int paramCount = yq.getDataTypes().get(0).length; yq.addParamCount(row, paramCount); } return yq; }
From source file:org.ambraproject.admin.action.ManageVirtualJournalsActionTest.java
@Test(dataProvider = "basicInfo", dependsOnMethods = { "testExecute" }, alwaysRun = true) public void testRemoveVolumes(Journal journal, String currentIssue) throws Exception { List<Volume> initialVolumes = dummyDataStore.get(Journal.class, journal.getID()).getVolumes(); String[] urisToDelte = new String[] { initialVolumes.get(0).getVolumeUri(), initialVolumes.get(2).getVolumeUri() }; List<Volume> volumesToDelete = new ArrayList<Volume>(urisToDelte.length); for (Volume volume : initialVolumes) { if (ArrayUtils.indexOf(urisToDelte, volume.getVolumeUri()) != -1) { volumesToDelete.add(volume); }/*from ww w . j av a2s. c o m*/ } Map<String, Object> request = getDefaultRequestAttributes(); request.put(VirtualJournalContext.PUB_VIRTUALJOURNAL_CONTEXT, makeVirtualJournalContext(journal)); action.setRequest(request); action.setCommand("REMOVE_VOLUMES"); action.setVolsToDelete(urisToDelte); String result = action.execute(); assertEquals(result, Action.SUCCESS, "action didn't return success"); assertEquals(action.getActionMessages().size(), 1, "Action didn't return message indicating success"); assertEquals(action.getActionErrors().size(), 0, "Action returned error messages"); //check the return values on the action assertEquals(action.getVolumes().size(), initialVolumes.size() - 2, "action didn't remove volumes"); assertTrue(action.getActionMessages().size() > 0, "Action didn't add message for deleting volumes"); assertEquals(action.getActionErrors().size(), 0, "Action returned error messages"); List<Volume> storedVolumes = dummyDataStore.get(Journal.class, journal.getID()).getVolumes(); for (Volume deletedVolume : volumesToDelete) { assertFalse(storedVolumes.contains(deletedVolume), "Volume " + deletedVolume + " didn't get removed from journal"); assertNull(dummyDataStore.get(Volume.class, deletedVolume.getID()), "Volume didn't get removed from the database"); } }