001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.geometry.core.partitioning; 018 019/** Class containing the result of splitting an object with a hyperplane. 020 * @param <T> Split type 021 */ 022public final class Split<T> { 023 024 /** Part of the object lying on the minus side of the splitting hyperplane. 025 */ 026 private final T minus; 027 028 /** Part of the object lying on the plus side of the splitting hyperplane. 029 */ 030 private final T plus; 031 032 /** Build a new instance from its parts. 033 * @param minus part of the object lying on the minus side of the 034 * splitting hyperplane or null if no such part exists 035 * @param plus part of the object lying on the plus side of the 036 * splitting hyperplane or null if no such part exists. 037 */ 038 public Split(final T minus, final T plus) { 039 this.minus = minus; 040 this.plus = plus; 041 } 042 043 /** Get the part of the object lying on the minus side of the splitting 044 * hyperplane or null if no such part exists. 045 * @return part of the object lying on the minus side of the splitting 046 * hyperplane 047 */ 048 public T getMinus() { 049 return minus; 050 } 051 052 /** Get the part of the object lying on the plus side of the splitting 053 * hyperplane or null if no such part exists. 054 * @return part of the object lying on the plus side of the splitting 055 * hyperplane 056 */ 057 public T getPlus() { 058 return plus; 059 } 060 061 /** Get the location of the object with respect to its splitting 062 * hyperplane. 063 * @return 064 * <ul> 065 * <li>{@link SplitLocation#PLUS} - if only {@link #getPlus()} is not null</li> 066 * <li>{@link SplitLocation#MINUS} - if only {@link #getMinus()} is not null</li> 067 * <li>{@link SplitLocation#BOTH} - if both {@link #getPlus()} and {@link #getMinus()} 068 * are not null</li> 069 * <li>{@link SplitLocation#NEITHER} - if both {@link #getPlus()} and {@link #getMinus()} 070 * are null</li> 071 * </ul> 072 */ 073 public SplitLocation getLocation() { 074 if (minus != null) { 075 return plus != null ? SplitLocation.BOTH : SplitLocation.MINUS; 076 } else if (plus != null) { 077 return SplitLocation.PLUS; 078 } 079 return SplitLocation.NEITHER; 080 } 081 082 /** {@inheritDoc} */ 083 @Override 084 public String toString() { 085 final StringBuilder sb = new StringBuilder(); 086 sb.append(this.getClass().getSimpleName()) 087 .append("[location= ") 088 .append(getLocation()) 089 .append(", minus= ") 090 .append(minus) 091 .append(", plus= ") 092 .append(plus) 093 .append(']'); 094 095 return sb.toString(); 096 } 097}