Java Code Examples for java.util.TreeSet#toString()

The following examples show how to use java.util.TreeSet#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpManagementUtil.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: 11286 Confirmity.java    From UVA with GNU General Public License v3.0 6 votes vote down vote up
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);
	}
}
 
Example 3
Source File: Test4058433.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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());
    }
}
 
Example 4
Source File: TreeSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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)));
    }
}
 
Example 5
Source File: casc.java    From Ngram-Graphs with Apache License 2.0 5 votes vote down vote up
public Triplet(String sV1, String sV2, String sV3) {
    TreeSet tsSet = new TreeSet();
    tsSet.add(sV1 + "_");
    tsSet.add(sV2 + "_");
    tsSet.add(sV3 + "_");
    
    sString = tsSet.toString();
}
 
Example 6
Source File: casc.java    From Ngram-Graphs with Apache License 2.0 5 votes vote down vote up
public Triplet(String sV1, String sV2, String sV3) {
    TreeSet tsSet = new TreeSet();
    tsSet.add(sV1 + "_");
    tsSet.add(sV2 + "_");
    tsSet.add(sV3 + "_");
    
    sString = tsSet.toString();
}
 
Example 7
Source File: LargeSetTest.java    From minperf with Apache License 2.0 5 votes vote down vote up
private static String toString(LongSet set) {
    TreeSet<Long> s2 = new TreeSet<Long>();
    for (long x : set) {
        s2.add(x);
    }
    return s2.toString();
}
 
Example 8
Source File: TreeSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * 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)));
    }
}
 
Example 9
Source File: ServiceRESTUtil.java    From ranger with Apache License 2.0 4 votes vote down vote up
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;
}