Search in sources :

Example 16 with Predicate

use of com.google.common.base.Predicate in project druid by druid-io.

the class ConvertSegmentTask method run.

@Override
public TaskStatus run(TaskToolbox toolbox) throws Exception {
    final Iterable<DataSegment> segmentsToUpdate;
    if (segment == null) {
        final List<DataSegment> segments = toolbox.getTaskActionClient().submit(new SegmentListUsedAction(getDataSource(), getInterval(), null));
        segmentsToUpdate = FunctionalIterable.create(segments).filter(new Predicate<DataSegment>() {

            @Override
            public boolean apply(DataSegment segment) {
                final Integer segmentVersion = segment.getBinaryVersion();
                if (!CURR_VERSION_INTEGER.equals(segmentVersion)) {
                    return true;
                } else if (force) {
                    log.info("Segment[%s] already at version[%s], forcing conversion", segment.getIdentifier(), segmentVersion);
                    return true;
                } else {
                    log.info("Skipping[%s], already version[%s]", segment.getIdentifier(), segmentVersion);
                    return false;
                }
            }
        });
    } else {
        log.info("I'm in a subless mood.");
        segmentsToUpdate = Collections.singleton(segment);
    }
    // Vestigial from a past time when this task spawned subtasks.
    for (final Task subTask : generateSubTasks(getGroupId(), segmentsToUpdate, indexSpec, force, validate, getContext())) {
        final TaskStatus status = subTask.run(toolbox);
        if (!status.isSuccess()) {
            return TaskStatus.fromCode(getId(), status.getStatusCode());
        }
    }
    return success();
}
Also used : SegmentListUsedAction(io.druid.indexing.common.actions.SegmentListUsedAction) TaskStatus(io.druid.indexing.common.TaskStatus) DataSegment(io.druid.timeline.DataSegment) Predicate(com.google.common.base.Predicate)

Example 17 with Predicate

use of com.google.common.base.Predicate in project buck by facebook.

the class OwnersReport method generateOwnersReport.

@VisibleForTesting
static OwnersReport generateOwnersReport(Cell rootCell, TargetNode<?, ?> targetNode, Iterable<String> filePaths) {
    // Process arguments assuming they are all relative file paths.
    Set<Path> inputs = Sets.newHashSet();
    Set<String> nonExistentInputs = Sets.newHashSet();
    Set<String> nonFileInputs = Sets.newHashSet();
    for (String filePath : filePaths) {
        Path file = rootCell.getFilesystem().getPathForRelativePath(filePath);
        if (!Files.exists(file)) {
            nonExistentInputs.add(filePath);
        } else if (!Files.isRegularFile(file)) {
            nonFileInputs.add(filePath);
        } else {
            inputs.add(rootCell.getFilesystem().getPath(filePath));
        }
    }
    // Try to find owners for each valid and existing file.
    Set<Path> inputsWithNoOwners = Sets.newHashSet(inputs);
    SetMultimap<TargetNode<?, ?>, Path> owners = TreeMultimap.create();
    for (final Path commandInput : inputs) {
        Predicate<Path> startsWith = input -> !commandInput.equals(input) && commandInput.startsWith(input);
        Set<Path> ruleInputs = targetNode.getInputs();
        if (ruleInputs.contains(commandInput) || FluentIterable.from(ruleInputs).anyMatch(startsWith)) {
            inputsWithNoOwners.remove(commandInput);
            owners.put(targetNode, commandInput);
        }
    }
    return new OwnersReport(owners, inputsWithNoOwners, nonExistentInputs, nonFileInputs);
}
Also used : Path(java.nio.file.Path) BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildFileTree(com.facebook.buck.model.BuildFileTree) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable(com.google.common.collect.FluentIterable) TreeMultimap(com.google.common.collect.TreeMultimap) Map(java.util.Map) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) Cell(com.facebook.buck.rules.Cell) Path(java.nio.file.Path) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) Parser(com.facebook.buck.parser.Parser) ImmutableSet(com.google.common.collect.ImmutableSet) Files(java.nio.file.Files) TargetNode(com.facebook.buck.rules.TargetNode) Set(java.util.Set) IOException(java.io.IOException) Console(com.facebook.buck.util.Console) Maps(com.google.common.collect.Maps) SetMultimap(com.google.common.collect.SetMultimap) Sets(com.google.common.collect.Sets) MorePaths(com.facebook.buck.io.MorePaths) Predicate(com.google.common.base.Predicate) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) TargetNode(com.facebook.buck.rules.TargetNode) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 18 with Predicate

use of com.google.common.base.Predicate in project buck by facebook.

the class AuditRulesCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    ProjectFilesystem projectFilesystem = params.getCell().getFilesystem();
    try (ProjectBuildFileParser parser = params.getCell().createBuildFileParser(new ConstructorArgMarshaller(new DefaultTypeCoercerFactory(params.getObjectMapper())), params.getConsole(), params.getBuckEventBus(), /* ignoreBuckAutodepsFiles */
    false)) {
        PrintStream out = params.getConsole().getStdOut();
        for (String pathToBuildFile : getArguments()) {
            if (!json) {
                // Print a comment with the path to the build file.
                out.printf("# %s\n\n", pathToBuildFile);
            }
            // Resolve the path specified by the user.
            Path path = Paths.get(pathToBuildFile);
            if (!path.isAbsolute()) {
                Path root = projectFilesystem.getRootPath();
                path = root.resolve(path);
            }
            // Parse the rules from the build file.
            List<Map<String, Object>> rawRules;
            try {
                rawRules = parser.getAll(path);
            } catch (BuildFileParseException e) {
                throw new HumanReadableException(e);
            }
            // Format and print the rules from the raw data, filtered by type.
            final ImmutableSet<String> types = getTypes();
            Predicate<String> includeType = type -> types.isEmpty() || types.contains(type);
            printRulesToStdout(params, rawRules, includeType);
        }
    } catch (BuildFileParseException e) {
        throw new HumanReadableException("Unable to create parser");
    }
    return 0;
}
Also used : Path(java.nio.file.Path) SortedSet(java.util.SortedSet) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) HashMap(java.util.HashMap) MoreStrings(com.facebook.buck.util.MoreStrings) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Lists(com.google.common.collect.Lists) Argument(org.kohsuke.args4j.Argument) ProjectBuildFileParser(com.facebook.buck.json.ProjectBuildFileParser) FluentIterable(com.google.common.collect.FluentIterable) Map(java.util.Map) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) Escaper(com.facebook.buck.util.Escaper) BuckPyFunction(com.facebook.buck.rules.BuckPyFunction) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) PrintStream(java.io.PrintStream) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Option(org.kohsuke.args4j.Option) HumanReadableException(com.facebook.buck.util.HumanReadableException) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) List(java.util.List) JsonFactory(com.fasterxml.jackson.core.JsonFactory) Predicate(com.google.common.base.Predicate) Paths(java.nio.file.Paths) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) PrintStream(java.io.PrintStream) ProjectBuildFileParser(com.facebook.buck.json.ProjectBuildFileParser) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) HumanReadableException(com.facebook.buck.util.HumanReadableException) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with Predicate

use of com.google.common.base.Predicate in project buck by facebook.

the class AuditRulesCommand method printRulesToStdout.

private void printRulesToStdout(CommandRunnerParams params, List<Map<String, Object>> rawRules, final Predicate<String> includeType) throws IOException {
    Iterable<Map<String, Object>> filteredRules = FluentIterable.from(rawRules).filter(rawRule -> {
        String type = (String) rawRule.get(BuckPyFunction.TYPE_PROPERTY_NAME);
        return includeType.apply(type);
    });
    PrintStream stdOut = params.getConsole().getStdOut();
    if (json) {
        Map<String, Object> rulesKeyedByName = new HashMap<>();
        for (Map<String, Object> rawRule : filteredRules) {
            String name = (String) rawRule.get("name");
            Preconditions.checkNotNull(name);
            rulesKeyedByName.put(name, Maps.filterValues(rawRule, v -> shouldInclude(v)));
        }
        // We create a new JsonGenerator that does not close the stream.
        ObjectMapper mapper = params.getObjectMapper();
        JsonFactory factory = mapper.getFactory();
        try (JsonGenerator generator = factory.createGenerator(stdOut).disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET).useDefaultPrettyPrinter()) {
            mapper.writeValue(generator, rulesKeyedByName);
        }
        stdOut.print('\n');
    } else {
        for (Map<String, Object> rawRule : filteredRules) {
            printRuleAsPythonToStdout(stdOut, rawRule);
        }
    }
}
Also used : SortedSet(java.util.SortedSet) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) HashMap(java.util.HashMap) MoreStrings(com.facebook.buck.util.MoreStrings) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Lists(com.google.common.collect.Lists) Argument(org.kohsuke.args4j.Argument) ProjectBuildFileParser(com.facebook.buck.json.ProjectBuildFileParser) FluentIterable(com.google.common.collect.FluentIterable) Map(java.util.Map) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) Escaper(com.facebook.buck.util.Escaper) BuckPyFunction(com.facebook.buck.rules.BuckPyFunction) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) PrintStream(java.io.PrintStream) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Option(org.kohsuke.args4j.Option) HumanReadableException(com.facebook.buck.util.HumanReadableException) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) List(java.util.List) JsonFactory(com.fasterxml.jackson.core.JsonFactory) Predicate(com.google.common.base.Predicate) Paths(java.nio.file.Paths) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) PrintStream(java.io.PrintStream) HashMap(java.util.HashMap) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 20 with Predicate

use of com.google.common.base.Predicate in project MinecraftForge by MinecraftForge.

the class ModelLoader method loadItemModels.

@Override
protected void loadItemModels() {
    // register model for the universal bucket, if it exists
    if (FluidRegistry.isUniversalBucketEnabled()) {
        setBucketModelDefinition(ForgeModContainer.getInstance().universalBucket);
    }
    registerVariantNames();
    List<Item> items = Lists.newArrayList(Iterables.filter(Item.REGISTRY, new Predicate<Item>() {

        public boolean apply(Item item) {
            return item.getRegistryName() != null;
        }
    }));
    Collections.sort(items, new Comparator<Item>() {

        public int compare(Item i1, Item i2) {
            return i1.getRegistryName().toString().compareTo(i2.getRegistryName().toString());
        }
    });
    ProgressBar itemBar = ProgressManager.push("ModelLoader: items", items.size());
    for (Item item : items) {
        itemBar.step(item.getRegistryName().toString());
        for (String s : getVariantNames(item)) {
            ResourceLocation file = getItemLocation(s);
            ModelResourceLocation memory = getInventoryVariant(s);
            IModel model = ModelLoaderRegistry.getMissingModel();
            Exception exception = null;
            try {
                model = ModelLoaderRegistry.getModel(file);
            } catch (Exception normalException) {
                // try blockstate json if the item model is missing
                FMLLog.fine("Item json isn't found for '" + memory + "', trying to load the variant from the blockstate json");
                try {
                    model = ModelLoaderRegistry.getModel(memory);
                } catch (Exception blockstateException) {
                    exception = new ItemLoadingException("Could not load item model either from the normal location " + file + " or from the blockstate", normalException, blockstateException);
                }
            }
            if (exception != null) {
                storeException(memory, exception);
                model = ModelLoaderRegistry.getMissingModel(memory, exception);
            }
            stateModels.put(memory, model);
        }
    }
    ProgressManager.pop(itemBar);
    // replace vanilla bucket models if desired. done afterwards for performance reasons
    if (ForgeModContainer.replaceVanillaBucketModel) {
        // ensure the bucket model is loaded
        if (!stateModels.containsKey(ModelDynBucket.LOCATION)) {
            // load forges blockstate json for it
            try {
                registerVariant(getModelBlockDefinition(ModelDynBucket.LOCATION), ModelDynBucket.LOCATION);
            } catch (Exception exception) {
                FMLLog.getLogger().error("Could not load the forge bucket model from the blockstate", exception);
                return;
            }
        }
        // empty bucket
        for (String s : getVariantNames(Items.BUCKET)) {
            ModelResourceLocation memory = getInventoryVariant(s);
            IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(ForgeVersion.MOD_ID, "item/bucket"));
            // only on successful load, otherwise continue using the old model
            if (model != getMissingModel()) {
                stateModels.put(memory, model);
            }
        }
        setBucketModel(Items.WATER_BUCKET);
        setBucketModel(Items.LAVA_BUCKET);
        // milk bucket only replaced if some mod adds milk
        if (FluidRegistry.isFluidRegistered("milk")) {
            // can the milk be put into a bucket?
            Fluid milk = FluidRegistry.getFluid("milk");
            FluidStack milkStack = new FluidStack(milk, Fluid.BUCKET_VOLUME);
            IFluidHandler bucketHandler = FluidUtil.getFluidHandler(new ItemStack(Items.BUCKET));
            if (bucketHandler != null && bucketHandler.fill(milkStack, false) == Fluid.BUCKET_VOLUME) {
                setBucketModel(Items.MILK_BUCKET);
            }
        } else {
            // milk bucket if no milk fluid is present
            for (String s : getVariantNames(Items.MILK_BUCKET)) {
                ModelResourceLocation memory = getInventoryVariant(s);
                IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(ForgeVersion.MOD_ID, "item/bucket_milk"));
                // only on successful load, otherwise continue using the old model
                if (model != getMissingModel()) {
                    stateModels.put(memory, model);
                }
            }
        }
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) MissingVariantException(net.minecraft.client.renderer.block.model.ModelBlockDefinition.MissingVariantException) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) Predicate(com.google.common.base.Predicate) Item(net.minecraft.item.Item) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) ProgressBar(net.minecraftforge.fml.common.ProgressManager.ProgressBar)

Aggregations

Predicate (com.google.common.base.Predicate)180 ArrayList (java.util.ArrayList)29 Nullable (javax.annotation.Nullable)29 Test (org.junit.Test)29 List (java.util.List)28 UUID (java.util.UUID)21 IOException (java.io.IOException)20 Map (java.util.Map)20 File (java.io.File)15 Test (org.testng.annotations.Test)14 ImmutableList (com.google.common.collect.ImmutableList)12 HashMap (java.util.HashMap)12 Set (java.util.Set)9 DateTime (org.joda.time.DateTime)9 BigDecimal (java.math.BigDecimal)8 Path (javax.ws.rs.Path)8 PaymentTransactionModelDao (org.killbill.billing.payment.dao.PaymentTransactionModelDao)8 Account (org.killbill.billing.account.api.Account)7 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)7 PaymentModelDao (org.killbill.billing.payment.dao.PaymentModelDao)7