List of usage examples for java.util SortedSet add
boolean add(E e);
From source file:com.spotify.heroic.filter.impl.OrFilterImpl.java
private static Filter optimize(SortedSet<Filter> statements) { final SortedSet<Filter> result = new TreeSet<>(); root: for (final Filter f : statements) { if (f instanceof Filter.Not) { final Filter.Not not = (Filter.Not) f; if (statements.contains(not.first())) { return TrueFilterImpl.get(); }/* ww w. ja va 2 s. c om*/ result.add(f); continue; } if (f instanceof Filter.StartsWith) { final Filter.StartsWith outer = (Filter.StartsWith) f; for (final Filter inner : statements) { if (inner.equals(outer)) { continue; } if (inner instanceof Filter.StartsWith) { final Filter.StartsWith starts = (Filter.StartsWith) inner; if (!outer.first().equals(starts.first())) { continue; } if (FilterComparatorUtils.prefixedWith(outer.second(), starts.second())) { continue root; } } } result.add(f); continue; } // all ok! result.add(f); } if (result.isEmpty()) { return TrueFilterImpl.get(); } if (result.size() == 1) { return result.iterator().next(); } return new OrFilterImpl(new ArrayList<>(result)); }
From source file:gov.nih.nci.cananolab.util.StringUtils.java
public static String sortJoin(Collection<String> strings, String delimiter) { SortedSet<SortableName> sortableNames = new TreeSet<SortableName>(); for (String str : strings) { sortableNames.add(new SortableName(str)); }/*w ww . j a v a 2 s .c om*/ String joinedStr = ""; if (sortableNames == null || sortableNames.isEmpty()) { return joinedStr; } StringBuilder sb = new StringBuilder(); int i = 0; for (SortableName sortableName : sortableNames) { if (i < sortableNames.size() - 1) { if (!StringUtils.isEmpty(sortableName.getName())) // joinedStr += sortableName.getName() + delimiter; sb.append(sortableName.getName()); sb.append(delimiter); } else { if (!StringUtils.isEmpty(sortableName.getName())) // joinedStr += sortableName.getName(); sb.append(sortableName.getName()); } i++; } joinedStr = sb.toString(); return joinedStr; }
From source file:org.apache.hive.ptest.execution.JIRAService.java
private static Map<String, Object> parseJsonFile(String jsonFile) throws IOException { JsonFactory jsonFactory = new JsonFactory(); JsonParser jsonParser = jsonFactory.createJsonParser(new File(jsonFile)); Map<String, Object> values = new HashMap<String, Object>(); while (jsonParser.nextToken() != JsonToken.END_OBJECT) { String fieldName = jsonParser.getCurrentName(); if (supportedJsonFields.containsKey(fieldName)) { jsonParser.nextToken();/* ww w . j av a 2 s . co m*/ Class clazz = supportedJsonFields.get(fieldName); if (clazz == String.class) { values.put(fieldName, jsonParser.getText()); } else if (clazz == Integer.class) { values.put(fieldName, Integer.valueOf(jsonParser.getText())); } else if (clazz == SortedSet.class) { SortedSet<String> failedTests = new TreeSet<String>(); while (jsonParser.nextToken() != JsonToken.END_ARRAY) { failedTests.add(jsonParser.getText()); } values.put(fieldName, failedTests); } else if (clazz == List.class) { List<String> messages = new ArrayList<String>(); while (jsonParser.nextToken() != JsonToken.END_ARRAY) { messages.add(jsonParser.getText()); } values.put(fieldName, messages); } } } jsonParser.close(); return values; }
From source file:com.rockagen.gnext.service.spring.security.extension.BasicSecurityUser.java
/** * Sort authorities.//from w w w. j a v a2 s. c o m * * @param authorities * the authorities * @return the sorted set */ private static SortedSet<GrantedAuthority> sortAuthorities(Collection<? extends GrantedAuthority> authorities) { Assert.notNull(authorities, "Cannot pass a null GrantedAuthority collection"); // Ensure array iteration order is predictable (as per UserDetails.getAuthorities() contract and SEC-717) SortedSet<GrantedAuthority> sortedAuthorities = new TreeSet<GrantedAuthority>(new AuthorityComparator()); for (GrantedAuthority grantedAuthority : authorities) { Assert.notNull(grantedAuthority, "GrantedAuthority list cannot contain any null elements"); sortedAuthorities.add(grantedAuthority); } return sortedAuthorities; }
From source file:com.kunckle.jetpower.core.user.entity.User.java
private static SortedSet<GrantedAuthority> sortAuthorities(Collection<? extends GrantedAuthority> authorities) { Assert.notNull(authorities, "Cannot pass a null GrantedAuthority collection"); // Ensure array iteration order is predictable (as per UserDetails.getUserSecurityRoles() contract and SEC-717) SortedSet<GrantedAuthority> sortedAuthorities = new TreeSet<>(new AuthorityComparator()); for (GrantedAuthority grantedAuthority : authorities) { Assert.notNull(grantedAuthority, "GrantedAuthority list cannot contain any null elements"); sortedAuthorities.add(grantedAuthority); }//from w w w. java 2s. c o m return sortedAuthorities; }
From source file:org.wrml.runtime.rest.RestUtils.java
public static final SortedSet<Parameter> extractUriQueryParameters(final URI uri) { if (uri == null) { return null; }/* w w w.j a v a2s . c om*/ final String queryPart = uri.getQuery(); if (queryPart == null || queryPart.isEmpty()) { return null; } final List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(uri, DEFAULT_ENCODING); if (nameValuePairs == null) { return null; } final SortedSet<Parameter> queryParameters = new TreeSet<Parameter>(); for (final NameValuePair nameValuePair : nameValuePairs) { final Parameter parameter = new Parameter(nameValuePair.getName(), nameValuePair.getValue()); queryParameters.add(parameter); } return queryParameters; }
From source file:gaffer.accumulostore.utils.IngestUtils.java
/** * Read a Base64 encoded splits file and return the splits as Text objects * <p>/* w ww . j a va 2 s . co m*/ * * @param fs - The FileSystem in which to create the splits file * @param splitsFile - A Path for the output splits file * @return A set of Text objects representing the locations of split points * in HDFS * @throws IOException for any IO issues reading from the file system. */ public static SortedSet<Text> getSplitsFromFile(final FileSystem fs, final Path splitsFile) throws IOException { final SortedSet<Text> splits = new TreeSet<>(); try (final FSDataInputStream fis = fs.open(splitsFile); final InputStreamReader streamReader = new InputStreamReader(fis, CommonConstants.UTF_8); final BufferedReader reader = new BufferedReader(streamReader)) { String line; while ((line = reader.readLine()) != null) { splits.add(new Text(Base64.decodeBase64(line))); } } return splits; }
From source file:org.thevortex.lighting.jinks.robot.Recurrence.java
/** * Parse from a partial ICAL string./* w ww.jav a 2 s. c o m*/ * * @param recurrenceString the string * @return a thing */ public static Recurrence parse(String recurrenceString) { if (recurrenceString == null) return null; Recurrence result = new Recurrence(); // each major part will be on a separate line String[] parts = recurrenceString.split("\\n"); // first one MUST be a "DTSTART;" or we're already fucked String working = checkAndStrip(DTSTART, parts[0]); result.startTime = LocalTime.parse(working, ICAL_DT); // if there are three parts, the second must be an end time if (parts.length == 3) { working = checkAndStrip(DTEND, parts[1]); LocalTime endsAt = LocalTime.parse(working, ICAL_DT); result.duration = Duration.between(result.startTime, endsAt); } // we always have a RRULE: first part is FREQ and if it's weekly, followed by BYDAY working = checkAndStrip(RRULE, parts[parts.length - 1]); parts = working.split(";"); // the type is first working = checkAndStrip(FREQ, parts[0]); result.frequency = Frequency.valueOf(working); // if it's weekly, there's more if (result.frequency == Frequency.WEEKLY) { SortedSet<DayOfWeek> list = new TreeSet<>(); working = checkAndStrip(BYDAY, parts[1]); for (String dayValue : working.split(",")) { for (DayOfWeek dow : DayOfWeek.values()) { if (dow.name().startsWith(dayValue)) { list.add(dow); break; } } } result.days = list; } return result; }
From source file:io.wcm.caravan.pipeline.impl.operators.CachePointTransformer.java
private static SortedSet<String> getSourceServiceIds(List<CaravanHttpRequest> requests) { SortedSet<String> sourceServiceIds = new TreeSet<String>(); for (CaravanHttpRequest request : requests) { sourceServiceIds.add(request.getServiceId()); }/*from w w w . ja v a 2 s . c o m*/ return sourceServiceIds; }
From source file:com.spotify.heroic.filter.impl.AndFilterImpl.java
private static Filter optimize(SortedSet<Filter> statements) { final SortedSet<Filter> result = new TreeSet<>(); root: for (final Filter f : statements) { if (f instanceof Filter.Not) { final Filter.Not not = (Filter.Not) f; if (statements.contains(not.first())) { return FalseFilterImpl.get(); }/*from w w w .j a v a 2 s .co m*/ result.add(f); continue; } /** * If there exists two MatchTag statements, but they check for different values. */ if (f instanceof Filter.MatchTag) { final Filter.MatchTag outer = (Filter.MatchTag) f; for (final Filter inner : statements) { if (inner.equals(outer)) { continue; } if (inner instanceof Filter.MatchTag) { final Filter.MatchTag matchTag = (Filter.MatchTag) inner; if (!outer.first().equals(matchTag.first())) { continue; } if (!FilterComparatorUtils.isEqual(outer.second(), matchTag.second())) { return FalseFilterImpl.get(); } } } result.add(f); continue; } if (f instanceof Filter.MatchTag) { final Filter.MatchTag outer = (Filter.MatchTag) f; for (final Filter inner : statements) { if (inner.equals(outer)) { continue; } if (inner instanceof Filter.MatchTag) { final Filter.MatchTag tag = (Filter.MatchTag) inner; if (!outer.first().equals(tag.first())) { continue; } if (!FilterComparatorUtils.isEqual(outer.second(), tag.second())) { return FalseFilterImpl.get(); } } } result.add(f); continue; } // optimize away prefixes which encompass eachother. // Example: foo ^ hello and foo ^ helloworld -> foo ^ helloworld if (f instanceof Filter.StartsWith) { final Filter.StartsWith outer = (Filter.StartsWith) f; for (final Filter inner : statements) { if (inner.equals(outer)) { continue; } if (inner instanceof Filter.StartsWith) { final Filter.StartsWith starts = (Filter.StartsWith) inner; if (!outer.first().equals(starts.first())) { continue; } if (FilterComparatorUtils.prefixedWith(starts.second(), outer.second())) { continue root; } } } result.add(f); continue; } // all ok! result.add(f); } if (result.isEmpty()) { return FalseFilterImpl.get(); } if (result.size() == 1) { return result.iterator().next(); } return new AndFilterImpl(new ArrayList<>(result)); }