下面列出了java.util.TreeSet#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static String getRequestPrincipals(HttpServletRequest httpRequest)
{
HttpSession session = httpRequest.getSession(false);
if (session != null)
{
Subject subject = HttpManagementUtil.getAuthorisedSubject(httpRequest);
if (subject != null)
{
Set<Principal> principalSet = subject.getPrincipals();
if (!principalSet.isEmpty())
{
TreeSet<String> principalNames = new TreeSet<>();
for (Principal principal : principalSet)
{
principalNames.add(principal.getName());
}
return principalNames.toString();
}
}
}
return null;
}
public static void main (String [] args) throws Exception {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s;
while (!(s=br.readLine()).equals("0")){
int n=Integer.parseInt(s);
HashMap<String,Integer> map=new HashMap<>();
for (int i=0;i<n;i++) {
StringTokenizer st=new StringTokenizer(br.readLine());
TreeSet<String> set=new TreeSet<>();
for (int i2=0;i2<5;i2++) set.add(st.nextToken());
String key=set.toString();
map.put(key, map.getOrDefault(key,0)+1);
}
int max=Collections.max(map.values());
System.out.println(map.values().stream().filter(i -> i == max).count()*max);
}
}
private static void print(FeatureDescriptor descriptor) {
String name = descriptor.getName();
String display = descriptor.getDisplayName();
String description = descriptor.getShortDescription();
System.out.println("name: " + name);
if (!Objects.equals(name, display)) {
System.out.println("display name: " + display);
}
if (!Objects.equals(display, description)) {
System.out.println("description: " + description.trim());
}
print("expert", descriptor.isExpert());
print("hidden", descriptor.isHidden());
print("preferred", descriptor.isPreferred());
TreeMap<String,Object> map = new TreeMap<>();
Enumeration<String> enumeration = descriptor.attributeNames();
while (enumeration.hasMoreElements()) {
String id = enumeration.nextElement();
Object value = descriptor.getValue(id);
if (value.getClass().isArray()) {
TreeSet<String> set = new TreeSet<>();
int index = 0;
int length = Array.getLength(value);
while (index < length) {
set.add(Array.get(value, index++) + ", " +
Array.get(value, index++) + ", " +
Array.get(value, index++));
}
value = set.toString();
}
map.put(id, value);
}
for (Entry<String,Object> entry : map.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
/**
* toString contains toStrings of elements
*/
public void testToString() {
TreeSet q = populatedSet(SIZE);
String s = q.toString();
for (int i = 0; i < SIZE; ++i) {
assertTrue(s.contains(String.valueOf(i)));
}
}
public Triplet(String sV1, String sV2, String sV3) {
TreeSet tsSet = new TreeSet();
tsSet.add(sV1 + "_");
tsSet.add(sV2 + "_");
tsSet.add(sV3 + "_");
sString = tsSet.toString();
}
public Triplet(String sV1, String sV2, String sV3) {
TreeSet tsSet = new TreeSet();
tsSet.add(sV1 + "_");
tsSet.add(sV2 + "_");
tsSet.add(sV3 + "_");
sString = tsSet.toString();
}
private static String toString(LongSet set) {
TreeSet<Long> s2 = new TreeSet<Long>();
for (long x : set) {
s2.add(x);
}
return s2.toString();
}
/**
* toString contains toStrings of elements
*/
public void testToString() {
TreeSet q = populatedSet(SIZE);
String s = q.toString();
for (int i = 0; i < SIZE; ++i) {
assertTrue(s.contains(String.valueOf(i)));
}
}
static private List<RangerPolicy.RangerPolicyItem> mergePolicyItems(List<RangerPolicy.RangerPolicyItem> policyItems) {
List<RangerPolicy.RangerPolicyItem> ret = new ArrayList<RangerPolicy.RangerPolicyItem>();
if (CollectionUtils.isNotEmpty(policyItems)) {
Map<String, RangerPolicy.RangerPolicyItem> matchedPolicyItems = new HashMap<String, RangerPolicy.RangerPolicyItem>();
for (RangerPolicy.RangerPolicyItem policyItem : policyItems) {
if((CollectionUtils.isEmpty(policyItem.getUsers()) && CollectionUtils.isEmpty(policyItem.getGroups()) && CollectionUtils.isEmpty(policyItem.getRoles())) ||
(CollectionUtils.isEmpty(policyItem.getAccesses()) && !policyItem.getDelegateAdmin())) {
continue;
}
if (policyItem.getConditions().size() > 1) {
ret.add(policyItem);
continue;
}
TreeSet<String> accesses = new TreeSet<String>();
for (RangerPolicy.RangerPolicyItemAccess access : policyItem.getAccesses()) {
accesses.add(access.getType());
}
if (policyItem.getDelegateAdmin()) {
accesses.add("delegateAdmin");
}
String allAccessesString = accesses.toString();
RangerPolicy.RangerPolicyItem matchingPolicyItem = matchedPolicyItems.get(allAccessesString);
if (matchingPolicyItem != null) {
addDistinctItems(policyItem.getUsers(), matchingPolicyItem.getUsers());
addDistinctItems(policyItem.getGroups(), matchingPolicyItem.getGroups());
addDistinctItems(policyItem.getRoles(), matchingPolicyItem.getRoles());
} else {
matchedPolicyItems.put(allAccessesString, policyItem);
}
}
for (Map.Entry<String, RangerPolicy.RangerPolicyItem> entry : matchedPolicyItems.entrySet()) {
ret.add(entry.getValue());
}
}
return ret;
}