"refonte debut annee"
This commit is contained in:
5
2019-2020/src/designPattern/facebookGhost/Event.java
Normal file
5
2019-2020/src/designPattern/facebookGhost/Event.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package designPattern.facebookGhost;
|
||||
|
||||
public interface Event {
|
||||
|
||||
}
|
@@ -0,0 +1,125 @@
|
||||
package designPattern.facebookGhost;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Observable;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Inspired by
|
||||
* //https://github.com/roundrop/facebook4j/blob/master/facebook4j-core/src/main/java/facebook4j/api/FriendMethods.java
|
||||
* pour imaginer une esquisse de rseau tr<74>s tr<74>s simplifi<66>
|
||||
* @author blay
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class FacebookGhostNetwork extends Observable {
|
||||
|
||||
public static final String DEFAULT_LOCATION = "unspecified";
|
||||
HashMap<String,User> users = new HashMap<> ();
|
||||
|
||||
public FacebookGhostNetwork() {
|
||||
}
|
||||
|
||||
|
||||
public User addUser(String nom, String profile){
|
||||
return addUser(nom, profile,DEFAULT_LOCATION);
|
||||
}
|
||||
|
||||
public User addUser(String nom, String profile, String location){
|
||||
User user = new UserImpl(nom, profile,location);
|
||||
users.put(nom, user);
|
||||
Event e = new UserEvent(user);
|
||||
setChanged();
|
||||
notifyObservers(e);
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a user's friends.
|
||||
* @param userId the ID of a user
|
||||
* @return users
|
||||
* @see <a href="https://developers.facebook.com/docs/reference/api/user/#friends">User#friends - Facebook Developers</a>
|
||||
*/
|
||||
ArrayList<User> getFriends(String userId){
|
||||
return getUser(userId).getFriends();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a user's family members.
|
||||
* @param userId the ID of a user
|
||||
* @return users
|
||||
* @see <a href="https://developers.facebook.com/docs/reference/api/user/#friends">User#friends - Facebook Developers</a>
|
||||
*/
|
||||
ArrayList<User> getFamily(String userId){
|
||||
return getUser(userId).getFamily();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a given user, specified by ID.
|
||||
* @param userId the ID of the user
|
||||
* @return user
|
||||
* remove but not the use of dedicated exception !! @throws FacebookException when Facebook service or network is unavailable
|
||||
* @see <a href="https://developers.facebook.com/docs/reference/api/user/">User - Facebook Developers</a>
|
||||
*/
|
||||
public User getUser(String userId) {
|
||||
return users.get(userId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a relation between 2 given members of a same family
|
||||
* @param id1 the ID of the user
|
||||
* @param id2 the ID of the user
|
||||
*/
|
||||
public void addFamilyRelation(String id1, String id2) {
|
||||
User u1 = users.get(id1);
|
||||
User u2 = users.get(id2);
|
||||
addFamilyRelation(u1, u2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void addFamilyRelation(User u1, User u2) {
|
||||
u1.addFamily(u2);
|
||||
u2.addFamily(u1);
|
||||
Event e = new RelationEvent("family",u1,u2);
|
||||
setChanged();
|
||||
notifyObservers(e);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a relation between 2 given friends
|
||||
* @param id1 the ID of the user
|
||||
* @param id2 the ID of the user
|
||||
*/
|
||||
public void addFriendRelation(String id1, String id2) {
|
||||
User u1 = users.get(id1);
|
||||
User u2 = users.get(id2);
|
||||
addFriendRelation(u1, u2);
|
||||
}
|
||||
|
||||
public void addFriendRelation(User u1, User u2) {
|
||||
u1.addFriend(u2);
|
||||
u2.addFriend(u1);
|
||||
Event e = new RelationEvent("Friend",u1,u2);
|
||||
setChanged();
|
||||
notifyObservers(e);
|
||||
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FacebookGhostNetwork [ " + users + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
package designPattern.facebookGhost;
|
||||
|
||||
public interface IdNameEntity {
|
||||
String getId();
|
||||
String getName();
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
package designPattern.facebookGhost;
|
||||
|
||||
public class IdNameEntityImpl implements IdNameEntity {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public IdNameEntityImpl(String id, String name) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
}
|
32
2019-2020/src/designPattern/facebookGhost/RelationEvent.java
Normal file
32
2019-2020/src/designPattern/facebookGhost/RelationEvent.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package designPattern.facebookGhost;
|
||||
|
||||
public class RelationEvent implements Event {
|
||||
public String getNature() {
|
||||
return nature;
|
||||
}
|
||||
|
||||
public User getU1() {
|
||||
return u1;
|
||||
}
|
||||
|
||||
public User getU2() {
|
||||
return u2;
|
||||
}
|
||||
|
||||
String nature;
|
||||
User u1;
|
||||
User u2;
|
||||
|
||||
public RelationEvent(String nature, User u1, User u2) {
|
||||
this.nature = nature;
|
||||
this.u1 = u1;
|
||||
this.u2=u2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RelationEvent [nature=" + nature + ", u1=" + u1 + ", u2=" + u2
|
||||
+ "]";
|
||||
}
|
||||
|
||||
}
|
104
2019-2020/src/designPattern/facebookGhost/User.java
Normal file
104
2019-2020/src/designPattern/facebookGhost/User.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package designPattern.facebookGhost;
|
||||
|
||||
/*import java.net.URL;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Emprunt<6E> <20> https://github.com/roundrop/facebook4j
|
||||
* @author Ryuji Yamashita - roundrop at gmail.com
|
||||
*/
|
||||
public interface User {
|
||||
|
||||
String myProfil();
|
||||
String getId();
|
||||
String getName();
|
||||
/* String getFirstName();
|
||||
String getMiddleName();
|
||||
String getLastName();
|
||||
String getGender();
|
||||
Locale getLocale();
|
||||
List<IdNameEntity> getLanguages();
|
||||
URL getLink();
|
||||
String getUsername();
|
||||
String getThirdPartyId();
|
||||
Boolean isInstalled();
|
||||
Double getTimezone();
|
||||
Date getUpdatedTime();
|
||||
Boolean isVerified();
|
||||
String getBio();
|
||||
String getBirthday();
|
||||
// Cover getCover();
|
||||
List<User.Education> getEducation();
|
||||
String getEmail();
|
||||
*/
|
||||
IdNameEntity getHometown();
|
||||
/*
|
||||
List<String> getInterestedIn();
|
||||
IdNameEntity getLocation();
|
||||
String getPolitical();
|
||||
List<IdNameEntity> getFavoriteAthletes();
|
||||
List<IdNameEntity> getFavoriteTeams();
|
||||
// Picture getPicture();
|
||||
String getQuotes();
|
||||
String getRelationshipStatus();
|
||||
String getReligion();
|
||||
IdNameEntity getSignificantOther();
|
||||
User.VideoUploadLimits getVideoUploadLimits();
|
||||
URL getWebsite();
|
||||
List<User.Work> getWork();
|
||||
;
|
||||
|
||||
interface Education {
|
||||
IdNameEntity getYear();
|
||||
String getType();
|
||||
IdNameEntity getSchool();
|
||||
IdNameEntity getDegree();
|
||||
List<IdNameEntity> getConcentration();
|
||||
List<User.EducationClass> getClasses();
|
||||
List<IdNameEntity> getWith();
|
||||
}
|
||||
|
||||
interface EducationClass {
|
||||
List<IdNameEntity> getWith();
|
||||
String getDescription();
|
||||
}
|
||||
|
||||
interface VideoUploadLimits {
|
||||
long getLength();
|
||||
long getSize();
|
||||
}
|
||||
|
||||
interface Work {
|
||||
IdNameEntity getEmployer();
|
||||
IdNameEntity getLocation();
|
||||
IdNameEntity getPosition();
|
||||
String getStartDate();
|
||||
String getEndDate();
|
||||
|
||||
}*/
|
||||
|
||||
User.AgeRange getAgeRange();
|
||||
interface AgeRange {
|
||||
// one value could be null (13-17 / 18-20 / 21 - null)
|
||||
Integer getMin();
|
||||
Integer getMax();
|
||||
int getAge();
|
||||
}
|
||||
ArrayList<User> getFriends();
|
||||
void addFriend(User friend);
|
||||
void addFamily(User familyMember);
|
||||
ArrayList <User>getFamily();
|
||||
|
||||
void setLocation(String name);
|
||||
//String BIRTHDAY_DATE_FORMAT = "MM/dd/yyyy";
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
11
2019-2020/src/designPattern/facebookGhost/UserEvent.java
Normal file
11
2019-2020/src/designPattern/facebookGhost/UserEvent.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package designPattern.facebookGhost;
|
||||
|
||||
public class UserEvent implements Event {
|
||||
|
||||
User user;
|
||||
|
||||
public UserEvent(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
}
|
105
2019-2020/src/designPattern/facebookGhost/UserImpl.java
Normal file
105
2019-2020/src/designPattern/facebookGhost/UserImpl.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package designPattern.facebookGhost;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class UserImpl implements User {
|
||||
|
||||
|
||||
private String id;
|
||||
private String myProfile;
|
||||
private User.AgeRange range;
|
||||
private IdNameEntity homeTown;
|
||||
|
||||
|
||||
class AgeRangeImpl implements User.AgeRange{
|
||||
|
||||
int age = 20;
|
||||
public Integer getMin() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Integer getMax() {
|
||||
return 120;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public UserImpl(String id, String profile, String phomeTown) {
|
||||
this.id = id;
|
||||
myProfile = profile;
|
||||
range = new AgeRangeImpl();
|
||||
homeTown = new IdNameEntityImpl(phomeTown,phomeTown);
|
||||
}
|
||||
|
||||
|
||||
public UserImpl(String id, String profile) {
|
||||
this.id = id;
|
||||
myProfile = profile;
|
||||
range = new AgeRangeImpl();
|
||||
}
|
||||
|
||||
public String myProfil() {
|
||||
return myProfile;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public AgeRange getAgeRange() {
|
||||
return range;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ArrayList friends = new ArrayList ();
|
||||
|
||||
public void addFriend(User friend) {
|
||||
friends.add(friend);
|
||||
}
|
||||
|
||||
public ArrayList getFriends() {
|
||||
return friends;
|
||||
}
|
||||
|
||||
private ArrayList family = new ArrayList ();
|
||||
|
||||
public void addFamily(User familyMember) {
|
||||
family.add(familyMember);
|
||||
}
|
||||
|
||||
public ArrayList getFamily(){
|
||||
return family;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserImpl [id=" + id + ", myProfile=" + myProfile + ", range="
|
||||
+ range +
|
||||
//",friends=" + friends + ", family=" + family +
|
||||
"]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdNameEntity getHometown() {
|
||||
return homeTown;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setLocation(String name) {
|
||||
homeTown = new IdNameEntityImpl(name,name) ;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user