/** update the current replacement of any original reader back to its original start */ private List<SSTableReader> restoreUpdatedOriginals() { Iterable<SSTableReader> torestore = filterIn(originals, logged.update, logged.obsolete); return ImmutableList.copyOf( transform( torestore, new Function<SSTableReader, SSTableReader>() { public SSTableReader apply(SSTableReader reader) { return current(reader).cloneWithNewStart(reader.first, null); } })); }
private static ImmutableSortedSet copyOfInternal(Comparator comparator1, Iterable iterable) { if (SortedIterables.hasSameComparator(comparator1, iterable) && (iterable instanceof ImmutableSortedSet)) { ImmutableSortedSet immutablesortedset = (ImmutableSortedSet) iterable; if (!immutablesortedset.isPartialView()) return immutablesortedset; } ImmutableList immutablelist = ImmutableList.copyOf(SortedIterables.sortedUnique(comparator1, iterable)); Object obj; if (immutablelist.isEmpty()) obj = emptySet(comparator1); else obj = new RegularImmutableSortedSet(immutablelist, comparator1); return ((ImmutableSortedSet) (obj)); }
/** Returns the path of an object in this schema. */ public List<String> path(String name) { final List<String> list = new ArrayList<String>(); if (name != null) { list.add(name); } for (OptiqSchema s = this; s != null; s = s.parent) { if (s.parent != null || !s.name.equals("")) { // Omit the root schema's name from the path if it's the empty string, // which it usually is. list.add(s.name); } } return ImmutableList.copyOf(Lists.reverse(list)); }
public DocIndexMetaData build() { partitionedBy = getPartitionedBy(); columnPolicy = getColumnPolicy(); createColumnDefinitions(); indices = createIndexDefinitions(); columns = ImmutableList.copyOf(columnsBuilder.build()); partitionedByColumns = partitionedByColumnsBuilder.build(); for (Tuple<ColumnIdent, ReferenceInfo> sysColumn : DocSysColumns.forTable(ident)) { referencesBuilder.put(sysColumn.v1(), sysColumn.v2()); } references = referencesBuilder.build(); primaryKey = getPrimaryKey(); routingCol = getRoutingCol(); return this; }
/** @return collection of the non-system tables */ public List<String> getNonSystemTables() { return ImmutableList.copyOf(Sets.difference(tables.keySet(), systemKeyspaceNames)); }
private static ImmutableSortedSet copyOfInternal(Comparator comparator1, Iterator iterator1) { ImmutableList immutablelist = ImmutableList.copyOf(SortedIterables.sortedUnique(comparator1, iterator1)); if (immutablelist.isEmpty()) return emptySet(comparator1); else return new RegularImmutableSortedSet(immutablelist, comparator1); }
private void init( PName name, PTableType type, long timeStamp, long sequenceNumber, String pkName, List<PColumn> columns, PTableStats stats) { this.name = name; this.type = type; this.timeStamp = timeStamp; this.sequenceNumber = sequenceNumber; this.columnsByName = ArrayListMultimap.create(columns.size(), 1); this.pkName = pkName; List<PColumn> pkColumns = Lists.newArrayListWithExpectedSize(columns.size() - 1); PColumn[] allColumns = new PColumn[columns.size()]; RowKeySchemaBuilder builder = new RowKeySchemaBuilder(); for (int i = 0; i < allColumns.length; i++) { PColumn column = columns.get(i); allColumns[column.getPosition()] = column; PName familyName = column.getFamilyName(); if (familyName == null) { pkColumns.add(column); builder.addField(column); } columnsByName.put(column.getName().getString(), column); } this.pkColumns = ImmutableList.copyOf(pkColumns); this.rowKeySchema = builder.setMinNullable(pkColumns.size()).build(); this.allColumns = ImmutableList.copyOf(allColumns); // Two pass so that column order in column families matches overall column order // and to ensure that column family order is constant int maxExpectedSize = allColumns.length - pkColumns.size(); // Maintain iteration order so that column families are ordered as they are listed Map<PName, List<PColumn>> familyMap = Maps.newLinkedHashMap(); for (PColumn column : allColumns) { PName familyName = column.getFamilyName(); if (familyName != null) { List<PColumn> columnsInFamily = familyMap.get(familyName); if (columnsInFamily == null) { columnsInFamily = Lists.newArrayListWithExpectedSize(maxExpectedSize); familyMap.put(familyName, columnsInFamily); } columnsInFamily.add(column); } } Iterator<Map.Entry<PName, List<PColumn>>> iterator = familyMap.entrySet().iterator(); PColumnFamily[] families = new PColumnFamily[familyMap.size()]; ImmutableMap.Builder<String, PColumnFamily> familyByString = ImmutableMap.builder(); ImmutableSortedMap.Builder<byte[], PColumnFamily> familyByBytes = ImmutableSortedMap.orderedBy(Bytes.BYTES_COMPARATOR); for (int i = 0; i < families.length; i++) { Map.Entry<PName, List<PColumn>> entry = iterator.next(); PColumnFamily family = new PColumnFamilyImpl(entry.getKey(), entry.getValue()); families[i] = family; familyByString.put(family.getName().getString(), family); familyByBytes.put(family.getName().getBytes(), family); } this.families = ImmutableList.copyOf(families); this.familyByBytes = familyByBytes.build(); this.familyByString = familyByString.build(); this.stats = stats; }
/** * Parse the given array of arguments. * * <p>Empty arguments are removed from the list of arguments. * * @param args an array with arguments * @param expectedValueFlags a set containing all value flags (pass null to disable value flag * parsing) * @param allowHangingFlag true if hanging flags are allowed * @param namespace the locals, null to create empty one * @throws CommandException thrown on a parsing error */ public CommandContext( String[] args, Set<Character> expectedValueFlags, boolean allowHangingFlag, Namespace namespace) throws CommandException { if (expectedValueFlags == null) { expectedValueFlags = Collections.emptySet(); } originalArgs = args; command = args[0]; this.namespace = namespace != null ? namespace : new Namespace(); boolean isHanging = false; SuggestionContext suggestionContext = SuggestionContext.hangingValue(); // Eliminate empty args and combine multiword args first List<Integer> argIndexList = new ArrayList<Integer>(args.length); List<String> argList = new ArrayList<String>(args.length); for (int i = 1; i < args.length; ++i) { isHanging = false; String arg = args[i]; if (arg.isEmpty()) { isHanging = true; continue; } argIndexList.add(i); switch (arg.charAt(0)) { case '\'': case '"': final StringBuilder build = new StringBuilder(); final char quotedChar = arg.charAt(0); int endIndex; for (endIndex = i; endIndex < args.length; ++endIndex) { final String arg2 = args[endIndex]; if (arg2.charAt(arg2.length() - 1) == quotedChar && arg2.length() > 1) { if (endIndex != i) build.append(' '); build.append(arg2.substring(endIndex == i ? 1 : 0, arg2.length() - 1)); break; } else if (endIndex == i) { build.append(arg2.substring(1)); } else { build.append(' ').append(arg2); } } if (endIndex < args.length) { arg = build.toString(); i = endIndex; } // In case there is an empty quoted string if (arg.isEmpty()) { continue; } // else raise exception about hanging quotes? } argList.add(arg); } // Then flags List<Integer> originalArgIndices = Lists.newArrayListWithCapacity(argIndexList.size()); List<String> parsedArgs = Lists.newArrayListWithCapacity(argList.size()); Map<Character, String> valueFlags = Maps.newHashMap(); List<Character> booleanFlags = Lists.newArrayList(); for (int nextArg = 0; nextArg < argList.size(); ) { // Fetch argument String arg = argList.get(nextArg++); suggestionContext = SuggestionContext.hangingValue(); // Not a flag? if (arg.charAt(0) != '-' || arg.length() == 1 || !arg.matches("^-[a-zA-Z\\?]+$")) { if (!isHanging) { suggestionContext = SuggestionContext.lastValue(); } originalArgIndices.add(argIndexList.get(nextArg - 1)); parsedArgs.add(arg); continue; } // Handle flag parsing terminator -- if (arg.equals("--")) { while (nextArg < argList.size()) { originalArgIndices.add(argIndexList.get(nextArg)); parsedArgs.add(argList.get(nextArg++)); } break; } // Go through the flag characters for (int i = 1; i < arg.length(); ++i) { char flagName = arg.charAt(i); if (expectedValueFlags.contains(flagName)) { if (valueFlags.containsKey(flagName)) { throw new CommandException("Value flag '" + flagName + "' already given"); } if (nextArg >= argList.size()) { if (allowHangingFlag) { suggestionContext = SuggestionContext.flag(flagName); break; } else { throw new CommandException("No value specified for the '-" + flagName + "' flag."); } } // If it is a value flag, read another argument and add it valueFlags.put(flagName, argList.get(nextArg++)); if (!isHanging) { suggestionContext = SuggestionContext.flag(flagName); } } else { booleanFlags.add(flagName); } } } ImmutableMap.Builder<Character, String> allFlagsBuilder = new ImmutableMap.Builder<Character, String>().putAll(valueFlags); for (Character flag : booleanFlags) { allFlagsBuilder.put(flag, "true"); } this.parsedArgs = ImmutableList.copyOf(parsedArgs); this.originalArgIndices = ImmutableList.copyOf(originalArgIndices); this.booleanFlags = ImmutableSet.copyOf(booleanFlags); this.valueFlags = ImmutableMap.copyOf(valueFlags); this.allFlags = allFlagsBuilder.build(); this.suggestionContext = suggestionContext; }
/** @deprecated retained for benefit of old tests */ public Collection<InetAddress> getWriteEndpoints( Token token, String keyspaceName, Collection<InetAddress> naturalEndpoints) { return ImmutableList.copyOf( Iterables.concat(naturalEndpoints, pendingEndpointsFor(token, keyspaceName))); }