Search in sources :

Example 1 with Arrays

use of java.util.Arrays in project vert.x by eclipse.

the class Http2ServerTest method testRequestResponseLifecycle.

@Test
public void testRequestResponseLifecycle() throws Exception {
    waitFor(2);
    server.requestHandler(req -> {
        req.endHandler(v -> {
            assertIllegalStateException(() -> req.setExpectMultipart(false));
            assertIllegalStateException(() -> req.handler(buf -> {
            }));
            assertIllegalStateException(() -> req.uploadHandler(upload -> {
            }));
            assertIllegalStateException(() -> req.endHandler(v2 -> {
            }));
            complete();
        });
        HttpServerResponse resp = req.response();
        resp.setChunked(true).write(Buffer.buffer("whatever"));
        assertTrue(resp.headWritten());
        assertIllegalStateException(() -> resp.setChunked(false));
        assertIllegalStateException(() -> resp.setStatusCode(100));
        assertIllegalStateException(() -> resp.setStatusMessage("whatever"));
        assertIllegalStateException(() -> resp.putHeader("a", "b"));
        assertIllegalStateException(() -> resp.putHeader("a", (CharSequence) "b"));
        assertIllegalStateException(() -> resp.putHeader("a", (Iterable<String>) Arrays.asList("a", "b")));
        assertIllegalStateException(() -> resp.putHeader("a", (Arrays.<CharSequence>asList("a", "b"))));
        assertIllegalStateException(resp::writeContinue);
        resp.end();
        assertIllegalStateException(() -> resp.write("a"));
        assertIllegalStateException(() -> resp.write("a", "UTF-8"));
        assertIllegalStateException(() -> resp.write(Buffer.buffer("a")));
        assertIllegalStateException(resp::end);
        assertIllegalStateException(() -> resp.end("a"));
        assertIllegalStateException(() -> resp.end("a", "UTF-8"));
        assertIllegalStateException(() -> resp.end(Buffer.buffer("a")));
        assertIllegalStateException(() -> resp.sendFile("the-file.txt"));
        assertIllegalStateException(() -> resp.reset(0));
        assertIllegalStateException(() -> resp.closeHandler(v -> {
        }));
        assertIllegalStateException(() -> resp.endHandler(v -> {
        }));
        assertIllegalStateException(() -> resp.drainHandler(v -> {
        }));
        assertIllegalStateException(() -> resp.exceptionHandler(err -> {
        }));
        assertIllegalStateException(resp::writeQueueFull);
        assertIllegalStateException(() -> resp.setWriteQueueMaxSize(100));
        assertIllegalStateException(() -> resp.putTrailer("a", "b"));
        assertIllegalStateException(() -> resp.putTrailer("a", (CharSequence) "b"));
        assertIllegalStateException(() -> resp.putTrailer("a", (Iterable<String>) Arrays.asList("a", "b")));
        assertIllegalStateException(() -> resp.putTrailer("a", (Arrays.<CharSequence>asList("a", "b"))));
        assertIllegalStateException(() -> resp.push(HttpMethod.GET, "/whatever", ar -> {
        }));
        complete();
    });
    startServer();
    TestClient client = new TestClient();
    ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
        int id = request.nextStreamId();
        request.encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
        request.context.flush();
    });
    fut.sync();
    await();
}
Also used : Arrays(java.util.Arrays) GZIPInputStream(java.util.zip.GZIPInputStream) HttpServer(io.vertx.core.http.HttpServer) MultiMap(io.vertx.core.MultiMap) Http2ConnectionEncoder(io.netty.handler.codec.http2.Http2ConnectionEncoder) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Context(io.vertx.core.Context) Unpooled(io.netty.buffer.Unpooled) Http2ConnectionDecoder(io.netty.handler.codec.http2.Http2ConnectionDecoder) ByteArrayInputStream(java.io.ByteArrayInputStream) HttpVersion(io.vertx.core.http.HttpVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Http2Exception(io.netty.handler.codec.http2.Http2Exception) Map(java.util.Map) ApplicationProtocolNegotiationHandler(io.netty.handler.ssl.ApplicationProtocolNegotiationHandler) ReadStream(io.vertx.core.streams.ReadStream) AbstractHttp2ConnectionHandlerBuilder(io.netty.handler.codec.http2.AbstractHttp2ConnectionHandlerBuilder) Http2FrameAdapter(io.netty.handler.codec.http2.Http2FrameAdapter) StreamResetException(io.vertx.core.http.StreamResetException) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) ChannelInitializer(io.netty.channel.ChannelInitializer) Http2Flags(io.netty.handler.codec.http2.Http2Flags) Set(java.util.Set) ChannelPipeline(io.netty.channel.ChannelPipeline) Http2ConnectionHandler(io.netty.handler.codec.http2.Http2ConnectionHandler) Future(io.vertx.core.Future) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) StandardCharsets(java.nio.charset.StandardCharsets) Base64(java.util.Base64) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) SslHandler(io.netty.handler.ssl.SslHandler) Http2Headers(io.netty.handler.codec.http2.Http2Headers) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Http2Error(io.netty.handler.codec.http2.Http2Error) HttpClient(io.vertx.core.http.HttpClient) NetSocket(io.vertx.core.net.NetSocket) Trust(io.vertx.test.core.tls.Trust) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) HttpServerRequest(io.vertx.core.http.HttpServerRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Http2EventAdapter(io.netty.handler.codec.http2.Http2EventAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpClientRequest(io.vertx.core.http.HttpClientRequest) ByteBuf(io.netty.buffer.ByteBuf) WriteStream(io.vertx.core.streams.WriteStream) Http2Stream(io.netty.handler.codec.http2.Http2Stream) BiConsumer(java.util.function.BiConsumer) AsyncResult(io.vertx.core.AsyncResult) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpConnection(io.vertx.core.http.HttpConnection) EventLoopGroup(io.netty.channel.EventLoopGroup) VertxInternal(io.vertx.core.impl.VertxInternal) ClosedChannelException(java.nio.channels.ClosedChannelException) Vertx(io.vertx.core.Vertx) FileOutputStream(java.io.FileOutputStream) ApplicationProtocolNames(io.netty.handler.ssl.ApplicationProtocolNames) Test(org.junit.Test) IOException(java.io.IOException) SSLHelper(io.vertx.core.net.impl.SSLHelper) File(java.io.File) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) Http2Settings(io.netty.handler.codec.http2.Http2Settings) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Bootstrap(io.netty.bootstrap.Bootstrap) AtomicLong(java.util.concurrent.atomic.AtomicLong) Http2Connection(io.netty.handler.codec.http2.Http2Connection) HttpMethod(io.vertx.core.http.HttpMethod) HttpUtils(io.vertx.core.http.impl.HttpUtils) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) Handler(io.vertx.core.Handler) Collections(java.util.Collections) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) ChannelFuture(io.netty.channel.ChannelFuture) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Test(org.junit.Test)

Example 2 with Arrays

use of java.util.Arrays in project buck by facebook.

the class AbstractJavacOptions method appendOptionsTo.

public void appendOptionsTo(OptionsConsumer optionsConsumer, SourcePathResolver pathResolver, ProjectFilesystem filesystem) {
    // Add some standard options.
    optionsConsumer.addOptionValue("source", getSourceLevel());
    optionsConsumer.addOptionValue("target", getTargetLevel());
    // Set the sourcepath to stop us reading source files out of jars by mistake.
    optionsConsumer.addOptionValue("sourcepath", "");
    if (isDebug()) {
        optionsConsumer.addFlag("g");
    }
    if (isVerbose()) {
        optionsConsumer.addFlag("verbose");
    }
    // Override the bootclasspath if Buck is building Java code for Android.
    if (getBootclasspath().isPresent()) {
        optionsConsumer.addOptionValue("bootclasspath", getBootclasspath().get());
    } else {
        String bcp = getSourceToBootclasspath().get(getSourceLevel());
        if (bcp != null) {
            optionsConsumer.addOptionValue("bootclasspath", bcp);
        }
    }
    // Add annotation processors.
    AnnotationProcessingParams annotationProcessingParams = getAnnotationProcessingParams();
    if (!annotationProcessingParams.isEmpty()) {
        // Specify where to generate sources so IntelliJ can pick them up.
        Path generateTo = annotationProcessingParams.getGeneratedSourceFolderName();
        if (generateTo != null) {
            //noinspection ConstantConditions
            optionsConsumer.addOptionValue("s", filesystem.resolve(generateTo).toString());
        }
        ImmutableList<ResolvedJavacPluginProperties> annotationProcessors = annotationProcessingParams.getAnnotationProcessors(filesystem, pathResolver);
        // Specify processorpath to search for processors.
        optionsConsumer.addOptionValue("processorpath", annotationProcessors.stream().map(ResolvedJavacPluginProperties::getClasspath).flatMap(Arrays::stream).distinct().map(URL::toString).collect(Collectors.joining(File.pathSeparator)));
        // Specify names of processors.
        optionsConsumer.addOptionValue("processor", annotationProcessors.stream().map(ResolvedJavacPluginProperties::getProcessorNames).flatMap(Collection::stream).collect(Collectors.joining(",")));
        // Add processor parameters.
        for (String parameter : annotationProcessingParams.getParameters()) {
            optionsConsumer.addFlag("A" + parameter);
        }
        if (annotationProcessingParams.getProcessOnly()) {
            optionsConsumer.addFlag("proc:only");
        }
    }
    // Add extra arguments.
    optionsConsumer.addExtras(getExtraArguments());
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) Collection(java.util.Collection) Arrays(java.util.Arrays) URL(java.net.URL)

Example 3 with Arrays

use of java.util.Arrays in project intellij-community by JetBrains.

the class ContractInferenceInterpreter method visitExpression.

@NotNull
private List<PreContract> visitExpression(final List<ValueConstraint[]> states, @Nullable LighterASTNode expr) {
    if (expr == null)
        return emptyList();
    if (states.isEmpty())
        return emptyList();
    // too complex
    if (states.size() > 300)
        return emptyList();
    IElementType type = expr.getTokenType();
    if (type == POLYADIC_EXPRESSION || type == BINARY_EXPRESSION) {
        return visitPolyadic(states, expr);
    }
    if (type == CONDITIONAL_EXPRESSION) {
        List<LighterASTNode> children = getExpressionChildren(myTree, expr);
        if (children.size() != 3)
            return emptyList();
        List<PreContract> conditionResults = visitExpression(states, children.get(0));
        return ContainerUtil.concat(visitExpression(antecedentsReturning(conditionResults, TRUE_VALUE), children.get(1)), visitExpression(antecedentsReturning(conditionResults, FALSE_VALUE), children.get(2)));
    }
    if (type == PARENTH_EXPRESSION) {
        return visitExpression(states, findExpressionChild(myTree, expr));
    }
    if (type == TYPE_CAST_EXPRESSION) {
        return visitExpression(states, findExpressionChild(myTree, expr));
    }
    if (isNegationExpression(expr)) {
        return ContainerUtil.mapNotNull(visitExpression(states, findExpressionChild(myTree, expr)), PreContract::negate);
    }
    if (type == INSTANCE_OF_EXPRESSION) {
        final int parameter = resolveParameter(findExpressionChild(myTree, expr));
        if (parameter >= 0) {
            return asPreContracts(ContainerUtil.mapNotNull(states, state -> contractWithConstraint(state, parameter, NULL_VALUE, FALSE_VALUE)));
        }
    }
    if (type == NEW_EXPRESSION || type == THIS_EXPRESSION) {
        return asPreContracts(toContracts(states, NOT_NULL_VALUE));
    }
    if (type == METHOD_CALL_EXPRESSION) {
        return singletonList(new MethodCallContract(ExpressionRange.create(expr, myBody.getStartOffset()), ContainerUtil.map(states, Arrays::asList)));
    }
    final ValueConstraint constraint = getLiteralConstraint(expr);
    if (constraint != null) {
        return asPreContracts(toContracts(states, constraint));
    }
    int paramIndex = resolveParameter(expr);
    if (paramIndex >= 0) {
        List<MethodContract> result = ContainerUtil.newArrayList();
        for (ValueConstraint[] state : states) {
            if (state[paramIndex] != ANY_VALUE) {
                // the second 'o' reference in cases like: if (o != null) return o;
                result.add(new MethodContract(state, state[paramIndex]));
            } else if (JavaTokenType.BOOLEAN_KEYWORD == getPrimitiveParameterType(paramIndex)) {
                // if (boolValue) ...
                ContainerUtil.addIfNotNull(result, contractWithConstraint(state, paramIndex, TRUE_VALUE, TRUE_VALUE));
                ContainerUtil.addIfNotNull(result, contractWithConstraint(state, paramIndex, FALSE_VALUE, FALSE_VALUE));
            }
        }
        return asPreContracts(result);
    }
    return emptyList();
}
Also used : Arrays(java.util.Arrays) JavaTokenType(com.intellij.psi.JavaTokenType) IElementType(com.intellij.psi.tree.IElementType) Collections.emptyList(java.util.Collections.emptyList) JavaElementType(com.intellij.psi.impl.source.tree.JavaElementType) ContainerUtil(com.intellij.util.containers.ContainerUtil) JavaLightTreeUtil(com.intellij.psi.impl.source.JavaLightTreeUtil) JavaLightTreeUtil.getExpressionChildren(com.intellij.psi.impl.source.JavaLightTreeUtil.getExpressionChildren) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ElementType(com.intellij.psi.impl.source.tree.ElementType) JavaLightTreeUtil.findExpressionChild(com.intellij.psi.impl.source.JavaLightTreeUtil.findExpressionChild) ValueConstraint(com.intellij.codeInspection.dataFlow.MethodContract.ValueConstraint) LightTreeUtil.firstChildOfType(com.intellij.psi.impl.source.tree.LightTreeUtil.firstChildOfType) LighterAST(com.intellij.lang.LighterAST) LighterASTNode(com.intellij.lang.LighterASTNode) LightTreeUtil.getChildrenOfType(com.intellij.psi.impl.source.tree.LightTreeUtil.getChildrenOfType) NotNull(org.jetbrains.annotations.NotNull) LighterASTNode(com.intellij.lang.LighterASTNode) ValueConstraint(com.intellij.codeInspection.dataFlow.MethodContract.ValueConstraint) ValueConstraint(com.intellij.codeInspection.dataFlow.MethodContract.ValueConstraint) IElementType(com.intellij.psi.tree.IElementType) Arrays(java.util.Arrays) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with Arrays

use of java.util.Arrays in project Gargoyle by callakrsos.

the class DaoWizardViewController method btnExecOnMouseClick.

/**
	 * 텍스트에 기술된 SQL문을 실행한다. 기본적으로 ROWNUM 기술문을 100개를 감싸서 SQL을 조회한다.
	 *
	 * @작성자 : KYJ
	 * @작성일 : 2015. 10. 21.
	 */
@FXML
public void btnExecOnMouseClick(MouseEvent e) {
    LOGGER.debug("event] btnExecOnMouseClick");
    String velocitySQL = txtSql.getText().trim();
    if (velocitySQL == null || velocitySQL.isEmpty())
        return;
    LOGGER.debug(String.format("velocitySQL : %s", velocitySQL));
    // 파라미터 컬럼값 반환받는다.
    ObservableList<TbpSysDaoFieldsDVO> items = tbParams.getItems();
    Map<String, TbpSysDaoColumnsDVO> unmapping = this.tbMappings.getItems().stream().filter(v -> {
        String lockYn = v.getLockYn();
        if ("Y".equals(lockYn))
            return true;
        return false;
    }).collect(Collectors.toMap(TbpSysDaoColumnsDVO::getColumnName, v -> v));
    Map<String, Object> paramMap = items.stream().filter(vo -> vo.getTestValue() != null && !vo.getTestValue().isEmpty()).collect(Collectors.toMap(TbpSysDaoFieldsDVO::getFieldName, new Function<TbpSysDaoFieldsDVO, Object>() {

        @Override
        public Object apply(TbpSysDaoFieldsDVO t) {
            if ("Arrays".equals(t.getType())) {
                String pattern = "'[^']{0,}'";
                List<String> regexMatchs = ValueUtil.regexMatchs(pattern, t.getTestValue(), str -> {
                    return str.substring(1, str.length() - 1);
                });
                return regexMatchs;
            }
            return t.getTestValue();
        }
    }));
    SimpleSQLResultView simpleSQLResultView = new SimpleSQLResultView(velocitySQL, paramMap);
    try {
        simpleSQLResultView.show();
        List<TableModelDVO> columns = simpleSQLResultView.getColumns();
        List<TbpSysDaoColumnsDVO> resultList = columns.stream().map(vo -> {
            TbpSysDaoColumnsDVO dvo = new TbpSysDaoColumnsDVO();
            dvo.setColumnName(vo.getDatabaseColumnName());
            String databaseTypeName = vo.getDatabaseTypeName();
            dvo.setColumnType(databaseTypeName);
            if (unmapping.containsKey(vo.getDatabaseColumnName())) {
                TbpSysDaoColumnsDVO tmp = unmapping.get(vo.getDatabaseColumnName());
                dvo.setProgramType(tmp.getProgramType());
                dvo.setLockYn(tmp.getLockYn());
            } else {
                String programType = DatabaseTypeMappingResourceLoader.getInstance().get(databaseTypeName);
                dvo.setProgramType(programType);
            }
            return dvo;
        }).collect(Collectors.toList());
        // if (!this.tbMappings.getItems().isEmpty())
        if (!resultList.isEmpty()) {
            try {
                this.tbMappings.getItems().clear();
                getSelectedMethodItem().getTbpSysDaoColumnsDVOList().clear();
                this.tbMappings.getItems().addAll(resultList);
                getSelectedMethodItem().getTbpSysDaoColumnsDVOList().addAll(resultList);
            } catch (NullPointerException n) {
                DialogUtil.showMessageDialog("메소드를 선택해주세요.");
            }
        }
    } catch (IOException e1) {
        LOGGER.error(ValueUtil.toString(e1));
        DialogUtil.showExceptionDailog(e1);
    }
}
Also used : SimpleSQLResultView(com.kyj.fx.voeditor.visual.component.popup.SimpleSQLResultView) Arrays(java.util.Arrays) Menus(com.kyj.fx.voeditor.visual.component.Menus) DbUtil(com.kyj.fx.voeditor.visual.util.DbUtil) NumberingCellValueFactory(com.kyj.fx.voeditor.visual.component.NumberingCellValueFactory) LoggerFactory(org.slf4j.LoggerFactory) NullExpresion(com.kyj.fx.voeditor.visual.util.NullExpresion) MeerketAbstractVoOpenClassResourceView(com.kyj.fx.voeditor.visual.component.popup.MeerketAbstractVoOpenClassResourceView) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ContextMenu(javafx.scene.control.ContextMenu) Map(java.util.Map) FileUtil(com.kyj.fx.voeditor.visual.util.FileUtil) TableView(javafx.scene.control.TableView) TbpSysDaoColumnsDVO(kyj.Fx.dao.wizard.core.model.vo.TbpSysDaoColumnsDVO) Path(java.nio.file.Path) EditorUtil(com.kyj.fx.voeditor.util.EditorUtil) DatabaseTypeMappingFunction(com.kyj.fx.voeditor.visual.functions.DatabaseTypeMappingFunction) ClassTypeResourceLoader(com.kyj.fx.voeditor.visual.momory.ClassTypeResourceLoader) TableMasterDVO(kyj.Fx.dao.wizard.core.model.vo.TableMasterDVO) SqlKeywords(com.kyj.fx.voeditor.visual.component.text.SqlKeywords) TextField(javafx.scene.control.TextField) Pair(javafx.util.Pair) MenuItem(javafx.scene.control.MenuItem) QuerygenUtil(kyj.Fx.dao.wizard.core.util.QuerygenUtil) TbpSysDaoMethodsDVO(kyj.Fx.dao.wizard.core.model.vo.TbpSysDaoMethodsDVO) Set(java.util.Set) KeyEvent(javafx.scene.input.KeyEvent) DatabaseTableView(com.kyj.fx.voeditor.visual.component.popup.DatabaseTableView) FxDAOReadFunction(com.kyj.fx.voeditor.visual.functions.FxDAOReadFunction) ConfigResourceLoader(com.kyj.fx.voeditor.visual.momory.ConfigResourceLoader) TableDVO(kyj.Fx.dao.wizard.core.model.vo.TableDVO) Collectors(java.util.stream.Collectors) FXML(javafx.fxml.FXML) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) List(java.util.List) ResourceLoader(com.kyj.fx.voeditor.visual.momory.ResourceLoader) Stream(java.util.stream.Stream) Optional(java.util.Optional) ChoiceBoxTableCell(javafx.scene.control.cell.ChoiceBoxTableCell) DateUtil(com.kyj.fx.voeditor.visual.util.DateUtil) CommonsContextMenu(com.kyj.fx.voeditor.visual.component.CommonsContextMenu) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) BaseOpenClassResourceView(com.kyj.fx.voeditor.visual.component.popup.BaseOpenClassResourceView) TextArea(javafx.scene.control.TextArea) MouseEvent(javafx.scene.input.MouseEvent) CommonContextMenuEvent(com.kyj.fx.voeditor.visual.events.CommonContextMenuEvent) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) DialogUtil(com.kyj.fx.voeditor.visual.util.DialogUtil) Function(java.util.function.Function) TbmSysDaoDVO(kyj.Fx.dao.wizard.core.model.vo.TbmSysDaoDVO) TableColumn(javafx.scene.control.TableColumn) Wizardtype(com.kyj.fx.voeditor.visual.framework.daowizard.GargoyleDaoWizardFactory.Wizardtype) FXMLLoader(javafx.fxml.FXMLLoader) FxCollectors(com.kyj.fx.voeditor.visual.util.FxCollectors) JavaTextView(com.kyj.fx.voeditor.visual.component.popup.JavaTextView) DaoWizard(kyj.Fx.dao.wizard.DaoWizard) LinkedHashSet(java.util.LinkedHashSet) ClassMeta(com.kyj.fx.voeditor.core.model.meta.ClassMeta) FxDAOSaveFunction(com.kyj.fx.voeditor.visual.functions.FxDAOSaveFunction) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) DaoWizardConverter(com.kyj.fx.voeditor.visual.util.DaoWizardConverter) Label(javafx.scene.control.Label) Iterator(java.util.Iterator) FieldMeta(com.kyj.fx.voeditor.core.model.meta.FieldMeta) DatabaseTypeMappingResourceLoader(kyj.Fx.dao.wizard.memory.DatabaseTypeMappingResourceLoader) IOException(java.io.IOException) LockImagedYnColumn(com.kyj.fx.voeditor.visual.component.LockImagedYnColumn) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) TbpSysDaoFieldsDVO(kyj.Fx.dao.wizard.core.model.vo.TbpSysDaoFieldsDVO) StringConverter(javafx.util.StringConverter) File(java.io.File) ActionEvent(javafx.event.ActionEvent) SelectionMode(javafx.scene.control.SelectionMode) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) TableModelDVO(kyj.Fx.dao.wizard.core.model.vo.TableModelDVO) ResultDialog(com.kyj.fx.voeditor.visual.component.ResultDialog) Collections(java.util.Collections) SharedMemory(com.kyj.fx.voeditor.visual.momory.SharedMemory) SimpleSQLResultView(com.kyj.fx.voeditor.visual.component.popup.SimpleSQLResultView) TableModelDVO(kyj.Fx.dao.wizard.core.model.vo.TableModelDVO) IOException(java.io.IOException) DatabaseTypeMappingFunction(com.kyj.fx.voeditor.visual.functions.DatabaseTypeMappingFunction) FxDAOReadFunction(com.kyj.fx.voeditor.visual.functions.FxDAOReadFunction) Function(java.util.function.Function) FxDAOSaveFunction(com.kyj.fx.voeditor.visual.functions.FxDAOSaveFunction) TbpSysDaoColumnsDVO(kyj.Fx.dao.wizard.core.model.vo.TbpSysDaoColumnsDVO) TbpSysDaoFieldsDVO(kyj.Fx.dao.wizard.core.model.vo.TbpSysDaoFieldsDVO) FXML(javafx.fxml.FXML)

Example 5 with Arrays

use of java.util.Arrays in project gatk-protected by broadinstitute.

the class IntegerCopyNumberTransitionProbabilityCacheUnitTest method testBasicSoundness.

@Test
public void testBasicSoundness() {
    for (final RealMatrix transitionMatrix : TRANSITION_MATRICES) {
        final IntegerCopyNumberTransitionProbabilityCache cache = new IntegerCopyNumberTransitionProbabilityCache(new IntegerCopyNumberTransitionMatrix(transitionMatrix, 0));
        for (final int dist : DISTANCES) {
            final RealMatrix transitionMatrixExponentiated = cache.getTransitionProbabilityMatrix(dist);
            /* assert positivity */
            Assert.assertTrue(Arrays.stream(transitionMatrixExponentiated.getData()).flatMapToDouble(Arrays::stream).allMatch(d -> d >= 0));
            /* assert conservation of probability */
            for (int c = 0; c < transitionMatrix.getColumnDimension(); c++) {
                Assert.assertEquals(Arrays.stream(transitionMatrixExponentiated.getColumn(c)).sum(), 1.0, EPSILON);
            }
            /* assert correctness, T(2*d) = T(d)*T(d) */
            assertEqualMatrices(cache.getTransitionProbabilityMatrix(2 * dist), transitionMatrixExponentiated.multiply(transitionMatrixExponentiated));
        }
        /* assert loss of initial state over long distances, i.e. all columns must be equal */
        final RealMatrix longRangeTransitionMatrix = cache.getTransitionProbabilityMatrix(Integer.MAX_VALUE);
        final double[] firstColumn = longRangeTransitionMatrix.getColumn(0);
        final RealMatrix syntheticLongRangeTransitionMatrix = new Array2DRowRealMatrix(firstColumn.length, firstColumn.length);
        for (int i = 0; i < firstColumn.length; i++) {
            syntheticLongRangeTransitionMatrix.setColumn(i, firstColumn);
        }
        assertEqualMatrices(longRangeTransitionMatrix, syntheticLongRangeTransitionMatrix);
        final double[] stationary = cache.getStationaryProbabilityVector().toArray();
        ArrayAsserts.assertArrayEquals(stationary, firstColumn, EPSILON);
    }
}
Also used : Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) Arrays(java.util.Arrays) Assert(org.testng.Assert) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Test(org.testng.annotations.Test) ArrayAsserts(org.testng.internal.junit.ArrayAsserts) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) Arrays(java.util.Arrays) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

Arrays (java.util.Arrays)76 List (java.util.List)50 ArrayList (java.util.ArrayList)42 Map (java.util.Map)38 Collections (java.util.Collections)26 Test (org.junit.Test)25 HashMap (java.util.HashMap)23 Collectors (java.util.stream.Collectors)19 IOException (java.io.IOException)15 Stream (java.util.stream.Stream)15 Optional (java.util.Optional)13 Set (java.util.Set)13 Function (java.util.function.Function)13 TimeUnit (java.util.concurrent.TimeUnit)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Objects (java.util.Objects)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 IntStream (java.util.stream.IntStream)9