本文整理汇总了Java中com.restfb.types.NamedFacebookType类的典型用法代码示例。如果您正苦于以下问题:Java NamedFacebookType类的具体用法?Java NamedFacebookType怎么用?Java NamedFacebookType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NamedFacebookType类属于com.restfb.types包,在下文中一共展示了NamedFacebookType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIdsOfPaginatedFriends
import com.restfb.types.NamedFacebookType; //导入依赖的package包/类
private List<String> getIdsOfPaginatedFriends(RenderRequest request, RenderResponse response, PortletSession session,
FacebookClientWrapper facebookClient) throws PortletException, IOException {
// Count total number of friends
Integer friendsCount = getFriendsCount(session, facebookClient);
// Obtain number of current page
Integer currentPage = getCurrentPageNumber(request, session);
Integer indexStart = (currentPage - 1) * ITEMS_PER_PAGE;
List<NamedFacebookType> friendsToDisplay = facebookClient.getPageOfFriends(indexStart, ITEMS_PER_PAGE);
getPaginatorUrls(friendsCount, response);
// Collect IDS of friends to display
List<String> ids = new ArrayList<String>();
for (NamedFacebookType current : friendsToDisplay) {
ids.add(current.getId());
}
return ids;
}
示例2: getIdsOfFilteredFriends
import com.restfb.types.NamedFacebookType; //导入依赖的package包/类
/**
* Filter string, which will be used for filtering of users by "contains" rule.
*
* <p>
* For example: You have 3 friends on Facebook with names: "John Woo", "Marc Boo", "Susie Cole" and filter will be "oo" Then
* output of this method will return "John Woo" and "Marc Boo"
* </p>
*
* @param filter Filter string, which will be used for filtering of users by "contains" rule. For example
* @return ids of filtered friends
*/
public List<String> getIdsOfFilteredFriends(String filter) throws PortletException, IOException {
// Not good to obtain all friends within each request, but we don't have better way atm (limitation of facebook search
// api...)
Connection<NamedFacebookType> connection = this.fetchConnection("me/friends", NamedFacebookType.class);
if (connection == null) {
return new ArrayList<String>();
}
List<NamedFacebookType> allFriends = connection.getData();
List<String> result = new ArrayList<String>();
for (NamedFacebookType current : allFriends) {
if (current.getName().contains(filter)) {
result.add(current.getId());
}
}
return result;
}
示例3: mapNamedType
import com.restfb.types.NamedFacebookType; //导入依赖的package包/类
protected Topic mapNamedType(NamedFacebookType type, TopicMap tm) throws TopicMapException{
Topic t;
// ToDo: resolve appropriate wrapper automatically
if(type instanceof Place){
Place place = (Place)type;
PlaceWrapper placeWrapper = new PlaceWrapper(place);
t = placeWrapper.mapToTopicMap(tm);
} else if (type instanceof Page){
Page page = (Page)type;
PageWrapper pageWrapper = new PageWrapper(page);
t = pageWrapper.mapToTopicMap(tm);
} else {
StubWrapper stub = new StubWrapper(type);
t = stub.mapToTopicMap(tm);
}
return t;
}
示例4: getPageOfFriends
import com.restfb.types.NamedFacebookType; //导入依赖的package包/类
/**
* get Page of friends according to given offset and limit
*
* @param offset
* @param limit
* @return friends starting from offset and number of returned friends will be limit
*/
public List<NamedFacebookType> getPageOfFriends(int offset, int limit) throws PortletException, IOException {
Connection<NamedFacebookType> con = this.fetchConnection("me/friends", NamedFacebookType.class,
Parameter.with("offset", offset), Parameter.with("limit", limit));
if (con != null) {
return con.getData();
} else {
return new ArrayList<NamedFacebookType>();
}
}
示例5: getStatusesOfPerson
import com.restfb.types.NamedFacebookType; //导入依赖的package包/类
/**
* return FacebookUserBean with filled status messages
*
* @param friendId
* @param myId This parameter is used only to recognize Facebook scope, which we need
* @param accessToken
* @return FacebookUserBean with filled status messages
*/
public FacebookUserBean getStatusesOfPerson(String friendId, String myId, AccessToken accessToken) throws PortletException,
IOException {
Connection<StatusMessage> statusMessageConnection = this.fetchConnection(friendId + "/statuses", StatusMessage.class,
Parameter.with("limit", 5));
if (statusMessageConnection == null) {
return null;
}
List<StatusMessage> statuses = statusMessageConnection.getData();
FacebookUserBean ffb = new FacebookUserBean();
ffb.setId(friendId);
ffb.setScope(false);
ffb.setStatuses(statuses);
if (statuses.size() == 0) {
// Different scope is needed for me and different for my friends
String neededScope = friendId.equals(myId) ? "user_status" : "friends_status";
if (accessToken.isScopeAvailable(neededScope)) {
ffb.setScope(true);
} else {
ffb.setNeededScope(neededScope);
}
} else {
NamedFacebookType currentFriendToDisplay = this.fetchObject(friendId, NamedFacebookType.class,
Parameter.with("fields", "id,name"));
if (currentFriendToDisplay != null) {
ffb.setName(currentFriendToDisplay.getName());
}
}
return ffb;
}
示例6: genLikes
import com.restfb.types.NamedFacebookType; //导入依赖的package包/类
public static String genLikes(List<NamedFacebookType> likes)
{
if (likes == null)
return "";
StringBuilder sb = new StringBuilder();
for (NamedFacebookType nft : likes)
{
sb.append(nft.getName() + ";");
}
if (sb.length() > 0)
sb.deleteCharAt(sb.length() - 1);
return sb.toString();
}
示例7: associateNamedType
import com.restfb.types.NamedFacebookType; //导入依赖的package包/类
protected void associateNamedType(TopicMap tm, NamedFacebookType type, String name, Topic parent, Topic parentType) throws TopicMapException{
Topic topic = mapNamedType(type, tm);
if(topic == null) return;
Topic topicType = getOrCreateType(tm, name);
Association employerAssoc = tm.createAssociation(topicType);
employerAssoc.addPlayer(parent, parentType);
employerAssoc.addPlayer(topic, topicType);
}
示例8: printField
import com.restfb.types.NamedFacebookType; //导入依赖的package包/类
public static void printField(PrintStream out, List<NamedFacebookType> values, boolean last) {
if (values == null) {
out.print("N/A" + ((last) ? "" : ", "));
} else {
for (NamedFacebookType value : values) {
out.print(value.getName().replaceAll("\n", "").replaceAll("\r", "").replaceAll(" ", "") + " ");
}
out.print(((last) ? "" : ", "));
}
}
示例9: getFriendsCount
import com.restfb.types.NamedFacebookType; //导入依赖的package包/类
/**
* @return number of all your friends on Facebook or -1 if error occured
*/
public int getFriendsCount() throws IOException, PortletException {
Connection<NamedFacebookType> myFriends = this.fetchConnection("me/friends", NamedFacebookType.class);
return myFriends != null ? myFriends.getData().size() : -1;
}
示例10: dataValidator
import com.restfb.types.NamedFacebookType; //导入依赖的package包/类
public static HashMap<String, String> dataValidator(HashMap<SerializerKey, Object> map)
{
HashMap<String, String> newMap = new HashMap<>();
if (map == null)
return newMap;
Iterator<SerializerKey> it = map.keySet().iterator();
while (it.hasNext())
{
SerializerKey key = it.next();
if (key != null && map.get(key) != null && key.getType() != null)
{
Object value = map.get(key);
String stringKey = key.toString();
String stringValue = null;
switch (key.getType())
{
case OTHER:
{
stringValue = packList(value);
break;
}
case DATE:
{
if (value instanceof Date)
stringValue = "" + ((Date) value).getTime();
break;
}
case LIST:
{
if (value instanceof List<?>)
stringValue = packList((List<?>) value);
break;
}
case NFT:
{
if (value instanceof NamedFacebookType)
stringValue = ((NamedFacebookType) value).getName();
break;
}
case CFT:
{
if (value instanceof CategorizedFacebookType)
stringValue = ((CategorizedFacebookType) value).getName();
break;
}
default:
{
stringValue = value.toString();
}
}
if (stringValue != null)
newMap.put(stringKey, stringValue);
}
}
return newMap;
}
示例11: accumulateUserActivity
import com.restfb.types.NamedFacebookType; //导入依赖的package包/类
private void accumulateUserActivity(HashMap<String, Integer> likedFriendsPosts,
HashMap<String, Integer> commentedFriendsPosts,
HashMap<String, Integer> sharedFriendsPosts,
HashMap<String, Integer> commonActivityUsers,
HashMap<String, Integer> postsPerUser,
ExtendedPost post) {
HashSet<String> activeUsers = new HashSet<String>();
boolean isActionedByUser = false;
if (!postsPerUser.containsKey(post.getFrom().getId())) {
postsPerUser.put(post.getFrom().getId(), 0);
}
postsPerUser.put(post.getFrom().getId(), postsPerUser.get(post.getFrom().getId()) + 1);
if (post.getLikes() != null) {
for (NamedFacebookType likedUser : post.getLikes().getData()) {
activeUsers.add(likedUser.getId());
if (likedUser.getId().equals(userId)) {
isActionedByUser = true;
if (!likedFriendsPosts.containsKey(post.getFrom().getId())) {
likedFriendsPosts.put(post.getFrom().getId(), 0);
}
likedFriendsPosts.put(post.getFrom().getId(), likedFriendsPosts.get(post.getFrom().getId()) + 1);
}
}
}
if (post.getComments() != null) {
for (Comment comment : post.getComments().getData()) {
activeUsers.add(comment.getFrom().getId());
if (comment.getFrom().getId().equals(userId) & !isActionedByUser) {
isActionedByUser = true;
if (!commentedFriendsPosts.containsKey(post.getFrom().getId())) {
commentedFriendsPosts.put(post.getFrom().getId(), 0);
}
commentedFriendsPosts.put(post.getFrom().getId(), commentedFriendsPosts.get(post.getFrom().getId()) + 1);
}
}
}
if (isActionedByUser) {
for (String id : activeUsers) {
if (!commonActivityUsers.containsKey(id)) {
commonActivityUsers.put(id, 0);
}
commonActivityUsers.put(id, commonActivityUsers.get(id) + 1);
}
}
}
示例12: testNulls
import com.restfb.types.NamedFacebookType; //导入依赖的package包/类
/**
* Makes sure we handle "null" when inside of a list instead of throwing a mapping exception.
*/
public void testNulls() {
List<NamedFacebookType> types =
createJsonMapper().toJavaList(jsonFromClasspath("nulls-in-list"), NamedFacebookType.class);
assertTrue(types.size() == 3);
}
示例13: mapToTopicMap
import com.restfb.types.NamedFacebookType; //导入依赖的package包/类
@Override
public Topic mapToTopicMap(TopicMap tm) throws TopicMapException{
Topic langTopic = getLangTopic(tm);
Topic userTopic = super.mapToTopicMap(tm);
Topic userType = getOrCreateType(tm, getType());
userTopic.setSubjectLocator(new Locator(AbstractFBGraphExtractor.URL_ROOT + user.getId()));
// Simple strings to map as occurrence data
final String[][] occurrenceData = {
{"Name", user.getName()},
{"About", user.getAbout()},
{"Bio", user.getBio()},
{"Birthday", user.getBirthday()},
{"Email", user.getEmail()},
{"Gender", user.getGender()},
{"Link", user.getLink()},
{"Locale", user.getLocale()},
{"Political", user.getPolitical()},
{"RelationshipStatus", user.getRelationshipStatus()},
{"Religion", user.getReligion()},
{"Quotes", user.getQuotes()},
{"Website", user.getWebsite()},
{"Currency", user.getCurrency() != null ? user.getCurrency().getUserCurrency() : null}
};
for (String[] datum : occurrenceData) {
Topic type = getOrCreateType(tm, datum[0]);
userTopic.setData(type, langTopic, datum[1]);
}
NamedFacebookType userLocation = user.getLocation();
associateNamedType(tm, userLocation, "Location", userTopic, userType);
List<NamedFacebookType> athletes = user.getFavoriteAthletes();
for(NamedFacebookType athlete: athletes){
associateNamedType(tm, athlete, "Athlete", userTopic, userType);
}
List<NamedFacebookType> teams = user.getFavoriteTeams();
for(NamedFacebookType team: teams){
associateNamedType(tm, team, "Team", userTopic, userType);
}
NamedFacebookType hometown = user.getHometown();
associateNamedType(tm, hometown, "Hometown", userTopic, userType);
List<User.Work> works = user.getWork();
Topic workType = getOrCreateType(tm, "Work");
for(User.Work work: works){
Topic workTopic = mapUserWork(work, tm);
Association workAssoc = tm.createAssociation(workType);
workAssoc.addPlayer(userTopic, userType);
workAssoc.addPlayer(workTopic, workType);
}
addPicture(tm, userTopic);
return userTopic;
}
示例14: mapToTopicMap
import com.restfb.types.NamedFacebookType; //导入依赖的package包/类
@Override
public Topic mapToTopicMap(TopicMap tm) throws TopicMapException {
Topic langTopic = getLangTopic(tm);
Topic workTopic = super.mapToTopicMap(tm);
Topic workType = getOrCreateType(tm, "Work");
final String[][] occurrenceData = {
{"startDate", work.getStartDate() != null ? work.getStartDate().toString() : null},
{"endDate", work.getEndDate() != null ? work.getEndDate().toString() : null},
{"description", work.getDescription()}
};
for (String[] datum : occurrenceData) {
Topic type = getOrCreateType(tm, datum[0]);
workTopic.setData(type, langTopic, datum[1]);
}
NamedFacebookType location = work.getLocation();
associateNamedType(tm, location, "Location", workTopic, workType);
NamedFacebookType employer = work.getEmployer();
associateNamedType(tm, employer, "Employer", workTopic, workType);
NamedFacebookType position = work.getPosition();
associateNamedType(tm, position, "Position", workTopic, workType);
return workTopic;
}
示例15: mapToTopicMap
import com.restfb.types.NamedFacebookType; //导入依赖的package包/类
@Override
Topic mapToTopicMap(TopicMap tm) throws TopicMapException {
FacebookType entity = getEnclosedEntity();
if(entity == null) return null;
String id = entity.getId();
String name;
if(entity instanceof NamedFacebookType){
name = ((NamedFacebookType)entity).getName();
} else {
name = id;
}
logger.log("Processing graph object: " + name);
Topic entityTopic = getOrCreateTopic(tm, getSIBase() + id, name + " (" + id + ")");
Topic entityType = getOrCreateType(tm, getType());
Topic facebookTopic = getFacebookTopic(tm);
makeSubclassOf(tm, entityType, facebookTopic);
entityTopic.addType(entityType);
Topic idType = getOrCreateType(tm, "id");
entityTopic.setData(idType, getLangTopic(tm), id);
return entityTopic;
}