Example usage for java.util.function BiConsumer accept

List of usage examples for java.util.function BiConsumer accept

Introduction

In this page you can find the example usage for java.util.function BiConsumer accept.

Prototype

void accept(T t, U u);

Source Link

Document

Performs this operation on the given arguments.

Usage

From source file:org.apache.hyracks.maven.license.GenerateFileMojo.java

private void resolveContent(Project project, JarFile jarFile, JarEntry entry, UnaryOperator<String> transformer,
        BiConsumer<Project, String> contentConsumer, final String name) throws IOException {
    String text = IOUtils.toString(jarFile.getInputStream(entry), StandardCharsets.UTF_8);
    text = transformer.apply(text);/*from   ww w  .ja  v  a 2 s.  c o  m*/
    text = LicenseUtil.trim(text);
    if (text.length() == 0) {
        getLog().warn("Ignoring empty " + name + " file ( " + entry + ") for " + project.gav());
    } else {
        contentConsumer.accept(project, text);
        getLog().debug("Resolved " + name + " text for " + project.gav() + ": \n" + text);
    }
}

From source file:org.apache.openmeetings.core.util.ChatWebSocketHelper.java

public static JSONObject getMessage(User curUser, List<ChatMessage> list, BiConsumer<JSONObject, User> uFmt) {
    JSONArray arr = new JSONArray();
    for (ChatMessage m : list) {
        String smsg = m.getMessage();
        smsg = smsg == null ? smsg : " " + smsg.replaceAll("&nbsp;", " ") + " ";
        JSONObject from = new JSONObject().put("id", m.getFromUser().getId())
                .put("displayName", m.getFromName()).put("name", m.getFromUser().getDisplayName());
        if (uFmt != null) {
            uFmt.accept(from, m.getFromUser());
        }//from w  w w. j a v a2  s  .co m
        arr.put(setDates(
                setScope(new JSONObject(), m, curUser.getId()).put("id", m.getId()).put("message", smsg)
                        .put("from", from)
                        .put("actions", curUser.getId() == m.getFromUser().getId() ? "short" : "full"),
                m, curUser, true));
    }
    return new JSONObject().put("type", "chat").put("msg", arr);
}

From source file:org.ballerinalang.langserver.command.testgen.template.RootTemplate.java

/**
 * Renders content into this file template.
 *
 * @param rendererOutput root {@link TemplateBasedRendererOutput}
 * @throws TestGeneratorException when template population process fails
 */// w w  w . j a v  a  2s.  com
public void render(RendererOutput rendererOutput) throws TestGeneratorException {
    BiConsumer<String, String> importsAcceptor = (orgName, alias) -> {
        if (isNonExistImport(orgName, alias)) {
            rendererOutput.append(PlaceHolder.IMPORTS, "import " + orgName + "/" + alias + ";" + LINE_FEED);
            imports.add(new ImmutablePair<>(orgName, alias));
            focusLineAcceptor.accept(null, 1); //Increment focus line by one
        }
    };

    // Add imports
    importsAcceptor.accept("ballerina", "test");
    importsAcceptor.accept("ballerina", "log");
    if (httpServices.size() > 0 || httpWSServices.size() > 0 || httpWSClientServices.size() > 0) {
        importsAcceptor.accept("ballerina", "http");
    }

    // Render test functions
    for (BLangFunction func : functions) {
        TestFunctionGenerator generator = new TestFunctionGenerator(importsAcceptor, builtTestFile.packageID,
                func);
        new FunctionTemplate(builtTestFile, func, focusLineAcceptor, generator).render(rendererOutput);
    }

    // Render httpService tests
    for (Pair<BLangService, BLangTypeInit> pair : httpServices) {
        BLangService service = pair.getLeft();
        BLangTypeInit init = pair.getRight();
        new HttpServiceTemplate(builtTestFile, service, init, focusLineAcceptor).render(rendererOutput);
    }

    // Render WS-Service tests
    for (Pair<BLangService, BLangTypeInit> pair : httpWSServices) {
        BLangService service = pair.getLeft();
        BLangTypeInit init = pair.getRight();
        new WSServiceTemplate(builtTestFile, service, init, focusLineAcceptor).render(rendererOutput);
    }
}

From source file:org.codice.ddf.catalog.ui.forms.filter.VisitableXmlElementImpl.java

@Override
public void accept(FilterVisitor2 visitor) {
    Class clazz = element.getDeclaredType();
    BiConsumer<FilterVisitor2, VisitableElement> biConsumer = VISIT_METHODS.get(clazz);
    if (biConsumer == null) {
        throw new FilterProcessingException(
                "Encountered an unexpected or unsupported type: " + clazz.getName());
    }//  w  ww .ja  va2s. com
    // Actually invoking one of the "visits" on local variable "visitor"
    biConsumer.accept(visitor, this);
}

From source file:org.codice.ddf.itests.common.ServiceManagerImpl.java

private void printInactiveBundles(Consumer<String> headerConsumer, BiConsumer<String, Object[]> logConsumer) {
    headerConsumer.accept("Listing inactive bundles");

    for (Bundle bundle : getBundleContext().getBundles()) {
        if (bundle.getState() != Bundle.ACTIVE) {
            Dictionary<String, String> headers = bundle.getHeaders();
            if (headers.get("Fragment-Host") != null) {
                continue;
            }/*from w  w  w.j ava 2 s .  c o  m*/

            StringBuilder headerString = new StringBuilder("[ ");
            Enumeration<String> keys = headers.keys();

            while (keys.hasMoreElements()) {
                String key = keys.nextElement();
                headerString.append(key).append("=").append(headers.get(key)).append(", ");
            }

            headerString.append(" ]");
            logConsumer.accept("\n\tBundle: {}_v{} | {}\n\tHeaders: {}",
                    new Object[] { bundle.getSymbolicName(), bundle.getVersion(),
                            BUNDLE_STATES.getOrDefault(bundle.getState(), "UNKNOWN"), headerString });
        }
    }
}

From source file:org.codice.ddf.libs.mpeg.transport.MpegTransportStreamMetadataExtractor.java

private void handleElementaryStreamPacket(final MTSPacket packet, final int packetId,
        final BiConsumer<Integer, byte[]> callback) {
    if (programElementaryStreams.containsKey(packetId)) {
        final PMTStream stream = programElementaryStreams.get(packetId);

        if (isMetadataStream(stream)) {
            final byte[] currentMetadataPacketBytes = currentMetadataPacketBytesByStream.get(packetId);

            final boolean startingNewMetadataPacket = packet.isPayloadUnitStartIndicator();
            final boolean currentMetadataPacketToHandle = currentMetadataPacketBytes != null;
            final boolean reachedEndOfCurrentMetadataPacket = startingNewMetadataPacket
                    && currentMetadataPacketToHandle;

            final byte[] payloadBytes = getByteBufferAsBytes(packet.getPayload());

            if (reachedEndOfCurrentMetadataPacket) {
                callback.accept(packetId, currentMetadataPacketBytes);
                startNewMetadataPacketBytes(packetId, payloadBytes);
            } else if (startingNewMetadataPacket) {
                startNewMetadataPacketBytes(packetId, payloadBytes);
            } else if (currentMetadataPacketToHandle) {
                final byte[] concatenatedMetadataPacket = ArrayUtils.addAll(currentMetadataPacketBytes,
                        payloadBytes);//from w  w w. jav  a 2s  .  c  om
                currentMetadataPacketBytesByStream.put(packetId, concatenatedMetadataPacket);
            }
        }
    }
}

From source file:org.codice.ddf.registry.schemabindings.helper.MapToSchemaElement.java

public Optional<T> populateBooleanElement(Map<String, Object> map, String mapKey,
        final Optional<T> referenceElement, BiConsumer<Boolean, T> updater) {
    Optional<T> elementToPopulate = Optional.empty();
    if (referenceElement.isPresent()) {
        elementToPopulate = Optional.of(referenceElement.get());
    }//from  w  w w.j  av a  2s  . co m

    Boolean booleanToPopulate = MapUtils.getBoolean(map, mapKey);
    if (booleanToPopulate != null) {
        if (!elementToPopulate.isPresent()) {
            elementToPopulate = Optional.of(objectFactory.get());
        }

        updater.accept(booleanToPopulate, elementToPopulate.get());
    }

    return elementToPopulate;
}

From source file:org.codice.ddf.registry.schemabindings.helper.MapToSchemaElement.java

public Optional<T> populateStringElement(Map<String, Object> map, String mapKey,
        final Optional<T> referenceElement, BiConsumer<String, T> updater) {
    Optional<T> elementToPopulate = Optional.empty();
    if (referenceElement.isPresent()) {
        elementToPopulate = Optional.of(referenceElement.get());
    }//from  www . java 2s.c  o m

    String valueToPopulate = MapUtils.getString(map, mapKey);
    if (StringUtils.isNotBlank(valueToPopulate)) {
        if (!elementToPopulate.isPresent()) {
            elementToPopulate = Optional.of(objectFactory.get());
        }

        updater.accept(valueToPopulate, elementToPopulate.get());
    }
    return elementToPopulate;
}

From source file:org.codice.ddf.registry.schemabindings.helper.MapToSchemaElement.java

public Optional<T> populateInternationalStringTypeElement(Map<String, Object> map, String mapKey,
        final Optional<T> referenceElement, BiConsumer<InternationalStringType, T> updater) {
    Optional<T> elementToPopulate = Optional.empty();
    if (referenceElement.isPresent()) {
        elementToPopulate = Optional.of(referenceElement.get());
    }// w  w  w  .  ja  v  a 2 s.c o m

    String valueToPopulate = MapUtils.getString(map, mapKey);
    if (StringUtils.isNotBlank(valueToPopulate)) {
        if (!elementToPopulate.isPresent()) {
            elementToPopulate = Optional.of(objectFactory.get());
        }

        InternationalStringType istToPopulate = INTERNATIONAL_STRING_TYPE_HELPER.create(valueToPopulate);
        if (istToPopulate != null) {
            updater.accept(istToPopulate, elementToPopulate.get());
        }
    }
    return elementToPopulate;
}

From source file:org.codice.ddf.registry.schemabindings.helper.MapToSchemaElement.java

public Optional<T> populateVersionInfoTypeElement(Map<String, Object> map, String mapKey,
        final Optional<T> referenceElement, BiConsumer<VersionInfoType, T> updater) {
    Optional<T> elementToPopulate = Optional.empty();
    if (referenceElement.isPresent()) {
        elementToPopulate = Optional.of(referenceElement.get());
    }//from  w w w . jav a2s.  c o m

    String valueToPopulate = MapUtils.getString(map, mapKey);
    if (StringUtils.isNotBlank(valueToPopulate)) {
        if (!elementToPopulate.isPresent()) {
            elementToPopulate = Optional.of(objectFactory.get());
        }

        VersionInfoType versionInfo = RIM_FACTORY.createVersionInfoType();
        versionInfo.setVersionName(valueToPopulate);

        updater.accept(versionInfo, elementToPopulate.get());
    }
    return elementToPopulate;
}