Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.apache.mahout.math.set;
 
 
 public abstract class AbstractCharSet extends AbstractSet {

  
Returns true if the receiver contains the specified key.

Returns:
true if the receiver contains the specified key.
 
   public boolean contains(final char key) {
     return !forEachKey(
         new CharProcedure() {
           @Override
           public boolean apply(char iterKey) {
             return (key != iterKey);
           }
         }
     );
   }

  
Returns a deep copy of the receiver; uses clone() and casts the result.

Returns:
a deep copy of the receiver.
 
   public AbstractCharSet copy() {
     return (AbstractCharSetclone();
   }
 
   public boolean equals(Object obj) {
     if (obj == this) {
       return true;
     }
 
     if (!(obj instanceof AbstractCharSet)) {
       return false;
     }
     final AbstractCharSet other = (AbstractCharSetobj;
     if (other.size() != size()) {
       return false;
     }
 
     return
         forEachKey(
             new CharProcedure() {
               @Override
               public boolean apply(char key) {
                 return other.contains(key);
               }
             }
         );
   }
 
   public int hashCode() {
     final int[] buf = new int[size()];
     forEachKey(
       new CharProcedure() {
         int i = 0;
 
         @Override
         public boolean apply(char iterKey) {
           buf[++] = HashUtils.hash(iterKey);
           return true;
         }
       }
     );
     Arrays.sort(buf);
     return IntBuffer.wrap(buf).hashCode();
   }

  
Applies a procedure to each key of the receiver, if any. Note: Iterates over the keys in no particular order. Subclasses can define a particular order, for example, "sorted by key". All methods which can be expressed in terms of this method (most methods can) must guarantee to use the same order defined by this method, even if it is no particular order. This is necessary so that, for example, methods keys and values will yield association pairs, not two uncorrelated lists.

Parameters:
procedure the procedure to be applied. Stops iteration if the procedure returns false, otherwise continues.
Returns:
false if the procedure stopped before all keys where iterated over, true otherwise.
  public abstract boolean forEachKey(CharProcedure procedure);

  
Returns a list filled with all keys contained in the receiver. The returned list has a size that equals this.size(). Iteration order is guaranteed to be identical to the order used by method forEachKey(org.apache.mahout.math.function.CharProcedure).

This method can be used to iterate over the keys of the receiver.

Returns:
the keys.
  public CharArrayList keys() {
    CharArrayList list = new CharArrayList(size());
    keys(list);
    return list;
  }

  
Fills all keys contained in the receiver into the specified list. Fills the list, starting at index 0. After this call returns the specified list has a new size that equals this.size(). Iteration order is guaranteed to be identical to the order used by method forEachKey(org.apache.mahout.math.function.CharProcedure).

This method can be used to iterate over the keys of the receiver.

Parameters:
list the list to be filled, can have any size.
  public void keys(final CharArrayList list) {
    list.clear();
    forEachKey(
        new CharProcedure() {
          @Override
          public boolean apply(char key) {
            list.add(key);
            return true;
          }
        }
    );
  }
  
Associates the given key with the given value. Replaces any old (key,someOtherValue) association, if existing.

Parameters:
key the key the value shall be associated with.
Returns:
true if the receiver did not already contain such a key; false if the receiver did already contain such a key - the new value has now replaced the formerly associated value.
  public abstract boolean add(char key);

  
Removes the given key with its associated element from the receiver, if present.

Parameters:
key the key to be removed from the receiver.
Returns:
true if the receiver contained the specified key, false otherwise.
  public abstract boolean remove(char key);

  
Returns a string representation of the receiver, containing the String representation of each key-value pair, sorted ascending by key.
  public String toString() {
    CharArrayList theKeys = keys();
    //theKeys.sort();
    StringBuilder buf = new StringBuilder();
    buf.append('[');
    int maxIndex = theKeys.size() - 1;
    for (int i = 0; i <= maxIndexi++) {
      char key = theKeys.get(i);
      buf.append(String.valueOf(key));
      if (i < maxIndex) {
        buf.append(", ");
      }
    }
    buf.append(']');
    return buf.toString();
  }
New to GrepCode? Check out our FAQ X