Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond.

Murilo Eduardo httpmurilo

💭
I may be slow to respond.
View GitHub Profile
View Aluno.java
package com.escola.entidade;
public class Aluno {
public static Aluno criarAlunoComDivisaoPadrao(String nome, Integer idade, String cidade, double notaDeCorte){
return new AlunoSM(nome, idade, cidade, notaDeCorte, 4);
}
//tradicional
private Aluno(String nome, Integer idade, String cidade, double notaDeCorte, Integer dividirPor) {
this.nome = nome;
View Aluno.java
package com.escola.modelo;
public class Aluno {
public Aluno(String nome, Integer idade, String cidade) {
this.nome = nome;
this.idade = idade;
this.cidade = cidade;
}
View Aluno.java
package com.escola.modelo;
public class Aluno {
public Aluno(String nome, Integer idade, String cidade, double notaDeCorte, Integer dividirPor) {
this.nome = nome;
this.idade = idade;
this.cidade = cidade;
this.notaDeCorte = notaDeCorte;
this.dividirPor = dividirPor;
View FakeService.java
package io.httpmurilo.sales.mock;
import io.httpmurilo.sales.dto.UserDTO;
import io.httpmurilo.sales.entity.User;
import io.httpmurilo.sales.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
public class FakeService {
@Autowired
View UserMapper.java
package io.httpmurilo.sales.mapper;
import io.httpmurilo.sales.dto.UserDTO;
import io.httpmurilo.sales.entity.User;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper(componentModel = "spring") //define que é um Spring bean e pode ser injetado via @Autowired
public abstract class UserMapper { //impedimos de instanciar diretamente
public static final UserMapper INSTANCE = Mappers.getMapper(UserMapper.class); //singleton
@httpmurilo
httpmurilo / UserDTO.java
Created February 9, 2022 23:49
Default Dto
View UserDTO.java
package io.httpmurilo.sales.dto;
import io.httpmurilo.sales.entity.User;
public class UserDTO {
//Esse construtor nunca irá parar de crescer X_X
public UserDTO convertToUser(User user) {
UserDTO dto = new UserDTO();
dto.setName(user.getName());
@httpmurilo
httpmurilo / UserDTO.java
Created February 9, 2022 23:40
Default DTO
View UserDTO.java
package io.httpmurilo.sales.dto;
import io.httpmurilo.sales.entity.User;
public class UserDTO {
public UserDTO convertToUser(User user) {
UserDTO dto = new UserDTO();
dto.setName(user.getName());
dto.setAge(user.getAge());
@httpmurilo
httpmurilo / User.java
Created February 9, 2022 23:34
Default user
View User.java
package io.httpmurilo.sales.entity;
public class User {
private Integer id;
private String name;
private Integer age;
private String email;
private boolean active;
@httpmurilo
httpmurilo / Student.java
Created January 23, 2022 21:40
Singleton static factory
View Student.java
package io.murilo.school.model;
public class Student {
private static final Student INSTANCE = new Student();
private Student() {
...
public static Student getInstance();
}
@httpmurilo
httpmurilo / Student.java
Created January 23, 2022 21:11
Singleton final
View Student.java
package io.murilo.school.model;
public class Student {
public static final Student INSTANCE = new Student();
private Integer id;
private String name;
private Integer age;
}