/**
     * Add a new state to the state machine. Bottom up addition of states is allowed but the same
     * state may only exist in one hierarchy.
     *
     * @param state the state to add
     * @param parent the parent of state
     * @return stateInfo for this state
     */
    private final StateInfo addState(State state, State parent) {
      if (mDbg) {
        Log.d(
            TAG,
            "addStateInternal: E state="
                + state.getName()
                + ",parent="
                + ((parent == null) ? "" : parent.getName()));
      }
      StateInfo parentStateInfo = null;
      if (parent != null) {
        parentStateInfo = mStateInfo.get(parent);
        if (parentStateInfo == null) {
          // Recursively add our parent as it's not been added yet.
          parentStateInfo = addState(parent, null);
        }
      }
      StateInfo stateInfo = mStateInfo.get(state);
      if (stateInfo == null) {
        stateInfo = new StateInfo();
        mStateInfo.put(state, stateInfo);
      }

      // Validate that we aren't adding the same state in two different hierarchies.
      if ((stateInfo.parentStateInfo != null) && (stateInfo.parentStateInfo != parentStateInfo)) {
        throw new RuntimeException("state already added");
      }
      stateInfo.state = state;
      stateInfo.parentStateInfo = parentStateInfo;
      stateInfo.active = false;
      if (mDbg) Log.d(TAG, "addStateInternal: X stateInfo: " + stateInfo);
      return stateInfo;
    }
Esempio n. 2
0
    public void startElement(String name, AttributeList atts) 
        throws org.xml.sax.SAXException
    {
        
        //-- strip namespace prefix
        int idx = name.indexOf(':');
        if (idx >= 0) {
            name = name.substring(idx+1);
        }

        StateInfo sInfo = null;
        
        boolean topLevel = false;
        //-- if we are currently in another element 
        //-- definition...flag as complex content
        if (!_siStack.isEmpty()) {
            sInfo = (StateInfo)_siStack.peek();
            sInfo.complex = true;
        }
        else {
            topLevel = true;
        }
        
        //-- create current holder for stateInformation
        sInfo = new StateInfo();
        sInfo.topLevel = topLevel;
        _siStack.push(sInfo);
        
        //-- create element definition
        sInfo.element = new ElementDecl(_schema, name);
        
        //-- create attributes
        for (int i = 0; i < atts.getLength(); i++) {
            
            String attName = atts.getName(i);
            
            //-- skip namespace declarations
            if (attName.equals(XMLNS)) continue;
            String prefix = "";
            idx = attName.indexOf(':');
            if (idx >= 0) {
                prefix = attName.substring(0, idx);
                attName = attName.substring(idx+1);
            }
            if (prefix.equals(XMLNS)) continue;
            
            AttributeDecl attr = new AttributeDecl(_schema, attName);
            
            //-- guess simple type
            String typeName = _nsPrefix + ':' + 
                DatatypeHandler.guessType(atts.getValue(i));
                
            attr.setSimpleTypeReference(typeName);
            
            sInfo.attributes.addElement(attr);
        }
        
    } //-- startElement
Esempio n. 3
0
  public void smallBoxLongClicked(View v) {
    SmallBox sb2 = (SmallBox) v;
    SmallBox sb1 = stateInfo.selectedSmallBox;
    boolean hadSelectedSmallBox = stateInfo.hasSelectedSmallBox;
    stateInfo.selectedSmallBox = sb2;
    stateInfo.hasSelectedSmallBox = true;
    stateInfo.selectingState = StateInfo.SELECTING_POSSIBLE_VALUE;

    if (hadSelectedSmallBox) sb1.invalidate();
    sb2.invalidate();
    refreshDigitButtons();
  }
Esempio n. 4
0
  private void setStatus() {
    try {
      getStateInfo myGetStateInfo = getStateInfo.getInstance(getApplicationContext());
      StateInfo myStateInfo = myGetStateInfo.getStateinfo();
      myStateInfo.setCurrentState(1);
      myGetStateInfo.setStateinfo(myStateInfo);

    } catch (Exception e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
  }
Esempio n. 5
0
  @Override
  public void select(
      List<Candidate> candi,
      BoardImage board,
      int player,
      int depth,
      int alpha,
      int beta,
      int depthLimit,
      StateHash<StateInfo> hash,
      SearchLogger logger) {
    int opponent = GameUtility.getOpponent(player);

    for (int x = 0; x < ChessGame.BOARD_WIDTH; x++)
      for (int y = 0; y < ChessGame.BOARD_HEIGHT; y++)
        if (board.getColorAt(x, y) == player) {
          Position[] targets = RuleEngine.getLegalMoves(board, x, y);
          for (Position target : targets) {
            assert (board.getColorAt(target) != player);

            Move move = new Move(new Position(x, y), target);
            int killedUnit = board.performMove(move);
            // this move leads to a new state that never happended
            // in history (which is ban move)
            if (historyStates == null || !historyStates.contains(board, opponent)) {
              StateInfo hashedState = hash.lookUp(board, opponent);
              String reason;
              int priority;

              if (hashedState != null && hashedState.getBeta() >= -alpha) {
                reason = "historical heuristic move.";
                priority = -hashedState.getAlpha() + 10;
              } else {
                if (killedUnit != ChessGame.EMPTY) {
                  reason = "killing move.";
                  priority = 10 + unitScoreTable.getUnitScore(target, killedUnit);
                } else {
                  reason = "normal move.";
                  priority = 10;
                }
              }

              priority += historyTable.getMoveScore(move);
              priority += killerTable.getMoveScore(depth, move);

              candi.add(new Candidate(move, priority, reason));
            }

            board.unperformMove(move, killedUnit);
          }
        }
  }
Esempio n. 6
0
 public void characters(char[] ch, int start, int length) 
     throws org.xml.sax.SAXException
 {
     if (_siStack.isEmpty()) return;
     
     StateInfo sInfo = (StateInfo)_siStack.peek();
     
     if (sInfo.buffer == null) {
         sInfo.buffer = new StringBuffer();
     }
     sInfo.buffer.append(ch, start, length);
     
     if (sInfo.complex) {
         sInfo.mixed = true;    
     }
 } //-- characters
Esempio n. 7
0
  /**
   * All build options require that appropriate units are built in appropriate places (e.g., armies
   * can't go in the water, fleets can't go in landlocked provinces, fleets must have coasts
   * specified if required, etc.). This method takes care of that.
   *
   * <p>returns false if we cannot build here.
   */
  private boolean checkBuildUnit(
      StateInfo stateInfo, Province province, Location loc, StringBuffer sb) {
    if (srcUnitType == null) {
      sb.append(Utils.getLocalString(NOBUILD_NO_UNIT_SELECTED));
      return false;
    }

    if (srcUnitType.equals(Unit.Type.ARMY)) {
      if (province.isSea()) {
        sb.append(Utils.getLocalString(NOBUILD_NO_ARMY_IN_SEA));
        return false;
      } else {
        // check borders
        if (!GUIOrderUtils.checkBorder(this, loc, srcUnitType, stateInfo.getPhase(), sb)) {
          return false;
        }

        sb.append(Utils.getLocalString(BUILD_ARMY_OK));
        return true;
      }
    } else if (srcUnitType.equals(Unit.Type.FLEET)) {
      if (province.isLandLocked()) {
        sb.append(Utils.getLocalString(NOBUILD_FLEET_LANDLOCKED));
        return false;
      } else {
        // check borders
        if (!GUIOrderUtils.checkBorder(this, loc, srcUnitType, stateInfo.getPhase(), sb)) {
          return false;
        }

        sb.append(Utils.getLocalString(BUILD_FLEET_OK));
        return true;
      }
    } else if (srcUnitType.equals(Unit.Type.WING)) {
      // check borders
      if (!GUIOrderUtils.checkBorder(this, loc, srcUnitType, stateInfo.getPhase(), sb)) {
        return false;
      }

      sb.append(Utils.getLocalString(BUILD_WING_OK));
      return true;
    }

    // this should not occur.
    sb.append("** Unknown unit type! **");
    return false;
  } // checkBuildUnit()
Esempio n. 8
0
 public void blankAreaClicked(View v) {
   boolean hadSelectedSmallBox = stateInfo.hasSelectedSmallBox;
   stateInfo.hasSelectedSmallBox = false;
   if (hadSelectedSmallBox) {
     stateInfo.selectedSmallBox.invalidate();
     refreshDigitButtons();
   }
 }
Esempio n. 9
0
 private void refreshTasks() {
   try {
     idanapp.setTasklist(getInfoValue.getTasks(stateinfo.getCurrentPerson().getPersonID()));
     tasklist = idanapp.getTasklist();
     mAdapter.notifyDataSetChanged();
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Esempio n. 10
0
 @Override
 protected void onSaveInstanceState(Bundle bundle) {
   super.onSaveInstanceState(bundle);
   /*
    * need to save StateInfo
    */
   this.areRestarting = true;
   bundle.putBoolean("areRestarting", areRestarting);
   stateInfo.saveInstanceState(bundle);
 }
Esempio n. 11
0
  public static StateInfo queryState(ContentResolver cr) {
    StateInfo info = new StateInfo();

    Cursor c = cr.query(CrsyncConstants.URI_STATE, null, null, null, null);

    if (c != null && c.moveToFirst()) {
      int actionColumn = c.getColumnIndex(CrsyncConstants.COLUMN_STATE_ACTION);
      int codeColumn = c.getColumnIndex(CrsyncConstants.COLUMN_STATE_CODE);

      info.mAction = c.getInt(actionColumn);
      info.mCode = c.getInt(codeColumn);
    } else {
      logger.severe("####StateInfo query URI fail");
    }
    if (c != null) {
      c.close();
    }
    return info;
  }
Esempio n. 12
0
  public void smallBoxClicked(View v) {
    SmallBox sb2 = (SmallBox) v;
    SmallBox sb1 = stateInfo.selectedSmallBox;
    /*
     * set has selected to true
     * set the selected box
     * set setting final value to true
     * invalidate the small box and the previously selected small box
     * invalidate the digitbuttons
     */

    boolean hadSelectedSmallBox = stateInfo.hasSelectedSmallBox;
    stateInfo.selectedSmallBox = sb2;
    stateInfo.hasSelectedSmallBox = true;
    stateInfo.selectingState = StateInfo.SELECTING_FINAL_VALUE;
    if (hadSelectedSmallBox) sb1.invalidate();
    sb2.invalidate();
    refreshDigitButtons();
  }
 @Override
 protected boolean checkNotNullable(
     DfaMemoryState state, DfaValue value, NullabilityProblem problem, PsiElement anchor) {
   boolean ok = super.checkNotNullable(state, value, problem, anchor);
   if (!ok && anchor != null) {
     myProblems.putValue(problem, anchor);
   }
   Pair<NullabilityProblem, PsiElement> key = Pair.create(problem, anchor);
   StateInfo info = myStateInfos.get(key);
   if (info == null) {
     myStateInfos.put(key, info = new StateInfo());
   }
   if (state.isEphemeral() && !ok) {
     info.ephemeralNpe = true;
   } else if (!state.isEphemeral()) {
     if (ok) info.normalOk = true;
     else info.normalNpe = true;
   }
   return ok;
 }
Esempio n. 14
0
 @Override
 protected void onResume() {
   // TODO Auto-generated method stub
   super.onResume();
   Log.i("jxb", "resume");
   //		menu.toggle();
   setStatus();
   try {
     stateinfo = getStateInfo.getInstance(getApplicationContext()).getStateinfo();
     pauseNote = stateinfo.getPauseNote();
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   refreshTasks();
 }
Esempio n. 15
0
  @Override
  public boolean setLocation(StateInfo stateInfo, Location location, StringBuffer sb) {
    if (testLocation(stateInfo, location, sb)) {
      currentLocNum++;

      src = new Location(location.getProvince(), location.getCoast());
      power = stateInfo.getPosition().getSupplyCenterOwner(location.getProvince());

      // srcUnitType: already defined
      assert (srcUnitType != null);

      sb.setLength(0);
      sb.append(Utils.getLocalString(GUIOrder.COMPLETE, getFullName()));
      return true;
    }

    return false;
  } // setLocation()
Esempio n. 16
0
 public void endElement(String name) 
     throws org.xml.sax.SAXException
 {
     
     //-- strip namespace prefix
     int idx = name.indexOf(':');
     if (idx >= 0) {
         name = name.substring(idx+1);
     }
     
     StateInfo sInfo = (StateInfo) _siStack.pop();
     
     //-- if we don't have a type, it means there are no
     //-- children and therefore the type is a simpleType or
     //-- simpleContent
     if ((sInfo.element.getType() == null) && (sInfo.buffer != null)) {
         
         //-- create SimpleType (guess type)
         String typeName = _nsPrefix + ':' + 
             DatatypeHandler.guessType(sInfo.buffer.toString());
         sInfo.element.setTypeReference(typeName);
         //-- simpleContent
         if (sInfo.attributes.size() > 0) {
             ComplexType cType = new ComplexType(_schema);
             //-- SHOULD CHANGE THIS TO SIMPLE CONTENT WHEN
             //-- SCHEMA WRITER BUGS ARE FIXED
             cType.setContentType(ContentType.mixed);
             sInfo.element.setType(cType);
             Group group = new Group();
             group.setOrder(_defaultGroupOrder);
             //-- add attributes
             try {
                 cType.addGroup(group);
                 for (int i = 0; i < sInfo.attributes.size(); i++) {
                     AttributeDecl attDecl = 
                         (AttributeDecl)sInfo.attributes.elementAt(i);
                     cType.addAttributeDecl(attDecl);
                 }
             }
             catch(SchemaException sx) {
                 throw new SAXException(sx);
             }
         }
     }
     else {
         ComplexType cType = (ComplexType)sInfo.element.getType();
         if (cType != null) {
             //-- add attributes
             try {
                 for (int i = 0; i < sInfo.attributes.size(); i++) {
                     AttributeDecl attDecl = 
                         (AttributeDecl)sInfo.attributes.elementAt(i);
                     cType.addAttributeDecl(attDecl);
                 }
             }
             catch(SchemaException sx) {
                 throw new SAXException(sx);
             }
         }
     }
     
     //-- put element into parent element or as top-level in schema
     if (!_siStack.isEmpty()) {
         StateInfo parentInfo = (StateInfo)_siStack.peek();
         ComplexType type = (ComplexType) parentInfo.element.getType();
         Group group = null;
         if (type == null) {
             parentInfo.complex = true;
             type = new ComplexType(_schema);
             parentInfo.element.setType(type);
             group = new Group();
             group.setOrder(_defaultGroupOrder);
             try {
                 type.addGroup(group);
                 //-- add element
                 group.addElementDecl(sInfo.element);
             }
             catch(SchemaException sx) {
                 throw new SAXException(sx);
             }
         }
         else {
             group = (Group) type.getParticle(0);
             //-- check for another element declaration with
             //-- same name ...
             ElementDecl element = group.getElementDecl(name);
             boolean checkGroupType = false;
             if (element != null) {
                 //-- if complex...merge definition
                 if (sInfo.complex) {
                     try {
                         merge(element, sInfo.element);
                     }
                     catch(SchemaException sx) {
                         throw new SAXException(sx);
                     }
                 }
                 element.setMaxOccurs(Particle.UNBOUNDED);
                 checkGroupType = true;
             }
             else {
                 try {
                     group.addElementDecl(sInfo.element);
                 }
                 catch(SchemaException sx) {
                     throw new SAXException(sx);
                 }
             }
             
             //-- change group type if necessary
             if (checkGroupType && (group.getOrder() == Order.seq)) {
                 //-- make sure element is last item in group,
                 //-- otherwise we need to switch to all
                 boolean found = false;
                 boolean changeType = false;
                 for (int i = 0; i < group.getParticleCount(); i++) {
                     if (found) {
                         changeType = true;
                         break;
                     }
                     if (element == group.getParticle(i)) found = true;
                 }
                 if (changeType) {
                     group.setOrder(Order.all);
                 }
             }
         }
     }
     else {
         try {
             _schema.addElementDecl(sInfo.element);
             
             //-- make complexType top-level also
             //XMLType type = sInfo.element.getType();
             //if ((type != null) && (type.isComplexType())) {
             //    if (type.getName() == null) {
             //        type.setName(sInfo.element.getName() + "Type");
             //        _schema.addComplexType((ComplexType)type);
             //    }
             //}
         }
         catch(SchemaException sx) {
             throw new SAXException(sx);
         }
     }
     
 } //-- endElement
Esempio n. 17
0
 @Override
 protected void onRestoreInstanceState(Bundle bundle) {
   super.onRestoreInstanceState(bundle);
   stateInfo.restoreInstanceState(bundle);
   this.areRestarting = bundle.getBoolean("areRestarting");
 }
Esempio n. 18
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i("jxb", "create");
    setContentView(R.layout.business_list);
    idanapp = iDanApp.getInstance();
    tasklist = idanapp.getTasklist();
    JPushInterface.init(getApplicationContext());
    try {
      stateinfo = getStateInfo.getInstance(getApplicationContext()).getStateinfo();
      pauseNote = stateinfo.getPauseNote();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      Toast.makeText(this.getApplicationContext(), R.string.error, 2000);
    }
    mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_ALIAS, stateinfo.getUserAccount()));
    ActivityControler.addActivity(this);

    findView();
    uploadNotes();
    tv_title.setText(iDanApp.getInstance().getUSERNAME());
    mAdapter = new MyAdapter(this);
    mListView.setAdapter(mAdapter);
    mListView.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // tasklist.get(position).setReadmark(0);
            curTask = tasklist.get(position);
            // curTask=iDanApp.getInstance().getTasklist().get(position);
            curTask.setReadmark(0);
            Intent intent = new Intent();
            intent.putExtra(POSITION, position);
            intent.setClass(getApplicationContext(), OrderDetail.class);
            startActivity(intent);
          }
        });
    tv_addStart.setVisibility(View.VISIBLE);
    tv_addEnd.setVisibility(View.GONE);
    if (stateinfo.getIsOutDoor()) {
      tv_addStart.setVisibility(View.VISIBLE);
      tv_addEnd.setVisibility(View.GONE);
    } else {
      tv_addStart.setVisibility(View.GONE);
      tv_addEnd.setVisibility(View.VISIBLE);
    }

    // configure the SlidingMenu
    MenuLeftFragment menuLayout = new MenuLeftFragment(getApplicationContext());
    // final SlidingMenu
    menu = new SlidingMenu(this);
    menu.setMode(SlidingMenu.LEFT);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.setShadowWidthRes(R.dimen.shadow_width);
    menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    menu.setFadeDegree(0.35f);
    /**
     * SLIDING_WINDOW will include the Title/ActionBar in the content section of the SlidingMenu,
     * while SLIDING_CONTENT does not.
     */
    menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
    menu.setMenu(R.layout.left_menu);

    checkVersion(this);

    iv_return.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            menu.showMenu();
            // refreshTasks();
          }
        });
    iv_refresh.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            refreshTasks();
          }
        });
    tv_addStart.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            final EditText editText = new EditText(MainActivity.this);
            editText.setInputType(InputType.TYPE_CLASS_NUMBER);
            new AlertDialog.Builder(MainActivity.this)
                .setTitle("请填写出场路码")
                .setView(editText)
                .setPositiveButton(
                    "确定",
                    new android.content.DialogInterface.OnClickListener() {

                      @Override
                      public void onClick(DialogInterface dialog, int which) {

                        String input = editText.getText().toString();
                        if (input.equals("")) {
                          Toast.makeText(getApplicationContext(), "路码不能为空", Toast.LENGTH_SHORT)
                              .show();
                        } else {
                          try {
                            getStateInfo myGetStateInfo =
                                getStateInfo.getInstance(getApplicationContext());
                            StateInfo myStateInfo = myGetStateInfo.getStateinfo();
                            myStateInfo.setBeginKMsOfToday(input);
                            myStateInfo.setIsOutDoor(false);
                            myGetStateInfo.setStateinfo(myStateInfo);
                            tv_addStart.setVisibility(View.GONE);
                            tv_addEnd.setVisibility(View.VISIBLE);
                          } catch (Exception e1) {
                            // TODO Auto-generated catch
                            // block
                            e1.printStackTrace();
                          }
                        }
                      }
                    })
                .show();
          }
        });
    tv_addEnd.setOnClickListener(myClickListener);
    stateinfo.setCurrentState(1);
    getStateInfo.getInstance(getApplicationContext()).setStateinfo(stateinfo);
  }
Esempio n. 19
0
  @Override
  public boolean testLocation(StateInfo stateInfo, Location location, StringBuffer sb) {
    sb.setLength(0);

    if (isComplete()) {
      sb.append(Utils.getLocalString(GUIOrder.COMPLETE, getFullName()));
      return false;
    }

    Position position = stateInfo.getPosition();
    Province province = location.getProvince();

    if (province.hasSupplyCenter()) {
      Power SCOwner = position.getSupplyCenterOwner(province);

      // general screening, applicable to all build options
      //
      if (SCOwner == null) {
        sb.append(Utils.getLocalString(NOBUILD_UNOWNED_SC));
        return false;
      }

      if (position.hasUnit(province)) {
        sb.append(Utils.getLocalString(NOBUILD_UNIT_PRESENT));
        return false;
      }

      if (!stateInfo.canIssueOrder(SCOwner)) {
        sb.append(Utils.getLocalString(NOBUILD_SC_NOT_CONTROLLED));
        return false;
      }

      // indicate if we have no builds available
      //
      Adjustment.AdjustmentInfo adjInfo = stateInfo.getAdjustmenInfoMap().get(SCOwner);
      if (adjInfo.getAdjustmentAmount() <= 0) {
        sb.append(Utils.getLocalString(NOBUILD_NO_BUILDS_AVAILABLE, SCOwner.getName()));
        return false;
      }

      // build-option-specific, based upon RuleOptions
      //
      RuleOptions ruleOpts = stateInfo.getRuleOptions();
      if (ruleOpts.getOptionValue(RuleOptions.OPTION_BUILDS)
          == RuleOptions.VALUE_BUILDS_ANY_OWNED) {
        return checkBuildUnit(stateInfo, province, location, sb);
      } else if (ruleOpts.getOptionValue(RuleOptions.OPTION_BUILDS)
          == RuleOptions.VALUE_BUILDS_ANY_IF_HOME_OWNED) {
        // check if we have ONE owned home supply center before buidling
        // in a non-home supply center.
        //
        if (SCOwner != position.getSupplyCenterHomePower(province)
            && !position.hasAnOwnedHomeSC(SCOwner)) {
          sb.append(Utils.getLocalString(NOBUILD_NEED_ONE_OWNED_SC));
          return false; // failed
        }

        // we (probably) can build here
        return checkBuildUnit(stateInfo, province, location, sb);
      } else {
        // build only in owned HOME supply centers
        //
        if (SCOwner == position.getSupplyCenterHomePower(province)) {
          // we (probably) can build here
          return checkBuildUnit(stateInfo, province, location, sb);
        }

        // build failure.
        sb.append(Utils.getLocalString(NOBUILD_NOT_OWNED_HOME_SC));
        return false;
      }
    } else {
      sb.append(Utils.getLocalString(NOBUILD_MUST_BE_AN_OWNED_SC));
      return false;
    }

    // NO return here: thus we must appropriately exit within an if/else block above.
  } // testLocation()