/** * Method getDouble returns the element at the given position i as a double. Zero if null. * * @param pos of type int * @return double */ public double getDouble(int pos) { Comparable value = get(pos); if (value instanceof Number) return ((Number) value).doubleValue(); else if (value == null) return 0; else return Double.parseDouble(value.toString()); }
/** * Method getFloat returns the element at the given position i as a float. Zero if null. * * @param pos of type int * @return float */ public float getFloat(int pos) { Comparable value = get(pos); if (value instanceof Number) return ((Number) value).floatValue(); else if (value == null) return 0; else return Float.parseFloat(value.toString()); }
/** * Method getLong returns the element at the given position i as an long. Zero if null. * * @param pos of type int * @return long */ public long getLong(int pos) { Comparable value = get(pos); if (value instanceof Number) return ((Number) value).longValue(); else if (value == null) return 0; else return Long.parseLong(value.toString()); }
/** * Method getInteger returns the element at the given position i as an int. Zero if null. * * @param pos of type int * @return int */ public int getInteger(int pos) { Comparable value = get(pos); if (value instanceof Number) return ((Number) value).intValue(); else if (value == null) return 0; else return Integer.parseInt(value.toString()); }
public static String initcap(Comparable<?> param) throws ParseException { if (param == null) { return null; } String inputStr = param.toString(); StringBuilder output = new StringBuilder(inputStr); boolean needUpper = true; final int len = inputStr.length(); for (int i = 0; i < len; i++) { char c = inputStr.charAt(i); if (needUpper && Character.isLetter(c)) { if (Character.isLowerCase(c)) { output.setCharAt(i, Character.toUpperCase(c)); } needUpper = false; } else if (!needUpper) { if (!Character.isLetterOrDigit(c)) { needUpper = true; } else if (Character.isUpperCase(c)) { output.setCharAt(i, Character.toLowerCase(c)); } } } return output.toString(); }
/** * Method getShort returns the element at the given position i as an short. Zero if null. * * @param pos of type int * @return long */ public short getShort(int pos) { Comparable value = get(pos); if (value instanceof Number) return ((Number) value).shortValue(); else if (value == null) return 0; else return Short.parseShort(value.toString()); }
/** * Method getBoolean returns the element at the given position as a boolean. If the value is (case * ignored) the string 'true', a {@code true} value will be returned. {@code false} if null. * * @param pos of type int * @return boolean */ public boolean getBoolean(int pos) { Comparable value = get(pos); if (value instanceof Boolean) return ((Boolean) value).booleanValue(); else if (value == null) return false; else return Boolean.parseBoolean(value.toString()); }
/** * Method getString returns the element at the given position i as a String. * * @param pos of type int * @return String */ public String getString(int pos) { Comparable value = get(pos); if (value == null) return null; return value.toString(); }
public String generateSectionLabel(final PieDataset dataset, final Comparable key) { String temp = null; if (dataset != null) { temp = key.toString(); temp = temp.toUpperCase(); } return temp; }
public static String testFPFlimsyIfGuard(Comparable<?> c, boolean isNumber) { String s = c.toString(); if (isNumber) { Number n = (Number) c; s += n.intValue(); } return s; }
/** * Creates a label. * * @param category the category. * @param width the available width. * @param edge the edge on which the axis appears. * @param g2 the graphics device. * @return A label. */ protected TextBlock createLabel( Comparable category, float width, RectangleEdge edge, Graphics2D g2) { TextBlock label = TextUtilities.createTextBlock( category.toString(), getTickLabelFont(category), getTickLabelPaint(category), width, this.maximumCategoryLabelLines, new G2TextMeasurer(g2)); return label; }
/** * Build a properties out of several locations. * * @param configs * @param locations */ static void build(Properties configs, Comparable[] locations) { List<Comparable> listLocations = Arrays.asList(locations); // sort by priority. Collections.sort(listLocations); // reverse the list so we can load from low priority to high priority. Collections.reverse(listLocations); for (Comparable comparable : listLocations) { Properties props = PropertiesLoader.loadFromFileResource(comparable.toString()); configs.putAll(props); } }
protected void customIncrement() { if (timeSeries != null && timeSeries.length > 0) { if (seriesNames == null) { seriesNames = new ArrayList<Comparable<?>>(); seriesMap = new HashMap<Comparable<?>, TimeSeries>(); labelsMap = new HashMap<Comparable<?>, Map<RegularTimePeriod, String>>(); itemHyperlinks = new HashMap<Comparable<?>, Map<RegularTimePeriod, JRPrintHyperlink>>(); } for (int i = 0; i < timeSeries.length; i++) { JRFillTimeSeries crtTimeSeries = timeSeries[i]; Comparable<?> seriesName = crtTimeSeries.getSeries(); if (seriesName == null) { throw new JRRuntimeException("Time series name is null."); } TimeSeries series = seriesMap.get(seriesName); if (series == null) { series = new TimeSeries(seriesName.toString(), getTimePeriod()); seriesNames.add(seriesName); seriesMap.put(seriesName, series); } RegularTimePeriod tp = RegularTimePeriod.createInstance( getTimePeriod(), crtTimeSeries.getTimePeriod(), getTimeZone()); series.addOrUpdate(tp, crtTimeSeries.getValue()); if (crtTimeSeries.getLabelExpression() != null) { Map<RegularTimePeriod, String> seriesLabels = labelsMap.get(seriesName); if (seriesLabels == null) { seriesLabels = new HashMap<RegularTimePeriod, String>(); labelsMap.put(seriesName, seriesLabels); } seriesLabels.put(tp, crtTimeSeries.getLabel()); } if (crtTimeSeries.hasItemHyperlink()) { Map<RegularTimePeriod, JRPrintHyperlink> seriesLinks = itemHyperlinks.get(seriesName); if (seriesLinks == null) { seriesLinks = new HashMap<RegularTimePeriod, JRPrintHyperlink>(); itemHyperlinks.put(seriesName, seriesLinks); } seriesLinks.put(tp, crtTimeSeries.getPrintItemHyperlink()); } } } }
/** * A recursive method that walks up the tree of pivot fields/values to build a list of the String * representations of the values that lead down to this PivotFacetValue. * * @return a mutable List of the pivot value Strings leading down to and including this pivot * value, will never be null but may contain nulls * @see PivotFacetField#getValuePath */ public List<String> getValuePath() { List<String> out = parentPivot.getValuePath(); // Note: this code doesn't play nice with custom FieldTypes -- see SOLR-6330 if (null == value) { out.add(null); } else if (value instanceof Date) { out.add(DateFormatUtil.formatExternal((Date) value)); } else { out.add(value.toString()); } return out; }
Comparable<?> coerceValue(Comparable<?> value, Class targetClass) { if (value == null) return null; if (value.getClass() == targetClass) return value; // FIXME: For now we convert by first converting the source value to a // string and then converting to the target type. This logic probably needs // another pass to make it more robust/optimized. String s = value.toString(); Comparable<?> obj = null; try { if (targetClass == Integer.class) { obj = new Integer(s); } else if (targetClass == Long.class) { obj = new Long(s); } else if (targetClass == Short.class) { obj = new Short(s); } else if (targetClass == Boolean.class) { obj = new Boolean(s); } else if (targetClass == Float.class) { obj = new Float(s); } else if (targetClass == Double.class) { obj = new Double(s); } else if (targetClass == Byte.class) { obj = new Byte(s); } else if (targetClass == String.class) { obj = s; } else if (targetClass == Date.class) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); try { obj = dateFormat.parse(s); } catch (ParseException exc) { throw new TypeMismatchStorageException( Date.class.getName(), value.getClass().getName(), "???"); } } } catch (Exception exc) { // Ignore the exception here. In this case obj will not be set, so we'll // throw the StorageException below when we check for a null obj. } if (obj == null) throw new StorageException("Column value could not be coerced to the correct type"); return obj; }
@Override public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { // Grab comparables from the ScriptEntry List<Comparable> comparables = (List<Comparable>) scriptEntry.getObject("comparables"); int counter = 1; // Evaluate comparables for (Comparable com : comparables) { com.determineOutcome(); // Show outcome of Comparable dB.echoDebug( scriptEntry, ChatColor.YELLOW + "Comparable " + counter + ": " + ChatColor.WHITE + com.toString()); counter++; } // Compare outcomes int ormet = 0; for (Comparable comparable : comparables) { if (comparable.bridge == Comparable.Bridge.OR) if (comparable.outcome) ormet++; } int andcount = 0; int andmet = 0; for (Comparable comparable : comparables) { if (comparable.bridge == Comparable.Bridge.AND) { if (comparable.outcome) andmet++; andcount++; } } boolean do_then; if (comparables.size() > 1) { do_then = (ormet > 0) || (andcount == andmet && comparables.get(0).outcome == true); } else do_then = comparables.get(0).outcome; // Determine outcome -- then, or else? if (do_then) { // dB.log("then: " + scriptEntry.getObject("then-outcome").toString()); doCommand(scriptEntry, "then-outcome"); } else { // dB.log("else: " + scriptEntry.getObject("else-outcome").toString()); doCommand(scriptEntry, "else-outcome"); } }
public String generateSectionLabel(final PieDataset dataset, final Comparable key) { String temp = null; if (dataset != null) { temp = key.toString(); temp = temp.toUpperCase() + " (" + (int) Double.parseDouble((String) vals.get(temp)) + " = " + PERCENT_FORMAT.format(Double.parseDouble((String) vals.get(temp)) * 100 / total) + "%)"; } return temp; }
/** * Returns the maximum of the relevant dimension (height or width) of the subcategory labels. * * @param g2 the graphics device. * @param edge the edge. * @return The maximum dimension. */ private double getMaxDim(Graphics2D g2, RectangleEdge edge) { double result = 0.0; g2.setFont(this.subLabelFont); FontMetrics fm = g2.getFontMetrics(); for (Comparable subcategory : this.subCategories) { String label = subcategory.toString(); Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm); double dim = 0.0; if (RectangleEdge.isLeftOrRight(edge)) { dim = bounds.getWidth(); } else { // must be top or bottom dim = bounds.getHeight(); } result = Math.max(result, dim); } return result; }
/** * Redefinici�n de toString * * @return representaci�n del contenido del nodo como un String */ public String toString() { return info.toString(); }
@Override public Document getXmlContent() { // Create a document that describes the result Document result = DocumentHelper.createDocument(); IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); setXslProperty( "baseUrl", requestContext.getContextPath()); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ setXslProperty( "fullyQualifiedServerUrl", PentahoSystem.getApplicationContext() .getFullyQualifiedServerURL()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ String mapName = "chart" + AbstractChartComponent.chartCount++; // $NON-NLS-1$ Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ); if (chartDefinition == null) { Element errorElement = result.addElement("error"); // $NON-NLS-1$ errorElement .addElement("title") .setText( Messages.getInstance() .getString( "ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$ // //$NON-NLS-2$ String message = Messages.getInstance() .getString( "CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", definitionPath); // $NON-NLS-1$ errorElement.addElement("message").setText(message); // $NON-NLS-1$ error(message); return result; } // create a pie definition from the XML definition dataDefinition = createChart(chartDefinition); if (dataDefinition == null) { Element errorElement = result.addElement("error"); // $NON-NLS-1$ errorElement .addElement("title") .setText( Messages.getInstance() .getString( "ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$ // //$NON-NLS-2$ String message = Messages.getInstance() .getString( "CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ errorElement.addElement("message").setText(message); // $NON-NLS-1$ // System .out.println( result.asXML() ); return result; } // create an image for the dial using the JFreeChart engine PrintWriter printWriter = new PrintWriter(new StringWriter()); // we'll dispay the title in HTML so that the dial image does not have // to // accommodate it String chartTitle = ""; // $NON-NLS-1$ try { if (width == -1) { width = Integer.parseInt( chartDefinition.selectSingleNode("/chart/width").getText()); // $NON-NLS-1$ } if (height == -1) { height = Integer.parseInt( chartDefinition.selectSingleNode("/chart/height").getText()); // $NON-NLS-1$ } } catch (Exception e) { // go with the default } if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$ urlTemplate = chartDefinition .selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) .getText(); //$NON-NLS-1$ } if (chartDefinition.selectSingleNode("/chart/paramName") != null) { // $NON-NLS-1$ paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); // $NON-NLS-1$ } Element root = result.addElement("charts"); // $NON-NLS-1$ TimeSeriesCollection chartDataDefinition = (TimeSeriesCollection) dataDefinition; if (chartDataDefinition.getSeriesCount() > 0) { // create temporary file names String[] tempFileInfo = createTempFile(); String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX]; String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX]; ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); JFreeChartEngine.saveChart( chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, JFreeChartEngine.OUTPUT_PNG, printWriter, info, this); //$NON-NLS-1$ applyOuterURLTemplateParam(); populateInfo(info); Element chartElement = root.addElement("chart"); // $NON-NLS-1$ chartElement.addElement("mapName").setText(mapName); // $NON-NLS-1$ chartElement.addElement("width").setText(Integer.toString(width)); // $NON-NLS-1$ chartElement.addElement("height").setText(Integer.toString(height)); // $NON-NLS-1$ for (int row = 0; row < chartDataDefinition.getSeriesCount(); row++) { for (int column = 0; column < chartDataDefinition.getItemCount(row); column++) { Number value = chartDataDefinition.getY(row, column); Comparable rowKey = chartDataDefinition.getSeriesKey(row); RegularTimePeriod columnKey = chartDataDefinition.getSeries(row).getTimePeriod(column); Element valueElement = chartElement.addElement("value2D"); // $NON-NLS-1$ valueElement.addElement("value").setText(value.toString()); // $NON-NLS-1$ valueElement.addElement("row-key").setText(rowKey.toString()); // $NON-NLS-1$ valueElement.addElement("column-key").setText(columnKey.toString()); // $NON-NLS-1$ } } String mapString = ImageMapUtilities.getImageMap(mapName, info); chartElement.addElement("imageMap").setText(mapString); // $NON-NLS-1$ chartElement.addElement("image").setText(fileName); // $NON-NLS-1$ } return result; }
public static String getString(Comparable o) { if (o instanceof String) return (String) o; return o == null ? null : o.toString(); }
@Test public void summarizeLSAT7dataTest() { System.out.println("Testing summary of LSAT7 data"); readLsat7Data(); // true values from mirt package in R String[][] trueValues = { {"[0, 0, 0, 0, 0]", "12"}, {"[0, 0, 0, 0, 1]", "19"}, {"[0, 0, 0, 1, 0]", "1"}, {"[0, 0, 0, 1, 1]", "7"}, {"[0, 0, 1, 0, 0]", "3"}, {"[0, 0, 1, 0, 1]", "19"}, {"[0, 0, 1, 1, 0]", "3"}, {"[0, 0, 1, 1, 1]", "17"}, {"[0, 1, 0, 0, 0]", "10"}, {"[0, 1, 0, 0, 1]", "5"}, {"[0, 1, 0, 1, 0]", "3"}, {"[0, 1, 0, 1, 1]", "7"}, {"[0, 1, 1, 0, 0]", "7"}, {"[0, 1, 1, 0, 1]", "23"}, {"[0, 1, 1, 1, 0]", "8"}, {"[0, 1, 1, 1, 1]", "28"}, {"[1, 0, 0, 0, 0]", "7"}, {"[1, 0, 0, 0, 1]", "39"}, {"[1, 0, 0, 1, 0]", "11"}, {"[1, 0, 0, 1, 1]", "34"}, {"[1, 0, 1, 0, 0]", "14"}, {"[1, 0, 1, 0, 1]", "51"}, {"[1, 0, 1, 1, 0]", "15"}, {"[1, 0, 1, 1, 1]", "90"}, {"[1, 1, 0, 0, 0]", "6"}, {"[1, 1, 0, 0, 1]", "25"}, {"[1, 1, 0, 1, 0]", "7"}, {"[1, 1, 0, 1, 1]", "35"}, {"[1, 1, 1, 0, 0]", "18"}, {"[1, 1, 1, 0, 1]", "136"}, {"[1, 1, 1, 1, 0]", "32"}, {"[1, 1, 1, 1, 1]", "308"} }; // summarize response vectors into a frequency object Frequency freq = new Frequency(); for (int i = 0; i < lsat7.length; i++) { freq.addValue(Arrays.toString(lsat7[i])); } assertEquals("Same number of response strings", trueValues.length, freq.getUniqueCount()); for (int i = 0; i < trueValues.length; i++) { assertEquals( "Response vector comparison: ", Double.parseDouble(trueValues[i][1]), Long.valueOf(freq.getCount(trueValues[i][0])).doubleValue(), 1e-5); } ItemResponseVector[] responseData = new ItemResponseVector[freq.getUniqueCount()]; ItemResponseVector irv = null; Iterator<Comparable<?>> iter = freq.valuesIterator(); int index = 0; // create array of ItemResponseVector objects while (iter.hasNext()) { // get response string from frequency summary and convert to byte array Comparable<?> value = iter.next(); String s = value.toString(); s = s.substring(1, s.lastIndexOf("]")); String[] sa = s.split(","); byte[] rv = new byte[sa.length]; for (int i = 0; i < sa.length; i++) { rv[i] = Byte.parseByte(sa[i].trim()); } // create response vector objects irv = new ItemResponseVector(rv, Long.valueOf(freq.getCount(value)).doubleValue()); responseData[index] = irv; index++; } // display results of summary for (int i = 0; i < responseData.length; i++) { System.out.println(responseData[i].toString() + ": " + responseData[i].getFrequency()); } }
@Test public void testRandomGrouping() throws Exception { try { int indexIter = 50 * RANDOM_MULTIPLIER; // make >0 to enable test int queryIter = 100 * RANDOM_MULTIPLIER; while (--indexIter >= 0) { int indexSize = random.nextInt(25 * RANDOM_MULTIPLIER); List<FldType> types = new ArrayList<FldType>(); types.add(new FldType("id", ONE_ONE, new SVal('A', 'Z', 4, 4))); types.add( new FldType("score_s1", ONE_ONE, new SVal('a', 'c', 1, 1))); // field used to score types.add(new FldType("bar_s1", ONE_ONE, new SVal('a', 'z', 3, 5))); types.add(new FldType(FOO_STRING_FIELD, ONE_ONE, new SVal('a', 'z', 1, 2))); types.add( new FldType( SMALL_STRING_FIELD, ZERO_ONE, new SVal('a', (char) ('c' + indexSize / 10), 1, 1))); clearIndex(); Map<Comparable, Doc> model = indexDocs(types, null, indexSize); // test with specific docs if (false) { clearIndex(); model.clear(); Doc d1 = createDoc(types); d1.getValues(SMALL_STRING_FIELD).set(0, "c"); d1.getValues(SMALL_INT_FIELD).set(0, 5); d1.order = 0; updateJ(toJSON(d1), params("commit", "true")); model.put(d1.id, d1); d1 = createDoc(types); d1.getValues(SMALL_STRING_FIELD).set(0, "b"); d1.getValues(SMALL_INT_FIELD).set(0, 5); d1.order = 1; updateJ(toJSON(d1), params("commit", "false")); model.put(d1.id, d1); d1 = createDoc(types); d1.getValues(SMALL_STRING_FIELD).set(0, "c"); d1.getValues(SMALL_INT_FIELD).set(0, 5); d1.order = 2; updateJ(toJSON(d1), params("commit", "false")); model.put(d1.id, d1); d1 = createDoc(types); d1.getValues(SMALL_STRING_FIELD).set(0, "c"); d1.getValues(SMALL_INT_FIELD).set(0, 5); d1.order = 3; updateJ(toJSON(d1), params("commit", "false")); model.put(d1.id, d1); d1 = createDoc(types); d1.getValues(SMALL_STRING_FIELD).set(0, "b"); d1.getValues(SMALL_INT_FIELD).set(0, 2); d1.order = 4; updateJ(toJSON(d1), params("commit", "true")); model.put(d1.id, d1); } for (int qiter = 0; qiter < queryIter; qiter++) { String groupField = types.get(random.nextInt(types.size())).fname; int rows = random.nextInt(10) == 0 ? random.nextInt(model.size() + 2) : random.nextInt(11) - 1; int start = random.nextInt(5) == 0 ? random.nextInt(model.size() + 2) : random.nextInt(5); // pick a small start normally for better coverage int group_limit = random.nextInt(10) == 0 ? random.nextInt(model.size() + 2) : random.nextInt(11) - 1; int group_offset = random.nextInt(10) == 0 ? random.nextInt(model.size() + 2) : random.nextInt(2); // pick a small start normally for better coverage String[] stringSortA = new String[1]; Comparator<Doc> sortComparator = createSort(h.getCore().getSchema(), types, stringSortA); String sortStr = stringSortA[0]; Comparator<Doc> groupComparator = random.nextBoolean() ? sortComparator : createSort(h.getCore().getSchema(), types, stringSortA); String groupSortStr = stringSortA[0]; // since groupSortStr defaults to sortStr, we need to normalize null to "score desc" if // sortStr != null. if (groupSortStr == null && groupSortStr != sortStr) { groupSortStr = "score desc"; } // Test specific case if (false) { groupField = SMALL_INT_FIELD; sortComparator = createComparator( Arrays.asList(createComparator(SMALL_STRING_FIELD, true, true, false, true))); sortStr = SMALL_STRING_FIELD + " asc"; groupComparator = createComparator( Arrays.asList(createComparator(SMALL_STRING_FIELD, true, true, false, false))); groupSortStr = SMALL_STRING_FIELD + " asc"; rows = 1; start = 0; group_offset = 1; group_limit = 1; } Map<Comparable, Grp> groups = groupBy(model.values(), groupField); // first sort the docs in each group for (Grp grp : groups.values()) { Collections.sort(grp.docs, groupComparator); } // now sort the groups // if sort != group.sort, we need to find the max doc by "sort" if (groupComparator != sortComparator) { for (Grp grp : groups.values()) grp.setMaxDoc(sortComparator); } List<Grp> sortedGroups = new ArrayList<Grp>(groups.values()); Collections.sort( sortedGroups, groupComparator == sortComparator ? createFirstDocComparator(sortComparator) : createMaxDocComparator(sortComparator)); boolean includeNGroups = random.nextBoolean(); Object modelResponse = buildGroupedResult( h.getCore().getSchema(), sortedGroups, start, rows, group_offset, group_limit, includeNGroups); boolean truncateGroups = random.nextBoolean(); Map<String, Integer> facetCounts = new TreeMap<String, Integer>(); if (truncateGroups) { for (Grp grp : sortedGroups) { Doc doc = grp.docs.get(0); if (doc.getValues(FOO_STRING_FIELD) == null) { continue; } String key = doc.getFirstValue(FOO_STRING_FIELD).toString(); boolean exists = facetCounts.containsKey(key); int count = exists ? facetCounts.get(key) : 0; facetCounts.put(key, ++count); } } else { for (Doc doc : model.values()) { if (doc.getValues(FOO_STRING_FIELD) == null) { continue; } for (Comparable field : doc.getValues(FOO_STRING_FIELD)) { String key = field.toString(); boolean exists = facetCounts.containsKey(key); int count = exists ? facetCounts.get(key) : 0; facetCounts.put(key, ++count); } } } List<Comparable> expectedFacetResponse = new ArrayList<Comparable>(); for (Map.Entry<String, Integer> stringIntegerEntry : facetCounts.entrySet()) { expectedFacetResponse.add(stringIntegerEntry.getKey()); expectedFacetResponse.add(stringIntegerEntry.getValue()); } int randomPercentage = random.nextInt(101); // TODO: create a random filter too SolrQueryRequest req = req( "group", "true", "wt", "json", "indent", "true", "echoParams", "all", "q", "{!func}score_f", "group.field", groupField, sortStr == null ? "nosort" : "sort", sortStr == null ? "" : sortStr, (groupSortStr == null || groupSortStr == sortStr) ? "noGroupsort" : "group.sort", groupSortStr == null ? "" : groupSortStr, "rows", "" + rows, "start", "" + start, "group.offset", "" + group_offset, "group.limit", "" + group_limit, GroupParams.GROUP_CACHE_PERCENTAGE, Integer.toString(randomPercentage), GroupParams.GROUP_TOTAL_COUNT, includeNGroups ? "true" : "false", "facet", "true", "facet.sort", "index", "facet.limit", "-1", "facet.field", FOO_STRING_FIELD, GroupParams.GROUP_TRUNCATE, truncateGroups ? "true" : "false", "facet.mincount", "1"); String strResponse = h.query(req); Object realResponse = ObjectBuilder.fromJSON(strResponse); String err = JSONTestUtil.matchObj("/grouped/" + groupField, realResponse, modelResponse); if (err != null) { log.error( "GROUPING MISMATCH: " + err + "\n\trequest=" + req + "\n\tresult=" + strResponse + "\n\texpected=" + JSONUtil.toJSON(modelResponse) + "\n\tsorted_model=" + sortedGroups); // re-execute the request... good for putting a breakpoint here for debugging String rsp = h.query(req); fail(err); } // assert post / pre grouping facets err = JSONTestUtil.matchObj( "/facet_counts/facet_fields/" + FOO_STRING_FIELD, realResponse, expectedFacetResponse); if (err != null) { log.error( "GROUPING MISMATCH: " + err + "\n\trequest=" + req + "\n\tresult=" + strResponse + "\n\texpected=" + JSONUtil.toJSON(expectedFacetResponse)); // re-execute the request... good for putting a breakpoint here for debugging h.query(req); fail(err); } } // end query iter } // end index iter } finally { // B/c the facet.field is also used of grouping we have the purge the FC to avoid FC insanity FieldCache.DEFAULT.purgeAllCaches(); } }