/** * Returns an instance of {@code SpaceAllocation} that has its tag set to * {@link Tag#TEAM}. * * <p> The user shares space with other members of their team. </p> * * @param value value to assign to this instance. * * @return Instance of {@code SpaceAllocation} with its tag set to {@link * Tag#TEAM}. * * @throws IllegalArgumentException if {@code value} is {@code null}. */ public static SpaceAllocation team(TeamSpaceAllocation value) { if (value == null) { throw new IllegalArgumentException("Value is null"); } return new SpaceAllocation().withTagAndTeam(Tag.TEAM, value); }
/** * Returns an instance of {@code SpaceAllocation} that has its tag set to * {@link Tag#INDIVIDUAL}. * * <p> The user's space allocation applies only to their individual account. * </p> * * @param value value to assign to this instance. * * @return Instance of {@code SpaceAllocation} with its tag set to {@link * Tag#INDIVIDUAL}. * * @throws IllegalArgumentException if {@code value} is {@code null}. */ public static SpaceAllocation individual(IndividualSpaceAllocation value) { if (value == null) { throw new IllegalArgumentException("Value is null"); } return new SpaceAllocation().withTagAndIndividual(Tag.INDIVIDUAL, value); }
@Override public Space get() throws BackgroundException { try { final SpaceUsage usage = new DbxUserUsersRequests(session.getClient()).getSpaceUsage(); final SpaceAllocation allocation = usage.getAllocation(); if(allocation.isIndividual()) { return new Space(usage.getUsed(), allocation.getIndividualValue().getAllocated()); } else if(allocation.isTeam()) { return new Space(usage.getUsed(), allocation.getTeamValue().getAllocated()); } return new Space(0L, Long.MAX_VALUE); } catch(DbxException e) { throw new DropboxExceptionMappingService().map("Failure to read attributes of {0}", e, new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory))); } } }
IndividualSpaceAllocation fieldValue = null; fieldValue = IndividualSpaceAllocation.Serializer.INSTANCE.deserialize(p, true); value = SpaceAllocation.individual(fieldValue); value = SpaceAllocation.team(fieldValue);
/** * Space is allocated differently based on the type of account. * * @param _tag Discriminating tag for this instance. */ private SpaceAllocation withTag(Tag _tag) { SpaceAllocation result = new SpaceAllocation(); result._tag = _tag; return result; }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj == null) { return false; } // be careful with inheritance else if (obj.getClass().equals(this.getClass())) { SpaceUsage other = (SpaceUsage) obj; return (this.used == other.used) && ((this.allocation == other.allocation) || (this.allocation.equals(other.allocation))) ; } else { return false; } }
@Override public void serialize(SpaceAllocation value, JsonGenerator g) throws IOException, JsonGenerationException { switch (value.tag()) { case INDIVIDUAL: { g.writeStartObject(); writeTag("individual", g); IndividualSpaceAllocation.Serializer.INSTANCE.serialize(value.individualValue, g, true); g.writeEndObject(); break; } case TEAM: { g.writeStartObject(); writeTag("team", g); TeamSpaceAllocation.Serializer.INSTANCE.serialize(value.teamValue, g, true); g.writeEndObject(); break; } default: { g.writeString("other"); } } }
/** * Space is allocated differently based on the type of account. * * @param teamValue The user shares space with other members of their team. * Must not be {@code null}. * @param _tag Discriminating tag for this instance. * * @throws IllegalArgumentException If any argument does not meet its * preconditions. */ private SpaceAllocation withTagAndTeam(Tag _tag, TeamSpaceAllocation teamValue) { SpaceAllocation result = new SpaceAllocation(); result._tag = _tag; result.teamValue = teamValue; return result; }
/** * Space is allocated differently based on the type of account. * * @param individualValue The user's space allocation applies only to their * individual account. Must not be {@code null}. * @param _tag Discriminating tag for this instance. * * @throws IllegalArgumentException If any argument does not meet its * preconditions. */ private SpaceAllocation withTagAndIndividual(Tag _tag, IndividualSpaceAllocation individualValue) { SpaceAllocation result = new SpaceAllocation(); result._tag = _tag; result.individualValue = individualValue; return result; }