List of usage examples for java.util List indexOf
int indexOf(Object o);
From source file:hydrograph.ui.propertywindow.widgets.dialog.hiveInput.HiveFieldDialogHelper.java
/** * Refreshes key values colunm and its data * @param propertyList/*from w w w . ja va2 s. c om*/ * @param keyValues * @param isKeyDeleted */ public List<HivePartitionFields> refreshKeyColumnsAndValues(List<String> propertyList, List<HivePartitionFields> keyValues, List<String> colNames, boolean isKeyDeleted) { if (isKeyDeleted) { for (String deltedColumn : checkIfNewColumnAddedOrDeleted(new ArrayList<>(propertyList), colNames)) { for (HivePartitionFields tempRows : keyValues) { tempRows.getRowFields().remove(colNames.indexOf(deltedColumn)); } } } else { for (int i = 0; i < checkIfNewColumnAddedOrDeleted(colNames, new ArrayList<>(propertyList)) .size(); i++) { for (HivePartitionFields tempRows : keyValues) { tempRows.getRowFields().add(""); } } } return keyValues; }
From source file:de.iteratec.iteraplan.presentation.dialog.GraphicalReporting.Line.JFreeChartLineGraphicCreator.java
private int getIndexLastElementBeforeFromDate(List<TimeseriesEntry> entries) { int idx = -1; for (TimeseriesEntry entry : entries) { Date date = entry.getDate(); if (date.before(fromDate)) { int idxDate = entries.indexOf(entry); if (idx < 0) { idx = idxDate;//from w ww. j a v a 2 s.c om } else { if (date.after(entries.get(idx).getDate())) { idx = idxDate; } } } } return idx; }
From source file:com.adaptris.jdbc.connection.FailoverConnection.java
private boolean createConnection(int start, int end) { List<String> list = config.getConnectionUrls(); if (start >= list.size()) { return createConnection(START_OF_LIST, end); }/* w ww . j a v a2 s . co m*/ Iterator i = list.listIterator(start == START_OF_LIST || start + 1 >= list.size() ? 0 : start + 1); while (i.hasNext()) { String url = i.next().toString(); if (list.indexOf(url) > end) { break; } if (isDebugMode()) { logR.trace("Connection attempt to " + url); } try { sqlConnection = DriverManager.getConnection(url, mergeConnectionProperties( config.getConnectionProperties(), config.getUsername(), config.getPassword())); sqlConnection.setAutoCommit(config.getAutoCommit()); currentIndex = list.indexOf(url); if (isDebugMode()) { logR.trace("Connected to [" + currentIndex + "] " + url); } return true; } catch (SQLException e) { logR.trace("Could not connect to " + url); } catch (PasswordException e) { logR.warn("Could not decode password"); break; } } return false; }
From source file:org.eclipse.virgo.ide.runtime.internal.core.DefaultServerDeployer.java
/** * {@inheritDoc}//from w w w. j av a 2s .c o m */ public void deploy(IModule... modules) { List<IModule> orderedModules = Arrays.asList(modules); // make sure we honor the user configured order final List<String> orderedArtefacts = getArtefactOrder(); // sort the modules according the order defined in the server configuration Collections.sort(orderedModules, new Comparator<IModule>() { public int compare(IModule o1, IModule o2) { Integer m1 = (orderedArtefacts.contains(o1.getId()) ? orderedArtefacts.indexOf(o1.getId()) : Integer.MAX_VALUE); Integer m2 = (orderedArtefacts.contains(o2.getId()) ? orderedArtefacts.indexOf(o2.getId()) : Integer.MAX_VALUE); return m1.compareTo(m2); } }); for (IModule module : orderedModules) { DeploymentIdentity identity = executeDeployerCommand(getServerDeployCommand(module)); if (behaviour instanceof ServerBehaviour) { ((ServerBehaviour) behaviour).tail(identity); } behaviour.onModulePublishStateChange(new IModule[] { module }, IServer.PUBLISH_STATE_NONE); // if (identity != null) { // behaviour.onModuleStateChange(new IModule[] { module }, IServer.STATE_STARTED); // } // else { // behaviour.onModuleStateChange(new IModule[] { module }, IServer.STATE_STOPPED); // } } }
From source file:dk.dma.msinm.service.AreaService.java
/** * Changes the sort order of an area, by moving it up or down compared to siblings. * <p>/* w w w . j av a2s.c o m*/ * Please note that by moving "up" we mean in a geographical tree structure, * i.e. a smaller sortOrder value. * * @param areaId the id of the area to move * @param moveUp whether to move the area up or down * @return the updated area */ public Area changeSortOrder(Integer areaId, boolean moveUp) { Area area = getByPrimaryKey(Area.class, areaId); boolean updated = false; // Non-root case if (area.getParent() != null) { List<Area> siblings = area.getParent().getChildren(); int index = siblings.indexOf(area); if (moveUp) { if (index == 1) { area.setSortOrder(siblings.get(0).getSortOrder() - 10.0); updated = true; } else if (index > 1) { double so1 = siblings.get(index - 1).getSortOrder(); double so2 = siblings.get(index - 2).getSortOrder(); area.setSortOrder((so1 + so2) / 2.0); updated = true; } } else { if (index == siblings.size() - 2) { area.setSortOrder(siblings.get(siblings.size() - 1).getSortOrder() + 10.0); updated = true; } else if (index < siblings.size() - 2) { double so1 = siblings.get(index + 1).getSortOrder(); double so2 = siblings.get(index + 2).getSortOrder(); area.setSortOrder((so1 + so2) / 2.0); updated = true; } } } else { // TODO root case } if (updated) { log.info("Updates sort order for area " + area.getId() + " to " + area.getSortOrder()); // Save the entity area = saveEntity(area); // NB: Cache eviction not needed since lineage is the same... } return area; }
From source file:org.gvnix.service.roo.addon.addon.util.WsdlParserUtils.java
/** * Check compatible address element of the root. * <p>//from w w w . j av a 2 s . c o m * Should exists only one compatible address using SOAP protocol version 1.1 * or 1.2. * </p> * * @param root Root element of wsdl. * @return First compatible address element or null if no element. */ public static Element checkCompatibleAddress(Element root) { Validate.notNull(root, ROOT_ELEMENT_REQUIRED); // Find all address elements List<Element> addresses = XmlUtils.findElements(ADDRESSES_XPATH, root); // Separate on a list the addresses prefix List<String> prefixes = new ArrayList<String>(); for (int i = 0; i < addresses.size(); i++) { String nodeName = addresses.get(i).getNodeName(); prefixes.add(i, getNamespace(nodeName)); } // Separate on a list the addresses namespace List<String> namespaces = new ArrayList<String>(); for (int i = 0; i < prefixes.size(); i++) { namespaces.add(i, getNamespaceURI(root, prefixes.get(i))); } // Any namepace is a SOAP namespace with or whitout final slash ? boolean isSoap12Compatible = false; boolean isSoap11Compatible = false; int indexSoap12 = 0; int indexSoap11 = 0; if ((indexSoap12 = namespaces.indexOf(SOAP_12_NAMESPACE)) != -1 || (indexSoap12 = namespaces.indexOf(NAMESPACE_WITHOUT_SLASH_12)) != -1) { // First preference: SOAP 1.2 protocol isSoap12Compatible = true; } if ((indexSoap11 = namespaces.indexOf(SOAP_11_NAMESPACE)) != -1 || (indexSoap11 = namespaces.indexOf(NAMESPACE_WITHOUT_SLASH_11)) != -1) { if (isSoap12Compatible) { Validate.validState(false, "There are defined SOAP 1.1 and 1.2 protocols.\nMust be only one protocol defined."); } isSoap11Compatible = true; // Second preference: SOAP 1.1 protocol } int index = 0; if (isSoap12Compatible && !isSoap11Compatible) { index = indexSoap12; } else if (isSoap11Compatible && !isSoap12Compatible) { index = indexSoap11; } else { // Other protocols not supported return null; } return addresses.get(index); }
From source file:burstcoin.jminer.core.checker.util.OCLChecker.java
private void check() { List<cl_platform_id> platforms = Platforms.getPlatforms(); LOG.info("-------------------------------------------------------"); LOG.info("List of system openCL platforms and devices (* = used for mining)"); LOG.info(""); for (cl_platform_id cl_platform_id : platforms) { int currentPlatformId = platforms.indexOf(cl_platform_id); if (currentPlatformId == CoreProperties.getPlatformId()) { String selector = " * "; String selectionPrefix = currentPlatformId == CoreProperties.getPlatformId() ? selector : " "; LOG.info(selectionPrefix + "PLATFORM-[" + currentPlatformId + "] " + PlatformInfos.getName(cl_platform_id) + " - " + "(" + PlatformInfos.getVersion(cl_platform_id) + ")"); List<cl_device_id> devices = Devices.getDevices(cl_platform_id); for (cl_device_id cl_device_id : devices) { int currentDeviceId = devices.indexOf(cl_device_id); selectionPrefix = currentDeviceId == CoreProperties.getDeviceId() ? selector : " "; LOG.info(selectionPrefix + " DEVICE-[" + currentDeviceId + "] " + DeviceInfos.getName(cl_device_id) + " " + "(" + bytesAsGigabyte(DeviceInfos.getMaxMemAllocSize(cl_device_id)) + ")" + " - " + DeviceInfos.getVendor(cl_device_id) + " (" + DeviceInfos.getDeviceVersion(cl_device_id) + " | '" + DeviceInfos.getDriverVersion(cl_device_id) + "')"); LOG.info(selectionPrefix + " [" + currentDeviceId + "] " + "work group size: '" + DeviceInfos.getMaxWorkGroupSize(cl_device_id) + "', " + "computing units: '" + DeviceInfos.getMaxComputeUnits(cl_device_id) + "', " + "available '" + DeviceInfos.getAvailable(cl_device_id) + "'"); }// w ww . j a va 2 s . c o m } } }
From source file:cz.muni.fi.mir.db.service.impl.FormulaServiceImpl.java
/** * Method takes elements from formula and matches them against already * persisted list of elements. If element already exist then it has id in * obtained list (from database) and id for element in formula is set. * Otherwise we check temp list which contains newly created elements. If * there is no match then new element is created and stored in temp list. * Equals method somehow fails on CascadeType.ALL, so this is reason why we * have to do manually. TODO redo in future. Possible solution would be to * have all possible elements already stored inside database. * * @param f formula of which we attach elements. *///from w ww. java 2 s . com private void attachElements(Formula f) { if (f.getElements() != null && !f.getElements().isEmpty()) { List<Element> list = elementDAO.getAllElements(); List<Element> newList = new ArrayList<>(); for (Element e : f.getElements()) { int index = list.indexOf(e); if (index == -1) { int index2 = newList.indexOf(e); if (index2 == -1) { elementDAO.create(e); newList.add(e); } else { e.setId(newList.get(index2).getId()); } } else { e.setId(list.get(index).getId()); } } } }
From source file:ai.grakn.test.graql.shell.GraqlShellIT.java
private String[] specifyUniqueKeyspace(String[] args) { List<String> argList = Lists.newArrayList(args); int keyspaceIndex = argList.indexOf("-k") + 1; if (keyspaceIndex == 0) { argList.add("-k"); argList.add(GraqlShell.DEFAULT_KEYSPACE); keyspaceIndex = argList.size() - 1; }//from ww w . jav a 2 s. c o m argList.set(keyspaceIndex, argList.get(keyspaceIndex) + keyspaceSuffix); return argList.toArray(new String[argList.size()]); }
From source file:org.openlmis.fulfillment.service.OrderCsvHelper.java
private void writeCsvLineItem(Order order, OrderLineItem orderLineItem, List<OrderFileColumn> orderFileColumns, Writer writer, int counter) throws IOException { JXPathContext orderContext = JXPathContext.newContext(order); JXPathContext lineItemContext = JXPathContext.newContext(orderLineItem); for (OrderFileColumn orderFileColumn : orderFileColumns) { if (orderFileColumn.getNested() == null || orderFileColumn.getNested().isEmpty()) { if (orderFileColumns.indexOf(orderFileColumn) < orderFileColumns.size() - 1) { writer.write(","); }/*from w w w . j av a2 s.c o m*/ continue; } Object columnValue = getColumnValue(counter, orderContext, lineItemContext, orderFileColumn); if (columnValue instanceof ZonedDateTime) { columnValue = ((ZonedDateTime) columnValue).format(ofPattern(orderFileColumn.getFormat())); } else if (columnValue instanceof LocalDate) { columnValue = ((LocalDate) columnValue).format(ofPattern(orderFileColumn.getFormat())); } if (ENCLOSE_VALUES_WITH_QUOTES) { writer.write("\"" + (columnValue).toString() + "\""); } else { writer.write((columnValue).toString()); } if (orderFileColumns.indexOf(orderFileColumn) < orderFileColumns.size() - 1) { writer.write(","); } } }