Search in sources :

Example 61 with Predicate

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

the class RulesResourceFilter method filter.

@Override
public ContainerRequest filter(ContainerRequest request) {
    if (getAuthConfig().isEnabled()) {
        // This is an experimental feature, see - https://github.com/druid-io/druid/pull/2424
        final String dataSourceName = request.getPathSegments().get(Iterables.indexOf(request.getPathSegments(), new Predicate<PathSegment>() {

            @Override
            public boolean apply(PathSegment input) {
                return input.getPath().equals("rules");
            }
        }) + 1).getPath();
        Preconditions.checkNotNull(dataSourceName);
        final AuthorizationInfo authorizationInfo = (AuthorizationInfo) getReq().getAttribute(AuthConfig.DRUID_AUTH_TOKEN);
        Preconditions.checkNotNull(authorizationInfo, "Security is enabled but no authorization info found in the request");
        final Access authResult = authorizationInfo.isAuthorized(new Resource(dataSourceName, ResourceType.DATASOURCE), getAction(request));
        if (!authResult.isAllowed()) {
            throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).entity(String.format("Access-Check-Result: %s", authResult.toString())).build());
        }
    }
    return request;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Access(io.druid.server.security.Access) Resource(io.druid.server.security.Resource) PathSegment(javax.ws.rs.core.PathSegment) AuthorizationInfo(io.druid.server.security.AuthorizationInfo) Predicate(com.google.common.base.Predicate)

Example 62 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 63 with Predicate

use of com.google.common.base.Predicate in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsObject method injectChunkIntoWorld.

public void injectChunkIntoWorld(Chunk chunk, int x, int z, boolean putInId2ChunkMap) {
    ChunkProviderServer provider = (ChunkProviderServer) worldObj.getChunkProvider();
    //TileEntities will break if you don't do this
    chunk.isChunkLoaded = true;
    chunk.isModified = true;
    claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ] = chunk;
    if (putInId2ChunkMap) {
        provider.id2ChunkMap.put(ChunkPos.chunkXZ2Int(x, z), chunk);
    }
    PlayerChunkMap map = ((WorldServer) worldObj).getPlayerChunkMap();
    PlayerChunkMapEntry entry = new PlayerChunkMapEntry(map, x, z) {

        @Override
        public boolean hasPlayerMatchingInRange(double range, Predicate<EntityPlayerMP> predicate) {
            return true;
        }
    };
    long i = map.getIndex(x, z);
    map.playerInstances.put(i, entry);
    map.playerInstanceList.add(entry);
    entry.sentToPlayers = true;
    entry.players = watchingPlayers;
    claimedChunksEntries[x - ownedChunks.minX][z - ownedChunks.minZ] = entry;
//		MinecraftForge.EVENT_BUS.post(new ChunkEvent.Load(chunk));
}
Also used : ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) WorldServer(net.minecraft.world.WorldServer) PlayerChunkMapEntry(net.minecraft.server.management.PlayerChunkMapEntry) PlayerChunkMap(net.minecraft.server.management.PlayerChunkMap) Predicate(com.google.common.base.Predicate)

Example 64 with Predicate

use of com.google.common.base.Predicate in project intellij-community by JetBrains.

the class CCUtils method updateHigherElements.

/**
   * This method decreases index and updates directory names of
   * all tasks/lessons that have higher index than specified object
   *
   * @param dirs         directories that are used to get tasks/lessons
   * @param getStudyItem function that is used to get task/lesson from VirtualFile. This function can return null
   * @param threshold    index is used as threshold
   * @param prefix       task or lesson directory name prefix
   */
public static void updateHigherElements(VirtualFile[] dirs, @NotNull final Function<VirtualFile, ? extends StudyItem> getStudyItem, final int threshold, final String prefix, final int delta) {
    ArrayList<VirtualFile> dirsToRename = new ArrayList<>(Collections2.filter(Arrays.asList(dirs), new Predicate<VirtualFile>() {

        @Override
        public boolean apply(VirtualFile dir) {
            final StudyItem item = getStudyItem.fun(dir);
            if (item == null) {
                return false;
            }
            int index = item.getIndex();
            return index > threshold;
        }
    }));
    Collections.sort(dirsToRename, (o1, o2) -> {
        StudyItem item1 = getStudyItem.fun(o1);
        StudyItem item2 = getStudyItem.fun(o2);
        //if we delete some dir we should start increasing numbers in dir names from the end
        return (-delta) * EduUtils.INDEX_COMPARATOR.compare(item1, item2);
    });
    for (final VirtualFile dir : dirsToRename) {
        final StudyItem item = getStudyItem.fun(dir);
        final int newIndex = item.getIndex() + delta;
        item.setIndex(newIndex);
        ApplicationManager.getApplication().runWriteAction(new Runnable() {

            @Override
            public void run() {
                try {
                    dir.rename(this, prefix + newIndex);
                } catch (IOException e) {
                    LOG.error(e);
                }
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) IOException(java.io.IOException) StudyItem(com.jetbrains.edu.learning.courseFormat.StudyItem) Predicate(com.google.common.base.Predicate)

Example 65 with Predicate

use of com.google.common.base.Predicate in project selenium-tests by Wikia.

the class TopNoteModalDialog method clickApprove.

public void clickApprove() {
    super.clickConfirm();
    new WebDriverWait(driver, DiscussionsConstants.TIMEOUT).until((Predicate<WebDriver>) input -> !post.getAttribute("class").contains("is-reported"));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Predicate(com.google.common.base.Predicate) WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) FindBy(org.openqa.selenium.support.FindBy) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Aggregations

Predicate (com.google.common.base.Predicate)217 List (java.util.List)37 Test (org.junit.Test)37 ArrayList (java.util.ArrayList)34 Nullable (javax.annotation.Nullable)33 Map (java.util.Map)24 UUID (java.util.UUID)21 IOException (java.io.IOException)20 File (java.io.File)18 HashMap (java.util.HashMap)15 Set (java.util.Set)14 Test (org.testng.annotations.Test)14 ImmutableList (com.google.common.collect.ImmutableList)13 Collection (java.util.Collection)11 DateTime (org.joda.time.DateTime)9 BigDecimal (java.math.BigDecimal)8 Path (javax.ws.rs.Path)8 Expression (com.sri.ai.expresso.api.Expression)7 Util (com.sri.ai.util.Util)7 XtextResource (org.eclipse.xtext.resource.XtextResource)7