refactoring sound
authorAnton Epple <toni.epple@eppleton.de>
Tue, 28 May 2013 12:29:21 +0200
branchsound
changeset 1090b12d1c32314
parent 108 7cc01dacf0e2
child 222 63b36aba87c7
refactoring
sound/src/main/java/net/java/html/sound/AudioClip.java
sound/src/main/java/net/java/html/sound/api/AudioClip.java
sound/src/main/java/net/java/html/sound/spi/AudioEnvironment.java
sound/src/main/java/org/apidesign/html/sound/spi/AudioEnvironment.java
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sound/src/main/java/net/java/html/sound/AudioClip.java	Tue May 28 12:29:21 2013 +0200
     1.3 @@ -0,0 +1,106 @@
     1.4 +/**
     1.5 + * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
     1.6 + * <jaroslav.tulach@apidesign.org>
     1.7 + *
     1.8 + * This program is free software: you can redistribute it and/or modify it under
     1.9 + * the terms of the GNU General Public License as published by the Free Software
    1.10 + * Foundation, version 2 of the License.
    1.11 + *
    1.12 + * This program is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.14 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1.15 + * details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU General Public License along with
    1.18 + * this program. Look for COPYING file in the top folder. If not, see
    1.19 + * http://opensource.org/licenses/GPL-2.0.
    1.20 + */
    1.21 +package net.java.html.sound;
    1.22 +
    1.23 +import java.util.ServiceLoader;
    1.24 +import org.apidesign.html.sound.spi.AudioEnvironment;
    1.25 +
    1.26 +/**
    1.27 + *
    1.28 + * @author antonepple
    1.29 + */
    1.30 +public final class AudioClip {
    1.31 +
    1.32 +    private Object cached;
    1.33 +    private int cacheHash;
    1.34 +    private final String src;
    1.35 +    private final AudioEnvironment audioEnvironment;
    1.36 +
    1.37 +    private AudioClip(String src) {
    1.38 +        this.src = src;
    1.39 +        ServiceLoader<AudioEnvironment> loader = ServiceLoader.load(AudioEnvironment.class);
    1.40 +        audioEnvironment = loader.iterator().next();
    1.41 +    }
    1.42 +
    1.43 +    public static AudioClip create(String src) {
    1.44 +        return new AudioClip(src);
    1.45 +    }
    1.46 +
    1.47 +    public void play() {
    1.48 +        Object nativeClip = audioEnvironment.play(this, cached);
    1.49 +        cache(nativeClip);
    1.50 +    }
    1.51 +
    1.52 +    public void pause() {
    1.53 +        Object nativeClip = audioEnvironment.pause(this, cached);
    1.54 +        cache(nativeClip);
    1.55 +    }
    1.56 +
    1.57 +    public void stop() {
    1.58 +        Object nativeClip = audioEnvironment.stop(this, cached);
    1.59 +        cache(nativeClip);
    1.60 +    }
    1.61 +
    1.62 +    public void setVolume(int volume) {
    1.63 +        Object nativeClip = audioEnvironment.setVolume(this, volume, cached);
    1.64 +        cache(nativeClip);
    1.65 +    }
    1.66 +
    1.67 +    public void playFrom(int seconds) {
    1.68 +        Object nativeClip = audioEnvironment.playFrom(this, seconds, cached);
    1.69 +        cache(nativeClip);
    1.70 +    }
    1.71 +
    1.72 +    void cache(Object toCache) {
    1.73 +        cacheHash = hashCode();
    1.74 +        this.cached = toCache;
    1.75 +    }
    1.76 +
    1.77 +    private boolean isCached() {
    1.78 +        return cacheHash == hashCode();
    1.79 +    }
    1.80 +
    1.81 +    Object getCached() {
    1.82 +        return isCached() ? cached : null;
    1.83 +    }
    1.84 +
    1.85 +    @Override
    1.86 +    public int hashCode() {
    1.87 +        int hash = 5;
    1.88 +        hash = 59 * hash + (this.src != null ? this.src.hashCode() : 0) ^ (cached==null? 1231 : 1237);
    1.89 +        return hash;
    1.90 +    }
    1.91 +
    1.92 +    @Override
    1.93 +    public boolean equals(Object obj) {
    1.94 +        if (obj == null) {
    1.95 +            return false;
    1.96 +        }
    1.97 +        if (getClass() != obj.getClass()) {
    1.98 +            return false;
    1.99 +        }
   1.100 +        final AudioClip other = (AudioClip) obj;
   1.101 +        if ((this.src == null) ? (other.src != null) : !this.src.equals(other.src)) {
   1.102 +            return false;
   1.103 +        }
   1.104 +        if ((this.cached == null) != (other.cached == null)) {
   1.105 +            return false;
   1.106 +        }
   1.107 +        return true;
   1.108 +    }
   1.109 +}
   1.110 \ No newline at end of file
     2.1 --- a/sound/src/main/java/net/java/html/sound/api/AudioClip.java	Tue May 28 08:16:32 2013 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,106 +0,0 @@
     2.4 -/**
     2.5 - * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
     2.6 - * <jaroslav.tulach@apidesign.org>
     2.7 - *
     2.8 - * This program is free software: you can redistribute it and/or modify it under
     2.9 - * the terms of the GNU General Public License as published by the Free Software
    2.10 - * Foundation, version 2 of the License.
    2.11 - *
    2.12 - * This program is distributed in the hope that it will be useful, but WITHOUT
    2.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    2.14 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    2.15 - * details.
    2.16 - *
    2.17 - * You should have received a copy of the GNU General Public License along with
    2.18 - * this program. Look for COPYING file in the top folder. If not, see
    2.19 - * http://opensource.org/licenses/GPL-2.0.
    2.20 - */
    2.21 -package net.java.html.sound.api;
    2.22 -
    2.23 -import java.util.ServiceLoader;
    2.24 -import net.java.html.sound.spi.AudioEnvironment;
    2.25 -
    2.26 -/**
    2.27 - *
    2.28 - * @author antonepple
    2.29 - */
    2.30 -public final class AudioClip {
    2.31 -
    2.32 -    private Object cached;
    2.33 -    private int cacheHash;
    2.34 -    private final String src;
    2.35 -    private final AudioEnvironment audioEnvironment;
    2.36 -
    2.37 -    private AudioClip(String src) {
    2.38 -        this.src = src;
    2.39 -        ServiceLoader<AudioEnvironment> loader = ServiceLoader.load(AudioEnvironment.class);
    2.40 -        audioEnvironment = loader.iterator().next();
    2.41 -    }
    2.42 -
    2.43 -    public static AudioClip create(String src) {
    2.44 -        return new AudioClip(src);
    2.45 -    }
    2.46 -
    2.47 -    public void play() {
    2.48 -        Object nativeClip = audioEnvironment.play(this, cached);
    2.49 -        cache(nativeClip);
    2.50 -    }
    2.51 -
    2.52 -    public void pause() {
    2.53 -        Object nativeClip = audioEnvironment.pause(this, cached);
    2.54 -        cache(nativeClip);
    2.55 -    }
    2.56 -
    2.57 -    public void stop() {
    2.58 -        Object nativeClip = audioEnvironment.stop(this, cached);
    2.59 -        cache(nativeClip);
    2.60 -    }
    2.61 -
    2.62 -    public void setVolume(int volume) {
    2.63 -        Object nativeClip = audioEnvironment.setVolume(this, volume, cached);
    2.64 -        cache(nativeClip);
    2.65 -    }
    2.66 -
    2.67 -    public void playFrom(int seconds) {
    2.68 -        Object nativeClip = audioEnvironment.playFrom(this, seconds, cached);
    2.69 -        cache(nativeClip);
    2.70 -    }
    2.71 -
    2.72 -    void cache(Object toCache) {
    2.73 -        cacheHash = hashCode();
    2.74 -        this.cached = toCache;
    2.75 -    }
    2.76 -
    2.77 -    private boolean isCached() {
    2.78 -        return cacheHash == hashCode();
    2.79 -    }
    2.80 -
    2.81 -    Object getCached() {
    2.82 -        return isCached() ? cached : null;
    2.83 -    }
    2.84 -
    2.85 -    @Override
    2.86 -    public int hashCode() {
    2.87 -        int hash = 5;
    2.88 -        hash = 59 * hash + (this.src != null ? this.src.hashCode() : 0) ^ (cached==null? 1231 : 1237);
    2.89 -        return hash;
    2.90 -    }
    2.91 -
    2.92 -    @Override
    2.93 -    public boolean equals(Object obj) {
    2.94 -        if (obj == null) {
    2.95 -            return false;
    2.96 -        }
    2.97 -        if (getClass() != obj.getClass()) {
    2.98 -            return false;
    2.99 -        }
   2.100 -        final AudioClip other = (AudioClip) obj;
   2.101 -        if ((this.src == null) ? (other.src != null) : !this.src.equals(other.src)) {
   2.102 -            return false;
   2.103 -        }
   2.104 -        if ((this.cached == null) != (other.cached == null)) {
   2.105 -            return false;
   2.106 -        }
   2.107 -        return true;
   2.108 -    }
   2.109 -}
   2.110 \ No newline at end of file
     3.1 --- a/sound/src/main/java/net/java/html/sound/spi/AudioEnvironment.java	Tue May 28 08:16:32 2013 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,38 +0,0 @@
     3.4 -/**
     3.5 - * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
     3.6 - * <jaroslav.tulach@apidesign.org>
     3.7 - *
     3.8 - * This program is free software: you can redistribute it and/or modify it under
     3.9 - * the terms of the GNU General Public License as published by the Free Software
    3.10 - * Foundation, version 2 of the License.
    3.11 - *
    3.12 - * This program is distributed in the hope that it will be useful, but WITHOUT
    3.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    3.14 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    3.15 - * details.
    3.16 - *
    3.17 - * You should have received a copy of the GNU General Public License along with
    3.18 - * this program. Look for COPYING file in the top folder. If not, see
    3.19 - * http://opensource.org/licenses/GPL-2.0.
    3.20 - */
    3.21 -package net.java.html.sound.spi;
    3.22 -
    3.23 -import net.java.html.sound.api.AudioClip;
    3.24 -
    3.25 -/**
    3.26 - *
    3.27 - * @author antonepple
    3.28 - */
    3.29 -public interface AudioEnvironment {
    3.30 -
    3.31 -    public  Object play(AudioClip aThis, Object cached);
    3.32 -
    3.33 -    public  Object pause(AudioClip aThis, Object cached);
    3.34 -
    3.35 -    public  Object stop(AudioClip aThis, Object cached);
    3.36 -
    3.37 -    public  Object setVolume(AudioClip aThis, int volume, Object cached);
    3.38 -
    3.39 -    public  Object playFrom(AudioClip aThis, int seconds, Object cached);
    3.40 -    
    3.41 -}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/sound/src/main/java/org/apidesign/html/sound/spi/AudioEnvironment.java	Tue May 28 12:29:21 2013 +0200
     4.3 @@ -0,0 +1,38 @@
     4.4 +/**
     4.5 + * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
     4.6 + * <jaroslav.tulach@apidesign.org>
     4.7 + *
     4.8 + * This program is free software: you can redistribute it and/or modify it under
     4.9 + * the terms of the GNU General Public License as published by the Free Software
    4.10 + * Foundation, version 2 of the License.
    4.11 + *
    4.12 + * This program is distributed in the hope that it will be useful, but WITHOUT
    4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    4.14 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    4.15 + * details.
    4.16 + *
    4.17 + * You should have received a copy of the GNU General Public License along with
    4.18 + * this program. Look for COPYING file in the top folder. If not, see
    4.19 + * http://opensource.org/licenses/GPL-2.0.
    4.20 + */
    4.21 +package org.apidesign.html.sound.spi;
    4.22 +
    4.23 +import net.java.html.sound.AudioClip;
    4.24 +
    4.25 +/**
    4.26 + *
    4.27 + * @author antonepple
    4.28 + */
    4.29 +public interface AudioEnvironment {
    4.30 +
    4.31 +    public  Object play(AudioClip aThis, Object cached);
    4.32 +
    4.33 +    public  Object pause(AudioClip aThis, Object cached);
    4.34 +
    4.35 +    public  Object stop(AudioClip aThis, Object cached);
    4.36 +
    4.37 +    public  Object setVolume(AudioClip aThis, int volume, Object cached);
    4.38 +
    4.39 +    public  Object playFrom(AudioClip aThis, int seconds, Object cached);
    4.40 +    
    4.41 +}