A factory method to create an instance of an alternate {@link AlternateOf}
@param entity1 an identifier for the first {@link Entity}
@param entity2 an identifier for the second {@link Entity}
@return an instance of {@link AlternateOf}
549335
public AlternateOf newAlternateOf(QualifiedName entity1, QualifiedName entity2) {
	AlternateOf res = of.createAlternateOf();
	res.setAlternate1(entity1);
	res.setAlternate2(entity2);
	return res;
    }
1158277
public static <A, B> Choice2<A, B> a(A a) {
        return new _A<>(a);
    }
645751
static function equals( $entity1, $entity2 ) {
			if ( is_null( $entity1 ) && is_null( $entity2 ) ) {
				return true;
			} else if ( is_object( $entity1 ) && is_object( $entity2 ) ) {
				return ( $entity1->id == $entity2->id );
			} else if ( is_object( $entity1 ) ) {
				return is_null( $entity1->id );
			} else {
				return is_null( $entity2->id );
			}
		}
681998
public void multiplePutEntities(String keyName1, String keyName2) {
    Datastore datastore = transaction.getDatastore();
    // [START multiplePutEntities]
    Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName1);
    Entity.Builder entityBuilder1 = Entity.newBuilder(key1);
    entityBuilder1.set("propertyName", "value1");
    Entity entity1 = entityBuilder1.build();

    Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName2);
    Entity.Builder entityBuilder2 = Entity.newBuilder(key2);
    entityBuilder2.set("propertyName", "value2");
    Entity entity2 = entityBuilder2.build();

    transaction.put(entity1, entity2);
    transaction.commit();
    // [END multiplePutEntities]
  }
1155187
public Alternatives<Beans<T>> getOrCreateAlternatives()
   {
      List<Node> nodeList = childNode.get("alternatives");
      if (nodeList != null &&  nodeList.size() > 0)
      {
         return new AlternativesImpl<Beans<T>>(this, "alternatives", childNode, nodeList.get(0));
      }
      return createAlternatives();
   }
408377
@Override
	public int compare(E entity1, E entity2) {
		T value = property.get(entity1);
		T value2 = property.get(entity2);
		return value.compareTo(value2);
	}
1360141
@Override
    public <X> EntityType<X> entity(Class<X> paramClass)
    {
        EntityType entityType = entityTypes.get(paramClass);
        if (entityType == null)
        {
            throw new IllegalArgumentException("Not an entity, {class:" + paramClass + "}");
        }
        return entityType;
    }
393959
private static TableModel entity2ModelWithConfig(Class<?> entityClass) {
		TableModel model;
		model = entity2ModelIgnoreConfigMethod(entityClass);
		Method method = null;
		try {
			method = entityClass.getMethod("config", TableModel.class);
		} catch (Exception e) {// NOSONAR
		}
		if (method != null)
			try {
				method.invoke(null, model);
			} catch (Exception e) {
				throw new DialectException(e);
			}
		if (model == null)
			throw new DialectException("Can not create TableModel for entityClass " + entityClass);
		return model;
	}
870233
@Transactional
    public E merge(E entity) {
        System.out.println("merge: " + entity.entityClassName() + ": " +entity + ": " + entity.getId());
        return entityManager.merge(entity);
    }
598990
public static Object initialize(EntityMetadata m, Object entity, Object id)
    {
        try
        {
            if (entity == null)
            {
                entity = createNewInstance(m.getEntityClazz());
            }
            if (id != null)
            {
                PropertyAccessorHelper.setId(entity, m, id);
            }
            return entity;
        }
        catch (Exception e)
        {
            throw new PersistenceException("Error occured while instantiating entity.", e);
        }
    }
1318405
public static <T1, T2, R> FluentFunctions.FluentBiFunction<T1, T2, R> of(final BiFunction<T1, T2, R> fn) {
        return new FluentBiFunction<>(
                                      fn);
    }
42564
static <E> List<E> toEntities(Class<E> entityClass, List<Entity> nativeEntities) {
    if (nativeEntities == null || nativeEntities.isEmpty()) {
      return new ArrayList<>();
    }
    List<E> entities = new ArrayList<>(nativeEntities.size());
    for (Entity nativeEntity : nativeEntities) {
      E entity = Unmarshaller.unmarshal(nativeEntity, entityClass);
      entities.add(entity);
    }
    return entities;
  }
789991
function create (entitySpec, id) {
  if (!_.isFunction(entitySpec)) {
    throw new Error(
      `Entity Factory '${id}' should be a function: ${JSON.stringify(
        entitySpec
      )}`
    )
  }

  if (entitySpec.length !== 2) {
    throw new Error(
      `Entity Factory '${id}' method should have an arity of 2, instead got: ${
        entitySpec.length
      }`
    )
  }

  return entitySpec
}
953664
@SuppressWarnings("unchecked")
    public ModelNode fromEntity(T entity)
    {

        ModelNode operation = new ModelNode();
        List<PropertyBinding> properties = metaData.getBeanMetaData(getType()).getProperties();
        Mutator mutator = metaData.getMutator(getType());

        for(PropertyBinding property : properties)
        {
            String[] splitDetypedName = property.getDetypedName().split("/");

            /**
             * KEYS
             */
            //      if(property.isKey()) continue;

            Object propertyValue = mutator.getValue(entity, property.getJavaName());

            /**
             * EXPRESSIONS
             */
            if(property.doesSupportExpression())
            {
                String exprValue = ExpressionAdapter.getExpressionValue(
                        entity, property.getJavaName()
                );

                if(exprValue!=null)
                {
                    operation.get(splitDetypedName).setExpression(exprValue);
                    continue; // expression have precedence over real values
                }
            }

            /**
             * VALUES
             */
            if(propertyValue!=null)
            {
                try {
                    ModelType modelType = resolveModelType(property.getJavaTypeName());
                    if ((modelType == ModelType.LIST) && (property.getListType() == PropertyBinding.class)) {
                        operation.get(splitDetypedName).set(modelType, property.getEntityAdapterForList().fromEntityPropertyList((List) propertyValue));
                    } else if (modelType == ModelType.LIST) {
                        operation.get(splitDetypedName).set(modelType,
                                property.getEntityAdapterForList().fromEntityList((List) propertyValue));
                    } else if (modelType == ModelType.OBJECT) {
                        // Only Map<String, String> is supported!
                        Map<String, String> map = (Map<String, String>) propertyValue;
                        for (Map.Entry<String, String> entry : map.entrySet()) {
                            operation.get(splitDetypedName).get(entry.getKey()).set(entry.getValue());
                        }
                    } else {
                        operation.get(splitDetypedName).set(modelType, propertyValue);
                    }
                } catch (RuntimeException e) {
                    throw new RuntimeException("Failed to get value "+property.getJavaName(), e);
                }
            }
        }

        return operation;
    }
1129119
public static Mapper concat(final Mapper first, final Mapper second){
        return new ConcatMapper(new Mapper[]{first,second});
    }
221695
public static AlternateTypeRule newRule(Type original, Type alternate, int order) {
    TypeResolver resolver = new TypeResolver();
    return new AlternateTypeRule(resolver.resolve(original), resolver.resolve(alternate), order);
  }
607141
public Alternatives<BeansDescriptor> getOrCreateAlternatives()
   {
      List<Node> nodeList = model.get("alternatives");
      if (nodeList != null && nodeList.size() > 0)
      {
         return new AlternativesImpl<BeansDescriptor>(this, "alternatives", model, nodeList.get(0));
      }
      return createAlternatives();
   }