@SuppressWarnings("CharUsedInArithmeticContext") private static void assertToStrings(Slice slice, int index) { // fill slice with FF slice.fill((byte) 0xFF); // set and get the value char[] chars = new char[(slice.length() - index) / 2]; for (int i = 0; i < chars.length; i++) { chars[i] = (char) ('a' + (i % 26)); } String string = new String(chars); Slice value = Slices.copiedBuffer(string, UTF_8); slice.setBytes(index, value); assertEquals(slice.toString(index, value.length(), UTF_8), string); for (int length = 0; length < value.length(); length++) { slice.fill((byte) 0xFF); slice.setBytes(index, value, 0, length); assertEquals(slice.toString(index, length, UTF_8), string.substring(0, length)); } }
/** * Recursive helper for tostring/toConstraintString * * @param seg * @param buf * @param forconstraint */ protected void dumpvar(Segment seg, StringBuilder buf, boolean forconstraint) { if (seg.var.isTopLevel()) buf.append(seg.var.getFQN()); else buf.append(seg.var.getShortName()); List<DapDimension> dimset = seg.var.getDimensions(); // Add any slices List<Slice> slices = seg.slices; if (slices == null) dimset = new ArrayList<DapDimension>(); else assert dimset.size() == slices.size(); for (int i = 0; i < dimset.size(); i++) { Slice slice = slices.get(i); DapDimension dim = dimset.get(i); try { buf.append(forconstraint ? slice.toConstraintString() : slice.toString()); } catch (DapException de) { } } // if the var is atomic, then we are done if (seg.var.getSort() == DapSort.ATOMICVARIABLE) return; // If structure and all fields are in the view, then done if (seg.var.getSort() == DapSort.STRUCTURE || seg.var.getSort() == DapSort.SEQUENCE) { if (!isWholeCompound((DapStructure) seg.var)) { // Need to insert {...} and recurse buf.append(LBRACE); DapStructure struct = (DapStructure) seg.var; boolean first = true; for (DapVariable field : struct.getFields()) { if (!first) buf.append(";"); first = false; Segment fseg = findSegment(field); dumpvar(fseg, buf, forconstraint); } buf.append(RBRACE); } if (seg.var.getSort() == DapSort.SEQUENCE && seg.filter != null) { buf.append("|"); buf.append(seg.filter.toString()); } } }