Object subclass: #Polygon instanceVariableNames: 'apex name originX originY left top right bottom' classVariableNames: '' poolDictionaries: '' category: 'ProgrammingLanguages'! !Polygon methodsFor: 'initialize-release'! initialize: numberApex name: newName oX: x oY: y name:=newName. apex:=Array new: numberApex. originX:= x. originY:= y. apex at: 1 put: originX@originY ! ! !Polygon methodsFor: 'accessing'! name ^name! name: new_name name:=new_name! left ^left! right ^right! top ^top! bottom ^bottom! ! Polygon subclass: #Hexagon instanceVariableNames: 'sideLength' classVariableNames: '' poolDictionaries: '' category: 'ProgrammingLanguages'! !Hexagon methodsFor: 'initialize-release'! initialize: side oX: x oY: y super initialize: 6 name: 'Hexagon' oX: x oY: y. sideLength:= side. apex at: 2 put: (x + ((side squared * (3 sqrt))/2))@(y + (0.5 * side)). apex at: 3 put: (x + ((side squared * (3 sqrt))/2))@(y + (1.5 * side)). apex at: 4 put: x@(y + (2* side)). apex at: 5 put: (x - ((side squared * (3 sqrt))/2))@(y + (1.5 * side)). apex at: 6 put: (x - ((side squared * (3 sqrt))/2))@(y + (0.5 * side)). left:= (x - ((side squared * (3 sqrt))/2)). top:= y. bottom:= (y + (2* side)). right:= (x + ((side squared * (3 sqrt))/2)). ! ! !Hexagon methodsFor: 'arithmetic'! + figure | p newSide | p:=self area + figure area. newSide:= (2 * p /((3 * 3 sqrt) sqrt)). ^(Hexagon new) initialize: newSide oX: originX oY: originY! ! !Hexagon methodsFor: 'actions'! getPoints Transcript cr. Transcript show: ('Dlugosc boku '). Transcript show: sideLength printString; cr. Transcript show: ('Pierwszy wierzcholek '). Transcript show: (apex at: 1) printString; cr. Transcript show: ('Drugi wierzcholek '). Transcript show: (apex at: 2) printString; cr. Transcript show: ('Trzeci wierzcholek '). Transcript show: (apex at: 3) printString; cr. Transcript show: ('Czwarty wierzcholek '). Transcript show: (apex at: 4) printString; cr. Transcript show: ('Piaty wierzcholek '). Transcript show: (apex at: 5) printString; cr. Transcript show: ('Szosty wierzcholek '). Transcript show: (apex at: 6) printString; cr. Transcript show: ('Pole pieciokata '). Transcript show: (self area) printString; cr. ! area ^((3 * sideLength squared * 3 sqrt)/2)! move: aa i: bb self initialize: sideLength oX: (originX + aa) oY: (originY + bb)! ! setOfHexagons := Set new. r1:= (Hexagon new) initialize: 6 oX: 5 oY: 5. setOfHexagons add: r1. r2:= (Hexagon new) initialize: 5 oX: 5 oY: 5. setOfHexagons add: r2. r3:= (Hexagon new) initialize: 4 oX: 5 oY: 5. setOfHexagons add: r3. r4:= (Hexagon new) initialize: 2 oX: 5 oY: 5. setOfHexagons add: r4. r5:= (Hexagon new) initialize: 1 oX: 5 oY: 5. setOfHexagons add: r5. r6:= (Hexagon new) initialize: 1 oX: 5 oY: 5. r6 move: 1 i: 1. setOfHexagons add: r6. r7:= (Hexagon new). r7:= r1 + r2. setOfHexagons do: [:x| x getPoints ].
public with sharing class MaintenanceRequestHelper { public static void updateWorkOrders(List<Case> updWorkOrders, Map<Id, Case> nonUpdCaseMap) { Set<Id> validIds = new Set<Id>(); for (Case c : updWorkOrders) { if (nonUpdCaseMap.get(c.Id).Status != 'Closed' && c.Status == 'Closed') { if (c.Type == 'Repair' || c.Type == 'Routine Maintenance') { validIds.add(c.Id); } } } if (!validIds.isEmpty()) { List<Case> newCases = new List<Case>(); Map<Id, Case> closedCasesM = new Map<Id, Case>( [SELECT Id, Vehicle__c, Equipment__c, Equipment__r.Maintenance_Cycle__c, (SELECT Id, Equipment__c, Quantity__c FROM Equipment_Maintenance_Items__r) FROM Case WHERE Id IN :validIds] ); Map<Id, Decimal> maintenanceCycles = new Map<Id, Decimal>(); AggregateResult[] results = [ SELECT Maintenance_Request__c, MIN(Equipment__r.Maintenance_Cycle__c) cycle FROM Equipment_Maintenance_Item__c WHERE Maintenance_Request__c IN :validIds GROUP BY Maintenance_Request__c ]; for (AggregateResult ar : results) { if (ar.get('cycle') != null) { maintenanceCycles.put( (Id) ar.get('Maintenance_Request__c'), (Decimal) ar.get('cycle') ); } } for (Case cc : closedCasesM.values()) { Case nc = new Case( ParentId = cc.Id, Status = 'New', Subject = 'Routine Maintenance', Type = 'Routine Maintenance', Vehicle__c = cc.Vehicle__c, Equipment__c = cc.Equipment__c, Origin = 'Web', Date_Reported__c = Date.today() ); if (maintenanceCycles.containsKey(cc.Id)) { nc.Date_Due__c = Date.today().addDays((Integer) maintenanceCycles.get(cc.Id)); } else if (cc.Equipment__r.Maintenance_Cycle__c != null) { nc.Date_Due__c = Date.today().addDays((Integer) cc.Equipment__r.Maintenance_Cycle__c); } newCases.add(nc); } if (!newCases.isEmpty()) { insert newCases; } List<Equipment_Maintenance_Item__c> clonedWPs = new List<Equipment_Maintenance_Item__c>(); for (Case nc : newCases) { if (closedCasesM.get(nc.ParentId).Equipment_Maintenance_Items__r != null) { for (Equipment_Maintenance_Item__c wp : closedCasesM.get(nc.ParentId).Equipment_Maintenance_Items__r) { Equipment_Maintenance_Item__c wpClone = wp.clone(false, true, false, false); wpClone.Maintenance_Request__c = nc.Id; clonedWPs.add(wpClone); } } } if (!clonedWPs.isEmpty()) { insert clonedWPs; } } } }
Dlugosc boku 5 Pierwszy wierzcholek 5@5 Drugi wierzcholek Object: 1 error: The program attempted to divide a number by zero ZeroDivide(Exception)>>signal (ExcHandling.st:254) SmallInteger(Number)>>zeroDivide (SysExcept.st:1426) Fraction>>setNumerator:setDenominator: (Fraction.st:485) Fraction class>>numerator:denominator: (Fraction.st:66) Fraction>>- (Fraction.st:151) FloatD(Float)>>printOn:special: (Float.st:533) FloatD(Float)>>printOn: (Float.st:436) WriteStream(Stream)>>print: (Stream.st:501) Point>>printOn: (Point.st:63) Point(Object)>>printString (Object.st:534) Hexagon>>getPoints (prog:83) optimized [] in UndefinedObject>>executeStatements (prog:123) Set(HashedCollection)>>do: (HashedColl.st:201) UndefinedObject>>executeStatements (prog:122)