/** * Process stimulus method that computes appropriate level of detail. * * @param criteria an enumeration of the criteria that caused the stimulus */ @Override public void processStimulus(Enumeration criteria) { // compute distance in virtual world View v = this.getView(); if (v == null) { wakeupOn(wakeupFrame); return; } ViewPlatform vp = v.getViewPlatform(); if (vp == null) { return; } // Handle stimulus double viewDistance = 0.0; int nSwitches, i, index = 0; Transform3D localToWorldTrans = new Transform3D(); localToWorldTrans.set(((NodeRetained) this.retained).getCurrentLocalToVworld()); // DistanceLOD's location in virutal world localToWorldTrans.transform(position, center); viewPosition.x = (float) ((ViewPlatformRetained) vp.retained).schedSphere.center.x; viewPosition.y = (float) ((ViewPlatformRetained) vp.retained).schedSphere.center.y; viewPosition.z = (float) ((ViewPlatformRetained) vp.retained).schedSphere.center.z; viewDistance = center.distance(viewPosition); // convert distance into local coordinates viewDistance = viewDistance / localToWorldTrans.getDistanceScale(); nSwitches = numSwitches(); index = distances.length; // viewDistance > distances[n-1] if (viewDistance <= distances[0]) { index = 0; } else { for (i = 1; i < distances.length; i++) { if ((viewDistance > distances[i - 1]) && (viewDistance <= distances[i])) { index = i; break; } } } for (i = nSwitches - 1; i >= 0; i--) { Switch sw = getSwitch(i); // Optimize, this behavior is passive // Note that we skip the capability check for getWhichChild() if (((SwitchRetained) sw.retained).getWhichChild() != index) { sw.setWhichChild(index); } } // Insert wakeup condition into queue wakeupOn(wakeupFrame); }
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override protected void onBindView(View view) { super.onBindView(view); View checkableView = view.findViewById(R.id.switchWidget); if (checkableView != null && checkableView instanceof Checkable) { ((Checkable) checkableView).setChecked(mChecked); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { if (checkableView instanceof Switch) { final Switch switchView = (Switch) checkableView; switchView.setTextOn(mSwitchOn); switchView.setTextOff(mSwitchOff); switchView.setOnCheckedChangeListener(mListener); } } else { if (checkableView instanceof android.widget.Switch) { final android.widget.Switch switchView = (android.widget.Switch) checkableView; switchView.setTextOn(mSwitchOn); switchView.setTextOff(mSwitchOff); switchView.setOnCheckedChangeListener(mListener); } } } syncSummaryView(view); }
public static void main(String[] args) { System.out.println("Test 2"); Network net3 = new Network(); net3.addConnection(1, 2); net3.addConnection(3, 1); net3.addConnection(2, 4); System.out.println(net3.addConnection(4, 3)); System.out.println(net3.addConnection(3, 3)); System.out.println(net3.addConnection(3, 3)); net3.addConnection(100, 4); net3.addConnection(3, 100); net3.addConnection(2, 5); net3.addConnection(5, 6); net3.addConnection(6, 7); net3.findTree(); Collection switches3 = net3.getSwitches(); Iterator iter3 = switches3.iterator(); while (iter3.hasNext()) { Switch y = (Switch) iter3.next(); System.out.println("Switch: Root, Parent, Hops to Root"); String output = " " + y.getMAC() + ": "; output = output + y.getRoot().getMAC() + " "; output = output + y.getParent().getMAC() + " "; output = output + y.getDistance(); System.out.println(output); } }
/** * Il design pattern Command incapsula una richiesta come un oggetto. Con ciò il client ha la * possibilità di effettuare diverse richieste, come log requests e queue. Promuove l'invocazione * di un metodo su un oggetto ed è object-oriented. E' utilizzato principalmente quando bisogna * fare richieste ad oggetti senza sapere nulla dell'operazione richiesta o del receiver della * richiesta. Tale pattern disaccoppia l'oggetto che invoca l'operazione dall'oggetto che conosce * come eseguirla. Per ottenere questa separazione il designer crea una classe astratta che mappa * un receiver (un oggetto) con un'azione (un puntatore a una funzione membro). La classe base * contiene un metodo execute() che semplicemente chiama l'azione sul receiver. Tutti i client * dell'oggetto Command trattano ogni oggetto come una "black box", eseguendo semplicemente * un'inovazione sul metodo execute sull'ogggetto ogni volta che il client richiede il "servizio" * dell'oggetto. La classe command gestisce il seguente insieme: - un oggetto - un metodo che può * essere applicato all'oggetto - gli argomenti necessari quando bisogna chiamare il metodo Il * metodo "execute" del command poi fa lavorare insieme questi pezzi * * <p>( + ) I design non solo accelerano la fase di design di un progetto object-oriented ma * incrementano la produttività del team di sviluppo e la qualità del software. Un Command pattern * è un design pattern comportamentale che ci abilita a ottenere un completo disaccoppiamento tra * il sender e il receiver. Un sender è un oggetto che invoca una operazione e un receiver è un * oggetto che riceve la richiesta a eseguire una certa operazione. Con il disaccoppiamento il * sender non ha conoscenza dell'interfaccia del Receiver, il termine request riferisce al command * che è eseguito. Tale pattern ci consente di cambiare quando e come la richiesta è compiuta, * otteniamo flessibilità e estendibilità. */ public static void main(String... args) { Light testLight = new Light(); LightOnCommand testLOC = new LightOnCommand(testLight); LightOffCommand testLFC = new LightOffCommand(testLight); Switch testSwitch = new Switch(testLOC, testLFC); testSwitch.flipUp(); testSwitch.flipDown(); }
public void validate() { if (argumentConsumption.getType() != ArgumentConsumptionType.LOOSE_ARGS) { if (_switch == null || (_switch.getShortSwitch() == null && _switch.getLongSwitch() == null)) { throw createInvalidOptionSpecificationException("Option specified without switchess"); } } validateType(); }
public List<Control> getControls(Appliance appliance, RunningTimeMonitor runningTimeMonitor) { List<Control> controls = new ArrayList<Control>(); if (appliance.getSwitches() != null) { for (Switch zwitch : appliance.getSwitches()) { zwitch.setRunningTimeMonitor(runningTimeMonitor); controls.add(zwitch); } } return controls; }
public static void main(String[] args) { try { sw.on(); // Code that can throw exceptions... OnOffSwitch.f(); } catch (OnOffException1 e) { System.out.println("OnOffException1"); } catch (OnOffException2 e) { System.out.println("OnOffException2"); } finally { sw.off(); } }
public static void main(String[] args) { try { sw.on(); // Code that can throw exceptions... sw.off(); } catch (NullPointerException e) { System.out.println("NullPointerException"); sw.off(); } catch (IllegalArgumentException e) { System.out.println("IOException"); sw.off(); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // the alarm is the thing that triggers monitor execution createMonitorAlarm(); // bind to monitoring service monitoringServiceConnector = new MonitoringServiceConnector(this); monitoringServiceConnector.bind( new MonitoringServiceConnector.RunPostBind() { @Override public void onPostBind(MonitoringService monitoringService) { onCreateAfterServiceBind(monitoringService); } }); // create inflater and UI handler mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); uiHandler = new Handler(); Button clearButton = (Button) findViewById(R.id.clearButton); clearButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { monitoringService.clearData(); } }); clearButton.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { monitoringService.toggleTestMode(); return true; } }); Switch killSwitch = (Switch) findViewById(R.id.monitorsEnabled); killSwitch.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { monitoringService.setMonitorsEnabled(isChecked); } }); }
/** * This methods receives and processes input made by the user. More specifically, it ckecks * whether the user has interacted with the current b:switchWidget. The default implementation * simply stores the input value in the list of submitted values. If the validation checks are * passed, the values in the <code>submittedValues</code> list are store in the backend bean. * * @param context the FacesContext. * @param component the current b:switchWidget. */ @Override public void decode(FacesContext context, UIComponent component) { Switch switchWidget = (Switch) component; if (switchWidget.isDisabled() || switchWidget.isReadonly()) { return; } decodeBehaviors(context, switchWidget); String clientId = switchWidget.getClientId(context); String submittedValue = (String) context.getExternalContext().getRequestParameterMap().get(clientId); if (submittedValue != null) { switchWidget.setSubmittedValue(submittedValue); } }
public static void init() { Add.init(); Address.init(); Align.init(); Alloc.init(); Anchor.init(); And.init(); Bad.init(); Bitcast.init(); Block.init(); Builtin.init(); Call.init(); Cmp.init(); Cond.init(); Confirm.init(); Const.init(); Conv.init(); CopyB.init(); Deleted.init(); Div.init(); Dummy.init(); End.init(); Eor.init(); Free.init(); IJmp.init(); Id.init(); Jmp.init(); Load.init(); Member.init(); Minus.init(); Mod.init(); Mul.init(); Mulh.init(); Mux.init(); NoMem.init(); Not.init(); Offset.init(); Or.init(); Phi.init(); Pin.init(); Proj.init(); Raise.init(); Return.init(); Sel.init(); Shl.init(); Shr.init(); Shrs.init(); Size.init(); Start.init(); Store.init(); Sub.init(); Switch.init(); Sync.init(); Tuple.init(); Unknown.init(); }
public static void main(String[] args) { Light lamp = new Light(); Command switchUp = new FlipUpCommand(lamp); Command switchDown = new FlipDownCommand(lamp); Switch s = new Switch(); try { if (args[0].equalsIgnoreCase("ON")) { s.storeAndExecute(switchUp); System.exit(0); } if (args[0].equalsIgnoreCase("OFF")) { s.storeAndExecute(switchDown); System.exit(0); } System.out.println("Argument \"ON\" or \"OFF\" is required."); } catch (Exception e) { System.out.println("Argument's required."); } }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final PhaseAssignment other = (PhaseAssignment) obj; if (!Arrays.equals(assignment, other.assignment)) { return false; } if (combiCSwitch == null) { if (other.combiCSwitch != null) { return false; } } else if (!combiCSwitch.equals(other.combiCSwitch)) { return false; } if (combiDSwitch == null) { if (other.combiDSwitch != null) { return false; } } else if (!combiDSwitch.equals(other.combiDSwitch)) { return false; } if (combiESwitch == null) { if (other.combiESwitch != null) { return false; } } else if (!combiESwitch.equals(other.combiESwitch)) { return false; } if (combiFSwitch == null) { if (other.combiFSwitch != null) { return false; } } else if (!combiFSwitch.equals(other.combiFSwitch)) { return false; } if (priorityASwitch == null) { if (other.priorityASwitch != null) { return false; } } else if (!priorityASwitch.equals(other.priorityASwitch)) { return false; } if (priorityBSwitch == null) { if (other.priorityBSwitch != null) { return false; } } else if (!priorityBSwitch.equals(other.priorityBSwitch)) { return false; } return true; }
public static void main(String[] args) { if (args.length != 1) { System.err.println("Argument \"On\" or \"Off\" is required."); System.exit(-1); } Light lamp = new Light(); Command switchUp = new FlipUpCommand(lamp); Command switchDown = new FlipDownCommand(lamp); Switch mySwitch = new Switch(); switch (args[0]) { case "On": mySwitch.storeAndExecute(switchUp); case "Off": mySwitch.storeAndExecute(switchDown); default: System.err.println("Argument \"On\" or \"Off\" is required."); System.exit(-1); } }
@Override public void onCreate(Bundle savedInstanceState) { // Open app in fullscreen mode super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); noteLayout = (RelativeLayout) findViewById(R.id.notePanel); canvasView = new CanvasView(this); switchy = new Switch(this); switchy = (Switch) findViewById(R.id.switch1); switchy.setOnCheckedChangeListener(this); inkRegion = new ArrayList<InkRegion>(); inkRegion.add(new InkRegion(this, 0)); inkRegion.add(new InkRegion(this, 1)); inkRegion.get(0).setBackgroundColor(Color.YELLOW); inkRegion.get(1).setBackgroundColor(Color.CYAN); // noteLayout.addView(canvasView); noteLayout.addView(canvasView); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(200, 200); params.leftMargin = 300; params.topMargin = 200; inkRegion.get(0).setBackgroundColor(Color.GREEN); inkRegion.get(0).setPivotX(0); inkRegion.get(0).setPivotY(0); inkRegion.get(0).setRotation(45); inkRegion.get(0).setScaleX((float) 0.2); inkRegion.get(0).setScaleY((float) 0.3); noteLayout.addView(inkRegion.get(0), params); RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(200, 200); params1.leftMargin = 300; params1.topMargin = 200; inkRegion.get(1).setBackgroundColor(Color.BLUE); inkRegion.get(1).setPivotX(0); inkRegion.get(1).setPivotY(0); inkRegion.get(1).setRotation(90); inkRegion.get(1).setScaleX((float) 0.2); inkRegion.get(1).setScaleY((float) 0.2); noteLayout.addView(inkRegion.get(1), params1); }
/** * Konstruktor * * @param id * @param status * @param location * @param description * @param actorIdTab * @param actorStatusTab * @param gid * @throws SocketException */ public AckSensor( int id, T status, String location, String description, int[] actorIdTab, T[] actorStatusTab, int gid) throws SocketException { super(id, status, location, description); this.actorIdTab = actorIdTab; this.actorStatusTab = actorStatusTab; this.actorAckTab = new boolean[actorIdTab.length]; this.gid = gid; if (actorStatusTab instanceof Boolean[]) { Switch.setNullToFalse((Boolean[]) actorStatusTab); } }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + Arrays.hashCode(assignment); result = prime * result + (combiCSwitch == null ? 0 : combiCSwitch.hashCode()); result = prime * result + (combiDSwitch == null ? 0 : combiDSwitch.hashCode()); result = prime * result + (combiESwitch == null ? 0 : combiESwitch.hashCode()); result = prime * result + (combiFSwitch == null ? 0 : combiFSwitch.hashCode()); result = prime * result + (priorityASwitch == null ? 0 : priorityASwitch.hashCode()); result = prime * result + (priorityBSwitch == null ? 0 : priorityBSwitch.hashCode()); return result; }
public void run() { InstField instField = new InstField(); instField.run(); StaticField.run(); IntMath.run(); FloatMath.run(); Compare.run(); Monitor.run(); Switch.run(); Array.run(); Classes.run(); Goto.run(); MethodCall.run(); Throw.run(); try { UnresTest1.run(); } catch (VerifyError ve) { System.out.println("Caught: " + ve); } try { UnresTest1.run(); } catch (VerifyError ve) { System.out.println("Caught (retry): " + ve); } try { UnresTest2.run(); } catch (VerifyError ve) { System.out.println("Caught: " + ve); } catch (Throwable th) { // We and the RI throw ClassNotFoundException, but that isn't declared so javac // won't let us try to catch it. th.printStackTrace(); } InternedString.run(); }
public void dispatch(Switch sw) { super.dispatch(sw); sw.onColumn(this); }
public static void main(String[] args) throws Exception { final Shell shell = new Shell(); final Display display = shell.getDisplay(); shell.setLayout(new GridLayout(1, false)); final Switch control = new Switch(shell); control.setLayoutData(GridDataFactory.swtDefaults().create()); control.setActiveText("Shown"); control.setActiveBackground(new Color(display, 135, 209, 243)); control.setInactiveBackground(new Color(display, 198, 198, 198)); control.setInactiveText("Hidden"); control.setFont(new Font(display, "Arial", 10, SWT.BOLD)); control.setEnabled(true); control.setSelection(true); final Switch control1 = new Switch(shell); control1.setLayoutData(GridDataFactory.swtDefaults().create()); control1.setActiveText("Shown"); control1.setActiveBackground(new Color(display, 135, 209, 243)); control1.setInactiveBackground(new Color(display, 198, 198, 198)); control1.setInactiveText("Hidden"); control1.setFont(new Font(display, "Arial", 10, SWT.BOLD)); control1.setEnabled(false); control1.setSelection(true); final Switch control2 = new Switch(shell); control2.setLayoutData(GridDataFactory.swtDefaults().create()); control2.setActiveText("Shown"); control2.setActiveBackground(new Color(display, 135, 209, 243)); control2.setInactiveBackground(new Color(display, 198, 198, 198)); control2.setInactiveText("Hidden"); control2.setFont(new Font(display, "Arial", 10, SWT.BOLD)); control2.setEnabled(false); control2.setSelection(false); final RoundedComposite c3 = new RoundedComposite(shell, SWT.LEFT); c3.setBackground(new Color(display, 135, 209, 243)); c3.setLayoutData( GridDataFactory // .swtDefaults() // .hint(SWT.DEFAULT, SWT.DEFAULT) // .create()); final Label label = new Label(c3, SWT.NONE); label.setText("Hi"); label.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); label.setFont(new Font(display, "Arial", 11, SWT.BOLD)); c3.setClient(label); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
/* [Internal, Wayside] Toggles switch and all its connections if attached to a switch block. */ public void toggleSwitch() { if (switcher != null) switcher.toggleSwitch(); }
public void dispatch(Switch sw) { super.dispatch(sw); sw.onAggressiveLoad(this); }
@Override public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_upload_matrix); super.onCreate(savedInstanceState); activity = this; mtxDAO = new LedMatrixDAO(this); final Intent intent = getIntent(); currMatrix = intent.getParcelableExtra(EXTRAS_LED_MATRIX); if (currMatrix == null) { currMatrix = mtxDAO.getDummyLedMatrix(); } GridLayout grid = (GridLayout) findViewById(R.id.gridLayout); String ledColorsStr = currMatrix.getMatrix(); if (ledColorsStr == null) { ledColorsStr = LedMatrixDAO.MTX_BLANK; } assert (ledColorsStr.length() == MATRIX_NN); DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int btnWidth = (displaymetrics.widthPixels - 50) / MATRIX_N - 4; Log.v(TAG, "btnWidth = " + btnWidth); char _c; int _ci; LedButton btn; for (int i = 0; i < MATRIX_NN; i++) { _c = ledColorsStr.charAt(i); _ci = Integer.valueOf("" + _c); ledColors.add(_ci); btn = new LedButton(this); btn.setColorIndex(_ci); ledButtons.add(btn); btn.setMinimumWidth(btnWidth); btn.setMinimumHeight(btnWidth); btn.setMaxWidth(btnWidth); btn.setMaxHeight(btnWidth); btn.setOnClickListener(onLedBtnClickListener); btn.setOnLongClickListener(onLedBtnLongClickListener); grid.addView(btn); } // Sets up UI references. mConnectionState = (TextView) findViewById(R.id.connection_state); // is serial present? isSerial = (TextView) findViewById(R.id.isSerial); switchDraw = (Switch) findViewById(R.id.switchDraw); switchDraw.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { updateMatrixInfo(currMatrix); if (isChecked) { drawMode = true; sendMessage("B:" + currMatrix.getMatrix() + "\n"); } else { drawMode = false; } } }); returnText = (TextView) findViewById(R.id.textReturn); buttonSave = (Button) findViewById(R.id.saveButton); buttonDelete = (Button) findViewById(R.id.deleteButton); buttonSend = (Button) findViewById(R.id.sendButton); buttonSave.setOnClickListener(onClickListener); buttonDelete.setOnClickListener(onClickListener); buttonSend.setOnClickListener(onClickListener); infoButton = (ImageView) findViewById(R.id.infoImage); infoButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { iascDialog(); } }); getActionBar().setTitle(getString(R.string.title_image) + ":" + currMatrix.getName()); getActionBar().setDisplayHomeAsUpEnabled(true); Intent gattServiceIntent = new Intent(this, BluetoothLeService.class); bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE); toastMessage(getString(R.string.opt_info)); }
public void dispatch(Switch sw) { sw.onAlias(this); }
public void dispatch(Switch sw) { super.dispatch(sw); sw.onReferenceKey(this); }
public void dispatch(Switch sw) { super.dispatch(sw); sw.onSQLBlock(this); }
public void dispatch(Switch sw) { super.dispatch(sw); sw.onQualias(this); }