| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Constant |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * #%L | |
| 3 | * Constant.java - mongodb-async-driver - Allanbank Consulting, Inc. | |
| 4 | * %% | |
| 5 | * Copyright (C) 2011 - 2014 Allanbank Consulting, Inc. | |
| 6 | * %% | |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 8 | * you may not use this file except in compliance with the License. | |
| 9 | * You may obtain a copy of the License at | |
| 10 | * | |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 12 | * | |
| 13 | * Unless required by applicable law or agreed to in writing, software | |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 16 | * See the License for the specific language governing permissions and | |
| 17 | * limitations under the License. | |
| 18 | * #L% | |
| 19 | */ | |
| 20 | ||
| 21 | package com.allanbank.mongodb.builder.expression; | |
| 22 | ||
| 23 | import com.allanbank.mongodb.bson.Element; | |
| 24 | ||
| 25 | /** | |
| 26 | * Represents constant value in an expression. | |
| 27 | * | |
| 28 | * @api.no This class is <b>NOT</b> part of the drivers API. This class may be | |
| 29 | * mutated in incompatible ways between any two releases of the driver. | |
| 30 | * @copyright 2012-2013, Allanbank Consulting, Inc., All Rights Reserved | |
| 31 | */ | |
| 32 | public class Constant implements Expression { | |
| 33 | ||
| 34 | /** The constant value. */ | |
| 35 | private final Element myConstant; | |
| 36 | ||
| 37 | /** | |
| 38 | * Creates a new Constant. | |
| 39 | * | |
| 40 | * @param constant | |
| 41 | * The constant element. | |
| 42 | */ | |
| 43 | 142 | public Constant(final Element constant) { |
| 44 | 142 | myConstant = constant; |
| 45 | 142 | } |
| 46 | ||
| 47 | /** | |
| 48 | * {@inheritDoc} | |
| 49 | * <p> | |
| 50 | * Overridden to return the constant value's element with the specified | |
| 51 | * name. | |
| 52 | * </p> | |
| 53 | */ | |
| 54 | @Override | |
| 55 | public Element toElement(final String name) { | |
| 56 | 145 | return myConstant.withName(name); |
| 57 | } | |
| 58 | ||
| 59 | /** | |
| 60 | * {@inheritDoc} | |
| 61 | * <p> | |
| 62 | * Overridden to return the constant value. | |
| 63 | * </p> | |
| 64 | * <blockquote> | |
| 65 | * | |
| 66 | * <pre> | |
| 67 | * <code> | |
| 68 | * value | |
| 69 | * </code> | |
| 70 | * </pre> | |
| 71 | * | |
| 72 | * </blockquote> | |
| 73 | */ | |
| 74 | @Override | |
| 75 | public String toString() { | |
| 76 | 1 | return myConstant.getValueAsString(); |
| 77 | } | |
| 78 | } |