Example usage for java.util StringJoiner StringJoiner

List of usage examples for java.util StringJoiner StringJoiner

Introduction

In this page you can find the example usage for java.util StringJoiner StringJoiner.

Prototype

public StringJoiner(CharSequence delimiter, CharSequence prefix, CharSequence suffix) 

Source Link

Document

Constructs a StringJoiner with no characters in it using copies of the supplied prefix , delimiter and suffix .

Usage

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testGetSettings() throws IOException {
    String[] indicesUnderTest = randomBoolean() ? null : randomIndicesNames(0, 5);

    GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices(indicesUnderTest);

    Map<String, String> expectedParams = new HashMap<>();
    setRandomMasterTimeout(getSettingsRequest, expectedParams);
    setRandomIndicesOptions(getSettingsRequest::indicesOptions, getSettingsRequest::indicesOptions,
            expectedParams);/*from  w ww . ja v  a  2 s  .c o m*/

    setRandomLocal(getSettingsRequest, expectedParams);

    if (randomBoolean()) {
        // the request object will not have include_defaults present unless it is set to
        // true
        getSettingsRequest.includeDefaults(randomBoolean());
        if (getSettingsRequest.includeDefaults()) {
            expectedParams.put("include_defaults", Boolean.toString(true));
        }
    }

    StringJoiner endpoint = new StringJoiner("/", "/", "");
    if (indicesUnderTest != null && indicesUnderTest.length > 0) {
        endpoint.add(String.join(",", indicesUnderTest));
    }
    endpoint.add("_settings");

    if (randomBoolean()) {
        String[] names = randomBoolean() ? null : new String[randomIntBetween(0, 3)];
        if (names != null) {
            for (int x = 0; x < names.length; x++) {
                names[x] = randomAlphaOfLengthBetween(3, 10);
            }
        }
        getSettingsRequest.names(names);
        if (names != null && names.length > 0) {
            endpoint.add(String.join(",", names));
        }
    }

    Request request = RequestConverters.getSettings(getSettingsRequest);

    assertThat(endpoint.toString(), equalTo(request.getEndpoint()));
    assertThat(request.getParameters(), equalTo(expectedParams));
    assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
    assertThat(request.getEntity(), nullValue());
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testOpenIndex() {
    String[] indices = randomIndicesNames(1, 5);
    OpenIndexRequest openIndexRequest = new OpenIndexRequest(indices);
    openIndexRequest.indices(indices);/*from   w ww.  j a  v a 2  s . c o  m*/

    Map<String, String> expectedParams = new HashMap<>();
    setRandomTimeout(openIndexRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
    setRandomMasterTimeout(openIndexRequest, expectedParams);
    setRandomIndicesOptions(openIndexRequest::indicesOptions, openIndexRequest::indicesOptions, expectedParams);
    setRandomWaitForActiveShards(openIndexRequest::waitForActiveShards, expectedParams);

    Request request = RequestConverters.openIndex(openIndexRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "").add(String.join(",", indices)).add("_open");
    assertThat(endpoint.toString(), equalTo(request.getEndpoint()));
    assertThat(expectedParams, equalTo(request.getParameters()));
    assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
    assertThat(request.getEntity(), nullValue());
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testCloseIndex() {
    String[] indices = randomIndicesNames(1, 5);
    CloseIndexRequest closeIndexRequest = new CloseIndexRequest(indices);

    Map<String, String> expectedParams = new HashMap<>();
    setRandomTimeout(closeIndexRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
    setRandomMasterTimeout(closeIndexRequest, expectedParams);
    setRandomIndicesOptions(closeIndexRequest::indicesOptions, closeIndexRequest::indicesOptions,
            expectedParams);/* w w  w  .  ja  v a 2  s .  com*/

    Request request = RequestConverters.closeIndex(closeIndexRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "").add(String.join(",", indices)).add("_close");
    assertThat(endpoint.toString(), equalTo(request.getEndpoint()));
    assertThat(expectedParams, equalTo(request.getParameters()));
    assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
    assertThat(request.getEntity(), nullValue());
}

From source file:org.ballerinalang.bre.bvm.BLangVM.java

/**
 * Act as a virtual CPU.//from w  w w  .  j av  a2s  .  c  o m
 */
private void exec() {
    int i;
    int j;
    int cpIndex; // Index of the constant pool
    FunctionCallCPEntry funcCallCPEntry;
    FunctionRefCPEntry funcRefCPEntry;
    TypeRefCPEntry typeRefCPEntry;
    FunctionInfo functionInfo;
    InstructionCALL callIns;

    boolean debugEnabled = programFile.getDebugger().isDebugEnabled();

    StackFrame currentSF, callersSF;
    int callersRetRegIndex;

    while (ip >= 0 && ip < code.length && controlStack.currentFrame != null) {

        if (debugEnabled) {
            debug();
        }
        Instruction instruction = code[ip];
        int opcode = instruction.getOpcode();
        int[] operands = instruction.getOperands();
        ip++;
        StackFrame sf = controlStack.currentFrame;

        switch (opcode) {
        case InstructionCodes.ICONST:
            cpIndex = operands[0];
            i = operands[1];
            sf.longRegs[i] = ((IntegerCPEntry) constPool[cpIndex]).getValue();
            break;
        case InstructionCodes.FCONST:
            cpIndex = operands[0];
            i = operands[1];
            sf.doubleRegs[i] = ((FloatCPEntry) constPool[cpIndex]).getValue();
            break;
        case InstructionCodes.SCONST:
            cpIndex = operands[0];
            i = operands[1];
            sf.stringRegs[i] = ((StringCPEntry) constPool[cpIndex]).getValue();
            break;
        case InstructionCodes.ICONST_0:
            i = operands[0];
            sf.longRegs[i] = 0;
            break;
        case InstructionCodes.ICONST_1:
            i = operands[0];
            sf.longRegs[i] = 1;
            break;
        case InstructionCodes.ICONST_2:
            i = operands[0];
            sf.longRegs[i] = 2;
            break;
        case InstructionCodes.ICONST_3:
            i = operands[0];
            sf.longRegs[i] = 3;
            break;
        case InstructionCodes.ICONST_4:
            i = operands[0];
            sf.longRegs[i] = 4;
            break;
        case InstructionCodes.ICONST_5:
            i = operands[0];
            sf.longRegs[i] = 5;
            break;
        case InstructionCodes.FCONST_0:
            i = operands[0];
            sf.doubleRegs[i] = 0;
            break;
        case InstructionCodes.FCONST_1:
            i = operands[0];
            sf.doubleRegs[i] = 1;
            break;
        case InstructionCodes.FCONST_2:
            i = operands[0];
            sf.doubleRegs[i] = 2;
            break;
        case InstructionCodes.FCONST_3:
            i = operands[0];
            sf.doubleRegs[i] = 3;
            break;
        case InstructionCodes.FCONST_4:
            i = operands[0];
            sf.doubleRegs[i] = 4;
            break;
        case InstructionCodes.FCONST_5:
            i = operands[0];
            sf.doubleRegs[i] = 5;
            break;
        case InstructionCodes.BCONST_0:
            i = operands[0];
            sf.intRegs[i] = 0;
            break;
        case InstructionCodes.BCONST_1:
            i = operands[0];
            sf.intRegs[i] = 1;
            break;
        case InstructionCodes.RCONST_NULL:
            i = operands[0];
            sf.refRegs[i] = null;
            break;

        case InstructionCodes.IMOVE:
        case InstructionCodes.FMOVE:
        case InstructionCodes.SMOVE:
        case InstructionCodes.BMOVE:
        case InstructionCodes.LMOVE:
        case InstructionCodes.RMOVE:
        case InstructionCodes.IALOAD:
        case InstructionCodes.FALOAD:
        case InstructionCodes.SALOAD:
        case InstructionCodes.BALOAD:
        case InstructionCodes.LALOAD:
        case InstructionCodes.RALOAD:
        case InstructionCodes.JSONALOAD:
        case InstructionCodes.IGLOAD:
        case InstructionCodes.FGLOAD:
        case InstructionCodes.SGLOAD:
        case InstructionCodes.BGLOAD:
        case InstructionCodes.LGLOAD:
        case InstructionCodes.RGLOAD:
        case InstructionCodes.IFIELDLOAD:
        case InstructionCodes.FFIELDLOAD:
        case InstructionCodes.SFIELDLOAD:
        case InstructionCodes.BFIELDLOAD:
        case InstructionCodes.LFIELDLOAD:
        case InstructionCodes.RFIELDLOAD:
        case InstructionCodes.MAPLOAD:
        case InstructionCodes.JSONLOAD:
        case InstructionCodes.ENUMERATORLOAD:
            execLoadOpcodes(sf, opcode, operands);
            break;

        case InstructionCodes.ISTORE:
        case InstructionCodes.FSTORE:
        case InstructionCodes.SSTORE:
        case InstructionCodes.BSTORE:
        case InstructionCodes.LSTORE:
        case InstructionCodes.RSTORE:
        case InstructionCodes.IASTORE:
        case InstructionCodes.FASTORE:
        case InstructionCodes.SASTORE:
        case InstructionCodes.BASTORE:
        case InstructionCodes.LASTORE:
        case InstructionCodes.RASTORE:
        case InstructionCodes.JSONASTORE:
        case InstructionCodes.IGSTORE:
        case InstructionCodes.FGSTORE:
        case InstructionCodes.SGSTORE:
        case InstructionCodes.BGSTORE:
        case InstructionCodes.LGSTORE:
        case InstructionCodes.RGSTORE:
        case InstructionCodes.IFIELDSTORE:
        case InstructionCodes.FFIELDSTORE:
        case InstructionCodes.SFIELDSTORE:
        case InstructionCodes.BFIELDSTORE:
        case InstructionCodes.LFIELDSTORE:
        case InstructionCodes.RFIELDSTORE:
        case InstructionCodes.MAPSTORE:
        case InstructionCodes.JSONSTORE:
            execStoreOpcodes(sf, opcode, operands);
            break;

        case InstructionCodes.IADD:
        case InstructionCodes.FADD:
        case InstructionCodes.SADD:
        case InstructionCodes.XMLADD:
        case InstructionCodes.ISUB:
        case InstructionCodes.FSUB:
        case InstructionCodes.IMUL:
        case InstructionCodes.FMUL:
        case InstructionCodes.IDIV:
        case InstructionCodes.FDIV:
        case InstructionCodes.IMOD:
        case InstructionCodes.FMOD:
        case InstructionCodes.INEG:
        case InstructionCodes.FNEG:
        case InstructionCodes.BNOT:
        case InstructionCodes.IEQ:
        case InstructionCodes.FEQ:
        case InstructionCodes.SEQ:
        case InstructionCodes.BEQ:
        case InstructionCodes.REQ:
        case InstructionCodes.TEQ:
        case InstructionCodes.INE:
        case InstructionCodes.FNE:
        case InstructionCodes.SNE:
        case InstructionCodes.BNE:
        case InstructionCodes.RNE:
        case InstructionCodes.TNE:
            execBinaryOpCodes(sf, opcode, operands);
            break;

        case InstructionCodes.LENGTHOF:
            calculateLength(operands, sf);
            break;
        case InstructionCodes.TYPELOAD:
            cpIndex = operands[0];
            j = operands[1];
            TypeRefCPEntry typeEntry = (TypeRefCPEntry) constPool[cpIndex];
            sf.refRegs[j] = new BTypeValue(typeEntry.getType());
            break;
        case InstructionCodes.TYPEOF:
            i = operands[0];
            j = operands[1];
            if (sf.refRegs[i] == null) {
                handleNullRefError();
                break;
            }
            sf.refRegs[j] = new BTypeValue(sf.refRegs[i].getType());
            break;

        case InstructionCodes.IGT:
        case InstructionCodes.FGT:
        case InstructionCodes.IGE:
        case InstructionCodes.FGE:
        case InstructionCodes.ILT:
        case InstructionCodes.FLT:
        case InstructionCodes.ILE:
        case InstructionCodes.FLE:
        case InstructionCodes.REQ_NULL:
        case InstructionCodes.RNE_NULL:
        case InstructionCodes.BR_TRUE:
        case InstructionCodes.BR_FALSE:
        case InstructionCodes.GOTO:
        case InstructionCodes.HALT:
        case InstructionCodes.SEQ_NULL:
        case InstructionCodes.SNE_NULL:
            execCmpAndBranchOpcodes(sf, opcode, operands);
            break;

        case InstructionCodes.TR_RETRY:
            i = operands[0];
            j = operands[1];
            retryTransaction(i, j);
            break;
        case InstructionCodes.CALL:
            callIns = (InstructionCALL) instruction;
            invokeCallableUnit(callIns.functionInfo, callIns.argRegs, callIns.retRegs);
            break;
        case InstructionCodes.VCALL:
            InstructionVCALL vcallIns = (InstructionVCALL) instruction;
            invokeVirtualFunction(vcallIns.receiverRegIndex, vcallIns.functionInfo, vcallIns.argRegs,
                    vcallIns.retRegs);
            break;
        case InstructionCodes.ACALL:
            InstructionACALL acallIns = (InstructionACALL) instruction;
            invokeAction(acallIns.actionName, acallIns.argRegs, acallIns.retRegs);
            break;
        case InstructionCodes.TCALL:
            InstructionTCALL tcallIns = (InstructionTCALL) instruction;
            invokeCallableUnit(tcallIns.transformerInfo, tcallIns.argRegs, tcallIns.retRegs);
            break;
        case InstructionCodes.TR_BEGIN:
            i = operands[0];
            j = operands[1];
            beginTransaction(i, j);
            break;
        case InstructionCodes.TR_END:
            i = operands[0];
            endTransaction(i);
            break;
        case InstructionCodes.WRKSEND:
            InstructionWRKSendReceive wrkSendIns = (InstructionWRKSendReceive) instruction;
            handleWorkerSend(wrkSendIns.dataChannelInfo, wrkSendIns.types, wrkSendIns.regs);
            break;
        case InstructionCodes.WRKRECEIVE:
            InstructionWRKSendReceive wrkReceiveIns = (InstructionWRKSendReceive) instruction;
            handleWorkerReceive(wrkReceiveIns.dataChannelInfo, wrkReceiveIns.types, wrkReceiveIns.regs);
            break;
        case InstructionCodes.FORKJOIN:
            InstructionFORKJOIN forkJoinIns = (InstructionFORKJOIN) instruction;
            invokeForkJoin(forkJoinIns);
            break;
        case InstructionCodes.WRKSTART:
            startWorkers();
            break;
        case InstructionCodes.WRKRETURN:
            handleWorkerReturn();
            break;
        case InstructionCodes.THROW:
            i = operands[0];
            if (i >= 0) {
                BStruct error = (BStruct) sf.refRegs[i];
                if (error == null) {
                    handleNullRefError();
                    break;
                }

                BLangVMErrors.attachCallStack(error, context, ip);
                context.setError(error);
            }
            handleError();
            break;
        case InstructionCodes.ERRSTORE:
            i = operands[0];
            sf.refRegs[i] = context.getError();
            // clear error.
            context.setError(null);
            break;
        case InstructionCodes.FPCALL:
            i = operands[0];
            if (sf.refRegs[i] == null) {
                handleNullRefError();
                break;
            }
            cpIndex = operands[1];
            funcCallCPEntry = (FunctionCallCPEntry) constPool[cpIndex];
            funcRefCPEntry = ((BFunctionPointer) sf.refRegs[i]).value();
            functionInfo = funcRefCPEntry.getFunctionInfo();
            if (functionInfo.isNative()) {
                invokeNativeFunction(functionInfo, funcCallCPEntry.getArgRegs(), funcCallCPEntry.getRetRegs());
            } else {
                invokeCallableUnit(functionInfo, funcCallCPEntry.getArgRegs(), funcCallCPEntry.getRetRegs());
            }
            break;
        case InstructionCodes.FPLOAD:
            i = operands[0];
            j = operands[1];
            funcRefCPEntry = (FunctionRefCPEntry) constPool[i];
            sf.refRegs[j] = new BFunctionPointer(funcRefCPEntry);
            break;

        case InstructionCodes.I2ANY:
        case InstructionCodes.F2ANY:
        case InstructionCodes.S2ANY:
        case InstructionCodes.B2ANY:
        case InstructionCodes.L2ANY:
        case InstructionCodes.ANY2I:
        case InstructionCodes.ANY2F:
        case InstructionCodes.ANY2S:
        case InstructionCodes.ANY2B:
        case InstructionCodes.ANY2L:
        case InstructionCodes.ANY2JSON:
        case InstructionCodes.ANY2XML:
        case InstructionCodes.ANY2MAP:
        case InstructionCodes.ANY2TYPE:
        case InstructionCodes.ANY2E:
        case InstructionCodes.ANY2T:
        case InstructionCodes.ANY2C:
        case InstructionCodes.NULL2JSON:
        case InstructionCodes.CHECKCAST:
        case InstructionCodes.B2JSON:
        case InstructionCodes.JSON2I:
        case InstructionCodes.JSON2F:
        case InstructionCodes.JSON2S:
        case InstructionCodes.JSON2B:
        case InstructionCodes.NULL2S:
            execTypeCastOpcodes(sf, opcode, operands);
            break;

        case InstructionCodes.I2F:
        case InstructionCodes.I2S:
        case InstructionCodes.I2B:
        case InstructionCodes.I2JSON:
        case InstructionCodes.F2I:
        case InstructionCodes.F2S:
        case InstructionCodes.F2B:
        case InstructionCodes.F2JSON:
        case InstructionCodes.S2I:
        case InstructionCodes.S2F:
        case InstructionCodes.S2B:
        case InstructionCodes.S2JSON:
        case InstructionCodes.B2I:
        case InstructionCodes.B2F:
        case InstructionCodes.B2S:
        case InstructionCodes.DT2XML:
        case InstructionCodes.DT2JSON:
        case InstructionCodes.T2MAP:
        case InstructionCodes.T2JSON:
        case InstructionCodes.MAP2T:
        case InstructionCodes.JSON2T:
        case InstructionCodes.XMLATTRS2MAP:
        case InstructionCodes.S2XML:
        case InstructionCodes.S2JSONX:
        case InstructionCodes.XML2S:
            execTypeConversionOpcodes(sf, opcode, operands);
            break;

        case InstructionCodes.INEWARRAY:
            i = operands[0];
            sf.refRegs[i] = new BIntArray();
            break;
        case InstructionCodes.ARRAYLEN:
            i = operands[0];
            j = operands[1];

            BValue value = sf.refRegs[i];

            if (value == null) {
                handleNullRefError();
                break;
            }

            if (value.getType().getTag() == TypeTags.JSON_TAG) {
                sf.longRegs[j] = ((BJSON) value).value().size();
                break;
            }

            sf.longRegs[j] = ((BNewArray) value).size();
            break;
        case InstructionCodes.FNEWARRAY:
            i = operands[0];
            sf.refRegs[i] = new BFloatArray();
            break;
        case InstructionCodes.SNEWARRAY:
            i = operands[0];
            sf.refRegs[i] = new BStringArray();
            break;
        case InstructionCodes.BNEWARRAY:
            i = operands[0];
            sf.refRegs[i] = new BBooleanArray();
            break;
        case InstructionCodes.LNEWARRAY:
            i = operands[0];
            sf.refRegs[i] = new BBlobArray();
            break;
        case InstructionCodes.RNEWARRAY:
            i = operands[0];
            cpIndex = operands[1];
            typeRefCPEntry = (TypeRefCPEntry) constPool[cpIndex];
            sf.refRegs[i] = new BRefValueArray(typeRefCPEntry.getType());
            break;
        case InstructionCodes.JSONNEWARRAY:
            i = operands[0];
            j = operands[1];
            // This is a temporary solution to create n-valued JSON array
            StringJoiner stringJoiner = new StringJoiner(",", "[", "]");
            for (int index = 0; index < sf.longRegs[j]; index++) {
                stringJoiner.add(null);
            }
            sf.refRegs[i] = new BJSON(stringJoiner.toString());
            break;

        case InstructionCodes.NEWSTRUCT:
            createNewStruct(operands, sf);
            break;
        case InstructionCodes.NEWCONNECTOR:
            createNewConnector(operands, sf);
            break;
        case InstructionCodes.NEWMAP:
            i = operands[0];
            sf.refRegs[i] = new BMap<String, BRefType>();
            break;
        case InstructionCodes.NEWJSON:
            i = operands[0];
            cpIndex = operands[1];
            typeRefCPEntry = (TypeRefCPEntry) constPool[cpIndex];
            sf.refRegs[i] = new BJSON("{}", typeRefCPEntry.getType());
            break;
        case InstructionCodes.NEWTABLE:
            i = operands[0];
            cpIndex = operands[1];
            typeRefCPEntry = (TypeRefCPEntry) constPool[cpIndex];
            sf.refRegs[i] = new BTable(typeRefCPEntry.getType());
            break;
        case InstructionCodes.NEW_INT_RANGE:
            createNewIntRange(operands, sf);
            break;
        case InstructionCodes.IRET:
            i = operands[0];
            j = operands[1];
            currentSF = controlStack.currentFrame;
            callersSF = controlStack.currentFrame.prevStackFrame;
            callersRetRegIndex = currentSF.retRegIndexes[i];
            callersSF.longRegs[callersRetRegIndex] = currentSF.longRegs[j];
            break;
        case InstructionCodes.FRET:
            i = operands[0];
            j = operands[1];
            currentSF = controlStack.currentFrame;
            callersSF = controlStack.currentFrame.prevStackFrame;
            callersRetRegIndex = currentSF.retRegIndexes[i];
            callersSF.doubleRegs[callersRetRegIndex] = currentSF.doubleRegs[j];
            break;
        case InstructionCodes.SRET:
            i = operands[0];
            j = operands[1];
            currentSF = controlStack.currentFrame;
            callersSF = controlStack.currentFrame.prevStackFrame;
            callersRetRegIndex = currentSF.retRegIndexes[i];
            callersSF.stringRegs[callersRetRegIndex] = currentSF.stringRegs[j];
            break;
        case InstructionCodes.BRET:
            i = operands[0];
            j = operands[1];
            currentSF = controlStack.currentFrame;
            callersSF = controlStack.currentFrame.prevStackFrame;
            callersRetRegIndex = currentSF.retRegIndexes[i];
            callersSF.intRegs[callersRetRegIndex] = currentSF.intRegs[j];
            break;
        case InstructionCodes.LRET:
            i = operands[0];
            j = operands[1];
            currentSF = controlStack.currentFrame;
            callersSF = controlStack.currentFrame.prevStackFrame;
            callersRetRegIndex = currentSF.retRegIndexes[i];
            callersSF.byteRegs[callersRetRegIndex] = currentSF.byteRegs[j];
            break;
        case InstructionCodes.RRET:
            i = operands[0];
            j = operands[1];
            currentSF = controlStack.currentFrame;
            callersSF = controlStack.currentFrame.prevStackFrame;
            callersRetRegIndex = currentSF.retRegIndexes[i];
            callersSF.refRegs[callersRetRegIndex] = currentSF.refRegs[j];
            break;
        case InstructionCodes.RET:
            handleReturn();
            break;
        case InstructionCodes.XMLATTRSTORE:
        case InstructionCodes.XMLATTRLOAD:
        case InstructionCodes.XML2XMLATTRS:
        case InstructionCodes.S2QNAME:
        case InstructionCodes.NEWQNAME:
        case InstructionCodes.NEWXMLELEMENT:
        case InstructionCodes.NEWXMLCOMMENT:
        case InstructionCodes.NEWXMLTEXT:
        case InstructionCodes.NEWXMLPI:
        case InstructionCodes.XMLSTORE:
        case InstructionCodes.XMLLOAD:
            execXMLOpcodes(sf, opcode, operands);
            break;
        case InstructionCodes.ITR_NEW:
        case InstructionCodes.ITR_NEXT:
        case InstructionCodes.ITR_HAS_NEXT:
            execIteratorOperation(sf, instruction);
            break;
        case InstructionCodes.LOCK:
            InstructionLock instructionLock = (InstructionLock) instruction;
            handleVariableLock(instructionLock.types, instructionLock.varRegs);
            break;
        case InstructionCodes.UNLOCK:
            InstructionLock instructionUnLock = (InstructionLock) instruction;
            handleVariableUnlock(instructionUnLock.types, instructionUnLock.varRegs);
            break;
        default:
            throw new UnsupportedOperationException();
        }
    }
}

From source file:iterator.test.matchers.type.annotation.AnnotationMap.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder("@");
    sb.append(getAnnotationClass().getSimpleName());
    StringJoiner joiner = new StringJoiner(COMMA, "(", ")");
    joiner.setEmptyValue(EMPTY);/*  ww w  .  j  a v a2  s . c om*/
    if (members.containsKey("value")) {
        MemberValue<?> mv = members.get("value");
        if (mv.isUndefined() || !mv.isDefault()) {
            if (members.size() > 1
                    && members.entrySet().stream().filter(entry -> !"value".equals(entry.getKey()))
                            .anyMatch(entry -> !entry.getValue().isDefault())) {
                joiner.add(String.format("value = %s", mv));
            } else {
                joiner.add(mv.toString());
            }
        }
    }
    members.entrySet().stream().filter(entry -> !"value".equals(entry.getKey())
            && (entry.getValue().isUndefined() || !entry.getValue().isDefault())).forEach(entry -> {
                joiner.add(String.format("%s = %s", entry.getKey(), entry.getValue()));
            });
    sb.append(joiner.toString());
    return sb.toString();
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testRefresh() {
    String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5);
    RefreshRequest refreshRequest;//from  w  w w.  j  a  va2 s . c o m
    if (randomBoolean()) {
        refreshRequest = new RefreshRequest(indices);
    } else {
        refreshRequest = new RefreshRequest();
        refreshRequest.indices(indices);
    }
    Map<String, String> expectedParams = new HashMap<>();
    setRandomIndicesOptions(refreshRequest::indicesOptions, refreshRequest::indicesOptions, expectedParams);
    Request request = RequestConverters.refresh(refreshRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    if (indices != null && indices.length > 0) {
        endpoint.add(String.join(",", indices));
    }
    endpoint.add("_refresh");
    assertThat(request.getEndpoint(), equalTo(endpoint.toString()));
    assertThat(request.getParameters(), equalTo(expectedParams));
    assertThat(request.getEntity(), nullValue());
    assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testFlush() {
    String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5);
    FlushRequest flushRequest;//w w  w  .  j a va  2  s. com
    if (randomBoolean()) {
        flushRequest = new FlushRequest(indices);
    } else {
        flushRequest = new FlushRequest();
        flushRequest.indices(indices);
    }
    Map<String, String> expectedParams = new HashMap<>();
    setRandomIndicesOptions(flushRequest::indicesOptions, flushRequest::indicesOptions, expectedParams);
    if (randomBoolean()) {
        flushRequest.force(randomBoolean());
    }
    expectedParams.put("force", Boolean.toString(flushRequest.force()));
    if (randomBoolean()) {
        flushRequest.waitIfOngoing(randomBoolean());
    }
    expectedParams.put("wait_if_ongoing", Boolean.toString(flushRequest.waitIfOngoing()));

    Request request = RequestConverters.flush(flushRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    if (indices != null && indices.length > 0) {
        endpoint.add(String.join(",", indices));
    }
    endpoint.add("_flush");
    assertThat(request.getEndpoint(), equalTo(endpoint.toString()));
    assertThat(request.getParameters(), equalTo(expectedParams));
    assertThat(request.getEntity(), nullValue());
    assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testSyncedFlush() {
    String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5);
    SyncedFlushRequest syncedFlushRequest;
    if (randomBoolean()) {
        syncedFlushRequest = new SyncedFlushRequest(indices);
    } else {//from  w w  w  . j a v  a2s.  com
        syncedFlushRequest = new SyncedFlushRequest();
        syncedFlushRequest.indices(indices);
    }
    Map<String, String> expectedParams = new HashMap<>();
    setRandomIndicesOptions(syncedFlushRequest::indicesOptions, syncedFlushRequest::indicesOptions,
            expectedParams);
    Request request = RequestConverters.flushSynced(syncedFlushRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    if (indices != null && indices.length > 0) {
        endpoint.add(String.join(",", indices));
    }
    endpoint.add("_flush/synced");
    assertThat(request.getEndpoint(), equalTo(endpoint.toString()));
    assertThat(request.getParameters(), equalTo(expectedParams));
    assertThat(request.getEntity(), nullValue());
    assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testForceMerge() {
    String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5);
    ForceMergeRequest forceMergeRequest;
    if (randomBoolean()) {
        forceMergeRequest = new ForceMergeRequest(indices);
    } else {//from w ww. j  ava 2  s  . co  m
        forceMergeRequest = new ForceMergeRequest();
        forceMergeRequest.indices(indices);
    }

    Map<String, String> expectedParams = new HashMap<>();
    setRandomIndicesOptions(forceMergeRequest::indicesOptions, forceMergeRequest::indicesOptions,
            expectedParams);
    if (randomBoolean()) {
        forceMergeRequest.maxNumSegments(randomInt());
    }
    expectedParams.put("max_num_segments", Integer.toString(forceMergeRequest.maxNumSegments()));
    if (randomBoolean()) {
        forceMergeRequest.onlyExpungeDeletes(randomBoolean());
    }
    expectedParams.put("only_expunge_deletes", Boolean.toString(forceMergeRequest.onlyExpungeDeletes()));
    if (randomBoolean()) {
        forceMergeRequest.flush(randomBoolean());
    }
    expectedParams.put("flush", Boolean.toString(forceMergeRequest.flush()));

    Request request = RequestConverters.forceMerge(forceMergeRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    if (indices != null && indices.length > 0) {
        endpoint.add(String.join(",", indices));
    }
    endpoint.add("_forcemerge");
    assertThat(request.getEndpoint(), equalTo(endpoint.toString()));
    assertThat(request.getParameters(), equalTo(expectedParams));
    assertThat(request.getEntity(), nullValue());
    assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testClearCache() {
    String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5);
    ClearIndicesCacheRequest clearIndicesCacheRequest;
    if (randomBoolean()) {
        clearIndicesCacheRequest = new ClearIndicesCacheRequest(indices);
    } else {//from  w  ww. j a v  a2 s. c  om
        clearIndicesCacheRequest = new ClearIndicesCacheRequest();
        clearIndicesCacheRequest.indices(indices);
    }
    Map<String, String> expectedParams = new HashMap<>();
    setRandomIndicesOptions(clearIndicesCacheRequest::indicesOptions, clearIndicesCacheRequest::indicesOptions,
            expectedParams);
    if (randomBoolean()) {
        clearIndicesCacheRequest.queryCache(randomBoolean());
    }
    expectedParams.put("query", Boolean.toString(clearIndicesCacheRequest.queryCache()));
    if (randomBoolean()) {
        clearIndicesCacheRequest.fieldDataCache(randomBoolean());
    }
    expectedParams.put("fielddata", Boolean.toString(clearIndicesCacheRequest.fieldDataCache()));
    if (randomBoolean()) {
        clearIndicesCacheRequest.requestCache(randomBoolean());
    }
    expectedParams.put("request", Boolean.toString(clearIndicesCacheRequest.requestCache()));
    if (randomBoolean()) {
        clearIndicesCacheRequest.fields(randomIndicesNames(1, 5));
        expectedParams.put("fields", String.join(",", clearIndicesCacheRequest.fields()));
    }

    Request request = RequestConverters.clearCache(clearIndicesCacheRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    if (indices != null && indices.length > 0) {
        endpoint.add(String.join(",", indices));
    }
    endpoint.add("_cache/clear");
    assertThat(request.getEndpoint(), equalTo(endpoint.toString()));
    assertThat(request.getParameters(), equalTo(expectedParams));
    assertThat(request.getEntity(), nullValue());
    assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
}