List of usage examples for java.util List set
E set(int index, E element);
From source file:jp.co.golorp.emarf.sql.MetaData.java
/** * @param cn/* w w w . j a v a2s .co m*/ * ? * @param tableName * ?? * @return ???Set */ private static Set<String> getPrimaryKeys(final Connection cn, final String tableName) { List<String> pkList = null; ResultSet rs = null; try { // ?? DatabaseMetaData dmd = cn.getMetaData(); rs = dmd.getPrimaryKeys(null, null, tableName); while (rs.next()) { if (pkList == null) { pkList = new ArrayList<String>(); } String columnName = rs.getString("COLUMN_NAME"); // rdbms? 1,2,3, // sqlite?0,1,2, ?? int keySeq = rs.getShort("KEY_SEQ"); while (pkList.size() <= keySeq) { pkList.add(null); } pkList.set(keySeq, columnName); } } catch (SQLException e) { throw new SystemError(e); } finally { DbUtils.closeQuietly(rs); } List<String> primaryKeys = null; if (pkList != null) { for (String pk : pkList) { if (StringUtil.isNotBlank(pk)) { if (primaryKeys == null) { primaryKeys = new ArrayList<String>(); } primaryKeys.add(pk); } } } if (primaryKeys == null) { return null; } return new LinkedHashSet<String>(primaryKeys); }
From source file:eu.delving.sip.files.FileImporter.java
private void consumeCSVFile(InputStream inputStream, OutputStream outputStream) throws IOException, CancelException { BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); Writer writer = new OutputStreamWriter(outputStream, "UTF-8"); writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); writer.write("<csv-entries>\n"); char delimiter = ','; String line;//from ww w.j a v a2s .co m List<String> titles = null; int lineNumber = 0; while ((line = reader.readLine()) != null) { if (lineNumber == 0) { delimiter = csvDelimiter(line); titles = csvLineParse(line, delimiter); for (int walk = 0; walk < titles.size(); walk++) { titles.set(walk, csvTitleToTag(titles.get(walk), walk)); } } else { List<String> values = csvLineParse(line, delimiter); if (values.size() != titles.size()) { if (values.size() == 1 && values.get(0).isEmpty()) continue; throw new IOException( String.format("Expected %d fields in CSV file on line %d", titles.size(), lineNumber)); } writer.write(String.format("<csv-entry line=\"%d\">\n", lineNumber)); for (int walk = 0; walk < titles.size(); walk++) { writer.write(String.format(" <%s>%s</%s>\n", titles.get(walk), csvEscapeXML(values.get(walk)), titles.get(walk))); } writer.write("</csv-entry>\n"); } lineNumber++; showProgress(); } writer.write("</csv-entries>\n"); writer.close(); }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.RemoveRedundantVariablesRule.java
private boolean handleGroupByVarRemapping(GroupByOperator groupOp) { boolean modified = false; for (Pair<LogicalVariable, Mutable<ILogicalExpression>> gp : groupOp.getGroupByList()) { if (gp.first == null || gp.second.getValue().getExpressionTag() != LogicalExpressionTag.VARIABLE) { continue; }/*from w w w. ja v a2 s .c om*/ LogicalVariable groupByVar = ((VariableReferenceExpression) gp.second.getValue()) .getVariableReference(); Iterator<Pair<LogicalVariable, Mutable<ILogicalExpression>>> iter = groupOp.getDecorList().iterator(); while (iter.hasNext()) { Pair<LogicalVariable, Mutable<ILogicalExpression>> dp = iter.next(); if (dp.first != null || dp.second.getValue().getExpressionTag() != LogicalExpressionTag.VARIABLE) { continue; } LogicalVariable dv = ((VariableReferenceExpression) dp.second.getValue()).getVariableReference(); if (dv == groupByVar) { // The decor variable is redundant, since it is propagated as a grouping variable. List<LogicalVariable> equivalentVars = equivalentVarsMap.get(groupByVar); if (equivalentVars != null) { // Change representative of this equivalence class. equivalentVars.set(0, gp.first); equivalentVarsMap.put(gp.first, equivalentVars); } else { updateEquivalenceClassMap(gp.first, groupByVar); } iter.remove(); modified = true; break; } } } // find the redundant variables within the decor list Map<LogicalVariable, LogicalVariable> variableToFirstDecorMap = new HashMap<LogicalVariable, LogicalVariable>(); Iterator<Pair<LogicalVariable, Mutable<ILogicalExpression>>> iter = groupOp.getDecorList().iterator(); while (iter.hasNext()) { Pair<LogicalVariable, Mutable<ILogicalExpression>> dp = iter.next(); if (dp.first == null || dp.second.getValue().getExpressionTag() != LogicalExpressionTag.VARIABLE) { continue; } LogicalVariable dv = ((VariableReferenceExpression) dp.second.getValue()).getVariableReference(); LogicalVariable firstDecor = variableToFirstDecorMap.get(dv); if (firstDecor == null) { variableToFirstDecorMap.put(dv, dp.first); } else { // The decor variable dp.first is redundant since firstDecor is exactly the same. updateEquivalenceClassMap(dp.first, firstDecor); iter.remove(); modified = true; } } return modified; }
From source file:edu.rit.flick.config.FileArchiverExtensionRegistry.java
public synchronized void registerFileArchiverExtensions(final RegisterFileDeflatorInflator fileDIP) throws InstantiationException, IllegalAccessException { final List<String> extensions = Arrays.asList(fileDIP.inflatedExtensions()); for (int e = 0; e < extensions.size(); e++) { String extension = extensions.get(e); if (!extension.startsWith(".")) extension = "." + extension; if (extension.matches("\\.{2,}.+")) extension = extension.replaceFirst("\\.{2,}", "."); extensions.set(e, extension); }//from w w w .jav a 2s . co m for (final String extension : extensions) { registry.put(extension, new FileDeflatorInflator(fileDIP.fileDeflator().newInstance(), fileDIP.fileInflator().newInstance(), extensions)); } deflationOptionSets.add(fileDIP.fileDeflatorOptionSet().newInstance()); inflationOptionSets.add(fileDIP.fileInflatorOptionSet().newInstance()); }
From source file:ClassTree.java
/** * Constructs an ordered list starting at the highest (most general) class * in the tree and moving down the tree, ensuring no generalization comes * after one of its specializations./*from ww w. j ava2 s . c om*/ * @return a list ordered as above */ public List getOrderedList() { List list = new ArrayList(); list.add(getBottom()); buildList(getBottom(), list); Collections.sort(list); // Refactor list into a list of classes from a list of ClassTreeNodes for (int i = 0; i < list.size(); i++) { ClassTreeNode node = (ClassTreeNode) list.get(i); list.set(i, node.getObjectClass()); } // Reverse the list so that the top class in the hierarchy comes first Collections.reverse(list); return list; }
From source file:com.evolveum.midpoint.task.quartzimpl.work.segmentation.StringWorkSegmentationStrategy.java
private boolean incrementIndices(List<Integer> currentIndices) { assert boundaries.size() == currentIndices.size(); for (int i = currentIndices.size() - 1; i >= 0; i--) { int nextValue = currentIndices.get(i) + 1; if (nextValue < boundaries.get(i).length()) { currentIndices.set(i, nextValue); return true; } else {/*from ww w . ja v a2 s .c o m*/ currentIndices.set(i, 0); } } return false; }
From source file:com.google.gwt.emultest.java.util.ListTestBase.java
public void testListIteratorSetInSeveralPositions() { List l = makeEmptyList(); for (int n = 0; n < 5; n += 2) { l.add(new Integer(n)); }/* www. j a v a 2s . c om*/ l.listIterator(); for (int n = 0; n < 3; n++) { l.set(n, new Integer(n)); } for (int n = 0; n < 3; n++) { assertEquals(new Integer(n), l.get(n)); } }
From source file:com.google.sampling.experiential.server.MapServiceImpl.java
/** * @param experimentId/*from ww w . j a v a 2s . com*/ * @param justUser * @return */ private void getDailyResponseRateFor(Long experimentId, ExperimentStatsDAO accum, boolean justUser) { Map<DateMidnight, DateStat> dateStatsMap = Maps.newHashMap(); Map<DateMidnight, Set<String>> sevenDayMap = Maps.newHashMap(); int missedSignals = 0; long totalMillisToRespond = 0; String queryString = ""; if (justUser) { queryString = "who=" + getWho() + ":"; } List<EventDAO> events = getEventsForQuery(queryString + "experimentId=" + experimentId); for (EventDAO event : events) { if (event.isJoinEvent()) { continue; } if (event.isMissedSignal()) { missedSignals++; continue; } totalMillisToRespond += event.responseTime(); Date date = event.getResponseTime(); if (date == null) { date = event.getWhen(); } DateMidnight dateMidnight = new DateMidnight(date); // Daily response count DateStat currentStat = dateStatsMap.get(dateMidnight); if (currentStat == null) { currentStat = new DateStat(dateMidnight.toDate()); currentStat.addValue(new Double(1)); dateStatsMap.put(dateMidnight, currentStat); } else { List<Double> values = currentStat.getValues(); values.set(0, values.get(0) + 1); } // 7 day counts DateMidnight beginningOfWeekDateMidnight = getBeginningOfWeek(dateMidnight); Set<String> current7Day = sevenDayMap.get(beginningOfWeekDateMidnight); if (current7Day == null) { current7Day = Sets.newHashSet(); sevenDayMap.put(beginningOfWeekDateMidnight, current7Day); } current7Day.add(event.getWho()); } // daily response ArrayList<DateStat> dateStats = Lists.newArrayList(dateStatsMap.values()); Collections.sort(dateStats); for (DateStat dateStat : dateStats) { dateStat.computeStats(); } // 7 day count ArrayList<DateStat> sevenDayDateStats = Lists.newArrayList(); for (DateMidnight dateKey : sevenDayMap.keySet()) { int count = sevenDayMap.get(dateKey).size(); DateStat dateStat = new DateStat(dateKey.toDate()); dateStat.addValue(new Double(count)); sevenDayDateStats.add(dateStat); dateStat.computeStats(); } Collections.sort(sevenDayDateStats); DateStat[] dsArray = new DateStat[dateStats.size()]; accum.setDailyResponseRate(dateStats.toArray(dsArray)); dsArray = new DateStat[sevenDayDateStats.size()]; accum.setSevenDayDateStats(sevenDayDateStats.toArray(dsArray)); String responseRateStr = "0%"; int respondedSignals = events.size() - missedSignals; if (events.size() > 0) { float responseRate = ((float) respondedSignals / (float) events.size()) * 100; responseRateStr = Float.toString(responseRate) + "%"; } accum.setResponseRate(responseRateStr); float avgResponseTime = (float) totalMillisToRespond / (float) respondedSignals / 60000; accum.setResponseTime(Float.toString(Math.round(avgResponseTime))); }
From source file:de.bund.bfr.math.MathUtils.java
public static List<StartValues> createStartValuesList(List<ParamRange> ranges, int n, ToDoubleFunction<List<Double>> errorFunction, DoubleConsumer progessListener, ExecutionContext exec) throws CanceledExecutionException { List<StartValues> valuesList = new ArrayList<>(); for (int i = 0; i < n; i++) { valuesList.add(new StartValues(Collections.nCopies(ranges.size(), i + 1.0), Double.POSITIVE_INFINITY)); }//from w ww . jav a 2 s . c o m List<Integer> paramStepIndex = new ArrayList<>(Collections.nCopies(ranges.size(), 0)); boolean done = false; int allStepSize = 1; int count = 0; for (ParamRange range : ranges) { allStepSize *= range.getStepCount(); } while (!done) { List<Double> values = new ArrayList<>(); for (int i = 0; i < ranges.size(); i++) { values.add(ranges.get(i).getMin() + paramStepIndex.get(i) * ranges.get(i).getStepSize()); } double error = errorFunction.applyAsDouble(values); if (Double.isFinite(error) || error < valuesList.get(n - 1).getError()) { for (int i = 0; i < n; i++) { if (error < valuesList.get(i).getError()) { valuesList.add(i, new StartValues(values, error)); valuesList.remove(n); break; } } } for (int i = 0;; i++) { if (i >= ranges.size()) { done = true; break; } paramStepIndex.set(i, paramStepIndex.get(i) + 1); if (paramStepIndex.get(i) >= ranges.get(i).getStepCount()) { paramStepIndex.set(i, 0); } else { break; } } if (exec != null) { exec.checkCanceled(); } progessListener.accept((double) ++count / (double) allStepSize); } return valuesList; }
From source file:info.magnolia.module.admininterface.dialogs.UserEditDialog.java
/** * Is called during showDialog(). Here can you create/ add controls for the dialog. * * @param configNode// w w w. j a v a2 s . c om * @param storageNode * @throws javax.jcr.RepositoryException */ protected Dialog createDialog(Content configNode, Content storageNode) throws RepositoryException { Dialog dialog = super.createDialog(configNode, storageNode); // dont do anythig if command is "save" if (this.getCommand().equalsIgnoreCase(COMMAND_SAVE)) return dialog; // replace UUID with Path for groups and roles DialogControlImpl control = dialog.getSub("groups"); HierarchyManager groupsHM = MgnlContext.getSystemContext() .getHierarchyManager(ContentRepository.USER_GROUPS); List values = control.getValues(); for (int index = 0; index < values.size(); index++) { // replace uuid with path String uuid = (String) values.get(index); if (StringUtils.isEmpty(uuid)) continue; try { values.set(index, groupsHM.getContentByUUID(uuid).getHandle()); } catch (ItemNotFoundException e) { // remove invalid ID values.remove(index); } } control = dialog.getSub("roles"); HierarchyManager rolesHM = MgnlContext.getSystemContext().getHierarchyManager(ContentRepository.USER_ROLES); values = control.getValues(); for (int index = 0; index < values.size(); index++) { // replace uuid with path String uuid = (String) values.get(index); if (StringUtils.isEmpty(uuid)) continue; try { values.set(index, rolesHM.getContentByUUID(uuid).getHandle()); } catch (ItemNotFoundException e) { // remove invalid ID values.remove(index); } } return dialog; }