Copyright (c) 2011-2014, Intel Corporation
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redist...
If you think the Android project pokerCCF listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
// This file is part of the 'texasholdem' project, an open source
// Texas Hold'em poker application written in Java.
////fromwww.java2s.com// Copyright 2009 Oscar Stigter
//
// Licensed 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 lo.wolo.pokerengine;
/**
* Represents the value of a poker hand. <br />
* <br />
*
* Implements the <code>Comparable</code> interface with <b>reversed</b>
* (descending sort) order.
*
* @author Oscar Stigter
*/publicclass HandValue implements Comparable<HandValue> {
/** The hand. */privatefinal Hand hand;
/** The hand value type. */privatefinal HandValueType type;
/** The exact, numeric hand value. */privatefinalint value;
/**
* Constructor.
*
* @param hand
* The hand.
*/public HandValue(Hand hand) {
this.hand = hand;
HandEvaluator evaluator = new HandEvaluator(hand);
type = evaluator.getType();
value = evaluator.getValue();
}
/**
* Returns the hand.
*
* @return The hand.
*/public Hand getHand() {
return hand;
}
/**
* Returns the hand value type.
*
* @return The hand value type.
*/public HandValueType getType() {
return type;
}
/**
* Returns a description of the hand value type.
*
* @return The description of the hand value type.
*/public String getDescription() {
return type.getDescription();
}
/**
* Returns the exact, numeric hand value.
*
* @return The exact, numeric hand value.
*/publicint getValue() {
return value;
}
/** {@inheritDoc} */
@Override
publicint hashCode() {
return value;
}
/** {@inheritDoc} */
@Override
publicboolean equals(Object obj) {
if (obj instanceof HandValue) {
return ((HandValue) obj).getValue() == value;
} else {
return false;
}
}
/** {@inheritDoc} */
@Override
publicint compareTo(HandValue handValue) {
if (value > handValue.getValue()) {
return -1;
} elseif (value < handValue.getValue()) {
return 1;
} else {
return 0;
}
}
/** {@inheritDoc} */
@Override
public String toString() {
return String.format("%s (%d)", type.getDescription(), value);
}
}