/// <summary>Removes a previously registered observer.</summary> /// <remarks> /// Removes a previously registered observer. The observer must not be null and it /// must already have been registered. /// </remarks> /// <param name="observer">the observer to unregister</param> /// <exception cref="System.ArgumentException">the observer is null</exception> /// <exception cref="System.InvalidOperationException">the observer is not yet registered /// </exception> public virtual void unregisterObserver(T observer) { if ((object)observer == null) { throw new System.ArgumentException("The observer is null."); } lock (mObservers) { int index = mObservers.indexOf(observer); if (index == -1) { throw new System.InvalidOperationException("Observer " + observer + " was not registered." ); } mObservers.remove(index); } }
private android.view.View findNextFocus(android.view.ViewGroup root, android.view.View focused, android.graphics.Rect focusedRect, int direction) { java.util.ArrayList <android.view.View> focusables = root.getFocusables(direction); if (focusables.isEmpty()) { // The focus cannot change. return(null); } if (direction == android.view.View.FOCUS_FORWARD || direction == android.view.View .FOCUS_BACKWARD) { if (focused != null && !focusables.contains(focused)) { // Add the currently focused view to the list to have it sorted // along with the other views. focusables.add(focused); } try { // Note: This sort is stable. mSequentialFocusComparator.setRoot(root); java.util.Collections.sort(focusables, mSequentialFocusComparator); } finally { mSequentialFocusComparator.recycle(); } int count = focusables.size(); switch (direction) { case android.view.View.FOCUS_FORWARD: { if (focused != null) { int position = focusables.lastIndexOf(focused); if (position >= 0 && position + 1 < count) { return(focusables.get(position + 1)); } } return(focusables.get(0)); } case android.view.View.FOCUS_BACKWARD: { if (focused != null) { int position = focusables.indexOf(focused); if (position > 0) { return(focusables.get(position - 1)); } } return(focusables.get(count - 1)); } } return(null); } // initialize the best candidate to something impossible // (so the first plausible view will become the best choice) mBestCandidateRect.set(focusedRect); switch (direction) { case android.view.View.FOCUS_LEFT: { mBestCandidateRect.offset(focusedRect.width() + 1, 0); break; } case android.view.View.FOCUS_RIGHT: { mBestCandidateRect.offset(-(focusedRect.width() + 1), 0); break; } case android.view.View.FOCUS_UP: { mBestCandidateRect.offset(0, focusedRect.height() + 1); break; } case android.view.View.FOCUS_DOWN: { mBestCandidateRect.offset(0, -(focusedRect.height() + 1)); break; } } android.view.View closest = null; int numFocusables = focusables.size(); { for (int i = 0; i < numFocusables; i++) { android.view.View focusable = focusables.get(i); // only interested in other non-root views if (focusable == focused || focusable == root) { continue; } // get visible bounds of other view in same coordinate system focusable.getDrawingRect(mOtherRect); root.offsetDescendantRectToMyCoords(focusable, mOtherRect); if (isBetterCandidate(direction, focusedRect, mOtherRect, mBestCandidateRect)) { mBestCandidateRect.set(mOtherRect); closest = focusable; } } } return(closest); }
public static void CreateArffFiles() { java.util.ArrayList atts; java.util.ArrayList attsRel; java.util.ArrayList attVals; java.util.ArrayList attValsRel; Instances data; Instances dataRel; double[] vals; double[] valsRel; int i; // 1. set up attributes atts = new java.util.ArrayList(); // - numeric atts.Add(new weka.core.Attribute("att1")); // - nominal attVals = new java.util.ArrayList(); for (i = 0; i < 5; i++) { attVals.add("val" + (i + 1)); } weka.core.Attribute nominal = new weka.core.Attribute("att2", attVals); atts.add(nominal); // - string atts.add(new weka.core.Attribute("att3", (java.util.ArrayList)null)); // - date atts.add(new weka.core.Attribute("att4", "yyyy-MM-dd")); // - relational attsRel = new java.util.ArrayList(); // -- numeric attsRel.add(new weka.core.Attribute("att5.1")); // -- nominal attValsRel = new java.util.ArrayList(); for (i = 0; i < 5; i++) { attValsRel.Add("val5." + (i + 1)); } attsRel.add(new weka.core.Attribute("att5.2", attValsRel)); dataRel = new Instances("att5", attsRel, 0); atts.add(new weka.core.Attribute("att5", dataRel, 0)); // 2. create Instances object data = new Instances("MyRelation", atts, 0); // 3. fill with data // first instance vals = new double[data.numAttributes()]; // - numeric vals[0] = Math.PI; // - nominal vals[1] = attVals.indexOf("val3"); // - string vals[2] = data.attribute(2).addStringValue("This is a string!"); // - date vals[3] = data.attribute(3).parseDate("2001-11-09"); // - relational dataRel = new Instances(data.attribute(4).relation(), 0); // -- first instance valsRel = new double[2]; valsRel[0] = Math.PI + 1; valsRel[1] = attValsRel.indexOf("val5.3"); weka.core.Instance inst = new DenseInstance(2); inst.setValue(1, valsRel[0]); inst.setValue(1, valsRel[1]); dataRel.add(inst); // -- second instance valsRel = new double[2]; valsRel[0] = Math.PI + 2; valsRel[1] = attValsRel.indexOf("val5.2"); dataRel.add(inst); vals[4] = data.attribute(4).addRelation(dataRel); // add weka.core.Instance inst2 = new DenseInstance(4); inst2.setValue(1, vals[0]); inst2.setValue(1, vals[1]); inst2.setValue(1, vals[2]); inst2.setValue(1, vals[3]); data.add(inst2); // second instance vals = new double[data.numAttributes()]; // important: needs NEW array! // - numeric vals[0] = Math.E; // - nominal vals[1] = attVals.indexOf("val1"); // - string vals[2] = data.attribute(2).addStringValue("And another one!"); // - date vals[3] = data.attribute(3).parseDate("2000-12-01"); // - relational dataRel = new Instances(data.attribute(4).relation(), 0); // -- first instance valsRel = new double[2]; valsRel[0] = Math.E + 1; valsRel[1] = attValsRel.indexOf("val5.4"); dataRel.add(inst); // -- second instance valsRel = new double[2]; valsRel[0] = Math.E + 2; valsRel[1] = attValsRel.indexOf("val5.1"); dataRel.add(inst); vals[4] = data.attribute(4).addRelation(dataRel); // add data.add(inst2); data.setClassIndex(data.numAttributes() - 1); // 4. output data for (int x = 0; x < data.numInstances(); x++) { weka.core.Instance ins = data.instance(x); System.Console.WriteLine(ins.value(x).ToString()); } return; }