@Test public void kmeans_test() throws IOException { File file = new File(filename); FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); String line; List<Vector<Double>> vectors = new ArrayList<Vector<Double>>(); List<Integer> oc = new ArrayList<Integer>(); while ((line = br.readLine()) != null) { String[] values = line.split(separator); Vector<Double> vector = new Vector<Double>(values.length - 1); for (int i = 0; i < values.length - 1; i++) { vector.add(i, Double.valueOf(values[i])); } vectors.add(vector); String clazz = values[values.length - 1]; if (clazz.equals("Iris-setosa")) { oc.add(0); } else if (clazz.equals("Iris-versicolor")) { oc.add(1); } else { oc.add(2); } } br.close(); fr.close(); Matrix matrix = new Matrix(vectors); KMeansClustering kmeans = new KMeansClustering(); int[] clusters = kmeans.cluster(matrix, 3); int[][] classMatrix = new int[3][3]; for (int i = 0; i < oc.size(); i++) { classMatrix[oc.get(i)][clusters[i]]++; } System.out.println(" setosa versicolor virginica"); System.out.println( "setosa " + classMatrix[0][0] + " " + classMatrix[0][1] + " " + classMatrix[0][2]); System.out.println( "versicolor " + classMatrix[1][0] + " " + classMatrix[1][1] + " " + classMatrix[1][2]); System.out.println( "virginica " + classMatrix[2][0] + " " + classMatrix[2][1] + " " + classMatrix[2][2]); System.out.println( "Rand index: " + new RandIndex().calculate(oc.toArray(new Integer[oc.size()]), clusters)); }
/** @param config */ public DecorateHandler(TagConfig config) { super(config); this.template = this.getRequiredAttribute("template"); this.handlers = new HashMap(); Iterator itr = this.findNextByType(DefineHandler.class); DefineHandler d = null; while (itr.hasNext()) { d = (DefineHandler) itr.next(); this.handlers.put(d.getName(), d); if (log.isLoggable(Level.FINE)) { log.fine(tag + " found Define[" + d.getName() + "]"); } } List paramC = new ArrayList(); itr = this.findNextByType(ParamHandler.class); while (itr.hasNext()) { paramC.add(itr.next()); } if (paramC.size() > 0) { this.params = new ParamHandler[paramC.size()]; for (int i = 0; i < this.params.length; i++) { this.params[i] = (ParamHandler) paramC.get(i); } } else { this.params = null; } }
public List<Shred> getShredsWithTagsInTagsList(List<String> tags) { StringBuilder shredId = new StringBuilder("SELECT s.Id FROM Shred s, TagsForShred tfs, Tag t "); shredId.append("WHERE tfs.ShredId = s.id AND tfs.TagId = t.Id AND "); shredId.append("("); for (int i = 0; i < tags.size() - 1; i++) { shredId.append(" t.Label='").append(tags.get(i)).append("' OR "); } shredId.append(" t.Label='").append(tags.get(tags.size() - 1)).append("' )"); shredId.append(" Group By ( s.id) HAVING (Count(s.id) >= ?)"); String selectShreds = "SELECT " + ShredderDAOImpl.SHREDDER_SQL + ", " + SHRED_SQL + " FROM Shred s," + " Rating r, Shredder sr, GuitarForShredder gs, " + " EquiptmentForShredder es WHERE r.ShredId = s.id AND " + "gs.ShredderId = sr.id AND es.ShredderId = sr.id AND s.Id IN (" + shredId.toString() + ") AND s.Owner = sr.id LIMIT " + NO_SHREDS_IN_RESULT_SET; long t1 = System.currentTimeMillis(); List<Shred> res = getShredsFromSQLString(selectShreds, new Object[] {tags.size()}, new ShredMapper()); System.out.println("Shreds by tags: " + (System.currentTimeMillis() - t1)); logger.info("Shreds by tags: " + (System.currentTimeMillis() - t1)); return res; }
@Test public void testUsingAnInQueryWithStringId() throws Exception { template.remove(new Query(), PersonWithIdPropertyOfTypeString.class); PersonWithIdPropertyOfTypeString p1 = new PersonWithIdPropertyOfTypeString(); p1.setFirstName("Sven"); p1.setAge(11); template.insert(p1); PersonWithIdPropertyOfTypeString p2 = new PersonWithIdPropertyOfTypeString(); p2.setFirstName("Mary"); p2.setAge(21); template.insert(p2); PersonWithIdPropertyOfTypeString p3 = new PersonWithIdPropertyOfTypeString(); p3.setFirstName("Ann"); p3.setAge(31); template.insert(p3); PersonWithIdPropertyOfTypeString p4 = new PersonWithIdPropertyOfTypeString(); p4.setFirstName("John"); p4.setAge(41); template.insert(p4); Query q1 = new Query(Criteria.where("age").in(11, 21, 41)); List<PersonWithIdPropertyOfTypeString> results1 = template.find(q1, PersonWithIdPropertyOfTypeString.class); Query q2 = new Query(Criteria.where("firstName").in("Ann", "Mary")); List<PersonWithIdPropertyOfTypeString> results2 = template.find(q2, PersonWithIdPropertyOfTypeString.class); Query q3 = new Query(Criteria.where("id").in(p3.getId(), p4.getId())); List<PersonWithIdPropertyOfTypeString> results3 = template.find(q3, PersonWithIdPropertyOfTypeString.class); assertThat(results1.size(), is(3)); assertThat(results2.size(), is(2)); assertThat(results3.size(), is(2)); }
public static VariableDeclarationFix createChangeModifierToFinalFix( final CompilationUnit compilationUnit, ASTNode[] selectedNodes) { HashMap writtenNames = new HashMap(); WrittenNamesFinder finder = new WrittenNamesFinder(writtenNames); compilationUnit.accept(finder); List ops = new ArrayList(); VariableDeclarationFinder visitor = new VariableDeclarationFinder(true, true, true, ops, writtenNames); if (selectedNodes.length == 1) { if (selectedNodes[0] instanceof SimpleName) { selectedNodes[0] = selectedNodes[0].getParent(); } selectedNodes[0].accept(visitor); } else { for (int i = 0; i < selectedNodes.length; i++) { ASTNode selectedNode = selectedNodes[i]; selectedNode.accept(visitor); } } if (ops.size() == 0) return null; CompilationUnitRewriteOperation[] result = (CompilationUnitRewriteOperation[]) ops.toArray(new CompilationUnitRewriteOperation[ops.size()]); String label; if (result.length == 1) { label = FixMessages.VariableDeclarationFix_changeModifierOfUnknownToFinal_description; } else { label = FixMessages.VariableDeclarationFix_ChangeMidifiersToFinalWherPossible_description; } return new VariableDeclarationFix(label, compilationUnit, result); }
/** Return all pairs of columns with the same type, and both are keys. */ private List<Pair<TableColumn, TableColumn>> getKeyPairs(List<TableInstance> tables) { List<Pair<TableColumn, TableColumn>> pairList = new LinkedList<Pair<TableColumn, TableColumn>>(); if (tables.size() == 1) { return pairList; } List<TableColumn> allKeys = new LinkedList<TableColumn>(); for (TableInstance t : tables) { allKeys.addAll(t.getKeyColumns()); } for (int i = 0; i < allKeys.size(); i++) { for (int j = i + 1; j < allKeys.size(); j++) { TableColumn key1 = allKeys.get(i); TableColumn key2 = allKeys.get(j); if (TableUtils.sameType(key1, key2)) { Pair<TableColumn, TableColumn> p = new Pair<TableColumn, TableColumn>(key1, key2); pairList.add(p); } } } return pairList; }
/** * Set the id associated with each quadrant. The quadrants are laid out: TopLeft, TopRight, Bottom * Left, Bottom Right * * @param keys */ public void setDivisionIds(List<Object> keys) { if (keys.size() > MAX_DIVISIONS) { throw new IllegalArgumentException("too many divisionIds: " + keys); } boolean needClear = getDivisionCount() != keys.size(); if (!needClear) { for (int i = 0; i < keys.size(); i++) { String divisionId = transformKeyToDivisionId(keys.get(i)); // different item or different place if (!mDivisionMap.containsKey(divisionId) || mDivisionMap.get(divisionId) != i) { needClear = true; break; } } } if (needClear) { mDivisionMap.clear(); mDivisionImages.clear(); int i = 0; for (Object key : keys) { String divisionId = transformKeyToDivisionId(key); mDivisionMap.put(divisionId, i); mDivisionImages.add(null); i++; } } }
@Transactional @Override public void doCrawl(String target) { List<PostServiceModel> serviceModels = new ArrayList<PostServiceModel>(); List<String> lines = WpUpdaterUtils.readLines(target); for (int i = 1, n = lines.size(); i < n; i += SKIP_SIZE) { String dmm = parseLineSafe(lines, n, i, 8); if (!StringUtils.isEmpty(dmm)) { PostServiceModel serviceModel = new PostServiceModel("xvideojpcon.ftl"); serviceModel.addCategorys("エロ動画"); serviceModel.setOrgPageUrl(target); serviceModel.setPostSourceUrl(parseLineSafe(lines, n, i, 1)); serviceModel.setPostTitle(parseLineSafe(lines, n, i, 2)); serviceModel.setPostImageUrl("http://rank.xvideo-jp.com/" + parseLineSafe(lines, n, i, 3)); serviceModel.addVideoUrls(dmm); serviceModels.add(serviceModel); log.debug(serviceModel.toString()); if (5 <= serviceModels.size()) { break; } } } postService.InsertPosts(serviceModels); }
@Override public String execute() throws Exception { ActionContext ctx = ActionContext.getContext(); ServletContext sc = (ServletContext) ctx.get(ServletActionContext.SERVLET_CONTEXT); ApplicationContext appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(sc); CourseManagerImpl cmi = (CourseManagerImpl) appContext.getBean("CourseManagerImpl"); StudentManagerImpl smi = (StudentManagerImpl) appContext.getBean("StuManagerImpl"); List cmiList = cmi.getCourses(); List smiList = smi.getStudents(); Map cmiMap = new HashMap(); Map smiMap = new HashMap(); for (int i = 0; i < cmiList.size(); i++) { Course course = (Course) cmiList.get(i); cmiMap.put(course.getCoursId(), course.getCoursName()); } for (int i = 0; i < smiList.size(); i++) { Student student = (Student) smiList.get(i); smiMap.put(student.getStuId(), student.getStuName()); } ActionContext actionContext = ActionContext.getContext(); Map session = actionContext.getSession(); session.put("cmiMap", cmiMap); session.put("smiMap", smiMap); return SUCCESS; }
/** * Does the configuration setup and schema parsing and setup. * * @param table_schema String * @param columnsToRead String */ private void setup(String table_schema) { if (table_schema == null) throw new RuntimeException( "The table schema must be defined as colname type, colname type. All types are hive types"); // create basic configuration for hdfs and hive conf = new Configuration(); hiveConf = new HiveConf(conf, SessionState.class); // parse the table_schema string List<String> types = HiveRCSchemaUtil.parseSchemaTypes(table_schema); List<String> cols = HiveRCSchemaUtil.parseSchema(pcols, table_schema); List<FieldSchema> fieldSchemaList = new ArrayList<FieldSchema>(cols.size()); for (int i = 0; i < cols.size(); i++) { fieldSchemaList.add( new FieldSchema(cols.get(i), HiveRCSchemaUtil.findPigDataType(types.get(i)))); } pigSchema = new ResourceSchema(new Schema(fieldSchemaList)); props = new Properties(); // setting table schema properties for ColumnarSerDe // these properties are never changed by the columns to read filter, // because the columnar serde needs to now the // complete format of each record. props.setProperty(Constants.LIST_COLUMNS, HiveRCSchemaUtil.listToString(cols)); props.setProperty(Constants.LIST_COLUMN_TYPES, HiveRCSchemaUtil.listToString(types)); }
@Override protected Double modifyARG() throws InvalidParameterValueException, IllegalModificationException, ModificationImpossibleException { List<ARGNode> internalNodes = arg.getInternalNodes(); int nodeNum = RandomSource.getNextIntFromTo(0, internalNodes.size() - 1); ARGNode node = internalNodes.get(nodeNum); if (internalNodes.size() == 1) // Must be two tips, no recomb nodes throw new ModificationImpossibleException("No internal nodes to modify"); // Pick a node that is not the root while (node.getParent(0) == null) { node = internalNodes.get(RandomSource.getNextIntFromTo(0, internalNodes.size() - 1)); } double hr; if (node instanceof CoalNode) { hr = swapCoalNode((CoalNode) node); } else { hr = swapRecombNode((RecombNode) node); } return hr; }
@Test public void testCumSumList_DoubleList() { logger.info("\ntesting cumsumList(List<Double> input)"); List<Double> result = null; List<Double> input = null; assertEquals(0, MathUtil.cumsumList(input).size()); assertEquals(true, MathUtil.cumsumList(input).isEmpty()); input = new ArrayList<Double>(); assertEquals(0, MathUtil.cumsumList(input).size()); assertEquals(true, MathUtil.cumsumList(input).isEmpty()); input.add(4.0); result = MathUtil.cumsumList(input); assertEquals(1, result.size()); assertEquals(4.0, result.get(0), 0.0); input.add(1.0); input.add(8.0); input.add(-3.0); result = MathUtil.cumsumList(input); assertEquals(4, result.size()); assertEquals(4.0, result.get(0), 0.0); assertEquals(5.0, result.get(1), 0.0); assertEquals(13.0, result.get(2), 0.0); assertEquals(10.0, result.get(3), 0.0); List input2 = new ArrayList<Integer>(); input2.add(1); input2.add(2); // List result2 = ListArrayUtil.cumsumList(input2); // logger.debug(toolbox.ListArrayUtil.listToString(input2)); }
public static String getLastLoggedString() { if (logStrings.size() > 0) { return logStrings.get(logStrings.size() - 1); } else { return null; } }
public void doExecute(Environment env) throws CommandException { if (table == null || field == null || value == null) { Set nextLinkStaffSet = env.getNextLinkStaffSet(); Iterator iterator = nextLinkStaffSet.iterator(); // TODO:现有的方式是仅仅获取第一个节点,同步此节点上的状态 if (iterator.hasNext()) { LinkStaffModel linkStaff = (LinkStaffModel) iterator.next(); List nodeStateList = linkStaff.getLink().getNextNode().getNodeStateList(); if (nodeStateList != null && nodeStateList.size() > 0) { NodeStateModel nodeState = (NodeStateModel) nodeStateList.get(0); // TODO:仅仅获取任意的节点状态 table = nodeState.getBindState().getTableId(); field = nodeState.getBindState().getFieldId(); value = nodeState.getStateValue(); } else { List linkStateList = linkStaff.getLink().getLinkStateList(); // 取节点上的状态 if (linkStateList != null && linkStateList.size() > 0) { LinkStateModel linkState = (LinkStateModel) linkStateList.get(0); // TODO:仅仅获取任意的路径状态 table = linkState.getBindState().getTableId(); field = linkState.getBindState().getFieldId(); value = linkState.getStateValue(); } } } } if (table != null && field != null && value != null) { WFRuntimeMapper dao = WFDaoFactory.getWFRuntimeDao(); dao.updateBusinessState(table, field, value, env.getInstance().getInstanceId()); } }
@Test public void testUsingUpdateWithMultipleSet() throws Exception { template.remove(new Query(), PersonWithIdPropertyOfTypeObjectId.class); PersonWithIdPropertyOfTypeObjectId p1 = new PersonWithIdPropertyOfTypeObjectId(); p1.setFirstName("Sven"); p1.setAge(11); template.insert(p1); PersonWithIdPropertyOfTypeObjectId p2 = new PersonWithIdPropertyOfTypeObjectId(); p2.setFirstName("Mary"); p2.setAge(21); template.insert(p2); Update u = new Update().set("firstName", "Bob").set("age", 10); WriteResult wr = template.updateMulti(new Query(), u, PersonWithIdPropertyOfTypeObjectId.class); assertThat(wr.getN(), is(2)); Query q1 = new Query(Criteria.where("age").in(11, 21)); List<PersonWithIdPropertyOfTypeObjectId> r1 = template.find(q1, PersonWithIdPropertyOfTypeObjectId.class); assertThat(r1.size(), is(0)); Query q2 = new Query(Criteria.where("age").is(10)); List<PersonWithIdPropertyOfTypeObjectId> r2 = template.find(q2, PersonWithIdPropertyOfTypeObjectId.class); assertThat(r2.size(), is(2)); for (PersonWithIdPropertyOfTypeObjectId p : r2) { assertThat(p.getAge(), is(10)); assertThat(p.getFirstName(), is("Bob")); } }
@Test public void testUsingRegexQueryWithOptions() throws Exception { template.remove(new Query(), PersonWithIdPropertyOfTypeObjectId.class); PersonWithIdPropertyOfTypeObjectId p1 = new PersonWithIdPropertyOfTypeObjectId(); p1.setFirstName("Sven"); p1.setAge(11); template.insert(p1); PersonWithIdPropertyOfTypeObjectId p2 = new PersonWithIdPropertyOfTypeObjectId(); p2.setFirstName("Mary"); p2.setAge(21); template.insert(p2); PersonWithIdPropertyOfTypeObjectId p3 = new PersonWithIdPropertyOfTypeObjectId(); p3.setFirstName("Ann"); p3.setAge(31); template.insert(p3); PersonWithIdPropertyOfTypeObjectId p4 = new PersonWithIdPropertyOfTypeObjectId(); p4.setFirstName("samantha"); p4.setAge(41); template.insert(p4); Query q1 = new Query(Criteria.where("firstName").regex("S.*")); List<PersonWithIdPropertyOfTypeObjectId> results1 = template.find(q1, PersonWithIdPropertyOfTypeObjectId.class); Query q2 = new Query(Criteria.where("firstName").regex("S.*", "i")); List<PersonWithIdPropertyOfTypeObjectId> results2 = template.find(q2, PersonWithIdPropertyOfTypeObjectId.class); assertThat(results1.size(), is(1)); assertThat(results2.size(), is(2)); }
private static UserOperation getOperationFromElement(Element e) { UserOperation op = new UserOperation(); op.setName(e.getAttribute("name")); op.setVerb(e.getAttribute("verb")); op.setPath(e.getAttribute("path")); op.setOneway(Boolean.parseBoolean(e.getAttribute("oneway"))); op.setConsumes(e.getAttribute("consumes")); op.setProduces(e.getAttribute("produces")); List<Element> paramEls = DOMUtils.findAllElementsByTagNameNS(e, "http://cxf.apache.org/jaxrs", "param"); List<Parameter> params = new ArrayList<Parameter>(paramEls.size()); for (int i = 0; i < paramEls.size(); i++) { Element paramEl = paramEls.get(i); Parameter p = new Parameter(paramEl.getAttribute("type"), i, paramEl.getAttribute("name")); p.setEncoded(Boolean.valueOf(paramEl.getAttribute("encoded"))); p.setDefaultValue(paramEl.getAttribute("defaultValue")); String pClass = paramEl.getAttribute("class"); if (!StringUtils.isEmpty(pClass)) { try { p.setJavaType(ClassLoaderUtils.loadClass(pClass, ResourceUtils.class)); } catch (Exception ex) { throw new RuntimeException(ex); } } params.add(p); } op.setParameters(params); return op; }
private void maybeCastArguments(List<Expression> args, List<ITypeBinding> argTypes) { // Possible varargs, don't cast vararg arguments. assert args.size() >= argTypes.size(); for (int i = 0; i < argTypes.size(); i++) { maybeAddCast(args.get(i), argTypes.get(i), false); } }
/** Create the frame */ private Object[][] getFileStates(List list) { Object[][] results = new Object[list.size()][columnNames.length]; for (int i = 0; i < list.size(); i++) { Salesman reader = (Salesman) list.get(i); // results[i][0]=reader.getId(); results[i][0] = reader.getName(); String sex; if (reader.getSex().equals("1")) { sex = "男"; } else sex = "女"; results[i][1] = sex; results[i][2] = reader.getAge(); results[i][3] = reader.getIdentityCard(); results[i][4] = reader.getDate(); results[i][5] = reader.getMaxNum(); results[i][6] = reader.getTel(); results[i][7] = reader.getKeepMoney(); results[i][8] = array[reader.getZj()]; results[i][9] = reader.getZy(); results[i][10] = reader.getISBN(); results[i][11] = reader.getBztime(); } return results; }
/** * 松开的时候 * * @param move */ private void actionUp(int move) { int newMove = 0; if (move > 0) { for (int i = 0; i < itemList.size(); i++) { if (itemList.get(i).isSelected()) { newMove = (int) itemList.get(i).moveToSelected(); if (onSelectListener != null) onSelectListener.endSelect(itemList.get(i).id, itemList.get(i).itemText); break; } } } else { for (int i = itemList.size() - 1; i >= 0; i--) { if (itemList.get(i).isSelected()) { newMove = (int) itemList.get(i).moveToSelected(); if (onSelectListener != null) onSelectListener.endSelect(itemList.get(i).id, itemList.get(i).itemText); break; } } } for (ItemObject item : itemList) { item.newY(move + 0); } slowMove(newMove); Message rMessage = new Message(); rMessage.what = REFRESH_VIEW; handler.sendMessage(rMessage); }
@Override public void addValue(final int index, final FeatureValue fvalue) { Preconditions.checkArgument(fvalue != null, "fvalue is null"); Preconditions.checkArgument( index <= values.size() && index >= 0, "index is not in range of: 0 and " + values.size()); values.add(index, fvalue); }
protected String getDefaultType(int level, int maxDepth) { List<String> types = getRequirementTypes(); // Flat structure: maxdepth 0 // cap, feature | level 0 => [1] // cap, feature,story | level 0 => [2] // 1-layer structure: maxdepth 1 // cap, feature | level 0 => [0] // cap, feature | level 1 => [1] // cap, feature,story | level 0 => [1] // cap, feature,story | level 1 => [2] // 2-layer structure: maxdepth 2 // cap, feature, story | level 0 => [0] // cap, feature, story | level 1 => [1] // cap, feature, story | level 2 => [2] int relativeLevel = types.size() - 1 - maxDepth + level; if (relativeLevel > types.size() - 1) { return types.get(types.size() - 1); } else if (relativeLevel >= 0) { return types.get(relativeLevel); } else { return types.get(0); } }
@Override public void observe(Event event) { if (event instanceof MoveSelectedEvent) { Move theMove = ((MoveSelectedEvent) event).getMove(); if (theQueue.size() < 2) { theQueue.add(theMove); } } else if (event instanceof ServerNewGameStateEvent) { stateFromServer = ((ServerNewGameStateEvent) event).getState(); } else if (event instanceof ServerCompletedMatchEvent) { theGUI.updateGameState(stateFromServer); List<Role> theRoles = getStateMachine().getRoles(); List<Integer> theGoals = ((ServerCompletedMatchEvent) event).getGoals(); StringBuilder finalMessage = new StringBuilder(); finalMessage.append("Goals: "); for (int i = 0; i < theRoles.size(); i++) { finalMessage.append(theRoles.get(i)); finalMessage.append(" = "); finalMessage.append(theGoals.get(i)); if (i < theRoles.size() - 1) { finalMessage.append(", "); } } theGUI.showFinalMessage(finalMessage.toString()); } }
@Override public String toString() { StringBuilder builder = new StringBuilder(); for (Object modifier : modifiers) { builder.append(modifier).append(' '); } if (extraTypeInfo != null) { builder.append(extraTypeInfo).append(' '); } builder.append(name).append('('); int length = parameterList.size(); for (int i = 0; i < length - 1; i++) { builder.append(parameterList.get(i)).append(", "); } if (length > 0) builder.append(parameterList.get(length - 1)); builder.append(')'); length = throwTypes.size(); if (length > 0) { builder.append(" throws "); for (int i = 0; i < length - 1; i++) { builder.append(throwTypes.get(i)).append(", "); } builder.append(throwTypes.get(length - 1)); } return builder.toString(); }
/** * Return all pairs that is not in the same table but with the same type and the same column name */ private List<Pair<TableColumn, TableColumn>> getNameMatchedPairs(List<TableInstance> tables) { if (tables.size() == 1) { return null; } List<Pair<TableColumn, TableColumn>> pairs = new LinkedList<Pair<TableColumn, TableColumn>>(); List<TableColumn> allColumns = new LinkedList<TableColumn>(); for (TableInstance t : tables) { allColumns.addAll(t.getColumns()); } for (int i = 0; i < allColumns.size(); i++) { for (int j = i; j < allColumns.size(); j++) { TableColumn c1 = allColumns.get(i); TableColumn c2 = allColumns.get(j); if (c1.isKey() && c2.isKey()) { continue; } if (TableUtils.sameType(c1, c2) && !c1.getTableName().equals(c2.getTableName()) && this.columnMatched(c1, c2)) { Pair<TableColumn, TableColumn> p = new Pair<TableColumn, TableColumn>(c1, c2); pairs.add(p); } } } return pairs; }
public RunInNewJVMStatment( String classPath, List<String> arguments, Class<?> testClass, List<FrameworkMethod> beforeFrameworkMethods, FrameworkMethod testFrameworkMethod, List<FrameworkMethod> afterFrameworkMethods) { _classPath = classPath; _arguments = arguments; _testClassName = testClass.getName(); _beforeMethodKeys = new ArrayList<MethodKey>(beforeFrameworkMethods.size()); for (FrameworkMethod frameworkMethod : beforeFrameworkMethods) { _beforeMethodKeys.add(new MethodKey(frameworkMethod.getMethod())); } _testMethodKey = new MethodKey(testFrameworkMethod.getMethod()); _afterMethodKeys = new ArrayList<MethodKey>(afterFrameworkMethods.size()); for (FrameworkMethod frameworkMethod : afterFrameworkMethods) { _afterMethodKeys.add(new MethodKey(frameworkMethod.getMethod())); } }
/** * Creates a list of names separated by commas or an and symbol if its the last separation. This * is then used to say hello to the list of names. * * <p>i.e. if the input was {John, Mary, Luke} the output would be John, Mary & Luke * * @param names A list of names * @return The list of names separated as described above. */ private String createNameListString(final List<String> names) { /* * If the list is null or empty then assume the call was anonymous. */ if (names == null || names.isEmpty()) { return "Anonymous!"; } final StringBuilder nameBuilder = new StringBuilder(); for (int i = 0; i < names.size(); i++) { /* * Add the separator if its not the first string or the last separator since that should be an and (&) symbol. */ if (i != 0 && i != names.size() - 1) nameBuilder.append(", "); else if (i != 0 && i == names.size() - 1) nameBuilder.append(" & "); nameBuilder.append(names.get(i)); } nameBuilder.append("!"); return nameBuilder.toString(); }
private Path resolveChildPath(Path parent, final String childPattern) { String[] list = parent .toFile() .list( new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.matches(childPattern); } }); if (list == null) throw new IllegalStateException("No files matched, for pattern [" + childPattern + "]"); List<String> results = Arrays.asList(list); if (results.isEmpty()) throw new IllegalStateException("No files matched, for pattern [" + childPattern + "]"); if (results.size() > 1) throw new IllegalStateException( "Expected a single result for pattern [" + childPattern + "], but got [" + results.size() + "]: " + results); return parent.resolve(results.get(0)); }
public String[] getNewsTitles() { String[] titles = new String[newsArticles.size()]; for (int i = 0; i < newsArticles.size(); i++) { titles[i] = Utils.toTitleCase(Html.fromHtml(newsArticles.get(i).getTitle()).toString()); } return titles; }
/** Create a block that contains the indicated stimuli. */ private static Block createBlock(List<Stimulus> stimuli, boolean training) { List<TrialGroup> trialGroups = new ArrayList<TrialGroup>(); ; List<Trial> trialsInCurrentTrialGroup = new ArrayList<Trial>(); Collections.shuffle( stimuli); // randomize stimulusorder to the order in which they will be displayed in this // block // go through all stimuli for (Stimulus s : stimuli) { if (trialsInCurrentTrialGroup.size() < Options.trialsPerTrialGroup) { // still working on the current trialGroup trialsInCurrentTrialGroup.add(new Trial(s)); } if (trialsInCurrentTrialGroup.size() == Options .trialsPerTrialGroup) { // current trialGroup is complete, create it and start a new // one trialGroups.add(new TrialGroup(trialsInCurrentTrialGroup, training)); trialsInCurrentTrialGroup.clear(); } } return new Block(trialGroups); }