コード例 #1
0
ファイル: Tuple.java プロジェクト: sgroschupf/cascading
  /**
   * Method get returns a new Tuple populated with only those values whose field names are specified
   * in the given selector. The declarator Fields instance declares the fields and positions in the
   * current Tuple instance.
   *
   * @param declarator of type Fields
   * @param selector of type Fields
   * @return Tuple
   */
  public Tuple get(Fields declarator, Fields selector) {
    if (!declarator.isUnknown() && elements.size() != declarator.size())
      throw new TupleException(
          "field declaration: " + declarator.print() + ", does not match tuple: " + print());

    return get(declarator.getPos(selector, size()));
  }
コード例 #2
0
ファイル: TupleViewTest.java プロジェクト: bs1/cascading
  // where outgoing fields are REPLACE
  @Test
  public void testSelectorReplace() {
    //    if( getOutputSelector().isReplace() )
    //      {
    //      Tuple result = new Tuple( inputEntry.getTuple() );
    //
    //      handle case where operation is declaring the argument fields, and they are positional
    //      if( getFieldDeclaration().isArguments() )
    //        result.set( inputEntry.getFields(), argumentSelector, output );
    //      else
    //        result.set( inputEntry.getFields(), declaredEntry.getFields(), output );
    //
    //      return result;
    //      }

    Fields incomingFields = new Fields("1", "2", "3", "4");
    Tuple incoming = new Tuple(1, 2, 3, 4);
    Fields resultFields = new Fields("3", "2");
    Tuple result = new Tuple(5, 6);

    int[] setPos = incomingFields.getPos(resultFields);
    Tuple view = TupleViews.createOverride(incomingFields.getPos(), incoming, setPos, result);

    assertEquals(new Tuple(1, 6, 5, 4), view);
    assertEquals(new Tuple(1, 6, 5, 4), new Tuple(view));
  }
コード例 #3
0
ファイル: TupleViewTest.java プロジェクト: bs1/cascading
  // where outgoing fields are SWAP
  @Test
  public void testSelectorSwap() {
    //    if( getOutputSelector().isSwap() )
    //      {
    //      if( remainderFields.size() == 0 ) // the same as Fields.RESULTS
    //        return output;
    //      else
    //        return inputEntry.selectTuple( remainderFields ).append( output );
    //      }

    Fields incomingFields = new Fields("1", "2", "3", "4");
    Tuple incoming = new Tuple(1, 2, 3, 4);

    Fields remainderFields = new Fields("1", "4");

    Tuple bottomView = TupleViews.createNarrow(incomingFields.getPos(remainderFields), incoming);

    assertEquals(new Tuple(1, 4), bottomView);
    assertEquals(new Tuple(1, 4), new Tuple(bottomView));

    Fields resultFields = new Fields("5", "6", "7");
    Tuple result = new Tuple(5, 6, 7);

    Tuple view = TupleViews.createComposite(bottomView, result);

    assertEquals(new Tuple(1, 4, 5, 6, 7), view);
    assertEquals(new Tuple(1, 4, 5, 6, 7), new Tuple(view));

    Tuple fieldView = TupleViews.createComposite(remainderFields, resultFields);

    TupleViews.reset(fieldView, view, result);

    assertEquals(new Tuple(1, 4, 5, 6, 7), fieldView);
    assertEquals(new Tuple(1, 4, 5, 6, 7), new Tuple(fieldView));
  }
コード例 #4
0
ファイル: Tuple.java プロジェクト: nahguam/cascading
 protected void set(Fields declarator, Fields selector, Tuple tuple, CoercibleType[] coercions) {
   try {
     set(declarator.getPos(selector), declarator.getTypes(), tuple, coercions);
   } catch (Exception exception) {
     throw new TupleException(
         "unable to set into: " + declarator.print() + ", using selector: " + selector.print(),
         exception);
   }
 }
コード例 #5
0
  // -----------------------------------------------------------------------
  protected void assemble(Fields fields) {
    if (getBase() == null) {
      super.assemble(fields);

      fields.era = ERA_FIELD;
      fields.monthOfYear = new BasicMonthOfYearDateTimeField(this, 12);
      fields.months = fields.monthOfYear.getDurationField();
    }
  }
コード例 #6
0
ファイル: Tuple.java プロジェクト: nahguam/cascading
 /**
  * Method get returns a new Tuple populated with only those values whose field names are specified
  * in the given selector. The declarator Fields instance declares the fields and positions in the
  * current Tuple instance.
  *
  * @param declarator of type Fields
  * @param selector of type Fields
  * @return Tuple
  */
 public Tuple get(Fields declarator, Fields selector) {
   try {
     return get(getPos(declarator, selector));
   } catch (Exception exception) {
     throw new TupleException(
         "unable to select from: " + declarator.print() + ", using selector: " + selector.print(),
         exception);
   }
 }
コード例 #7
0
ファイル: Tuple.java プロジェクト: nahguam/cascading
 /**
  * Method set sets the values in the given selector positions to the values from the given Tuple.
  *
  * <p>If type information is given, each incoming value from tuple will be coerced from its
  * canonical type to the current type as declared in the declarator.
  *
  * @param declarator of type Fields
  * @param selector of type Fields
  * @param tuple of type Tuple
  */
 public void set(Fields declarator, Fields selector, Tuple tuple) {
   try {
     set(
         declarator.getPos(selector),
         declarator.getTypes(),
         tuple,
         TupleEntry.getCoercions(declarator, tuple));
   } catch (Exception exception) {
     throw new TupleException(
         "unable to set into: " + declarator.print() + ", using selector: " + selector.print(),
         exception);
   }
 }
コード例 #8
0
ファイル: AbstractRecord.java プロジェクト: rahultongia/jOOQ
  @Override
  public final void fromArray(Object[] array, Field<?>... f) {
    Fields accept = new Fields(f);
    int size = fields.size();

    for (int i = 0; i < size && i < array.length; i++) {
      Field field = fields.field(i);

      if (accept.field(field) != null) {
        Utils.setValue(this, field, array[i]);
      }
    }
  }
コード例 #9
0
  // -----------------------------------------------------------------------
  protected void assemble(Fields fields) {
    if (getBase() == null) {
      super.assemble(fields);

      // Ethiopic, like Julian, has no year zero.
      fields.year = new SkipDateTimeField(this, fields.year);
      fields.weekyear = new SkipDateTimeField(this, fields.weekyear);

      fields.era = ERA_FIELD;
      fields.monthOfYear = new BasicMonthOfYearDateTimeField(this, 13);
      fields.months = fields.monthOfYear.getDurationField();
    }
  }
コード例 #10
0
ファイル: JRESerializer.java プロジェクト: Njol/Yggdrasil
 @Override
 public Fields serialize(final Object o) {
   if (!set.contains(o.getClass())) throw new IllegalArgumentException();
   final Fields f = new Fields();
   if (o instanceof Collection) {
     final Collection<?> c = ((Collection<?>) o);
     f.putObject("values", c.toArray());
   } else if (o instanceof Map) {
     final Map<?, ?> m = ((Map<?, ?>) o);
     f.putObject("keys", m.keySet().toArray());
     f.putObject("values", m.values().toArray());
   }
   assert f.size() > 0 : o;
   return f;
 }
コード例 #11
0
ファイル: ISOChronology.java プロジェクト: seungbeomi/Study
  protected void assemble(Fields fields) {
    if (getBase().getZone() == DateTimeZone.UTC) {
      // Use zero based century and year of century.
      fields.centuryOfEra =
          new DividedDateTimeField(
              ISOYearOfEraDateTimeField.INSTANCE, DateTimeFieldType.centuryOfEra(), 100);
      fields.yearOfCentury =
          new RemainderDateTimeField(
              (DividedDateTimeField) fields.centuryOfEra, DateTimeFieldType.yearOfCentury());
      fields.weekyearOfCentury =
          new RemainderDateTimeField(
              (DividedDateTimeField) fields.centuryOfEra, DateTimeFieldType.weekyearOfCentury());

      fields.centuries = fields.centuryOfEra.getDurationField();
    }
  }
コード例 #12
0
ファイル: Tuple.java プロジェクト: sgroschupf/cascading
  /**
   * Method put places the values of the given tuple into the positions specified by the fields
   * argument. The declarator Fields value declares the fields in this Tuple instance.
   *
   * @param declarator of type Fields
   * @param fields of type Fields
   * @param tuple of type Tuple
   */
  public void put(Fields declarator, Fields fields, Tuple tuple) {
    verifyModifiable();

    int[] pos = declarator.getPos(fields, size());

    for (int i = 0; i < pos.length; i++) elements.set(pos[i], tuple.get(i));
  }
コード例 #13
0
  protected void assemble(Fields fields) {
    if (getParam() == null) {
      // julian chrono removed zero, but we need to put it back
      DateTimeField field = fields.year;
      fields.year =
          new OffsetDateTimeField(new SkipUndoDateTimeField(this, field), BUDDHIST_OFFSET);

      // one era, so yearOfEra is the same
      field = fields.yearOfEra;
      fields.yearOfEra = new DelegatedDateTimeField(fields.year, DateTimeFieldType.yearOfEra());

      // julian chrono removed zero, but we need to put it back
      field = fields.weekyear;
      fields.weekyear =
          new OffsetDateTimeField(new SkipUndoDateTimeField(this, field), BUDDHIST_OFFSET);

      field = new OffsetDateTimeField(fields.yearOfEra, 99);
      fields.centuryOfEra = new DividedDateTimeField(field, DateTimeFieldType.centuryOfEra(), 100);

      field = new RemainderDateTimeField((DividedDateTimeField) fields.centuryOfEra);
      fields.yearOfCentury = new OffsetDateTimeField(field, DateTimeFieldType.yearOfCentury(), 1);

      field =
          new RemainderDateTimeField(fields.weekyear, DateTimeFieldType.weekyearOfCentury(), 100);
      fields.weekyearOfCentury =
          new OffsetDateTimeField(field, DateTimeFieldType.weekyearOfCentury(), 1);

      fields.era = ERA_FIELD;
    }
  }
コード例 #14
0
ファイル: UserResource.java プロジェクト: sudhavn/neo4j-akka
 private void checkWhetherSynchIsNeeded(User user, Fields fields) {
   for (Field field : fields.getFields()) {
     if (field.getName().contains("goodreadsAccessTokenSecret")) {
       initiateGoodreadsSynch(user);
     } else if (field.getName().contains("fbId")) {
       // todo kick off fb stuff
     }
   }
 }
コード例 #15
0
    /**
     * Creates a new {@link Output} for the given field.
     *
     * @param operation the actual operation key, must not be {@literal null} or empty.
     * @param values the values to pass into the operation, must not be {@literal null}.
     */
    public OperationOutput(String operation, Collection<? extends Object> values) {

      super(Fields.field(operation));

      Assert.hasText(operation, "Operation must not be null or empty!");
      Assert.notNull(values, "Values must not be null!");

      this.operation = operation;
      this.values = new ArrayList<Object>(values);
    }
コード例 #16
0
ファイル: TupleViewTest.java プロジェクト: bs1/cascading
  // tests actual swap algebra
  @Test
  public void testSelectorSwap2() {
    Fields incomingFields = new Fields("0", "1", 2, 3);
    Tuple incoming = new Tuple(0, 1, 2, 3);

    Fields resultFields = new Fields("0", "1");
    Tuple result = new Tuple(0, 1);

    Fields remainderFields = incomingFields.subtract(resultFields);

    Tuple remainderView = createNarrow(incomingFields.getPos(remainderFields));
    Tuple outgoingTuple = createComposite(Fields.asDeclaration(remainderFields), resultFields);

    TupleViews.reset(remainderView, incoming);
    TupleViews.reset(outgoingTuple, remainderView, result);

    assertEquals(new Tuple(2, 3, 0, 1), outgoingTuple);
    assertEquals(new Tuple(2, 3, 0, 1), new Tuple(outgoingTuple));
  }
コード例 #17
0
    /**
     * Creates a new {@link SpelExpressionOutput} for the given field, SpEL expression and
     * parameters.
     *
     * @param expression must not be {@literal null} or empty.
     * @param parameters must not be {@literal null}.
     */
    public SpelExpressionOutput(String expression, Object[] parameters) {

      super(Fields.field(expression));

      Assert.hasText(expression, "Expression must not be null!");
      Assert.notNull(parameters, "Parameters must not be null!");

      this.expression = expression;
      this.params = parameters.clone();
    }
コード例 #18
0
ファイル: test.java プロジェクト: khelsen/jacob
  public static void printRS(Recordset rs) {
    Fields fs = rs.getFields();

    for (int i = 0; i < fs.getCount(); i++) {
      System.out.print(fs.getItem(i).getName() + " ");
    }
    System.out.println("");

    rs.MoveFirst();
    while (!rs.getEOF()) {
      for (int i = 0; i < fs.getCount(); i++) {
        Field f = fs.getItem(i);
        Variant v = f.getValue();
        System.out.print(v + " ");
      }
      System.out.println("");
      rs.MoveNext();
    }
  }
コード例 #19
0
  @Override
  public Fields updateBucket(int key, byte val, UpdateCallback callback) {
    hasher.updateBucket(key, val, callback);

    if (hasher.getNumElements() >= growthBound) {
      int[] fields = hasher.getFields();
      this.growthBound = 3 * (fields.length >>> 2);
      if (fields.length == switchToDenseSize) {
        Fields retVal = denseFactory.make(preamble);
        BucketIterator iter = getBucketIterator();
        while (iter.next()) {
          retVal.updateBucket(iter.getKey(), iter.getValue(), NOOP_CB);
        }
        return retVal;
      } else {
        hasher.resetFields(fields.length << 1);
        hasher.boostrap(fields);
      }
    }

    return this;
  }
コード例 #20
0
ファイル: UserResource.java プロジェクト: sudhavn/neo4j-akka
 private void setUpdatedFields(User user, Fields fields) throws Exception {
   ObjectMapper objectMapper = new ObjectMapper();
   for (Field field : fields.getFields()) {
     BeanUtils.setProperty(user, field.getName(), field.getValue());
   }
   Long currentTime = System.currentTimeMillis();
   String targetUserId = user.getId();
   String targetUserName = objectMapper.writeValueAsString(fields);
   String targetUrl = null;
   Target target = new Target(IdType.USER_ID.toString(), targetUserName, targetUrl);
   Event followedUSerEvent =
       new Event(AuditEventType.USER_UPDATED.toString(), target, currentTime, false);
   auditEventDao.addEvent(targetUserId, followedUSerEvent);
 }
コード例 #21
0
    /**
     * Returns the finally to be applied {@link BucketOperation} with the given alias.
     *
     * @param alias will never be {@literal null} or empty.
     * @return
     */
    public T as(String alias) {

      if (value instanceof OperationOutput) {
        return this.operation.andOutput(((OperationOutput) this.value).withAlias(alias));
      }

      if (value instanceof Field) {
        throw new IllegalStateException(
            "Cannot add a field as top-level output. Use accumulator expressions.");
      }

      return this.operation.andOutput(
          new AggregationExpressionOutput(Fields.field(alias), (AggregationExpression) value));
    }
コード例 #22
0
ファイル: TupleViewTest.java プロジェクト: bs1/cascading
  // where outgoing fields are a combination of incoming and results
  @Test
  public void testSelectorMixed() {
    //    declaredEntry.setTuple( output );
    //
    //    return TupleEntry.select( outgoingSelector, inputEntry, declaredEntry );

    Fields incomingFields = new Fields("1", "2", "3", "4");
    Tuple incoming = new Tuple(1, 2, 3, 4);
    Fields resultFields = new Fields("5", "6", "7");
    Tuple result = new Tuple(5, 6, 7);

    Tuple bottomView = TupleViews.createComposite(incoming, result);

    assertEquals(new Tuple(1, 2, 3, 4, 5, 6, 7), bottomView);
    assertEquals(new Tuple(1, 2, 3, 4, 5, 6, 7), new Tuple(bottomView));

    Fields allFields = Fields.join(incomingFields, resultFields);
    Fields selector = new Fields("3", "2");

    Tuple view = TupleViews.createNarrow(allFields.getPos(selector), bottomView);

    assertTuple(view);
  }
コード例 #23
0
ファイル: JRESerializer.java プロジェクト: Njol/Yggdrasil
 @SuppressWarnings({"unchecked", "rawtypes"})
 @Override
 public void deserialize(final Object o, final Fields fields) throws StreamCorruptedException {
   try {
     if (o instanceof Collection) {
       final Collection<?> c = ((Collection<?>) o);
       final Object[] values = fields.getObject("values", Object[].class);
       if (values == null) throw new StreamCorruptedException();
       c.addAll((Collection) Arrays.asList(values));
       return;
     } else if (o instanceof Map) {
       final Map<?, ?> m = ((Map<?, ?>) o);
       final Object[] keys = fields.getObject("keys", Object[].class),
           values = fields.getObject("values", Object[].class);
       if (keys == null || values == null || keys.length != values.length)
         throw new StreamCorruptedException();
       for (int i = 0; i < keys.length; i++) ((Map) m).put(keys[i], values[i]);
       return;
     }
   } catch (final Exception e) {
     throw new StreamCorruptedException(e.getClass().getSimpleName() + ": " + e.getMessage());
   }
   throw new StreamCorruptedException();
 }
コード例 #24
0
ファイル: TupleViewTest.java プロジェクト: bs1/cascading
  // where outgoing fields are ALL
  @Test
  public void testSelectorAll() {
    //    if( getOutputSelector().isAll() )
    //      return inputEntry.getTuple().append( output );

    Fields incomingFields = new Fields("1", "2", "3", "4");
    Tuple incoming = new Tuple(1, 2, 3, 4);
    Fields resultFields = new Fields("5", "6", "7");
    Tuple result = new Tuple(5, 6, 7);

    Tuple view = TupleViews.createComposite(incoming, result);

    assertEquals(new Tuple(1, 2, 3, 4, 5, 6, 7), view);
    assertEquals(new Tuple(1, 2, 3, 4, 5, 6, 7), new Tuple(view));

    Fields allFields = Fields.join(incomingFields, resultFields);
    Fields selector = new Fields("3", "2");

    assertTuple(view.get(allFields, selector));
  }
コード例 #25
0
    /**
     * Creates a new instance of this {@link OperationOutput} with the given alias.
     *
     * @param alias the alias to set
     * @return
     */
    public OperationOutput withAlias(String alias) {

      final Field aliasedField = Fields.field(alias);
      return new OperationOutput(aliasedField, this) {

        @Override
        protected Field getField() {
          return aliasedField;
        }

        @Override
        protected List<Object> getOperationArguments(AggregationOperationContext context) {

          // We have to make sure that we use the arguments from the "previous" OperationOutput that
          // we replace
          // with this new instance.
          return OperationOutput.this.getOperationArguments(context);
        }
      };
    }
コード例 #26
0
  protected void assemble(Fields fields) {
    fields.year = convertField(fields.year);
    fields.yearOfEra = convertField(fields.yearOfEra);
    fields.yearOfCentury = convertField(fields.yearOfCentury);
    fields.centuryOfEra = convertField(fields.centuryOfEra);
    fields.era = convertField(fields.era);
    fields.dayOfWeek = convertField(fields.dayOfWeek);
    fields.dayOfMonth = convertField(fields.dayOfMonth);
    fields.dayOfYear = convertField(fields.dayOfYear);
    fields.monthOfYear = convertField(fields.monthOfYear);
    fields.weekOfWeekyear = convertField(fields.weekOfWeekyear);
    fields.weekyear = convertField(fields.weekyear);
    fields.weekyearOfCentury = convertField(fields.weekyearOfCentury);

    fields.millisOfSecond = convertField(fields.millisOfSecond);
    fields.millisOfDay = convertField(fields.millisOfDay);
    fields.secondOfMinute = convertField(fields.secondOfMinute);
    fields.secondOfDay = convertField(fields.secondOfDay);
    fields.minuteOfHour = convertField(fields.minuteOfHour);
    fields.minuteOfDay = convertField(fields.minuteOfDay);
    fields.hourOfDay = convertField(fields.hourOfDay);
    fields.hourOfHalfday = convertField(fields.hourOfHalfday);
    fields.clockhourOfDay = convertField(fields.clockhourOfDay);
    fields.clockhourOfHalfday = convertField(fields.clockhourOfHalfday);
    fields.halfdayOfDay = convertField(fields.halfdayOfDay);
  }
コード例 #27
0
 @Override
 public Fields unionInto(Fields recipient, UpdateCallback cb) {
   return recipient.unionBucketIterator(getBucketIterator(), cb);
 }
  protected void assemble(Fields fields) {
    // Keep a local cache of converted fields so as not to create redundant
    // objects.
    HashMap<Object, Object> converted = new HashMap<Object, Object>();

    // Convert duration fields...

    fields.eras = convertField(fields.eras, converted);
    fields.centuries = convertField(fields.centuries, converted);
    fields.years = convertField(fields.years, converted);
    fields.months = convertField(fields.months, converted);
    fields.weekyears = convertField(fields.weekyears, converted);
    fields.weeks = convertField(fields.weeks, converted);
    fields.days = convertField(fields.days, converted);

    fields.halfdays = convertField(fields.halfdays, converted);
    fields.hours = convertField(fields.hours, converted);
    fields.minutes = convertField(fields.minutes, converted);
    fields.seconds = convertField(fields.seconds, converted);
    fields.millis = convertField(fields.millis, converted);

    // Convert datetime fields...

    fields.year = convertField(fields.year, converted);
    fields.yearOfEra = convertField(fields.yearOfEra, converted);
    fields.yearOfCentury = convertField(fields.yearOfCentury, converted);
    fields.centuryOfEra = convertField(fields.centuryOfEra, converted);
    fields.era = convertField(fields.era, converted);
    fields.dayOfWeek = convertField(fields.dayOfWeek, converted);
    fields.dayOfMonth = convertField(fields.dayOfMonth, converted);
    fields.dayOfYear = convertField(fields.dayOfYear, converted);
    fields.monthOfYear = convertField(fields.monthOfYear, converted);
    fields.weekOfWeekyear = convertField(fields.weekOfWeekyear, converted);
    fields.weekyear = convertField(fields.weekyear, converted);
    fields.weekyearOfCentury = convertField(fields.weekyearOfCentury, converted);

    fields.millisOfSecond = convertField(fields.millisOfSecond, converted);
    fields.millisOfDay = convertField(fields.millisOfDay, converted);
    fields.secondOfMinute = convertField(fields.secondOfMinute, converted);
    fields.secondOfDay = convertField(fields.secondOfDay, converted);
    fields.minuteOfHour = convertField(fields.minuteOfHour, converted);
    fields.minuteOfDay = convertField(fields.minuteOfDay, converted);
    fields.hourOfDay = convertField(fields.hourOfDay, converted);
    fields.hourOfHalfday = convertField(fields.hourOfHalfday, converted);
    fields.clockhourOfDay = convertField(fields.clockhourOfDay, converted);
    fields.clockhourOfHalfday = convertField(fields.clockhourOfHalfday, converted);
    fields.halfdayOfDay = convertField(fields.halfdayOfDay, converted);
  }
コード例 #29
0
ファイル: Tuple.java プロジェクト: sgroschupf/cascading
 /**
  * Method set sets the values in the given selector positions to the values from the given Tuple.
  *
  * @param declarator of type Fields
  * @param selector of type Fields
  * @param tuple of type Tuple
  */
 public void set(Fields declarator, Fields selector, Tuple tuple) {
   set(declarator.getPos(selector), tuple);
 }
コード例 #30
0
ファイル: Tuple.java プロジェクト: sgroschupf/cascading
 /**
  * Method remove removes the values specified by the given selector. The declarator declares the
  * fields in this instance.
  *
  * @param declarator of type Fields
  * @param selector of type Fields
  * @return Tuple
  */
 public Tuple remove(Fields declarator, Fields selector) {
   return remove(declarator.getPos(selector, size()));
 }