markarray.java

来自「经典的货郎担问题解决办法」· Java 代码 · 共 85 行

JAVA
85
字号
/*** This code was written by Kent Paul Dolan.  See accompanying file** TravellerDoc.html for status for your use.*/package com.well.www.user.xanthian.java.tools;public class MarkArray{  private boolean m_marks[] = null;  private int     m_setCount = 0;  public MarkArray( int size )   {    m_marks = new boolean[ size ];    for ( int i=0; i<size; i++ ) { m_marks[i] = false; }    m_setCount = 0;  }  public synchronized void setAllMarksTrue()  {    for ( int i=0; i<m_marks.length; i++ ) { m_marks[i] = true; }    m_setCount = m_marks.length;  }  public synchronized void setAllMarksFalse()  {    for ( int i=0; i<m_marks.length; i++ ) { m_marks[i] = false; }    m_setCount = 0;  }  public synchronized boolean setMarkAndCheckIfAllMarksAreSet( int index )  {    if ( m_marks[ index ] == false )    {      m_setCount++;      m_marks[ index ] = true;    }    if ( m_setCount == m_marks.length )    {      return true;    }    else    {      return false;    }  }  public synchronized boolean clearMarkAndCheckIfAllMarksAreClear( int index )  {    if ( m_marks[ index ] == true )    {      m_setCount--;      m_marks[ index ] = false;    }    if ( m_setCount == 0 )    {      return true;    }    else    {      return false;    }  }  public synchronized void clear( int index )  {    m_marks[ index ] = false;  }  public synchronized void set( int index )  {    m_marks[ index ] = true;  }  public synchronized int getCount()  {    return m_setCount;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?