Você está na página 1de 15

CatalogPieceOfFurniture.java 1 /* 2 * CatalogPieceOfFurniture.java 7 avr. 2006 3 * 4 * Sweet Home 3D, Copyright (c) 2006 Emmanuel PUYBARET / eTeks <info@eteks.

com> 5 * 6 * This program is free software; you can redistribute it and/or modify it under 7 * the terms of the GNU General Public License as published by the Free Software 8 * Foundation; either version 2 of the License, or (at your option) any later 9 * version. 10 * 11 * This program is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 * details. 15 * 16 * You should have received a copy of the GNU General Public License along with 17 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 18 * Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 package com.eteks.sweethome3d.model; 21 22 import java.math.BigDecimal; 23 import java.text.Collator; 24 import java.util.ArrayList; 25 import java.util.List; 26 import java.util.Map; 27 import java.util.WeakHashMap; 28 29 /** 30 * A catalog piece of furniture. 31 * @author Emmanuel Puybaret 32 */ 33 public class CatalogPieceOfFurniture implements Comparable<CatalogPieceOfFurniture>, PieceOfFurniture { 34 private static final float [][] INDENTITY_ROTATION = new float [][] {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; 35 private static final byte [][] EMPTY_CRITERIA = new byte [0][]; 36 37 private final String id; 38 private final String name; 39 private final String description; 40 private final String information; 41 private final String [] tags; 42 private final Long creationDate; 43 private final Float grade; 44 private final Content icon; 45 private final Content planIcon; 46 private final Content model; 47 private final float width; 48 private final float depth; 49 private final float height; 50 private final boolean proportional; 51 private final float elevation; 52 private final boolean movable; 53 private final boolean doorOrWindow; 54 private final float [][] modelRotation; 55 private final String staircaseCutOutShape; 56 private final String creator; 57 private final boolean backFaceShown; 58 private final Integer color; Page 1

CatalogPieceOfFurniture.java 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 private private private private private private private private final final final final final final final final float boolean boolean boolean boolean BigDecimal BigDecimal String iconYaw; modifiable; resizable; deformable; texturable; price; valueAddedTaxPercentage; currency; category; filterCollationKey;

private FurnitureCategory private byte []

private static final Collator COMPARATOR; private static final Map<String, byte [][]> recentFilters; static { COMPARATOR = Collator.getInstance(); COMPARATOR.setStrength(Collator.PRIMARY); recentFilters = new WeakHashMap<String, byte[][]>(); } /** * Creates a catalog piece of furniture. * @param name the name of the new piece * @param icon content of the icon of the new piece * @param model content of the 3D model of the new piece * @param width the width in centimeters of the new piece * @param depth the depth in centimeters of the new piece * @param height the height in centimeters of the new piece * @param movable if <code>true</code>, the new piece is movable * @param doorOrWindow if <code>true</code>, the new piece is a door or a window * @deprecated As of version 1.7, use constructor without <code>doorOrWindow</code> * parameter since a catalog door and window is supposed to be an instance * of {@link CatalogDoorOrWindow} */ public CatalogPieceOfFurniture(String name, Content icon, Content model, float width, float depth, float height, boolean movable, boolean doorOrWindow) { this(null, name, null, icon, model, width, depth, height, 0, movable, doorOrWindow, INDENTITY_ROTATION, null, true, null, null); } /** * Creates an unmodifiable catalog piece of furniture of the default catalog. * @param id the id of the new piece or <code>null</code> * @param name the name of the new piece * @param description the description of the new piece * @param icon content of the icon of the new piece * @param model content of the 3D model of the new piece * @param width the width in centimeters of the new piece * @param depth the depth in centimeters of the new piece * @param height the height in centimeters of the new piece * @param elevation the elevation in centimeters of the new piece * @param movable if <code>true</code>, the new piece is movable * @param doorOrWindow if <code>true</code>, the new piece is a door or a window * @param modelRotation the rotation 3 by 3 matrix applied to the piece model * @param creator the creator of the model * @param resizable if <code>true</code>, the size of the new piece may be edited * @param price the price of the new piece or <code>null</code> * @param valueAddedTaxPercentage the Value Added Tax percentage applied to the Page 2

CatalogPieceOfFurniture.java 119 120 121 122 123 124 * price of the new piece or <code>null</code> * @deprecated As of version 1.7, use constructor without <code>doorOrWindow</code> * parameter since a catalog door and window is supposed to be an instance * of {@link CatalogDoorOrWindow} */ public CatalogPieceOfFurniture(String id, String name, String description, Content icon, Content model, 125 float width, float depth, float height, float elevation, 126 boolean movable, boolean doorOrWindow, 127 float [][] modelRotation, String creator, 128 boolean resizable, BigDecimal price, BigDecimal valueAddedTaxPercentage) { 129 this(id, name, description, icon, model, width, depth, height, elevation, movable, 130 modelRotation, creator, resizable, price, valueAddedTaxPercentage); 131 } 132 133 /** 134 * Creates an unmodifiable catalog piece of furniture of the default catalog. 135 * @param id the id of the new piece or <code>null</code> 136 * @param name the name of the new piece 137 * @param description the description of the new piece 138 * @param icon content of the icon of the new piece 139 * @param model content of the 3D model of the new piece 140 * @param width the width in centimeters of the new piece 141 * @param depth the depth in centimeters of the new piece 142 * @param height the height in centimeters of the new piece 143 * @param elevation the elevation in centimeters of the new piece 144 * @param movable if <code>true</code>, the new piece is movable 145 * @param modelRotation the rotation 3 by 3 matrix applied to the piece model 146 * @param creator the creator of the model 147 * @param resizable if <code>true</code>, the size of the new piece may be edited 148 * @param price the price of the new piece or <code>null</code> 149 * @param valueAddedTaxPercentage the Value Added Tax percentage applied to the 150 * price of the new piece or <code>null</code> 151 * @since 1.7 152 */ 153 public CatalogPieceOfFurniture(String id, String name, String description, Content icon, Content model, 154 float width, float depth, float height, float elevation, 155 boolean movable, float [][] modelRotation, String creator, 156 boolean resizable, BigDecimal price, BigDecimal valueAddedTaxPercentage) { 157 this(id, name, description, icon, null, model, width, depth, height, elevation, movable, 158 modelRotation, creator, resizable, price, valueAddedTaxPercentage); 159 } 160 161 /** 162 * Creates an unmodifiable catalog piece of furniture of the default catalog. 163 * @param id the id of the new piece or <code>null</code> 164 * @param name the name of the new piece 165 * @param description the description of the new piece 166 * @param icon content of the icon of the new piece 167 * @param planIcon content of the icon of the new piece displayed in plan 168 * @param model content of the 3D model of the new piece 169 * @param width the width in centimeters of the new piece 170 * @param depth the depth in centimeters of the new piece 171 * @param height the height in centimeters of the new piece 172 * @param elevation the elevation in centimeters of the new piece 173 * @param movable if <code>true</code>, the new piece is movable Page 3

CatalogPieceOfFurniture.java 174 175 176 177 178 179 180 181 182 183 184 185 186 * @param modelRotation the rotation 3 by 3 matrix applied to the piece model * @param creator the creator of the model * @param resizable if <code>true</code>, the size of the new piece may be edited * @param price the price of the new piece or <code>null</code> * @param valueAddedTaxPercentage the Value Added Tax percentage applied to the * price of the new piece or <code>null</code> * @since 2.2 */ public CatalogPieceOfFurniture(String id, String name, String description, Content icon, Content planIcon, Content model, float width, float depth, float height, float elevation, boolean movable, float [][] modelRotation, String creator, boolean resizable, BigDecimal price, BigDecimal valueAddedTaxPercentage) { 187 this(id, name, description, icon, planIcon, model, width, depth, height, elevation, movable, 188 modelRotation, creator, resizable, true, true, price, valueAddedTaxPercentage); 189 } 190 191 /** 192 * Creates an unmodifiable catalog piece of furniture of the default catalog. 193 * @param id the id of the new piece or <code>null</code> 194 * @param name the name of the new piece 195 * @param description the description of the new piece 196 * @param icon content of the icon of the new piece 197 * @param planIcon content of the icon of the new piece displayed in plan 198 * @param model content of the 3D model of the new piece 199 * @param width the width in centimeters of the new piece 200 * @param depth the depth in centimeters of the new piece 201 * @param height the height in centimeters of the new piece 202 * @param elevation the elevation in centimeters of the new piece 203 * @param movable if <code>true</code>, the new piece is movable 204 * @param modelRotation the rotation 3 by 3 matrix applied to the piece model 205 * @param creator the creator of the model 206 * @param resizable if <code>true</code>, the size of the new piece may be edited 207 * @param deformable if <code>true</code>, the width, depth and height of the new piece may 208 * change independently from each other 209 * @param texturable if <code>false</code> this piece should always keep the same color or texture. 210 * @param price the price of the new piece or <code>null</code> 211 * @param valueAddedTaxPercentage the Value Added Tax percentage applied to the 212 * price of the new piece or <code>null</code> 213 * @since 3.0 214 */ 215 public CatalogPieceOfFurniture(String id, String name, String description, 216 Content icon, Content planIcon, Content model, 217 float width, float depth, float height, float elevation, 218 boolean movable, float [][] modelRotation, String creator, 219 boolean resizable, boolean deformable, boolean texturable, 220 BigDecimal price, BigDecimal valueAddedTaxPercentage) { 221 this(id, name, description, icon, planIcon, model, width, depth, height, elevation, 222 movable, null, modelRotation, creator, resizable, deformable, texturable, 223 price, valueAddedTaxPercentage, null); 224 } 225 226 /** 227 * Creates an unmodifiable catalog piece of furniture of the default catalog. 228 * @param id the id of the new piece or <code>null</code> 229 * @param name the name of the new piece Page 4

CatalogPieceOfFurniture.java 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 * @param description the description of the new piece * @param icon content of the icon of the new piece * @param planIcon content of the icon of the new piece displayed in plan * @param model content of the 3D model of the new piece * @param width the width in centimeters of the new piece * @param depth the depth in centimeters of the new piece * @param height the height in centimeters of the new piece * @param elevation the elevation in centimeters of the new piece * @param movable if <code>true</code>, the new piece is movable * @param staircaseCutOutShape the shape used to cut out upper levels when they intersect * with the piece like a staircase * @param modelRotation the rotation 3 by 3 matrix applied to the piece model * @param creator the creator of the model * @param resizable if <code>true</code>, the size of the new piece may be edited * @param deformable if <code>true</code>, the width, depth and height of the new piece may 245 * change independently from each other 246 * @param texturable if <code>false</code> this piece should always keep the same color or texture. 247 * @param price the price of the new piece or <code>null</code> 248 * @param valueAddedTaxPercentage the Value Added Tax percentage applied to the 249 * price of the new piece or <code>null</code> 250 * @param currency the price currency, noted with ISO 4217 code, or <code>null</code> 251 * @since 3.4 252 */ 253 public CatalogPieceOfFurniture(String id, String name, String description, 254 Content icon, Content planIcon, Content model, 255 float width, float depth, float height, 256 float elevation, boolean movable, String staircaseCutOutShape, 257 float [][] modelRotation, String creator, 258 boolean resizable, boolean deformable, boolean texturable, 259 BigDecimal price, BigDecimal valueAddedTaxPercentage, String currency) { 260 this(id, name, description, null, new String [0], null, null, icon, planIcon, model, width, depth, 261 height, elevation, movable, staircaseCutOutShape, modelRotation, creator, resizable, deformable, 262 texturable, price, valueAddedTaxPercentage, currency); 263 } 264 265 /** 266 * Creates an unmodifiable catalog piece of furniture of the default catalog. 267 * @param id the id of the new piece or <code>null</code> 268 * @param name the name of the new piece 269 * @param description the description of the new piece 270 * @param information additional information associated to the new piece 271 * @param tags tags associated to the new piece 272 * @param creationDate creation date of the new piece in milliseconds since the epoch 273 * @param grade grade of the piece of furniture or <code>null</code> 274 * @param icon content of the icon of the new piece 275 * @param planIcon content of the icon of the new piece displayed in plan 276 * @param model content of the 3D model of the new piece 277 * @param width the width in centimeters of the new piece 278 * @param depth the depth in centimeters of the new piece 279 * @param height the height in centimeters of the new piece 280 * @param elevation the elevation in centimeters of the new piece 281 * @param movable if <code>true</code>, the new piece is movable 282 * @param staircaseCutOutShape the shape used to cut out upper levels when they intersect 283 * with the piece like a staircase Page 5

CatalogPieceOfFurniture.java 284 285 286 287 * @param modelRotation the rotation 3 by 3 matrix applied to the piece model * @param creator the creator of the model * @param resizable if <code>true</code>, the size of the new piece may be edited * @param deformable if <code>true</code>, the width, depth and height of the new piece may 288 * change independently from each other 289 * @param texturable if <code>false</code> this piece should always keep the same color or texture. 290 * @param price the price of the new piece or <code>null</code> 291 * @param valueAddedTaxPercentage the Value Added Tax percentage applied to the 292 * price of the new piece or <code>null</code> 293 * @param currency the price currency, noted with ISO 4217 code, or <code>null</code> 294 * @since 3.6 295 */ 296 public CatalogPieceOfFurniture(String id, String name, String description, 297 String information, String [] tags, Long creationDate, Float grade, 298 Content icon, Content planIcon, Content model, 299 float width, float depth, float height, 300 float elevation, boolean movable, String staircaseCutOutShape, 301 float [][] modelRotation, String creator, 302 boolean resizable, boolean deformable, boolean texturable, 303 BigDecimal price, BigDecimal valueAddedTaxPercentage, String currency) { 304 this(id, name, description, information, tags, creationDate, grade, icon, planIcon, model, width, depth, 305 height, elevation, movable, false, staircaseCutOutShape, null, modelRotation, creator, false, resizable, deformable, 306 texturable, price, valueAddedTaxPercentage, currency, (float)Math.PI / 8, true, false); 307 } 308 309 /** 310 * Creates a modifiable catalog piece of furniture with all its values. 311 * @param name the name of the new piece 312 * @param icon content of the icon of the new piece 313 * @param model content of the 3D model of the new piece 314 * @param width the width in centimeters of the new piece 315 * @param depth the depth in centimeters of the new piece 316 * @param height the height in centimeters of the new piece 317 * @param elevation the elevation in centimeters of the new piece 318 * @param movable if <code>true</code>, the new piece is movable 319 * @param doorOrWindow if <code>true</code>, the new piece is a door or a window 320 * @param color the color of the piece as RGB code or <code>null</code> if piece color is unchanged 321 * @param modelRotation the rotation 3 by 3 matrix applied to the piece model 322 * @param backFaceShown <code>true</code> if back face should be shown 323 * @param iconYaw the yaw angle used to create the piece icon 324 * @param proportional if <code>true</code>, size proportions will be kept 325 * @deprecated As of version 1.7, use constructor without <code>doorOrWindow</code> 326 * parameter since a catalog door and window is supposed to be an instance 327 * of {@link CatalogDoorOrWindow} 328 */ 329 public CatalogPieceOfFurniture(String name, Content icon, Content model, 330 float width, float depth, float height, float elevation, 331 boolean movable, boolean doorOrWindow, Integer color, 332 float [][] modelRotation, boolean backFaceShown, 333 float iconYaw, boolean proportional) { 334 this(name, icon, model, width, depth, height, elevation, movable, Page 6

CatalogPieceOfFurniture.java 335 336 337 338 339 340 341 342 343 344 345 346 347 348 color, modelRotation, backFaceShown, iconYaw, proportional); }

/** * Creates a modifiable catalog piece of furniture with all its values. * @param name the name of the new piece * @param icon content of the icon of the new piece * @param model content of the 3D model of the new piece * @param width the width in centimeters of the new piece * @param depth the depth in centimeters of the new piece * @param height the height in centimeters of the new piece * @param elevation the elevation in centimeters of the new piece * @param movable if <code>true</code>, the new piece is movable * @param color the color of the piece as RGB code or <code>null</code> if piece color is unchanged 349 * @param modelRotation the rotation 3 by 3 matrix applied to the piece model 350 * @param backFaceShown <code>true</code> if back face should be shown 351 * @param iconYaw the yaw angle used to create the piece icon 352 * @param proportional if <code>true</code>, size proportions will be kept 353 * @since 1.7 354 */ 355 public CatalogPieceOfFurniture(String name, Content icon, Content model, 356 float width, float depth, float height, float elevation, 357 boolean movable, Integer color, 358 float [][] modelRotation, boolean backFaceShown, 359 float iconYaw, boolean proportional) { 360 this(name, icon, model, width, depth, height, elevation, movable, 361 null, color, modelRotation, backFaceShown, iconYaw, proportional); 362 } 363 364 /** 365 * Creates a modifiable catalog piece of furniture with all its values. 366 * @param name the name of the new piece 367 * @param icon content of the icon of the new piece 368 * @param model content of the 3D model of the new piece 369 * @param width the width in centimeters of the new piece 370 * @param depth the depth in centimeters of the new piece 371 * @param height the height in centimeters of the new piece 372 * @param elevation the elevation in centimeters of the new piece 373 * @param movable if <code>true</code>, the new piece is movable 374 * @param staircaseCutOutShape the shape used to cut out upper levels when they intersect 375 * with the piece like a staircase 376 * @param color the color of the piece as RGB code or <code>null</code> if piece color is unchanged 377 * @param modelRotation the rotation 3 by 3 matrix applied to the piece model 378 * @param backFaceShown <code>true</code> if back face should be shown 379 * @param iconYaw the yaw angle used to create the piece icon 380 * @param proportional if <code>true</code>, size proportions will be kept 381 * @since 3.4 382 */ 383 public CatalogPieceOfFurniture(String name, Content icon, Content model, 384 float width, float depth, float height, float elevation, 385 boolean movable, String staircaseCutOutShape, 386 Integer color, float [][] modelRotation, 387 boolean backFaceShown, 388 float iconYaw, boolean proportional) { 389 this(null, name, null, null, new String [0], System.currentTimeMillis(), null, icon, null, model, width, depth, height, elevation, 390 movable, false, staircaseCutOutShape, color, modelRotation, null, backFaceShown, true, true, true, null, null, null, iconYaw, proportional, true); Page 7

CatalogPieceOfFurniture.java 391 392 393 394 }

private CatalogPieceOfFurniture(String id, String name, String description, String information, String [] tags, Long creationDate, Float grade, 395 Content icon, Content planIcon, Content model, 396 float width, float depth, float height, 397 float elevation, boolean movable, boolean doorOrWindow, String staircaseCutOutShape, 398 Integer color, float [][] modelRotation, String creator, 399 boolean backFaceShown, boolean resizable, boolean deformable, boolean texturable, 400 BigDecimal price, BigDecimal valueAddedTaxPercentage, String currency, 401 float iconYaw, boolean proportional, boolean modifiable) { 402 this.id = id; 403 this.name = name; 404 this.description = description; 405 this.information = information; 406 this.tags = tags; 407 this.creationDate = creationDate; 408 this.grade = grade; 409 this.icon = icon; 410 this.planIcon = planIcon; 411 this.model = model; 412 this.width = width; 413 this.depth = depth; 414 this.height = height; 415 this.elevation = elevation; 416 this.movable = movable; 417 this.doorOrWindow = doorOrWindow; 418 this.color = color; 419 this.staircaseCutOutShape = staircaseCutOutShape; 420 this.creator = creator; 421 this.price = price; 422 this.valueAddedTaxPercentage = valueAddedTaxPercentage; 423 this.currency = currency; 424 if (modelRotation == null) { 425 this.modelRotation = INDENTITY_ROTATION; 426 } else { 427 this.modelRotation = deepCopy(modelRotation); 428 } 429 this.backFaceShown = backFaceShown; 430 this.resizable = resizable; 431 this.deformable = deformable; 432 this.texturable = texturable; 433 this.iconYaw = iconYaw; 434 this.proportional = proportional; 435 this.modifiable = modifiable; 436 } 437 438 /** 439 * Returns the ID of this piece of furniture or <code>null</code>. 440 */ 441 public String getId() { 442 return this.id; 443 } 444 445 /** Page 8

CatalogPieceOfFurniture.java 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 * Returns the name of this piece of furniture. */ public String getName() { return this.name; } /** * Returns the description of this piece of furniture. * The returned value may be <code>null</code>. */ public String getDescription() { return this.description; } /** * Returns the additional information associated to this piece, or <code>null</code>. * @since 3.6 */ public String getInformation() { return this.information; } /** * Returns the tags associated to this piece. * @since 3.6 */ public String [] getTags() { return this.tags; } /** * Returns the creation date of this piece in milliseconds since the epoch, * or <code>null</code> if no date is given to this piece. * @since 3.6 */ public Long getCreationDate() { return this.creationDate; }

/** * Returns the grade of this piece, or <code>null</code> if no grade is given to this piece. 487 * @since 3.6 488 */ 489 public Float getGrade() { 490 return this.grade; 491 } 492 493 /** 494 * Returns the depth of this piece of furniture. 495 */ 496 public float getDepth() { 497 return this.depth; 498 } 499 500 /** 501 * Returns the height of this piece of furniture. 502 */ 503 public float getHeight() { 504 return this.height; Page 9

CatalogPieceOfFurniture.java 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 } /** * Returns the width of this piece of furniture. */ public float getWidth() { return this.width; } /** * Returns the elevation of this piece of furniture. */ public float getElevation() { return this.elevation; } /** * Returns <code>true</code> if this piece of furniture is movable. */ public boolean isMovable() { return this.movable; }

/** * Returns <code>true</code> if this piece of furniture is a door or a window. * As this method existed before {@linkplain CatalogDoorOrWindow CatalogDoorOrWindow} class, 531 * you shouldn't rely on the value returned by this method to guess if a piece 532 * is an instance of <code>DoorOrWindow</code> class. 533 */ 534 public boolean isDoorOrWindow() { 535 return this.doorOrWindow; 536 } 537 538 /** 539 * Returns the icon of this piece of furniture. 540 */ 541 public Content getIcon() { 542 return this.icon; 543 } 544 545 /** 546 * Returns the icon of this piece of furniture displayed in plan or <code>null</code>. 547 * @since 2.2 548 */ 549 public Content getPlanIcon() { 550 return this.planIcon; 551 } 552 553 /** 554 * Returns the 3D model of this piece of furniture. 555 */ 556 public Content getModel() { 557 return this.model; 558 } 559 560 /** 561 * Returns the rotation 3 by 3 matrix of this piece of furniture that ensures 562 * its model is correctly oriented. 563 */ Page 10

CatalogPieceOfFurniture.java 564 565 566 567 568 569 570 public float [][] getModelRotation() { // Return a deep copy to avoid any misuse of piece data return deepCopy(this.modelRotation); }

private float [][] deepCopy(float [][] modelRotation) { return new float [][] {{modelRotation [0][0], modelRotation [0][1], modelRotation [0] [2]}, 571 {modelRotation [1][0], modelRotation [1][1], modelRotation [1] [2]}, 572 {modelRotation [2][0], modelRotation [2][1], modelRotation [2] [2]}}; 573 } 574 575 /** 576 * Returns the shape used to cut out upper levels when they intersect with the piece 577 * like a staircase. 578 * @since 3.4 579 */ 580 public String getStaircaseCutOutShape() { 581 return this.staircaseCutOutShape; 582 } 583 584 /** 585 * Returns the creator of this piece. 586 */ 587 public String getCreator() { 588 return this.creator; 589 } 590 591 /** 592 * Returns <code>true</code> if the back face of the piece of furniture 593 * model should be displayed. 594 */ 595 public boolean isBackFaceShown() { 596 return this.backFaceShown; 597 } 598 599 /** 600 * Returns the color of this piece of furniture. 601 */ 602 public Integer getColor() { 603 return this.color; 604 } 605 606 /** 607 * Returns the yaw angle used to create the piece icon. 608 */ 609 public float getIconYaw() { 610 return this.iconYaw; 611 } 612 613 /** 614 * Returns <code>true</code> if size proportions should be kept. 615 */ 616 public boolean isProportional() { 617 return this.proportional; 618 } 619 620 /** Page 11

CatalogPieceOfFurniture.java 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 * Returns <code>true</code> if this piece is modifiable (not read from resources). */ public boolean isModifiable() { return this.modifiable; } /** * Returns <code>true</code> if this piece is resizable. */ public boolean isResizable() { return this.resizable; } /** * Returns <code>true</code> if this piece is deformable. * @since 3.0 */ public boolean isDeformable() { return this.deformable; } /** * Returns <code>false</code> if this piece should always keep the same color or texture. * @since 3.0 */ public boolean isTexturable() { return this.texturable; } /** * Returns the price of this piece of furniture or <code>null</code>. */ public BigDecimal getPrice() { return this.price; }

/** * Returns the Value Added Tax percentage applied to the price of this piece of furniture. 659 */ 660 public BigDecimal getValueAddedTaxPercentage() { 661 return this.valueAddedTaxPercentage; 662 } 663 664 /** 665 * Returns the price currency, noted with ISO 4217 code, or <code>null</code> 666 * if it has no price or default currency should be used. 667 * @since 3.4 668 */ 669 public String getCurrency() { 670 return this.currency; 671 } 672 673 /** 674 * Returns the category of this piece of furniture. 675 */ 676 public FurnitureCategory getCategory() { 677 return this.category; 678 } 679 Page 12

CatalogPieceOfFurniture.java 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 /** * Sets the category of this piece of furniture. */ void setCategory(FurnitureCategory category) { this.category = category; } /** * Returns <code>true</code> if this piece and the one in parameter are the same objects. * Note that, from version 3.6, two pieces of furniture can have the same name. */ @Override public boolean equals(Object obj) { return super.equals(obj); } /** * Returns default hash code. */ @Override public int hashCode() { return super.hashCode(); } /** * Compares the names of this piece and the one in parameter. */ public int compareTo(CatalogPieceOfFurniture piece) { int nameComparison = COMPARATOR.compare(this.name, piece.name); if (nameComparison != 0) { return nameComparison; } else { return this.modifiable == piece.modifiable ? 0 : (this.modifiable ? 1 : -1); } }

/** * Returns <code>true</code> if this piece matches the given <code>filter</code> text. * Each substring of the <code>filter</code> is considered as a search criterion that can math 721 * the name, the category name, the creator, the description or the tags of this piece. 722 * @since 4.2 723 */ 724 public boolean matchesFilter(String filter) { 725 byte [][] filterCriteriaCollationKeys = getFilterCollationKeys(filter); 726 int checkedCriteria = 0; 727 if (filterCriteriaCollationKeys.length > 0) { 728 byte [] furnitureCollationKey = getPieceOfFurnitureCollationKey(); 729 for (int i = 0; i < filterCriteriaCollationKeys.length; i++) { 730 if (isSubCollationKey(furnitureCollationKey, filterCriteriaCollationKeys [i], 0)) { 731 checkedCriteria++; 732 } else { 733 break; 734 } 735 } 736 } 737 return checkedCriteria == filterCriteriaCollationKeys.length; 738 } Page 13

CatalogPieceOfFurniture.java 739 740 741 742 743 744 745 746 747 748 749 750 751

/** * Returns the collation key bytes of each criterion in the given <code>filter</code>. */ private byte [][] getFilterCollationKeys(String filter) { if (filter.length() == 0) { return EMPTY_CRITERIA; } byte [][] filterCollationKeys = recentFilters.get(filter); if (filterCollationKeys == null) { // Each substring in filter is a search criterion that must be verified String [] filterCriteria = filter.split("\\s|\\p{Punct}"); List<byte []> filterCriteriaCollationKeys = new ArrayList<byte []>(filterCriteria.length); 752 for (String criterion : filterCriteria) { 753 if (criterion.length() > 0) { 754 filterCriteriaCollationKeys.add(COMPARATOR.getCollationKey(criterion).toByteArray()); 755 } 756 } 757 if (filterCriteriaCollationKeys.size() == 0) { 758 filterCollationKeys = EMPTY_CRITERIA; 759 } else { 760 filterCollationKeys = filterCriteriaCollationKeys.toArray(new byte [filterCriteriaCollationKeys.size()][]); 761 } 762 recentFilters.put(filter, filterCollationKeys); 763 } 764 return filterCollationKeys; 765 } 766 767 /** 768 * Returns the collation key bytes used to compare the given <code>piece</code> with filter. 769 */ 770 private byte [] getPieceOfFurnitureCollationKey() { 771 if (this.filterCollationKey == null) { 772 // Prepare filter string collation key 773 // (collect the name, category, creator, description and tags of each piece) 774 StringBuilder search = new StringBuilder(); 775 search.append(getName()); 776 search.append('\t'); 777 if (getCategory() != null) { 778 search.append(getCategory().getName()); 779 search.append('\t'); 780 } 781 if (getCreator() != null) { 782 search.append(getCreator()); 783 search.append('\t'); 784 } 785 if (getDescription() != null) { 786 search.append(getDescription()); 787 search.append('\t'); 788 } 789 for (String tag : getTags()) { 790 search.append(tag); 791 search.append('\t'); 792 } 793 794 this.filterCollationKey = Page 14

CatalogPieceOfFurniture.java COMPARATOR.getCollationKey(search.toString()).toByteArray(); } return this.filterCollationKey; }

795 796 797 798 799 800

/** * Returns <code>true</code> if the given filter collation key is a sub part of the first array collator key. 801 */ 802 private boolean isSubCollationKey(byte [] collationKey, byte [] filterCollationKey, int start) { 803 // Ignore the last 4 bytes of the collator key 804 for (int i = start, n = collationKey.length - 4, m = filterCollationKey.length - 4; i < n && i < n - m + 1; i++) { 805 if (collationKey [i] == filterCollationKey [0]) { 806 for (int j = 1; j < m; j++) { 807 if (collationKey [i + j] != filterCollationKey [j]) { 808 return isSubCollationKey(collationKey, filterCollationKey, i + 1); 809 } 810 } 811 return true; 812 } 813 } 814 return false; 815 } 816 } 817

Page 15

Você também pode gostar