public static Move makeMove(int moveColumn, Boolean inMainLoop) { if (inMainLoop) { for (int j = 0; j <= Loop.height - 1; j++) { if (BoardState.board[j][moveColumn] == 99) { if (Loop.DetermineTurn()) { Loop.lastMove = new Move(j, moveColumn, 1); return Loop.lastMove; } else { Loop.lastMove = new Move(j, moveColumn, 0); return Loop.lastMove; } } else { } } return new Move(0, 0, 0); } else { for (int j = 0; j <= Loop.height - 1; j++) { if (BoardState.board[j][moveColumn] == 99) { if (Loop.DetermineTurn()) { return new Move(j, moveColumn, 1); } else { return new Move(j, moveColumn, 0); } } else { } } return new Move(0, 0, 0); } }
public void extractShipmentLevelREF(Loop inLoop) throws OBOEException { Segment segment = null; try { int numberOfSegmentsInVector = inLoop.getCount("REF"); for (int i = 0; i < numberOfSegmentsInVector; i++) { segment = inLoop.getSegment("REF", i); String refIdentificatorQualifier = getField( segment, 1, true, "Missing Reference Identificator Qualifier in segment REF*0"); if (refIdentificatorQualifier == null) { errorMsgs.add("Reference Identificator Qualifier is null"); setValid(false); return; } ediInp856Vw.setRefIdentQualif(refIdentificatorQualifier); String refIdentificator = getField(segment, 2, true, "Missing Reference Identificator in segment REF*0"); if (refIdentificator == null) { errorMsgs.add("Reference Identificator is null"); setValid(false); return; } ediInp856Vw.setRefIdent(refIdentificator); } } catch (OBOEException oe) { return; } }
private LinkedList<String> getInformation(String query, Node i) { XPathNodeUniprot XPathNoder = new XPathNodeUniprot(); NodeList entrynodelist = XPathNoder.getNodeListByXPath(query, i); Loop l1 = new Loop(); LinkedList<String> information = l1.getStringfromNodelist(entrynodelist); return information; }
public static void main(String args[]) { int n; Scanner in = new Scanner(System.in); Loop l = new Loop(); System.out.print("Enter a number: "); n = in.nextInt(); for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { System.out.print(" "); } l.inner(i); l.inner(i - 1); System.out.println(""); } System.out.println("Lipika"); for (int i = n - 1; i > 0; i--) { for (int j = 0; j < n - i; j++) { System.out.print(" "); } l.inner(i - 1); l.inner(i - 2); System.out.println(""); } }
public void extractReferenceIdentificationREF(Loop inLoop) throws OBOEException { int qty; try { qty = inLoop.getSegmentCount("REF"); } catch (Exception e) { return; } Segment segment = null; // valid = true; for (int ii = 0; ii < qty; ii++) { try { segment = inLoop.getSegment("REF", ii); } catch (Exception exc) { } if (segment == null) { return; } String identQualifier = getField(segment, 1, false, null); String identification = getField(segment, 2, false, null); if ("1V".equals(identQualifier)) { ediInp856Vw.setPurchOrderNum(identification); } else if ("2I".equals(identQualifier) || "CN".equals(identQualifier)) { ediInp856Vw.setTrackingNum(identification); } else if ("D2".equals(identQualifier)) { ediInp856Vw.setDistOrderNum(identification); } else if ("ZZ".equals(identQualifier)) { ediInp856Vw.setPurchOrderNum(identification); } } return; }
/** * Reads a chunk and puts an Instrument property into the RepInfo object. * * @return <code>false</code> if the chunk is structurally invalid, otherwise <code>true</code> */ public boolean readChunk(RepInfo info) throws IOException { AiffModule module = (AiffModule) _module; int baseNote = ModuleBase.readUnsignedByte(_dstream, module); int detune = ModuleBase.readSignedByte(_dstream, module); int lowNote = ModuleBase.readUnsignedByte(_dstream, module); int highNote = ModuleBase.readUnsignedByte(_dstream, module); int lowVelocity = ModuleBase.readUnsignedByte(_dstream, module); int highVelocity = ModuleBase.readUnsignedByte(_dstream, module); int gain = module.readSignedShort(_dstream); Loop sustainLoop = readLoop(module); Loop releaseLoop = readLoop(module); List propList = new ArrayList(9); propList.add(new Property("BaseNote", PropertyType.INTEGER, new Integer(baseNote))); propList.add(new Property("Detune", PropertyType.INTEGER, new Integer(detune))); propList.add(new Property("LowNote", PropertyType.INTEGER, new Integer(lowNote))); propList.add(new Property("HighNote", PropertyType.INTEGER, new Integer(highNote))); propList.add(new Property("LowVelocity", PropertyType.INTEGER, new Integer(lowVelocity))); propList.add(new Property("HighVelocity", PropertyType.INTEGER, new Integer(highVelocity))); propList.add(new Property("Gain", PropertyType.INTEGER, new Integer(gain))); propList.add(sustainLoop.loopProp("SustainLoop")); propList.add(releaseLoop.loopProp("ReleaseLoop")); module.addAiffProperty( new Property("Instrument", PropertyType.PROPERTY, PropertyArity.LIST, propList)); return true; }
public boolean leadsTo( BaseLocalData localData, Graph gr, GraphSource code, GraphPart part, List<Loop> loops) throws InterruptedException { for (Loop l : loops) { l.leadsToMark = 0; } return leadsTo(localData, gr, code, part, new ArrayList<>(), loops); }
public void extractShipmentDTM(Loop inLoop) throws OBOEException { Segment segment = null; // valid = false; int qty = inLoop.getSegmentCount("DTM"); for (int ii = 0; ii < qty; ii++) { try { segment = inLoop.getSegment("DTM", ii); } catch (Exception exc) { } if (segment == null) { errorMsgs.add("Segments DTM missing," + ii); setValid(false); return; } String dateTimeQualifier = getField(segment, 1, true, "Missing Date/Time Qualifier in segment DTM"); if (dateTimeQualifier == null) { errorMsgs.add("Date/Time Qualifier is null"); setValid(false); return; } if (!"011".equals(dateTimeQualifier)) { errorMsgs.add("Invalid value of Date/Time Qualifier in segment DTM: " + dateTimeQualifier); setValid(false); return; } String shipmentDateS = getField(segment, 2, true, "Missing Shipment Date in segment DTM"); if (shipmentDateS == null) { errorMsgs.add("Shipment Date is null"); setValid(false); return; } if (shipmentDateS.length() != 8) { errorMsgs.add("Invalid value of Shipment Date: " + shipmentDateS); setValid(false); return; } SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Date shipmentDate = null; try { shipmentDate = sdf.parse(shipmentDateS); } catch (Exception exc) { errorMsgs.add("Invalid value of Shipment Date: " + shipmentDateS); setValid(false); return; } if (!shipmentDateS.equals(sdf.format(shipmentDate))) { errorMsgs.add("Invalid value of Shipment Date: " + shipmentDateS); setValid(false); return; } ediInp856Vw.setShipDate(shipmentDate); } return; }
/** * @param args * @return */ public static void main(String[] args) { Loop f = new Loop(); System.out.println(f.fact(3)); System.out.println(f.fact(5)); System.out.println(f.fact(7)); }
/** * This is called immediately after the surface is first created. Implementations of this should * start up whatever rendering code they desire. Note that only one thread can ever draw into a * {@link Surface}, so you should not draw into the Surface here if your normal rendering will be * in another thread. * * @param holder The SurfaceHolder whose surface is being created. */ @Override public void surfaceCreated(SurfaceHolder holder) { Rect surface = holder.getSurfaceFrame(); width = surface.width(); height = surface.height(); x = width / 2; y = circleRadius; loop = new Loop(this); loop.isRunning(true); loop.start(); }
/** * This is called immediately before a surface is being destroyed. After returning from this call, * you should no longer try to access this surface. If you have a rendering thread that directly * accesses the surface, you must ensure that thread is no longer touching the Surface before * returning from this function. * * @param holder The SurfaceHolder whose surface is being destroyed. */ @Override public void surfaceDestroyed(SurfaceHolder holder) { boolean retry = true; loop.isRunning(false); while (retry) { try { loop.join(); retry = false; } catch (InterruptedException e) { e.printStackTrace(); } } }
public static void main(String[] args) { double rate = 0.4; Design design = new Design("design23e", rate, "loop", false, ""); Loop loop = new Loop(design, new int[][] {{0, 48}, {50, 62}, {64, design.scaffoldLength}}); Loop loop2 = new Loop(design, new int[][] {{62, 64}}); Loop loop3 = new Loop(design, new int[][] {{48, 50}}); assertEquals("Segment test", (int) loop.getNumOfCrossoverSegments(), (int) 2); loop.mergeWith(loop2); assertEquals( "test1", loop.toString(), new Loop(new int[][] {{0, 48}, {50, design.scaffoldLength}}).toString()); loop.mergeWith(loop3); assertEquals( "test2", loop.toString(), new Loop(new int[][] {{0, design.scaffoldLength}}).toString()); Loop newLoop = new Loop(design); loop.split(27, 29, newLoop); assertEquals( "test3", loop.toString(), new Loop(new int[][] {{0, 27}, {29, design.scaffoldLength}}).toString()); System.out.println("LoopTest done!"); }
/** * This is called immediately after the surface is first created. Implementations of this should * start up whatever rendering code they desire. Note that only one thread can ever draw into a * {@link Surface}, so you should not draw into the Surface here if your normal rendering will be * in another thread. * * @param holder The SurfaceHolder whose surface is being created. */ @Override public void surfaceCreated(SurfaceHolder holder) { Rect surface = holder.getSurfaceFrame(); width = surface.width(); height = surface.height(); x = width / 2; y = circleRadius; loop = new Loop(this); loop.isRunning(true); loop.start(); Log.d("ANAS", "++++++++++++++SURFACE CREATED LOOP: " + loop.getState()); }
@Override public void surfaceDestroyed(SurfaceHolder holder) { // simply copied from sample application LunarLander: // we have to tell thread to shut down & wait for it to finish, or else // it might touch the Surface after we return and explode boolean retry = true; loop.isRunning(false); while (retry) { try { loop.join(); retry = false; } catch (InterruptedException e) { // we will try it again and again... } } }
/** * switch case for ALL orders * * @param e the EObject w'd like to know more about */ private void execute(EObject e) { if (e instanceof Refresh) { refresh(); } else if (e instanceof Navigate) { navigateTo(((Navigate) e).getUrl()); } else if (e instanceof Store) { store((Store) e); } else if (e instanceof ReDefine) { redefine((ReDefine) e); } else if (e instanceof Delete) { delete((Delete) e); } else if (e instanceof ActionSelect) { select((ActionSelect) e); } else if (e instanceof ActionWithObject) { ActionWithObject awo = (ActionWithObject) e; execute(awo.getObject(), awo); } else if (e instanceof CheckBox) { tickBox((CheckBox) e); } else if (e instanceof Rickroll) { rickRoll(); } else if (e instanceof DoWait) { waitFor(((DoWait) e).getMillisec()); } // conditions : else if (Condition.class.isAssignableFrom(e.getClass())) { eval((Condition) e); } // structures : else if (e instanceof If) { If i = ((If) e); structureIf(i.getCond(), i.getActionThen(), i.getActionElse()); } else if (e instanceof Loop) { Loop i = (Loop) e; structureLoop(i.getCond(), i.getMilliseconds(), i.getActions()); } else if (e instanceof DoAll) { DoAll i = (DoAll) e; structureDoAll(i.getColl(), i.getTodo()); } else if (e instanceof Execute) { executeSubProcedure((Execute) e); } }
public void extractShipmentTD5(Loop inLoop) throws OBOEException { Segment segment = null; try { int numberOfSegmentsInVector = inLoop.getCount("TD5"); for (int i = 0; i < numberOfSegmentsInVector; i++) { segment = inLoop.getSegment("TD5", i); if (segment == null) return; String carrierCode = getField( segment, 2, true, "Missing Carrier Code"); // may not be right field but not used in integration // services ediInp856Vw.setCarrierCode(carrierCode); String carrierName = getField(segment, 5, false, "Missing Carrier Name"); ediInp856Vw.setCarrierName(carrierName); } } catch (Exception exc) { } return; }
public void extractShipByN1(Loop inLoop) throws OBOEException { Loop loop = null; int numberInVector = inLoop.getCount("N1"); for (int i = 0; i < numberInVector; i++) { loop = inLoop.getLoop("N1", i); if (loop == null) return; Segment segment = loop.getSegment("N1"); String qualif = getField(segment, 1, false, null); if ("ST".equals(qualif)) { String shipToName = getField(segment, 2, false, null); ediInp856Vw.setShipToName(shipToName); String identQualifier = getField(segment, 3, false, null); if ("01".equals(identQualifier)) { String shipToCode = getField(segment, 4, false, null); ediInp856Vw.setShipToCode(shipToCode); } extractShipFromN4(loop); } else { String distName = qualif; ediInp856Vw.setDistName(distName); String distCodeQualifier = getField(segment, 2, false, null); ediInp856Vw.setDistIdentCodeQualif(distCodeQualifier); if (!Utility.isSet(distName) && !Utility.isSet(distCodeQualifier)) { errorMsgs.add("No distributor info in segment N1"); setValid(false); return; } if (Utility.isSet(distCodeQualifier)) { String distCode = getField(segment, 3, false, null); ediInp856Vw.setDistIdentCode(distCode); if (!Utility.isSet(distCode) && !Utility.isSet(distName)) { errorMsgs.add("No distributor info in segment N1"); setValid(false); return; } } } } }
public void extractItemIdentificationREF(Loop inLoop) throws OBOEException { try { int numberOfSegmentsInVector = inLoop.getCount("REF"); Segment segment = null; ArrayList trackingNums = new ArrayList(); for (int i = 0; i < numberOfSegmentsInVector; i++) { segment = inLoop.getSegment("REF", i); if (segment == null) return; String identQualifier = getField(segment, 1, false, null); String identification = getField(segment, 2, false, null); if ("2I".equals(identQualifier) || "CN".equals(identQualifier)) { trackingNums.add(identification); } } ediInp856ItemVw.setTrackingNumList(trackingNums); } catch (Exception e) { return; } return; }
private void searchRef(StringArrayRef ref, Loop loop) { String temp_name = ref.getArrayName(); Iterator<Unit> iter = loop.getBodyBlocks().get(0).getBody().getUnits().iterator(); while (iter.hasNext()) { Unit curr = iter.next(); if (defines(curr, temp_name) && curr instanceof AssignStmt) { AssignStmt assign = (AssignStmt) curr; Value right = assign.getRightOp(); if (right instanceof FieldRef) { FieldRef field_ref = (FieldRef) right; ref.setFieldSignature(field_ref.getField().getSignature()); ref.setField(field_ref.getField().getName()); } } } }
public void extractPurchaseOrderReferencePRF(Loop inLoop) throws OBOEException { Segment segment = null; try { segment = inLoop.getSegment("PRF"); } catch (Exception exc) { } if (segment == null) { return; } String purchaseOrderNumber = getField(segment, 1, false, null); if (Utility.isSet(ediInp856Vw.getDistOrderNum()) && !ediInp856Vw.getDistOrderNum().equals(purchaseOrderNumber)) { ediHandler.appendIntegrationRequest(ediInp856Vw); ediInp856Vw = ediInp856Vw.copy(); ediInp856Vw.setItems(new EdiInp856ItemViewVector()); } ediInp856Vw.setDistOrderNum(purchaseOrderNumber); return; }
public void extractShipFromN4(Loop inLoop) throws OBOEException { Segment segment = null; // valid = true; try { segment = inLoop.getSegment("N4"); } catch (Exception exc) { } if (segment == null) { // The N4 ship from is optional. return; } String cityName = getField(segment, 1, false, null); ediInp856Vw.setShipFromCity(cityName); String stateProvinceCode = getField(segment, 2, false, null); ediInp856Vw.setShipFromState(stateProvinceCode); String postalCode = getField(segment, 3, false, null); ediInp856Vw.setShipFromPostalCode(postalCode); return; }
public void extractItemShipmentDetailSN1(Loop inLoop) throws OBOEException { Segment segment = null; // valid = false; try { segment = inLoop.getSegment("SN1"); } catch (Exception exc) { } if (segment == null) { errorMsgs.add("Segment SN1 missing"); setValid(false); return; } String shippedQtyS = getField(segment, 2, true, "Missing Number of Units Shipped"); if (shippedQtyS == null) { errorMsgs.add("Number of Units Shipped is null"); setValid(false); return; } int shippedQty = 0; try { shippedQty = Integer.parseInt(shippedQtyS); } catch (Exception exc) { errorMsgs.add("Invalid value of item shipped number: " + shippedQtyS); setValid(false); return; } ediInp856ItemVw.setShippedQty(shippedQty); String uom = getField(segment, 3, true, "Missing Unit (Basis) for Measurement Code"); if (uom == null) { errorMsgs.add("UOM is null"); setValid(false); return; } ediInp856ItemVw.setUom(uom); return; }
/** * 用回调的方式,遍历一个对象,可以支持遍历 * * <ul> * <li>数组 * <li>集合 * <li>Map * <li>单一元素 * </ul> * * @param obj 对象 * @param loopMap 是否循环 Map,如果循环 Map 则主要看 callback 的 T,如果是 Map.Entry 则循环 Entry 否循环 value。如果本值为 * false, 则将 Map 当作一个完整的对象来看待 * @param callback 回调 */ @SuppressWarnings({"rawtypes", "unchecked"}) public static <T> void each(Object obj, boolean loopMap, Each<T> callback) { if (null == obj || null == callback) return; try { // 循环开始 if (callback instanceof Loop) if (!((Loop) callback).begin()) return; // 进行循环 Class<T> eType = Mirror.getTypeParam(callback.getClass(), 0); if (obj.getClass().isArray()) { int len = Array.getLength(obj); for (int i = 0; i < len; i++) try { callback.invoke(i, (T) Array.get(obj, i), len); } catch (ContinueLoop e) { } catch (ExitLoop e) { break; } } else if (obj instanceof Collection) { int len = ((Collection) obj).size(); int i = 0; for (Iterator<T> it = ((Collection) obj).iterator(); it.hasNext(); ) try { callback.invoke(i++, it.next(), len); } catch (ContinueLoop e) { } catch (ExitLoop e) { break; } } else if (loopMap && obj instanceof Map) { Map map = (Map) obj; int len = map.size(); int i = 0; if (null != eType && eType != Object.class && eType.isAssignableFrom(Entry.class)) { for (Object v : map.entrySet()) try { callback.invoke(i++, (T) v, len); } catch (ContinueLoop e) { } catch (ExitLoop e) { break; } } else { for (Object v : map.entrySet()) try { callback.invoke(i++, (T) ((Entry) v).getValue(), len); } catch (ContinueLoop e) { } catch (ExitLoop e) { break; } } } else if (obj instanceof Iterator<?>) { Iterator<?> it = (Iterator<?>) obj; int i = 0; while (it.hasNext()) { try { callback.invoke(i++, (T) it.next(), -1); } catch (ContinueLoop e) { } catch (ExitLoop e) { break; } } } else try { callback.invoke(0, (T) obj, 1); } catch (ContinueLoop e) { } catch (ExitLoop e) { } // 循环结束 if (callback instanceof Loop) ((Loop) callback).end(); } catch (LoopException e) { throw Lang.wrapThrow(e.getCause()); } }
public void generate(String inputFileName) throws Exception { List<MetaClass> metaClasses = new ArrayList<>(); List<LifeLine> lifeLines = new ArrayList<>(); List<MethodInvocation> rootMessages = new ArrayList<>(); MethodInvocation parentMessage = new MethodInvocation(); GsonBuilder builder = new GsonBuilder(); List<MethodInvocation> methodInvocations = new ArrayList<>(); Package mainPackage = new Package(); List<Guard> listOfGuards = new ArrayList<>(); Map<Guard, Instruction> guardToCFMap = new HashMap<>(); List<Instruction> combinedFragments = new ArrayList<Instruction>(); List<Operation> operationsList = new ArrayList<>(); builder.registerTypeAdapter(RefObject.class, new RefObjectJsonDeSerializer()); Gson gson = builder.create(); Element myTypes = gson.fromJson(new FileReader(inputFileName), Element.class); if (myTypes._type.equals("Project")) { List<Element> umlElements = myTypes .ownedElements .stream() .filter(f -> f._type.equals("UMLModel")) .collect(Collectors.toList()); if (umlElements.size() > 0) { // There has be to atleast one UMLModel package Element element = umlElements.get(0); // package that the classes are supposed to be in mainPackage.setName(element.name); List<Element> umlPackages = element .ownedElements .stream() .filter(g -> g._type.equals("UMLPackage")) .collect(Collectors.toList()); if (umlPackages.size() > 1) { // There has to be two packages- one for class one for behaviour Element classes = umlPackages.get(0); Element behaviour = umlPackages.get(1); // *--------------------------CLASSES-------------------------------*// // in the first pass, get all classes that are defined in the diagram // get details that can be directly inferred from the json like, fields and operations, // which do not refer to other classes for (Element umlClass : classes.getOwnedElements()) { MetaClass metaClass = new MetaClass(umlClass.name, umlClass._id); // check if class is interface or not because there is no distinction in json if (umlClass._type.equals("UMLClass")) { metaClass.setInterface(false); } else { metaClass.setInterface(true); } if (umlClass.operations != null) { metaClass.setOperations(umlClass.operations); operationsList.addAll(metaClass.operations); } if (umlClass.attributes != null) { metaClass.setFields(umlClass.attributes); } metaClasses.add(metaClass); } // in second pass, define associations and generalizations for these classes for (Element umlClass : classes.getOwnedElements()) { if (umlClass.ownedElements != null) { // find corresponding metaclass, then populate the secondary inferences List<MetaClass> correspondingMetaClassList = metaClasses .stream() .filter(f -> f._id.equals(umlClass._id)) .collect(Collectors.toList()); MetaClass correspondingMetaClass = correspondingMetaClassList.get(0); List<Element> umlAssociations = umlClass .ownedElements .stream() .filter(f -> f._type.equals("UMLAssociation")) .collect(Collectors.toList()); if (umlAssociations.size() > 0) { correspondingMetaClass.setAssociations(metaClasses, umlAssociations); } List<Element> umlGeneralization = umlClass .ownedElements .stream() .filter(f -> f._type.equals("UMLGeneralization")) .collect(Collectors.toList()); if (umlGeneralization.size() > 0) { correspondingMetaClass.setGeneralizations(metaClasses, umlGeneralization); } List<Element> umlRealization = umlClass .ownedElements .stream() .filter(f -> f._type.equals("UMLInterfaceRealization")) .collect(Collectors.toList()); if (umlRealization.size() > 0) { correspondingMetaClass.setInterfaceRealization(metaClasses, umlRealization); } } } // *--------------------------CLASSES-------------------------------*// // *----------------------- BEHAVIOUR---------------------------------*// for (Element umlCollaboration : behaviour.getOwnedElements()) { // Role to Class mapping ArrayList<Element> attributes = umlCollaboration.attributes; HashMap<String, MetaClass> roleToClassMap = new HashMap<>(); if (attributes != null) { for (Element attribute : attributes) { List<MetaClass> roleClass = metaClasses .stream() .filter(f -> f._id.equals(attribute.type.$ref)) .collect(Collectors.toList()); roleToClassMap.put(attribute._id, roleClass.get(0)); } } for (Element umlInteraction : umlCollaboration.ownedElements) { // mapping lifelines to the classes they correspond ArrayList<Element> participants = umlInteraction.participants; if (participants != null && participants.size() > 0) { for (Element participant : participants) { MetaClass participantClass = roleToClassMap.get(participant.represent.$ref); LifeLine lifeLine = new LifeLine(); lifeLine.setName(participant.name); lifeLine.setId(participant._id); lifeLine.setMetaClass(participantClass); lifeLines.add(lifeLine); } } // first parse all the combined fragments and get ready if (umlInteraction.fragments != null) { for (Element fragment : umlInteraction.fragments) { // depending on the fragment set the class Instruction instruction = null; if (fragment.interactionOperator.equals("loop")) { Loop loop = new Loop(); loop.setId(fragment._id); loop.setWeight(0); Guard guard = new Guard(fragment.operands.get(0)._id); // loop can have only one condition--- one condition-- condition is made up of // AND or OR's guard.setCondition(fragment.operands.get(0).guard); loop.setGuard(guard); instruction = loop; combinedFragments.add(loop); listOfGuards.add(guard); guardToCFMap.put(guard, loop); } if (fragment.interactionOperator.equals("alt")) { Conditional c = new Conditional(); c.setId(fragment._id); c.setWeight(0); instruction = c; combinedFragments.add(c); Guard consequence = new Guard(fragment.operands.get(0)._id); consequence.setCondition(fragment.operands.get(0).guard); c.setCons(consequence); listOfGuards.add(consequence); guardToCFMap.put(consequence, c); consequence.setConsequence(true); if (fragment.operands.size() > 1) { Guard alternate = new Guard(fragment.operands.get(1)._id); alternate.setCondition(fragment.operands.get(1).guard); c.setAlt(alternate); listOfGuards.add(alternate); guardToCFMap.put(alternate, c); alternate.setAlternative(true); } } if (fragment.tags != null) { for (Element tag : fragment.tags) { if (tag.name.equals("parent")) { List<Instruction> instructionList = combinedFragments .stream() .filter(e -> e.getId().equals(tag.reference.$ref)) .collect(Collectors.toList()); if (instructionList.size() > 0) { instructionList.get(0).getBlock().add(instruction); instruction.setParent(instructionList.get(0)); } } } } } } // parsing the messages and make nodes out them to later build a tree from the // lifelines ArrayList<Element> messages = umlInteraction.messages; Element startMessage = messages.get(0); String sourceRef = startMessage.source.$ref; String targetRef = startMessage.target.$ref; Element endMessage = null; LifeLine sourceLifeLine = getLifeLine(lifeLines, sourceRef); LifeLine targetLifeLine = getLifeLine(lifeLines, targetRef); // First message processing parentMessage = new MethodInvocation(); parentMessage.setAssignmentTarget(startMessage.assignmentTarget); parentMessage.setMessageSort(startMessage.messageSort); parentMessage.setSource(sourceLifeLine.getMetaClass()); parentMessage.setTarget(targetLifeLine.getMetaClass()); parentMessage.setName(startMessage.name); parentMessage.setId(startMessage._id); if (sourceLifeLine.getId().equals(targetLifeLine.getId())) { parentMessage.setCallerObject("this"); } else { parentMessage.setCallerObject(targetLifeLine.getName()); } int weight = 0; parentMessage.setWeight(weight++); if (startMessage.signature != null) { parentMessage.setSignature(startMessage.signature.$ref); } if (startMessage.tags != null) { for (Element tag : startMessage.tags) { // if (tag.name.equals("CF")) { // parentMessage.setInCF(true); // // parentMessage.setCfID(tag.reference.$ref); // } if (tag.name.equals("operand")) { parentMessage.setOperandId(tag.reference.$ref); } } } MethodInvocation rootMessage = parentMessage; methodInvocations.add(rootMessage); rootMessages.add(rootMessage); Iterator<Element> iter = messages.iterator(); while (iter.hasNext()) { if (iter.next() == endMessage) { continue; } iter.remove(); List<Element> childMessages = getChildMessages(messages, targetRef); for (Element child : childMessages) { LifeLine childSource = getLifeLine(lifeLines, child.source.$ref); LifeLine childTarget = getLifeLine(lifeLines, child.target.$ref); MethodInvocation childMessage = new MethodInvocation(); childMessage.setMessageSort(child.messageSort); childMessage.setSource(childSource.getMetaClass()); childMessage.setTarget(childTarget.getMetaClass()); childMessage.setAssignmentTarget(child.assignmentTarget); childMessage.setName(child.name); childMessage.setId(child._id); childMessage.setWeight(weight++); childMessage.setArguments(child.arguments); if (childSource.getId().equals(childTarget.getId())) { childMessage.setCallerObject("this"); } else { childMessage.setCallerObject(childTarget.getName()); } if (child.signature != null) { childMessage.setSignature(child.signature.$ref); } if (child.tags != null) { for (Element tag : child.tags) { // if (tag.name.equals("CF")) { // childMessage.setInCF(true); // // childMessage.setCfID(tag.reference.$ref); // } if (tag.name.equals("operand")) { childMessage.setOperandId(tag.reference.$ref); } } } parentMessage.childNodes.add(childMessage); methodInvocations.add(childMessage); } if (childMessages.size() > 0) { List<MethodInvocation> nextMessage = parentMessage .childNodes .stream() .filter(f -> !f.source.equals(f.target)) .collect(Collectors.toList()); List<Element> startMessageNext = childMessages .stream() .filter(f -> !f.source.$ref.equals(f.target.$ref)) .collect(Collectors.toList()); startMessage = startMessageNext.get(0); targetRef = startMessage.target.$ref; sourceRef = startMessage.source.$ref; parentMessage = nextMessage.get(0); if (childMessages.size() > 1) { endMessage = childMessages.get(childMessages.size() - 1); } } } } for (MethodInvocation methodInvocation : methodInvocations) { List<Operation> matchingOperation = operationsList .stream() .filter(f -> f._id.equals(methodInvocation.getSignature())) .collect(Collectors.toList()); if (matchingOperation.size() > 0) { operationMap.put(methodInvocation, matchingOperation.get(0)._id); methodInvocation.setOperation(matchingOperation.get(0)); } } Stack stack = new Stack(); for (MethodInvocation root : methodInvocations) { stack.push(root); while (!stack.empty()) { MethodInvocation methodInvocation = (MethodInvocation) stack.pop(); Operation currentOperation = methodInvocation.getOperation(); if (currentOperation != null) { // all child nodes of this node make up its body List<MethodInvocation> childNodes = methodInvocation.childNodes; for (MethodInvocation child : childNodes) { stack.push(child); } for (MethodInvocation childNode : childNodes) { if (childNode.getOperandId() != null) { List<Instruction> combinedFragmentsList = combinedFragments .stream() .filter(f -> f.getId().equals(childNode.getCfID())) .collect(Collectors.toList()); List<Guard> guardList = listOfGuards .stream() .filter(f -> f.id.equals(childNode.getOperandId())) .collect(Collectors.toList()); if (guardList.size() > 0) { Guard currentGuard = guardList.get(0); Instruction instruction = guardToCFMap.get(guardList.get(0)); // get the topmost CF if it is in a tree Instruction parent = instruction.getParent(); while (instruction.getParent() != null) { instruction = instruction.getParent(); } if (currentGuard.isConsequence) { Conditional conditional = (Conditional) instruction; if (!conditional.getConsequence().contains(childNode)) { conditional.getConsequence().add(childNode); } } if (currentGuard.isAlternative) { Conditional conditional = (Conditional) instruction; if (!conditional.getAlternative().contains(childNode)) { conditional.getAlternative().add(childNode); } } if (!currentGuard.isAlternative && !currentGuard.isConsequence) { Loop loop = (Loop) instruction; loop.getBlock().add(childNode); } else { if (!currentOperation.getBlock().contains(instruction)) { currentOperation.getBlock().add(instruction); } } } } else { if (!currentOperation.getBlock().contains(childNode)) { currentOperation.getBlock().add(childNode); } } } } } } } } } } // //// printAllData(metaClasses); // while (parentMessage.childNodes != null || parentMessage.childNodes.size() > 0) { // System.out.println("parent " + parentMessage.name); // for (com.cbpro.main.MethodInvocation child : parentMessage.childNodes) { // System.out.println("child " + child.name); // } // if (parentMessage.childNodes.size() > 0) { // parentMessage = parentMessage.childNodes.get(0); // } else { // break; // } // } mainPackage.print(); File dir = new File("/home/ramyashenoy/Desktop/DemoFolder/" + mainPackage.getName()); boolean successful = dir.mkdir(); if (successful) { System.out.println("directory was created successfully"); for (MetaClass metaClass : metaClasses) { if (metaClass.name.equals("Main")) { continue; } else { String data = metaClass.print(); BufferedWriter out = null; try { FileWriter fstream = new FileWriter( dir.getPath() + "/" + metaClass.name + ".java", true); // true tells to append data. out = new BufferedWriter(fstream); out.write(data); } catch (IOException e) { System.err.println("Error: " + e.getMessage()); } finally { if (out != null) { out.close(); } } } } } else { // creating the directory failed System.out.println("failed trying to create the directory"); } mainPackage.setClasses(metaClasses); }
/** Extract all segments included in ST - SE Segment */ public void extract() throws OBOEException { ediInp856Vw = EdiInp856View.createValue(); ediInp856Vw.setItems(new EdiInp856ItemViewVector()); Table table = ts.getHeaderTable(); if (table != null) { extractHeaderBSN(table); } table = ts.getDetailTable(); if (table != null) { int HLLoopSize = table.getLoopCount("HL"); for (int i = 0; i < HLLoopSize; i++) { Loop loop = table.getLoop("HL", i); Segment segment = loop.getSegment("HL"); String levelCode = getField(segment, 3, true, "Missing Hierarchical Level Code in segment HL*" + i); if (levelCode == null) { errorMsgs.add("Level Code is null"); setValid(false); continue; } if (i == 0) { if (!"S".equals(levelCode)) { errorMsgs.add("Invalid Hierarchical Level Code in segment HL*0 : " + levelCode); setValid(false); continue; } extractShipmentLevelREF(loop); extractShipmentDTM(loop); extractShipmentTD5(loop); extractShipByN1(loop); } else if (i == 1) { if (!"O".equals(levelCode)) { errorMsgs.add("Invalid Hierarchical Level Code in segment HL*1 : " + levelCode); setValid(false); continue; } extractPurchaseOrderReferencePRF(loop); extractReferenceIdentificationREF(loop); } else { if ("O".equals(levelCode)) { extractPurchaseOrderReferencePRF(loop); extractReferenceIdentificationREF(loop); } else if (!"I".equals(levelCode)) { errorMsgs.add( "Invalid value of Hierarchical Level Code in segment HL *" + i + " : " + levelCode); setValid(false); continue; } else { ediInp856ItemVw = EdiInp856ItemView.createValue(); ediInp856Vw.getItems().add(ediInp856ItemVw); extractItemIdentificationLIN(loop); extractItemShipmentDetailSN1(loop); extractItemIdentificationREF(loop); } } } } table = ts.getSummaryTable(); if (table != null) { // extractHeaderTDS(table); // extractHeaderSAC(table); } }
public void find(Loop loop) { List<StringArrayRef> refs = loop.getArrayRefs(); for (StringArrayRef ref : refs) { searchRef(ref, loop); } }
public void extractItemIdentificationLIN(Loop inLoop) throws OBOEException { Segment segment = null; boolean ignoreMissingLineInfo = Utility.isTrue( getTranslator() .getConfigurationProperty( RefCodeNames.ENTITY_PROPERTY_TYPE.IGNORE_MISSING_LINE_INFO)); // valid = false; try { segment = inLoop.getSegment("LIN"); } catch (Exception exc) { exc.printStackTrace(); } if (segment == null && !ignoreMissingLineInfo) { errorMsgs.add("Segment LIN missing"); setValid(false); return; } String orderLineNumS = getField(segment, 1, true, "Missing order line number in LIN segment"); if (orderLineNumS == null && !ignoreMissingLineInfo) { errorMsgs.add("Order Line Number in LIN segment is null"); setValid(false); return; } int orderLineNum = 0; try { orderLineNum = Integer.parseInt(orderLineNumS); } catch (Exception exc) { // JD China will use line num 3.1 for line 3 if order is split for shipment. int ix = orderLineNumS.indexOf('.'); if (ix > 0) { String orderLineNumSs = orderLineNumS.substring(0, ix); try { orderLineNum = Integer.parseInt(orderLineNumSs); } catch (Exception ex) { } } if (orderLineNum == 0 && !ignoreMissingLineInfo) { errorMsgs.add("Invalid value of order line number in LIN segment: " + orderLineNumS); setValid(false); return; } } ediInp856ItemVw.setPurchOrderLineNum(orderLineNum); for (int fieldNum = 1; fieldNum <= 7; fieldNum += 2) { try { String productNumQualifier = getField(segment, 1 + fieldNum, false, ""); if (productNumQualifier == null) { // errorMsgs.add("Product Service Id Qualifier is null"); // setValid(false); // return; break; } String productNum = getField(segment, 1 + fieldNum + 1, false, ""); if ("VP".equals(productNumQualifier) || "VN".equals(productNumQualifier)) { ediInp856ItemVw.setDistSkuNum(productNum); } } catch (Exception exc) { break; } } return; }