static RepresentationType getType(FirstItemIterable<Representation> representations) {
   Representation representation = representations.getFirst();
   if (representation == null) {
     return RepresentationType.STRING;
   }
   return representation.getRepresentationType();
 }
Exemplo n.º 2
0
  public Representation<?> createRepresentation(Class<?> clazz) {

    /* If we have a specific representation for this type, use it. */
    if (reprMap_.containsKey(clazz)) {
      return reprMap_.get(clazz);
    }

    /* Arrays need treating specially. */
    else if (clazz.isArray()) {
      Class<?> scalarClass = getScalarClass(clazz);
      if (reprMap_.containsKey(scalarClass)) {
        Representation<?> scalarRepr = reprMap_.get(scalarClass);

        /* If the scalar type is a structured object
         * (either appears in the map of known types with
         * isColumn=false, or implicitly structured by being absent
         * from that map),
         * there's not much we can do with it, since you
         * can't map that structure to a sequence of columns
         * (you don't know how many there would be).
         * So we have to discard it. */
        if (scalarRepr == null || !scalarRepr.isColumn()) {
          return null;
        }

        /* If the scalar type is a column type, assume that it's
         * OK for an array (or array of arrays, or ...) to be
         * a column too.  Note however that this code is not
         * quite right at the moment; it will work for identity
         * representations, but ones that convert input objects
         * to a different representation (e.g. toString) will
         * go wrong here. */
        else {
          return createSimpleColumnRepresentation(clazz);
        }
      } else {
        return null;
      }
    }

    /* Non-array types with no special instructions will be treated
     * as structured objects. */
    else {
      return createIdentityRepresentation(clazz, false);
    }
  }
Exemplo n.º 3
0
 @Override
 public Job requestJob() {
   Job assignJob = null;
   synchronized (this.lock) {
     for (int i = 0; i < this.nonSubmitted.size(); i++) {
       Representation repSrc =
           ResourceClosetImpl.getInstance()
               .getResource(this.nonSubmitted.elementAt(i).getResource())
               .getRepresentation(this.nonSubmitted.elementAt(i).getRepresentationSource());
       if (repSrc.isReady()) {
         assignJob = this.nonSubmitted.elementAt(i);
         this.levelUp(assignJob);
         return assignJob;
       }
     }
   }
   return assignJob;
 }
Exemplo n.º 4
0
 public Object freeze(ColumnLoader.ValueSet valueSet) {
   final int n = valueSet.map.keySet().size();
   int extra = valueSet.containsNull ? 1 : 0;
   Comparable[] codeValues = valueSet.map.keySet().toArray(new Comparable[n + extra]);
   Arrays.sort(codeValues, 0, n);
   ColumnLoader.ValueSet codeValueSet = new ColumnLoader.ValueSet(int.class);
   for (Comparable value : valueSet.values) {
     int code;
     if (value == null) {
       code = n;
     } else {
       code = Arrays.binarySearch(codeValues, value);
       assert code >= 0 : code + ", " + value;
     }
     codeValueSet.add(code);
   }
   Object codes = representation.freeze(codeValueSet);
   return Pair.of(codes, codeValues);
 }
Exemplo n.º 5
0
 public Object getObject(Object dataSet, int ordinal) {
   Pair<Object, Object[]> pair = (Pair<Object, Object[]>) dataSet;
   int code = representation.getInt(pair.left, ordinal);
   return pair.right[code];
 }
Exemplo n.º 6
0
 /** {@inheritDoc} */
 @Override
 public String getValueRepresentation(WritableAssertionInfo info, Value value) {
   return displayer.getValueRepresentation(info, value);
 }
Exemplo n.º 7
0
 /** {@inheritDoc} */
 @Override
 public String getColumnRepresentation(WritableAssertionInfo info, Column column) {
   return displayer.getColumnRepresentation(info, column);
 }
Exemplo n.º 8
0
 /** {@inheritDoc} */
 @Override
 public String getRowRepresentation(WritableAssertionInfo info, Row row) {
   return displayer.getRowRepresentation(info, row);
 }
Exemplo n.º 9
0
 /** {@inheritDoc} */
 @Override
 public String getChangeRepresentation(WritableAssertionInfo info, Change change) {
   return displayer.getChangeRepresentation(info, change);
 }
Exemplo n.º 10
0
 /** {@inheritDoc} */
 @Override
 public String getRequestRepresentation(WritableAssertionInfo info, Request request) {
   return displayer.getRequestRepresentation(info, request);
 }
Exemplo n.º 11
0
 /** {@inheritDoc} */
 @Override
 public String getTableRepresentation(WritableAssertionInfo info, Table table) {
   return displayer.getTableRepresentation(info, table);
 }
Exemplo n.º 12
0
 public final Response ok(Representation representation) {
   if (representation.isEmpty()) {
     return noContent();
   }
   return response(Response.ok(), representation);
 }
Exemplo n.º 13
0
 public String assemble(Representation representation) {
   return representation.serialize(format, baseUri, extensions);
 }
Exemplo n.º 14
0
 public static void write(
     Representation representation, RepresentationFormat format, URI baseUri) {
   representation.serialize(format, baseUri, null);
 }