Example #1
0
  public static void main(String[] args) throws Exception {
    System.out.println("Well, you think your EnumSingleton is really a singleton");

    System.out.println(
        "The id of the INSTANCE object is " + System.identityHashCode(EnumSingleton.INSTANCE));

    System.out.println("I will create another instance using reflection");
    Constructor<EnumSingleton> privateConstructor =
        EnumSingleton.class.getDeclaredConstructor(String.class, int.class);
    privateConstructor.setAccessible(true);
    try {
      privateConstructor.newInstance();
    } catch (IllegalArgumentException e) {
      System.out.println(
          "D'oh! An exception prevented me from creating a new instance: " + e.getMessage());
    }

    System.out.println("Hmm, I will try one more option - Serialisation");

    EnumSingleton clone = SerializationUtils.clone(EnumSingleton.INSTANCE);

    System.out.println(
        "D'oh! Even serialization did not work. id = " + System.identityHashCode(clone));

    System.out.println("I give up");
  }
  @Test
  public void testLimitedView() throws IOException {
    File file = folder.newFile();
    FileChannel chan = new RandomAccessFile(file, "rw").getChannel();
    BinaryIndexTableWriter writer = BinaryIndexTableWriter.create(BinaryFormat.create(), chan, 3);
    writer.writeEntry(12, new int[] {0});
    writer.writeEntry(17, new int[] {1, 3});
    writer.writeEntry(19, new int[] {4, 5});

    MappedByteBuffer buffer = chan.map(FileChannel.MapMode.READ_ONLY, 0, chan.size());
    BinaryIndexTable tbl = BinaryIndexTable.fromBuffer(3, buffer);
    tbl = tbl.createLimitedView(2);
    assertThat(tbl.getKeys(), hasSize(2));
    assertThat(tbl.getKeys(), contains(12L, 17L));
    assertThat(tbl.getEntry(12), contains(0));
    assertThat(tbl.getEntry(17), contains(1));
    assertThat(tbl.getEntry(19), nullValue());
    assertThat(tbl.getEntry(-1), nullValue());

    BinaryIndexTable serializedTbl = SerializationUtils.clone(tbl);
    assertThat(serializedTbl.getKeys(), hasSize(2));
    assertThat(serializedTbl.getKeys(), contains(12L, 17L));
    assertThat(serializedTbl.getEntry(12), contains(0));
    assertThat(serializedTbl.getEntry(17), contains(1));
    assertThat(serializedTbl.getEntry(19), nullValue());
    assertThat(serializedTbl.getEntry(-1), nullValue());
  }
Example #3
0
  @Test
  public void testOutputFormatVertex() {
    try {
      final TestingOutputFormat outputFormat = new TestingOutputFormat();
      final OutputFormatVertex of = new OutputFormatVertex("Name");
      new TaskConfig(of.getConfiguration())
          .setStubWrapper(new UserCodeObjectWrapper<OutputFormat<?>>(outputFormat));
      final ClassLoader cl = getClass().getClassLoader();

      try {
        of.initializeOnMaster(cl);
        fail("Did not throw expected exception.");
      } catch (TestException e) {
        // all good
      }

      OutputFormatVertex copy = SerializationUtils.clone(of);
      try {
        copy.initializeOnMaster(cl);
        fail("Did not throw expected exception.");
      } catch (TestException e) {
        // all good
      }
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
 @SuppressWarnings("unchecked")
 @Override
 public T getUserCodeObject() {
   // return a clone because some code retrieves this and runs configure() on it before
   // the job is actually run. This way we can always hand out a pristine copy.
   Serializable ser = (Serializable) userCodeObject;
   T cloned = (T) SerializationUtils.clone(ser);
   return cloned;
 }
Example #5
0
 public Conf copy() {
   return SerializationUtils.clone(this);
 }
 @Override
 public Object clone(Object obj) {
   return SerializationUtils.clone((Serializable) obj);
 }
  /**
   * Obtiene la configuraci\u00F3n de entregas del pedido
   *
   * @param session
   */
  public void obtenerEntregas(HttpSession session) {
    // cjui\u00F1a
    Collection<EntregaDetallePedidoDTO> entregasResp = new ArrayList<EntregaDetallePedidoDTO>();
    Collection<DetallePedidoDTO> detPedResp = new ArrayList<DetallePedidoDTO>();
    Collection<VistaDetallePedidoDTO> detallePedidoDTOCol =
        (Collection<VistaDetallePedidoDTO>) session.getAttribute(DETALLELPEDIDOAUX);
    if (!CollectionUtils.isEmpty(detallePedidoDTOCol)) {
      for (VistaDetallePedidoDTO detPed : detallePedidoDTOCol) {
        if (!CollectionUtils.isEmpty(detPed.getEntregaDetallePedidoCol())) {
          Collection<EntregaDetallePedidoDTO> entregas =
              (Collection<EntregaDetallePedidoDTO>) detPed.getEntregaDetallePedidoCol();
          if (CollectionUtils.isEmpty(entregasResp)) {
            entregasResp =
                (Collection<EntregaDetallePedidoDTO>)
                    SerializationUtils.clone((Serializable) entregas);
            for (EntregaDetallePedidoDTO entPed : entregasResp) {
              detPedResp = new ArrayList<DetallePedidoDTO>();
              entPed.getEntregaPedidoDTO().setNpDetallePedido(new ArrayList<DetallePedidoDTO>());
              DetallePedidoDTO dp = new DetallePedidoDTO();
              dp.setArticuloDTO(new ArticuloDTO());
              dp.getArticuloDTO()
                  .setId(
                      (ArticuloID)
                          SerializationUtils.clone((Serializable) detPed.getArticuloDTO().getId()));
              dp.getArticuloDTO()
                  .setDescripcionArticulo(detPed.getArticuloDTO().getDescripcionArticulo());
              dp.getArticuloDTO().setCodigoBarrasActivo(new ArticuloBitacoraCodigoBarrasDTO());
              dp.getArticuloDTO()
                  .getCodigoBarrasActivo()
                  .setId(
                      (ArticuloBitacoraCodigoBarrasID)
                          SerializationUtils.clone(
                              (Serializable)
                                  detPed.getArticuloDTO().getCodigoBarrasActivo().getId()));
              dp.setEstadoDetallePedidoDTO(new EstadoDetallePedidoDTO());
              dp.getEstadoDetallePedidoDTO().setCantidadEstado(entPed.getCantidadEntrega());
              dp.setNpContadorDespacho(entPed.getCantidadDespacho());
              dp.setNpContadorEntrega(entPed.getCantidadEntrega());
              detPedResp.add(dp);
              entPed.getEntregaPedidoDTO().setNpDetallePedido(detPedResp);
            }
          } else {
            for (EntregaDetallePedidoDTO entDetPed : entregas) {
              Boolean existeEntrega = Boolean.FALSE;
              DetallePedidoDTO dp = new DetallePedidoDTO();
              dp.setArticuloDTO(new ArticuloDTO());
              dp.getArticuloDTO()
                  .setId(
                      (ArticuloID)
                          SerializationUtils.clone((Serializable) detPed.getArticuloDTO().getId()));
              dp.getArticuloDTO()
                  .setDescripcionArticulo(detPed.getArticuloDTO().getDescripcionArticulo());
              dp.getArticuloDTO().setCodigoBarrasActivo(new ArticuloBitacoraCodigoBarrasDTO());
              dp.getArticuloDTO()
                  .getCodigoBarrasActivo()
                  .setId(
                      (ArticuloBitacoraCodigoBarrasID)
                          SerializationUtils.clone(
                              (Serializable)
                                  detPed.getArticuloDTO().getCodigoBarrasActivo().getId()));
              dp.setEstadoDetallePedidoDTO(new EstadoDetallePedidoDTO());
              dp.getEstadoDetallePedidoDTO().setCantidadEstado(entDetPed.getCantidadEntrega());
              dp.setNpContadorDespacho(entDetPed.getCantidadDespacho());
              dp.setNpContadorEntrega(entDetPed.getCantidadEntrega());

              for (EntregaDetallePedidoDTO entPedRes : entregasResp) {
                Long diferencia =
                    entDetPed.getEntregaPedidoDTO().getFechaEntregaCliente().getTime()
                        - entPedRes.getEntregaPedidoDTO().getFechaEntregaCliente().getTime();
                if (diferencia == 0L
                    && entDetPed
                        .getEntregaPedidoDTO()
                        .getDireccionEntrega()
                        .toUpperCase()
                        .trim()
                        .equals(
                            entPedRes
                                .getEntregaPedidoDTO()
                                .getDireccionEntrega()
                                .toUpperCase()
                                .trim())) {
                  entPedRes.getEntregaPedidoDTO().getNpDetallePedido().add(dp);
                  existeEntrega = Boolean.TRUE;
                  break;
                }
              }
              if (!existeEntrega) {
                entDetPed
                    .getEntregaPedidoDTO()
                    .setNpDetallePedido(new ArrayList<DetallePedidoDTO>());
                entDetPed.getEntregaPedidoDTO().getNpDetallePedido().add(dp);
                entregasResp.add(entDetPed);
              }
            }
          }
        }
      }
    }

    for (EntregaDetallePedidoDTO entPed : entregasResp) {
      Long cantidadDespacho = 0L;
      Long cantidadEntrega = 0L;
      for (DetallePedidoDTO detallePedido : entPed.getEntregaPedidoDTO().getNpDetallePedido()) {
        cantidadDespacho = cantidadDespacho + detallePedido.getNpContadorDespacho();
        cantidadEntrega = cantidadEntrega + detallePedido.getNpContadorEntrega();
      }
      entPed.setCantidadDespacho(cantidadDespacho);
      entPed.setCantidadEntrega(cantidadEntrega);
    }
    session.setAttribute(ENTREGAS_RESPONSABLES, entregasResp);
  }
Example #8
0
 public static List<LabelValue> makeListBlank(Class<? extends Enum> clazz) {
   ArrayList<LabelValue> list = (ArrayList<LabelValue>) makeList(clazz);
   List<LabelValue> result = SerializationUtils.clone(list);
   result.add(0, new LabelValue("请选择", ""));
   return result;
 }
Example #9
0
 /** @return the deep copy of the internal <code>Properties</code> of this TachyonConf instance. */
 public Properties getInternalProperties() {
   return SerializationUtils.clone(mProperties);
 }
Example #10
0
  private int processEntityContext(
      final EntityTypeInvocationHandler handler,
      int pos,
      final TransactionItems items,
      final List<EntityLinkDesc> delayedUpdates,
      final ODataChangeset changeset) {

    LOG.debug("Process '{}'", handler);

    items.put(handler, null);

    final ODataEntity entity = SerializationUtils.clone(handler.getEntity());
    entity.getNavigationLinks().clear();

    final AttachedEntityStatus currentStatus =
        EntityContainerFactory.getContext().entityContext().getStatus(handler);

    if (AttachedEntityStatus.DELETED != currentStatus) {
      entity.getProperties().clear();
      EngineUtils.addProperties(factory.getMetadata(), handler.getPropertyChanges(), entity);
    }

    for (Map.Entry<NavigationProperty, Object> property : handler.getLinkChanges().entrySet()) {
      final ODataLinkType type =
          Collection.class.isAssignableFrom(property.getValue().getClass())
              ? ODataLinkType.ENTITY_SET_NAVIGATION
              : ODataLinkType.ENTITY_NAVIGATION;

      final Set<EntityTypeInvocationHandler> toBeLinked =
          new HashSet<EntityTypeInvocationHandler>();
      final String serviceRoot = factory.getServiceRoot();

      for (Object proxy :
          type == ODataLinkType.ENTITY_SET_NAVIGATION
              ? (Collection) property.getValue()
              : Collections.singleton(property.getValue())) {

        final EntityTypeInvocationHandler target =
            (EntityTypeInvocationHandler) Proxy.getInvocationHandler(proxy);

        final AttachedEntityStatus status =
            EntityContainerFactory.getContext().entityContext().getStatus(target);

        final URI editLink = target.getEntity().getEditLink();

        if ((status == AttachedEntityStatus.ATTACHED || status == AttachedEntityStatus.LINKED)
            && !target.isChanged()) {
          entity.addLink(
              buildNavigationLink(
                  property.getKey().name(),
                  URIUtils.getURI(serviceRoot, editLink.toASCIIString()),
                  type));
        } else {
          if (!items.contains(target)) {
            pos = processEntityContext(target, pos, items, delayedUpdates, changeset);
            pos++;
          }

          final Integer targetPos = items.get(target);
          if (targetPos == null) {
            // schedule update for the current object
            LOG.debug("Schedule '{}' from '{}' to '{}'", type.name(), handler, target);
            toBeLinked.add(target);
          } else if (status == AttachedEntityStatus.CHANGED) {
            entity.addLink(
                buildNavigationLink(
                    property.getKey().name(),
                    URIUtils.getURI(serviceRoot, editLink.toASCIIString()),
                    type));
          } else {
            // create the link for the current object
            LOG.debug("'{}' from '{}' to (${}) '{}'", type.name(), handler, targetPos, target);

            entity.addLink(
                buildNavigationLink(property.getKey().name(), URI.create("$" + targetPos), type));
          }
        }
      }

      if (!toBeLinked.isEmpty()) {
        delayedUpdates.add(new EntityLinkDesc(property.getKey().name(), handler, toBeLinked, type));
      }
    }

    // insert into the batch
    LOG.debug("{}: Insert '{}' into the batch", pos, handler);
    batch(handler, entity, changeset);

    items.put(handler, pos);

    int startingPos = pos;

    if (handler.getEntity().isMediaEntity()) {

      // update media properties
      if (!handler.getPropertyChanges().isEmpty()) {
        final URI targetURI =
            currentStatus == AttachedEntityStatus.NEW
                ? URI.create("$" + startingPos)
                : URIUtils.getURI(
                    factory.getServiceRoot(), handler.getEntity().getEditLink().toASCIIString());
        batchUpdate(handler, targetURI, entity, changeset);
        pos++;
        items.put(handler, pos);
      }

      // update media content
      if (handler.getStreamChanges() != null) {
        final URI targetURI =
            currentStatus == AttachedEntityStatus.NEW
                ? URI.create("$" + startingPos + "/$value")
                : URIUtils.getURI(
                    factory.getServiceRoot(),
                    handler.getEntity().getEditLink().toASCIIString() + "/$value");

        batchUpdateMediaEntity(handler, targetURI, handler.getStreamChanges(), changeset);

        // update media info (use null key)
        pos++;
        items.put(null, pos);
      }
    }

    for (Map.Entry<String, InputStream> streamedChanges :
        handler.getStreamedPropertyChanges().entrySet()) {
      final URI targetURI =
          currentStatus == AttachedEntityStatus.NEW
              ? URI.create("$" + startingPos)
              : URIUtils.getURI(
                  factory.getServiceRoot(),
                  EngineUtils.getEditMediaLink(streamedChanges.getKey(), entity).toASCIIString());

      batchUpdateMediaResource(handler, targetURI, streamedChanges.getValue(), changeset);

      // update media info (use null key)
      pos++;
      items.put(handler, pos);
    }

    return pos;
  }