public SlotStatusRepresentationFactory(List<SlotStatus> slotStatuses, Repository repository) { this.shortIdPrefixSize = shortestUniquePrefix(transform(slotStatuses, idGetter()), MIN_PREFIX_SIZE); this.commonLocationParts = commonPrefixSegments('/', transform(slotStatuses, locationGetter()), MIN_LOCATION_SEGMENTS); this.repository = repository; }
public static int shortestUniquePrefix(Collection<String> strings, int minSize) { Preconditions.checkNotNull(strings, "strings is null"); // remove nulls strings = ImmutableList.copyOf(Iterables.filter(strings, Predicates.notNull())); // must have at least two strings to calculate min size if (strings.size() < 2) { return minSize; } SortedSet<String> sorted = Sets.newTreeSet(strings); if (sorted.size() != strings.size()) { throw new IllegalArgumentException("Cannot compute unique prefix size for collection with duplicate entries"); } int prefix = shortestUniquePrefixStartingAt(ImmutableList.copyOf(sorted), 0); return max(prefix, minSize); }
public AgentStatusRepresentation create(AgentStatus status) { Builder<SlotStatusRepresentation> builder = ImmutableList.builder(); for (SlotStatus slot : status.getSlotStatuses()) { builder.add(SlotStatusRepresentation.from(slot, Integer.MAX_VALUE, repository)); } return new AgentStatusRepresentation( status.getAgentId(), safeTruncate(status.getAgentId(), shortIdPrefixSize), status.getInstanceId(), status.getState(), status.getInternalUri(), status.getExternalUri(), status.getLocation(), trimLeadingSegments(status.getLocation(), '/', commonLocationParts), status.getInstanceType(), builder.build(), status.getResources(), status.getVersion()); } }
private static int shortestUniquePrefixStartingAt(List<String> strings, int charPosition) Preconditions.checkArgument(charPosition < Collections.max(transform(strings, lengthGetter())), "charPosition is beyond the size of all the provided strings"); if (index - sequenceStart > 1) { result = max(result, shortestUniquePrefixStartingAt(strings.subList(sequenceStart, index), charPosition + 1) + 1); result = max(result, shortestUniquePrefixStartingAt(strings.subList(sequenceStart, strings.size()), charPosition + 1) + 1);
public static int commonPrefixSegments(char separator, Collection<String> strings) { return commonPrefixSegments(separator, strings, 0); }
public static int shortestUniquePrefix(Collection<String> strings) { return shortestUniquePrefix(strings, 1); }
public static int commonPrefixSegments(char separator, Collection<String> strings, int minSize) { Preconditions.checkNotNull(strings, "strings is null"); Preconditions.checkArgument(minSize >= 0, "minSize is negative"); if (strings.isEmpty()) { return 0; } int shortestNumberOfParts = Integer.MAX_VALUE; List<List<String>> stringsParts = newArrayList(); for (String string : strings) { List<String> parts = ImmutableList.copyOf(Splitter.on(separator).split(string)); if (parts.isEmpty() || !parts.get(0).isEmpty()) { throw new IllegalArgumentException("All strings must start with the separator character"); } parts = parts.subList(1, parts.size()); stringsParts.add(parts); shortestNumberOfParts = min(parts.size(), shortestNumberOfParts); } int maxNumberOfSharedParts = max(shortestNumberOfParts - minSize, 0); int commonParts = 0; while (commonParts < maxNumberOfSharedParts && isPartEqual(commonParts, stringsParts)) { commonParts++; } return commonParts; }
safeTruncate(slotStatus.getId().toString(), shortIdPrefixSize), slotStatus.getSelf(), slotStatus.getExternalUri(),
public CoordinatorStatusRepresentation create(CoordinatorStatus status) { return new CoordinatorStatusRepresentation( status.getCoordinatorId(), safeTruncate(status.getCoordinatorId(), shortIdPrefixSize), status.getInstanceId(), status.getState(), status.getInternalUri(), status.getExternalUri(), status.getLocation(), trimLeadingSegments(status.getLocation(), '/', commonLocationParts), status.getInstanceType(), status.getVersion()); } }
public CoordinatorStatusRepresentationFactory(List<CoordinatorStatus> coordinatorStatuses) { this.shortIdPrefixSize = shortestUniquePrefix(transform(coordinatorStatuses, idGetter()), MIN_PREFIX_SIZE); this.commonLocationParts = commonPrefixSegments('/', transform(coordinatorStatuses, locationGetter()), MIN_LOCATION_SEGMENTS); }
safeTruncate(status.getId().toString(), shortIdPrefixSize), status.getSelf(), status.getExternalUri(), status.getInstanceId(), status.getLocation(), trimLeadingSegments(status.getLocation(), '/', commonLocationParts), binary, shortBinary,
public AgentStatusRepresentationFactory(List<AgentStatus> agentStatuses, Repository repository) { this.shortIdPrefixSize = shortestUniquePrefix(transform(agentStatuses, idGetter()), MIN_PREFIX_SIZE); this.commonLocationParts = commonPrefixSegments('/', transform(agentStatuses, locationGetter()), MIN_LOCATION_SEGMENTS); this.repository = repository; }