private NameUtil() { // Don't allow creating an instance of this class
}
/** * Deprecated: See {@code GetGroupDisplayNameUseCase}
*/
@NonNull
@Deprecated publicstatic String getGroupDisplayName(
@NonNull GroupModelData groupModelData,
@NonNull ContactModelRepository contactModelRepository,
@NonNull UserService userService,
@NonNull ContactNameFormat contactNameFormat
) { // Use the name if it is not empty if (groupModelData.name != null && !groupModelData.name.isEmpty()) { return groupModelData.name;
}
// List members if the name is empty
String memberList = groupModelData.otherMembers.stream().map(identity -> {
ch.threema.data.models.ContactModel contactModel =
contactModelRepository.getByIdentity(identity); if (contactModel != null) { return getContactDisplayName(contactModel, contactNameFormat);
} else { return identity;
}
})
.sorted()
.collect(java.util.stream.Collectors.joining(", "));
if (groupModelData.groupIdentity.getCreatorIdentity().equals(myIdentity)) { // If the user is the creator, we prepend it to the list return prependUserToList(userService, memberList);
} elseif (groupModelData.isMember()) { // If the user is not the creator but a member, we prepend the creator and the user to // the list
memberList = prependCreatorToList(
contactModelRepository,
groupModelData.groupIdentity.getCreatorIdentity(),
memberList,
contactNameFormat
); return prependUserToList(userService, memberList);
} else { // If the user is not the creator and not a member, we prepend the creator to the list. return prependCreatorToList(
contactModelRepository,
groupModelData.groupIdentity.getCreatorIdentity(),
memberList,
contactNameFormat
);
}
}
/** * Return the display name for a group. * <br> * <br> * Deprecated: See {@code GetGroupDisplayNameUseCase}
*/
@Nullable
@Deprecated publicstatic String getGroupDisplayName(
@NonNull GroupModelOld groupModel,
@NonNull GroupService groupService,
@NonNull ContactNameFormat contactNameFormat
) { if (groupModel.getName() != null && !groupModel.getName().isEmpty()) { return groupModel.getName();
}
// list members
StringBuilder name = new StringBuilder(); for (ContactModel contactModel : groupService.getMembers(groupModel)) { if (name.length() > 0) {
name.append(", ");
}
name.append(NameUtil.getContactDisplayName(contactModel, contactNameFormat));
}
if (name.length() > 0) { return name.toString();
}
return groupModel.getApiGroupId().toString();
}
/** * Return the display name for a distribution list.
*/
@NonNull publicstatic String getDistributionListDisplayName(
@NonNull DistributionListModel distributionListModel,
@NonNull DistributionListService distributionListService,
@NonNull ContactNameFormat contactNameFormat
) { final @Nullable String distributionListModelName = distributionListModel.getName(); if (distributionListModelName != null && !distributionListModelName.isEmpty()) { return distributionListModelName;
}
StringBuilder name = new StringBuilder(); for (ContactModel contactModel : distributionListService.getMembers(distributionListModel)) { if (name.length() > 0) {
name.append(", ");
}
name.append(NameUtil.getContactDisplayName(contactModel, contactNameFormat));
}
if (name.length() > 0) { return name.toString();
}
/** * Return the name used for quotes and mentions.
*/
@NonNull publicstatic String getQuoteName(
@Nullable ContactModel contactModel,
@NonNull UserService userService,
@NonNull ContactNameFormat contactNameFormat
) { if (contactModel == null) { return"";
}
// If the contact is the local user, and the nickname does not equal the identity, // return the nickname. if (userService.isMe(contactModel.getIdentity())) { final String myNickname = userService.getPublicNickname(); if (!TestUtil.isEmptyOrNull(myNickname) && !myNickname.equals(userService.getIdentity())) { return myNickname;
}
}
/** * Return the name used for quotes and mentions. If the contact is not known or an error occurs * while getting the quote name, the identity is returned if not null. Otherwise an empty string * is returned.
*/
@NonNull publicstatic String getQuoteName(
@Nullable String identity,
@Nullable ContactService contactService,
@Nullable UserService userService,
@NonNull ContactNameFormat contactNameFormat
) { if (contactService == null || userService == null || identity == null) { return (identity != null) ? identity : "";
} if (ContactService.ALL_USERS_PLACEHOLDER_ID.equals(identity)) { return ThreemaApplication.getAppContext().getString(R.string.all);
} final @Nullable ContactModel contactModel = contactService.getByIdentity(identity); final @NonNull String quoteName = getQuoteName(contactModel, userService, contactNameFormat); return (quoteName.isBlank()) ? identity : quoteName;
}
/** * Extract first and last name from display name as provided by the Android contact database * If displayName is empty or null, empty strings will be returned for first/last name. * * @param displayName Name of the contact to split * @return A Pair containing first and last name
*/
@NonNull publicstatic Pair<String, String> getFirstLastNameFromDisplayName(@Nullable String displayName) { final String[] parts = displayName == null ? null : displayName.split(" "); if (parts == null || parts.length == 0) { returnnew Pair<>("", "");
} final String firstName = parts[0]; final String lastName = Arrays.stream(parts)
.skip(1)
.collect(Collectors.joining(" ")); returnnew Pair<>(firstName, lastName);
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-04-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.